Flutter Engine
The Flutter Engine
SkATrace.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "src/core/SkATrace.h"
9
11
12#ifdef SK_BUILD_FOR_ANDROID
13 #include <dlfcn.h>
14#endif
15
16#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
17 #include <cutils/trace.h>
18 #include "src/core/SkTraceEventCommon.h" // for SkAndroidFrameworkTraceUtil
19#endif
20
21SkATrace::SkATrace() : fBeginSection(nullptr), fEndSection(nullptr), fIsEnabled(nullptr) {
22#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK)
23 fIsEnabled = []{ return static_cast<bool>(CC_UNLIKELY(ATRACE_ENABLED())); };
24 fBeginSection = [](const char* name){ ATRACE_BEGIN(name); };
25 fEndSection = []{ ATRACE_END(); };
26#elif defined(SK_BUILD_FOR_ANDROID)
27 if (void* lib = dlopen("libandroid.so", RTLD_NOW | RTLD_LOCAL)) {
28 fBeginSection = (decltype(fBeginSection))dlsym(lib, "ATrace_beginSection");
29 fEndSection = (decltype(fEndSection))dlsym(lib, "ATrace_endSection");
30 fIsEnabled = (decltype(fIsEnabled))dlsym(lib, "ATrace_isEnabled");
31 }
32#endif
33
34 if (!fIsEnabled) {
35 fIsEnabled = []{ return false; };
36 }
37}
38
40 const uint8_t* categoryEnabledFlag,
41 const char* name,
42 uint64_t id,
43 int numArgs,
44 const char** argNames,
45 const uint8_t* argTypes,
46 const uint64_t* argValues,
47 uint8_t flags) {
48 if (fIsEnabled()) {
49 if (TRACE_EVENT_PHASE_COMPLETE == phase ||
51 fBeginSection(name);
52 }
53
54 if (TRACE_EVENT_PHASE_INSTANT == phase) {
55 fEndSection();
56 }
57 }
58 return 0;
59}
60
61void SkATrace::updateTraceEventDuration(const uint8_t* categoryEnabledFlag,
62 const char* name,
63 SkEventTracer::Handle handle) {
64 // This is only ever called from a scoped trace event so we will just end the ATrace section.
65 if (fIsEnabled()) {
66 fEndSection();
67 }
68}
69
70const uint8_t* SkATrace::getCategoryGroupEnabled(const char* name) {
71 // Chrome tracing is setup to not repeatly call this function once it has been initialized. So
72 // we can't use this to do a check for ATrace isEnabled(). Thus we will always return yes here
73 // and then check to see if ATrace is enabled when beginning and ending a section.
75 return &yes;
76}
77
78
79#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
80
81bool SkAndroidFrameworkTraceUtil::gEnableAndroidTracing = false;
82bool SkAndroidFrameworkTraceUtil::gUsePerfettoTrackEvents = false;
83
84#endif //SK_BUILD_FOR_ANDROID_FRAMEWORK
85
86
87
#define TRACE_EVENT_PHASE_INSTANT
#define TRACE_EVENT_PHASE_COMPLETE
SkEventTracer::Handle addTraceEvent(char phase, const uint8_t *categoryEnabledFlag, const char *name, uint64_t id, int numArgs, const char **argNames, const uint8_t *argTypes, const uint64_t *argValues, uint8_t flags) override
Definition: SkATrace.cpp:39
const uint8_t * getCategoryGroupEnabled(const char *name) override
Definition: SkATrace.cpp:70
SkATrace()
Definition: SkATrace.cpp:21
void updateTraceEventDuration(const uint8_t *categoryEnabledFlag, const char *name, SkEventTracer::Handle handle) override
Definition: SkATrace.cpp:61
uint64_t Handle
Definition: SkEventTracer.h:26
@ kEnabledForRecording_CategoryGroupEnabledFlags
Definition: SkEventTracer.h:55
FlutterSemanticsFlag flags
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32