• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef SkATrace_DEFINED
9 #define SkATrace_DEFINED
10 
11 #include "include/utils/SkEventTracer.h"
12 
13 /**
14  * This class is used to support ATrace in android apps. It hooks into the SkEventTracer system. It
15  * currently supports the macros TRACE_EVENT*, TRACE_EVENT_INSTANT*, and TRACE_EVENT_BEGIN/END*.
16  * For versions of these calls that take additoinal args and value pairs we currently just drop them
17  * and report only the name. Since ATrace is a simple push and pop system (all traces are fully
18  * nested), if using BEGIN and END you should also make sure your calls are properly nested (i.e. if
19  * startA is before startB, then endB is before endA).
20  */
21 class SkATrace : public SkEventTracer {
22 public:
23     SkATrace();
24 
25     SkEventTracer::Handle addTraceEvent(char phase,
26                                         const uint8_t* categoryEnabledFlag,
27                                         const char* name,
28                                         uint64_t id,
29                                         int numArgs,
30                                         const char** argNames,
31                                         const uint8_t* argTypes,
32                                         const uint64_t* argValues,
33                                         uint8_t flags) override;
34 
35 
36     void updateTraceEventDuration(const uint8_t* categoryEnabledFlag,
37                                   const char* name,
38                                   SkEventTracer::Handle handle) override;
39 
40     const uint8_t* getCategoryGroupEnabled(const char* name) override;
41 
getCategoryGroupName(const uint8_t * categoryEnabledFlag)42     const char* getCategoryGroupName(const uint8_t* categoryEnabledFlag) override {
43         static const char* category = "skiaATrace";
44         return category;
45     }
46 
47 private:
48     SkATrace(const SkATrace&) = delete;
49     SkATrace& operator=(const SkATrace&) = delete;
50 
51     void (*fBeginSection)(const char*);
52     void (*fEndSection)(void);
53     bool (*fIsEnabled)(void);
54 };
55 
56 #endif
57