• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "SkAtomics.h"
9 #include "SkEventTracer.h"
10 #include "SkOncePtr.h"
11 
12 #include <stdlib.h>
13 
14 class SkDefaultEventTracer : public SkEventTracer {
15     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)16         addTraceEvent(char phase,
17                       const uint8_t* categoryEnabledFlag,
18                       const char* name,
19                       uint64_t id,
20                       int numArgs,
21                       const char** argNames,
22                       const uint8_t* argTypes,
23                       const uint64_t* argValues,
24                       uint8_t flags) override { return 0; }
25 
26     void
updateTraceEventDuration(const uint8_t * categoryEnabledFlag,const char * name,SkEventTracer::Handle handle)27         updateTraceEventDuration(const uint8_t* categoryEnabledFlag,
28                                  const char* name,
29                                  SkEventTracer::Handle handle) override {}
30 
getCategoryGroupEnabled(const char * name)31     const uint8_t* getCategoryGroupEnabled(const char* name) override {
32         static uint8_t no = 0;
33         return &no;
34     }
getCategoryGroupName(const uint8_t * categoryEnabledFlag)35     const char* getCategoryGroupName(
36       const uint8_t* categoryEnabledFlag) override {
37         static const char* dummy = "dummy";
38         return dummy;
39     }
40 };
41 
42 // We prefer gUserTracer if it's been set, otherwise we fall back on gDefaultTracer.
43 static SkEventTracer* gUserTracer = nullptr;
44 SK_DECLARE_STATIC_ONCE_PTR(SkDefaultEventTracer, gDefaultTracer);
45 
SetInstance(SkEventTracer * tracer)46 void SkEventTracer::SetInstance(SkEventTracer* tracer) {
47     SkASSERT(nullptr == sk_atomic_load(&gUserTracer, sk_memory_order_acquire));
48     sk_atomic_store(&gUserTracer, tracer, sk_memory_order_release);
49     // An atomic load during process shutdown is probably overkill, but safe overkill.
50     atexit([]() { delete sk_atomic_load(&gUserTracer, sk_memory_order_acquire); });
51 }
52 
GetInstance()53 SkEventTracer* SkEventTracer::GetInstance() {
54     if (SkEventTracer* tracer = sk_atomic_load(&gUserTracer, sk_memory_order_acquire)) {
55         return tracer;
56     }
57     return gDefaultTracer.get([]{ return new SkDefaultEventTracer; });
58 }
59