| 1 |
/* |
| 2 |
* Copyright 2017 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 ChromeTracingTracer_DEFINED |
| 9 |
#define ChromeTracingTracer_DEFINED |
| 10 |
|
| 11 |
#include "include/core/SkString.h" |
| 12 |
#include "include/utils/SkEventTracer.h" |
| 13 |
#include "src/base/SkSpinlock.h" |
| 14 |
#include "src/core/SkTHash.h" |
| 15 |
#include "tools/trace/EventTracingPriv.h" |
| 16 |
|
| 17 |
class SkJSONWriter; |
| 18 |
|
| 19 |
/** |
| 20 |
* A SkEventTracer implementation that logs events to JSON for viewing with chrome://tracing. |
| 21 |
*/ |
| 22 |
class ChromeTracingTracer : public SkEventTracer { |
| 23 |
public: |
| 24 |
explicit ChromeTracingTracer(const char* filename); |
| 25 |
~ChromeTracingTracer() override; |
| 26 |
|
| 27 |
SkEventTracer::Handle addTraceEvent(char phase, |
| 28 |
const uint8_t* categoryEnabledFlag, |
| 29 |
const char* name, |
| 30 |
uint64_t id, |
| 31 |
int numArgs, |
| 32 |
const char** argNames, |
| 33 |
const uint8_t* argTypes, |
| 34 |
const uint64_t* argValues, |
| 35 |
uint8_t flags) override; |
| 36 |
|
| 37 |
void updateTraceEventDuration(const uint8_t* categoryEnabledFlag, |
| 38 |
const char* name, |
| 39 |
SkEventTracer::Handle handle) override; |
| 40 |
|
| 41 |
const uint8_t* getCategoryGroupEnabled(const char* name) override { |
| 42 |
return fCategories.getCategoryGroupEnabled(name); |
| 43 |
} |
| 44 |
|
| 45 |
const char* getCategoryGroupName(const uint8_t* categoryEnabledFlag) override { |
| 46 |
return fCategories.getCategoryGroupName(categoryEnabledFlag); |
| 47 |
} |
| 48 |
|
| 49 |
// The Chrome tracer does not yet support splitting up trace output into sections. |
| 50 |
void newTracingSection(const char* name) override {} |
| 51 |
|
| 52 |
private: |
| 53 |
void flush(); |
| 54 |
|
| 55 |
enum { |
| 56 |
// Events are variable size, but most commonly 48 bytes, assuming 64-bit pointers and |
| 57 |
// reasonable packing. This is a first guess at a number that balances memory usage vs. |
| 58 |
// time overhead of allocating blocks. |
| 59 |
kBlockSize = 512 * 1024, |
| 60 |
}; |
| 61 |
|
| 62 |
typedef std::unique_ptr<uint8_t[]> BlockPtr; |
| 63 |
struct TraceEventBlock { |
| 64 |
BlockPtr fBlock; |
| 65 |
int fEventsInBlock; |
| 66 |
}; |
| 67 |
|
| 68 |
void createBlock(); |
| 69 |
|
| 70 |
Handle appendEvent(const void* data, size_t size); |
| 71 |
|
| 72 |
SkString fFilename; |
| 73 |
SkSpinlock fMutex; |
| 74 |
SkEventTracingCategories fCategories; |
| 75 |
|
| 76 |
TraceEventBlock fCurBlock; |
| 77 |
size_t fCurBlockUsed; |
| 78 |
|
| 79 |
skia_private::TArray<TraceEventBlock> fBlocks; |
| 80 |
}; |
| 81 |
|
| 82 |
#endif |