1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/trace_event/trace_event.h"
6 #include "skia/ext/event_tracer_impl.h"
7 #include "third_party/skia/include/utils/SkEventTracer.h"
11 class SkChromiumEventTracer
: public SkEventTracer
{
12 const uint8_t* getCategoryGroupEnabled(const char* name
) override
;
13 const char* getCategoryGroupName(const uint8_t* categoryEnabledFlag
) override
;
14 SkEventTracer::Handle
addTraceEvent(char phase
,
15 const uint8_t* categoryEnabledFlag
,
19 const char** argNames
,
20 const uint8_t* argTypes
,
21 const uint64_t* argValues
,
22 uint8_t flags
) override
;
23 void updateTraceEventDuration(const uint8_t* categoryEnabledFlag
,
25 SkEventTracer::Handle handle
) override
;
29 SkChromiumEventTracer::getCategoryGroupEnabled(const char* name
) {
30 return TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(name
);
33 const char* SkChromiumEventTracer::getCategoryGroupName(
34 const uint8_t* categoryEnabledFlag
) {
35 return base::trace_event::TraceLog::GetCategoryGroupName(categoryEnabledFlag
);
39 SkChromiumEventTracer::addTraceEvent(char phase
,
40 const uint8_t* categoryEnabledFlag
,
44 const char** argNames
,
45 const uint8_t* argTypes
,
46 const uint64_t* argValues
,
48 base::trace_event::TraceEventHandle handle
= TRACE_EVENT_API_ADD_TRACE_EVENT(
49 phase
, categoryEnabledFlag
, name
, id
, numArgs
, argNames
, argTypes
,
50 (const long long unsigned int*)argValues
, NULL
, flags
);
51 SkEventTracer::Handle result
;
52 memcpy(&result
, &handle
, sizeof(result
));
57 SkChromiumEventTracer::updateTraceEventDuration(
58 const uint8_t* categoryEnabledFlag
,
60 SkEventTracer::Handle handle
) {
61 base::trace_event::TraceEventHandle traceEventHandle
;
62 memcpy(&traceEventHandle
, &handle
, sizeof(handle
));
63 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(
64 categoryEnabledFlag
, name
, traceEventHandle
);
70 void InitSkiaEventTracer() {
71 // Initialize the binding to Skia's tracing events. Skia will
72 // take ownership of and clean up the memory allocated here.
73 SkEventTracer::SetInstance(new skia::SkChromiumEventTracer());