aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/trace/SkChromeTracingTracer.h
blob: da34205aa5bf1a035bbe9e55c90ccd1bef494ee4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
 * Copyright 2017 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef SkChromeTracingTracer_DEFINED
#define SkChromeTracingTracer_DEFINED

#include "SkEventTracer.h"
#include "SkJSONCPP.h"
#include "SkString.h"

/**
 * A SkEventTracer implementation that logs events to JSON for viewing with chrome://tracing.
 */
class SkChromeTracingTracer : public SkEventTracer {
public:
    SkChromeTracingTracer(const char* filename) : fRoot(Json::arrayValue), fFilename(filename) {}
    ~SkChromeTracingTracer() override { this->flush(); }

    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) override;

    void updateTraceEventDuration(const uint8_t* categoryEnabledFlag,
                                  const char* name,
                                  SkEventTracer::Handle handle) override;

    const uint8_t* getCategoryGroupEnabled(const char* name) override;

    const char* getCategoryGroupName(const uint8_t* categoryEnabledFlag) override {
        static const char* category = "category?";
        return category;
    }

private:
    void flush();

    Json::Value fRoot;
    SkString fFilename;
};

#endif