| 1 |
/* |
| 2 |
* Copyright (C) 2014 Google Inc. All rights reserved. |
| 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 SkEventTracer_DEFINED |
| 9 |
#define SkEventTracer_DEFINED |
| 10 |
|
| 11 |
// The class in this header defines the interface between Skia's internal |
| 12 |
// tracing macros and an external entity (e.g., Chrome) that will consume them. |
| 13 |
// Such an entity should subclass SkEventTracer and provide an instance of |
| 14 |
// that event to SkEventTracer::SetInstance. |
| 15 |
|
| 16 |
// If you're looking for the tracing macros to instrument Skia itself, those |
| 17 |
// live in src/core/SkTraceEvent.h |
| 18 |
|
| 19 |
#include "include/core/SkTypes.h" |
| 20 |
|
| 21 |
#include <cstdint> |
| 22 |
|
| 23 |
class SK_API SkEventTracer { |
| 24 |
public: |
| 25 |
|
| 26 |
typedef uint64_t Handle; |
| 27 |
|
| 28 |
/** |
| 29 |
* If this is the first call to SetInstance or GetInstance then the passed instance is |
| 30 |
* installed and true is returned. Otherwise, false is returned. In either case ownership of the |
| 31 |
* tracer is transferred and it will be deleted when no longer needed. |
| 32 |
* |
| 33 |
* Not deleting the tracer on process exit should not cause problems as |
| 34 |
* the whole heap is about to go away with the process. This can also |
| 35 |
* improve performance by reducing the amount of work needed. |
| 36 |
* |
| 37 |
* @param leakTracer Do not delete tracer on process exit. |
| 38 |
*/ |
| 39 |
static bool SetInstance(SkEventTracer*, bool leakTracer = false); |
| 40 |
|
| 41 |
/** |
| 42 |
* Gets the event tracer. If this is the first call to SetInstance or GetIntance then a default |
| 43 |
* event tracer is installed and returned. |
| 44 |
*/ |
| 45 |
static SkEventTracer* GetInstance(); |
| 46 |
|
| 47 |
virtual ~SkEventTracer() = default; |
| 48 |
|
| 49 |
// The pointer returned from GetCategoryGroupEnabled() points to a |
| 50 |
// value with zero or more of the following bits. Used in this class only. |
| 51 |
// The TRACE_EVENT macros should only use the value as a bool. |
| 52 |
// These values must be in sync with macro values in trace_event.h in chromium. |
| 53 |
enum CategoryGroupEnabledFlags { |
| 54 |
// Category group enabled for the recording mode. |
| 55 |
kEnabledForRecording_CategoryGroupEnabledFlags = 1 << 0, |
| 56 |
// Category group enabled for the monitoring mode. |
| 57 |
kEnabledForMonitoring_CategoryGroupEnabledFlags = 1 << 1, |
| 58 |
// Category group enabled by SetEventCallbackEnabled(). |
| 59 |
kEnabledForEventCallback_CategoryGroupEnabledFlags = 1 << 2, |
| 60 |
}; |
| 61 |
|
| 62 |
virtual const uint8_t* getCategoryGroupEnabled(const char* name) = 0; |
| 63 |
virtual const char* getCategoryGroupName(const uint8_t* categoryEnabledFlag) = 0; |
| 64 |
|
| 65 |
virtual SkEventTracer::Handle |
| 66 |
addTraceEvent(char phase, |
| 67 |
const uint8_t* categoryEnabledFlag, |
| 68 |
const char* name, |
| 69 |
uint64_t id, |
| 70 |
int32_t numArgs, |
| 71 |
const char** argNames, |
| 72 |
const uint8_t* argTypes, |
| 73 |
const uint64_t* argValues, |
| 74 |
uint8_t flags) = 0; |
| 75 |
|
| 76 |
virtual void |
| 77 |
updateTraceEventDuration(const uint8_t* categoryEnabledFlag, |
| 78 |
const char* name, |
| 79 |
SkEventTracer::Handle handle) = 0; |
| 80 |
|
| 81 |
// Optional method that can be implemented to allow splitting up traces into different sections. |
| 82 |
virtual void newTracingSection(const char*) {} |
| 83 |
|
| 84 |
protected: |
| 85 |
SkEventTracer() = default; |
| 86 |
SkEventTracer(const SkEventTracer&) = delete; |
| 87 |
SkEventTracer& operator=(const SkEventTracer&) = delete; |
| 88 |
}; |
| 89 |
|
| 90 |
#endif // SkEventTracer_DEFINED |