Debian Codegraph @

src/utils/SkEventTracer.cpp

raw
1 /*
2 * Copyright 2014 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 "include/utils/SkEventTracer.h"
9
10 #include <stdlib.h>
11 #include <atomic>
12
13 class SkDefaultEventTracer : public SkEventTracer {
14 SkEventTracer::Handle
15 addTraceEvent(char phase,
16 const uint8_t* categoryEnabledFlag,
17 const char* name,
18 uint64_t id,
19 int numArgs,
20 const char** argNames,
21 const uint8_t* argTypes,
22 const uint64_t* argValues,
23 uint8_t flags) override { return 0; }
24
25 void
26 updateTraceEventDuration(const uint8_t* categoryEnabledFlag,
27 const char* name,
28 SkEventTracer::Handle handle) override {}
29
30 const uint8_t* getCategoryGroupEnabled(const char* name) override {
31 static uint8_t no = 0;
32 return &no;
33 }
34 const char* getCategoryGroupName(
35 const uint8_t* categoryEnabledFlag) override {
36 static const char* stub = "stub";
37 return stub;
38 }
39
40 // The default tracer does not yet support splitting up trace output into sections.
41 void newTracingSection(const char* name) override {}
42 };
43
44 // We prefer gUserTracer if it's been set, otherwise we fall back on a default tracer;
45 static std::atomic<SkEventTracer*> gUserTracer{nullptr};
46
47 bool SkEventTracer::SetInstance(SkEventTracer* tracer, bool leakTracer) {
48 SkEventTracer* expected = nullptr;
49 if (!gUserTracer.compare_exchange_strong(expected, tracer)) {
50 delete tracer;
51 return false;
52 }
53 // If leaking the tracer is accepted then there is no need to install
54 // the atexit.
55 if (!leakTracer) {
56 atexit([]() { delete gUserTracer.load(); });
57 }
58 return true;
59 }
60
61 SkEventTracer* SkEventTracer::GetInstance() {
62 if (auto tracer = gUserTracer.load(std::memory_order_acquire)) {
63 return tracer;
64 }
65 static SkDefaultEventTracer* defaultTracer = new SkDefaultEventTracer;
66 return defaultTracer;
67 }