1 /*
2  * Copyright 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <android_runtime/AndroidRuntime.h>
18 #include <android_runtime/Log.h>
19 #include <nativehelper/JNIHelp.h>
20 #include <perfetto/public/data_source.h>
21 #include <perfetto/public/producer.h>
22 #include <perfetto/public/protos/trace/test_event.pzc.h>
23 #include <perfetto/public/protos/trace/trace_packet.pzc.h>
24 #include <utils/Log.h>
25 #include <utils/RefBase.h>
26 
27 #include <sstream>
28 #include <thread>
29 
30 #include "core_jni_helpers.h"
31 
32 namespace android {
33 
34 class PerfettoDataSourceInstance {
35 public:
36     PerfettoDataSourceInstance(JNIEnv* env, jobject javaDataSourceInstance,
37                                PerfettoDsInstanceIndex inst_idx);
38     ~PerfettoDataSourceInstance();
39 
40     void onStart(JNIEnv* env);
41     void onFlush(JNIEnv* env);
42     void onStop(JNIEnv* env);
43 
GetJavaDataSourceInstance()44     jobject GetJavaDataSourceInstance() {
45         return mJavaDataSourceInstance;
46     }
47 
getIndex()48     PerfettoDsInstanceIndex getIndex() {
49         return inst_idx;
50     }
51 
52 private:
53     PerfettoDsInstanceIndex inst_idx;
54     jobject mJavaDataSourceInstance;
55 };
56 } // namespace android