SkEventTracer.cpp revision 4c18e9fbb685cccf23342757e786027a032197da
16169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org/*
26169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org * Copyright 2014 Google Inc.
36169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org *
46169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org * Use of this source code is governed by a BSD-style license that can be
56169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org * found in the LICENSE file.
66169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org */
76169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
86169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#include "SkEventTracer.h"
96169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#include "SkOnce.h"
106169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
116169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgclass SkDefaultEventTracer: public SkEventTracer {
124c18e9fbb685cccf23342757e786027a032197daskia.committer@gmail.com    virtual SkEventTracer::Handle
136169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        addTraceEvent(char phase,
146169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                      const uint8_t* categoryEnabledFlag,
156169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                      const char* name,
166169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                      uint64_t id,
176169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                      int numArgs,
186169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                      const char** argNames,
196169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                      const uint8_t* argTypes,
206169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                      const uint64_t* argValues,
216169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                      uint8_t flags) SK_OVERRIDE { return 0; }
224c18e9fbb685cccf23342757e786027a032197daskia.committer@gmail.com
234c18e9fbb685cccf23342757e786027a032197daskia.committer@gmail.com    virtual void
244c18e9fbb685cccf23342757e786027a032197daskia.committer@gmail.com        updateTraceEventDuration(const uint8_t* categoryEnabledFlag,
254c18e9fbb685cccf23342757e786027a032197daskia.committer@gmail.com                                 const char* name,
266169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                                 SkEventTracer::Handle) SK_OVERRIDE {};
276169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
286169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    virtual const uint8_t* getCategoryGroupEnabled(const char* name) SK_OVERRIDE {
296169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        static uint8_t no = 0;
306169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        return &no;
316169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    };
326169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    virtual const char* getCategoryGroupName(
336169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org      const uint8_t* category_group_enabled) SK_OVERRIDE {
346169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        static const char* dummy = "dummy";
356169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        return dummy;
366169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    };
376169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org};
386169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
396169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgSkEventTracer *SkEventTracer::gInstance;
406169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
416169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgstatic void intiailize_default_tracer(int) {
426169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    SkEventTracer::SetInstance(SkNEW(SkDefaultEventTracer));
436169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org}
446169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
456169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgstatic void cleanup_tracer() {
466169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    // calling SetInstance will delete the existing instance.
476169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    SkEventTracer::SetInstance(NULL);
486169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org}
496169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
506169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgSkEventTracer* SkEventTracer::GetInstance() {
516169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    SK_DECLARE_STATIC_ONCE(once);
526169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    SkOnce(&once, intiailize_default_tracer, 0, cleanup_tracer);
536169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    SkASSERT(NULL != SkEventTracer::gInstance);
546169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    return SkEventTracer::gInstance;
556169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org}
56