1 /* 2 * Copyright (C) 2022 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 <string> 18 #include "perfetto/perfetto.h" 19 #include "trace_categories.h" 20 #include "tracing_perfetto.h" 21 22 // TODO: define API for categories 23 #define CATEGORY_RENDERING "rendering" 24 25 // Concept of version useful e.g. for human-readable error messages, and stable once released. 26 // Does not replace the need for a binary verification mechanism (e.g. checksum check). 27 // TODO: populate using CMake 28 #define VERSION "1.0.0" 29 30 namespace tracing_perfetto { RegisterWithPerfetto()31 void RegisterWithPerfetto() { 32 perfetto::TracingInitArgs args; 33 // The backends determine where trace events are recorded. Here we 34 // are going to use the system-wide tracing service, so that we can see our 35 // app's events in context with system profiling information. 36 args.backends = perfetto::kSystemBackend; // TODO: make this configurable 37 38 perfetto::Tracing::Initialize(args); 39 perfetto::TrackEvent::Register(); 40 } 41 TraceEventBegin(int key,const char * traceInfo)42 void TraceEventBegin(int key, const char *traceInfo) { 43 // Note: key is ignored for now 44 TRACE_EVENT_BEGIN(CATEGORY_RENDERING, nullptr, [&](perfetto::EventContext ctx) { 45 ctx.event()->set_name(traceInfo); 46 }); 47 } 48 TraceEventEnd()49 void TraceEventEnd() { 50 TRACE_EVENT_END(CATEGORY_RENDERING); 51 } 52 Version()53 const char* Version() { 54 return VERSION; 55 } 56 } // tracing_perfetto 57