Brian Osman | 53136aa | 2017-07-20 15:43:35 -0400 | [diff] [blame^] | 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 SkChromeTracingTracer_DEFINED |
| 9 | #define SkChromeTracingTracer_DEFINED |
| 10 | |
| 11 | #include "SkEventTracer.h" |
| 12 | #include "SkJSONCPP.h" |
| 13 | #include "SkString.h" |
| 14 | |
| 15 | /** |
| 16 | * A SkEventTracer implementation that logs events to JSON for viewing with chrome://tracing. |
| 17 | */ |
| 18 | class SkChromeTracingTracer : public SkEventTracer { |
| 19 | public: |
| 20 | SkChromeTracingTracer(const char* filename) : fRoot(Json::arrayValue), fFilename(filename) {} |
| 21 | ~SkChromeTracingTracer() override { this->flush(); } |
| 22 | |
| 23 | SkEventTracer::Handle addTraceEvent(char phase, |
| 24 | const uint8_t* categoryEnabledFlag, |
| 25 | const char* name, |
| 26 | uint64_t id, |
| 27 | int numArgs, |
| 28 | const char** argNames, |
| 29 | const uint8_t* argTypes, |
| 30 | const uint64_t* argValues, |
| 31 | uint8_t flags) override; |
| 32 | |
| 33 | void updateTraceEventDuration(const uint8_t* categoryEnabledFlag, |
| 34 | const char* name, |
| 35 | SkEventTracer::Handle handle) override; |
| 36 | |
| 37 | const uint8_t* getCategoryGroupEnabled(const char* name) override; |
| 38 | |
| 39 | const char* getCategoryGroupName(const uint8_t* categoryEnabledFlag) override { |
| 40 | static const char* category = "category?"; |
| 41 | return category; |
| 42 | } |
| 43 | |
| 44 | private: |
| 45 | void flush(); |
| 46 | |
| 47 | Json::Value fRoot; |
| 48 | SkString fFilename; |
| 49 | }; |
| 50 | |
| 51 | #endif |