16169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org/*
26169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org * Copyright (C) 2014 Google Inc. All rights reserved.
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#ifndef SkEventTracer_DEFINED
96169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define SkEventTracer_DEFINED
106169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
116169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// The class in this header defines the interface between Skia's internal
126169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// tracing macros and an external entity (e.g., Chrome) that will consume them.
134c18e9fbb685cccf23342757e786027a032197daskia.committer@gmail.com// Such an entity should subclass SkEventTracer and provide an instance of
146169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// that event to SkEventTracer::SetInstance.
156169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
166169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// If you're looking for the tracing macros to instrument Skia itself, those
176169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// live in src/core/SkTraceEvent.h
186169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
196169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#include "SkTypes.h"
206169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
216169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// This will mark the trace event as disabled by default. The user will need
226169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org// to explicitly enable the event.
236169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#define TRACE_DISABLED_BY_DEFAULT(name) "disabled-by-default-" name
246169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
256169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgclass SK_API SkEventTracer {
266169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.orgpublic:
276169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
282859f9fbf3764d401b3b9b27f3d9e9bddeaf3a14commit-bot@chromium.org    typedef uint64_t Handle;
294c18e9fbb685cccf23342757e786027a032197daskia.committer@gmail.com
30175f588831c3d9f76349af8c27c64ceaa4460871Brian Salomon    /**
31175f588831c3d9f76349af8c27c64ceaa4460871Brian Salomon     * If this is the first call to SetInstance or GetInstance then the passed instance is
32175f588831c3d9f76349af8c27c64ceaa4460871Brian Salomon     * installed and true is returned. Otherwise, false is returned. In either case ownership of the
33175f588831c3d9f76349af8c27c64ceaa4460871Brian Salomon     * tracer is transferred and it will be deleted when no longer needed.
34175f588831c3d9f76349af8c27c64ceaa4460871Brian Salomon     */
35175f588831c3d9f76349af8c27c64ceaa4460871Brian Salomon    static bool SetInstance(SkEventTracer*);
36175f588831c3d9f76349af8c27c64ceaa4460871Brian Salomon
37175f588831c3d9f76349af8c27c64ceaa4460871Brian Salomon    /**
38175f588831c3d9f76349af8c27c64ceaa4460871Brian Salomon     * Gets the event tracer. If this is the first call to SetInstance or GetIntance then a default
39175f588831c3d9f76349af8c27c64ceaa4460871Brian Salomon     * event tracer is installed and returned.
40175f588831c3d9f76349af8c27c64ceaa4460871Brian Salomon     */
416169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    static SkEventTracer* GetInstance();
426169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
436169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    virtual ~SkEventTracer() { }
446169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
456169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    // The pointer returned from GetCategoryGroupEnabled() points to a
466169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    // value with zero or more of the following bits. Used in this class only.
476169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    // The TRACE_EVENT macros should only use the value as a bool.
486169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    // These values must be in sync with macro values in trace_event.h in chromium.
496169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    enum CategoryGroupEnabledFlags {
506169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        // Category group enabled for the recording mode.
516169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        kEnabledForRecording_CategoryGroupEnabledFlags = 1 << 0,
526169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        // Category group enabled for the monitoring mode.
536169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        kEnabledForMonitoring_CategoryGroupEnabledFlags = 1 << 1,
546169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        // Category group enabled by SetEventCallbackEnabled().
556169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        kEnabledForEventCallback_CategoryGroupEnabledFlags = 1 << 2,
566169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    };
576169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
583458a1736feae84eba985591a8ab8d26530d96c8commit-bot@chromium.org    virtual const uint8_t* getCategoryGroupEnabled(const char* name) = 0;
596169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org    virtual const char* getCategoryGroupName(
602859f9fbf3764d401b3b9b27f3d9e9bddeaf3a14commit-bot@chromium.org      const uint8_t* categoryEnabledFlag) = 0;
614c18e9fbb685cccf23342757e786027a032197daskia.committer@gmail.com
624c18e9fbb685cccf23342757e786027a032197daskia.committer@gmail.com    virtual SkEventTracer::Handle
636169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org        addTraceEvent(char phase,
646169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                      const uint8_t* categoryEnabledFlag,
656169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                      const char* name,
666169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                      uint64_t id,
676169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                      int32_t numArgs,
686169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                      const char** argNames,
696169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                      const uint8_t* argTypes,
706169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                      const uint64_t* argValues,
716169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org                      uint8_t flags) = 0;
724c18e9fbb685cccf23342757e786027a032197daskia.committer@gmail.com
734c18e9fbb685cccf23342757e786027a032197daskia.committer@gmail.com    virtual void
744c18e9fbb685cccf23342757e786027a032197daskia.committer@gmail.com        updateTraceEventDuration(const uint8_t* categoryEnabledFlag,
754c18e9fbb685cccf23342757e786027a032197daskia.committer@gmail.com                                 const char* name,
763458a1736feae84eba985591a8ab8d26530d96c8commit-bot@chromium.org                                 SkEventTracer::Handle handle) = 0;
776169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org};
786169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org
796169f2b4da39099b4e593f5ff85538dfe2f0249ecommit-bot@chromium.org#endif // SkEventTracer_DEFINED
80