• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #define LOG_TAG "Perfetto"
18 
19 #include <android_runtime/AndroidRuntime.h>
20 #include <android_runtime/Log.h>
21 #include <nativehelper/JNIHelp.h>
22 #include <perfetto/public/data_source.h>
23 #include <perfetto/public/producer.h>
24 #include <perfetto/public/protos/trace/test_event.pzc.h>
25 #include <perfetto/public/protos/trace/trace_packet.pzc.h>
26 #include <utils/Log.h>
27 #include <utils/RefBase.h>
28 
29 #include <sstream>
30 #include <thread>
31 
32 #include "android_tracing_PerfettoDataSource.h"
33 #include "core_jni_helpers.h"
34 
35 namespace android {
36 
perfettoProducerInit(JNIEnv * env,jclass clazz,PerfettoBackendTypes backends,uint32_t shmem_size_hint_kb)37 void perfettoProducerInit(JNIEnv* env, jclass clazz, PerfettoBackendTypes backends,
38                           uint32_t shmem_size_hint_kb) {
39     struct PerfettoProducerInitArgs args = PERFETTO_PRODUCER_INIT_ARGS_INIT();
40     args.backends = backends;
41     args.shmem_size_hint_kb = shmem_size_hint_kb;
42     PerfettoProducerInit(args);
43 }
44 
45 const JNINativeMethod gMethods[] = {
46         /* name, signature, funcPtr */
47         {"nativePerfettoProducerInit", "(II)V", (void*)perfettoProducerInit},
48 };
49 
register_android_tracing_PerfettoProducer(JNIEnv * env)50 int register_android_tracing_PerfettoProducer(JNIEnv* env) {
51     int res = jniRegisterNativeMethods(env, "android/tracing/perfetto/Producer", gMethods,
52                                        NELEM(gMethods));
53 
54     LOG_ALWAYS_FATAL_IF(res < 0, "Unable to register native methods.");
55 
56     return 0;
57 }
58 
59 } // namespace android