skia2/include/utils/SkEventTracer.h
Kevin Lubick 68d6ff9222 [includes] Reduce IWYU exports from SkTypes.h
SkTypes.h was found exporting <stddef.h> and <stdint.h>.
Thus if a Skia file includes SkTypes.h, it did not need
to include either of those files to use things like
size_t or uint8_t respectively. [1]

This also resulted in strange IWYU warnings like:
warning: size_t is defined in "include/core/SkTypes.h", which isn't directly #included.

Thus, this CL removes those additional exports, and as a result,
adds many more includes of <cstddef> and <cstdint>.

The second change this CL is to not use the default IWYU
mappings which are hard-coded into IWYU [2]. These defaults
are valid, but make suggestions for the C version of
headers and not the C++ ones (i.e. <stddef.h> over <cstddef>).

To make these recommendations align better with our preferred
style (the C++ ones), we use IWYU with --no_default_mappings
and then have to expand our existing mappings to better deal
with how IWYU would resolve some of these headers.

[1] https://codereview.chromium.org/1207893002/#msg49
[2] 4c0f396159/iwyu_include_picker.cc (L1221-L1234)

Change-Id: Iafebe190f8f3e86f252147b9f538c182bcc34af4
Bug: skia:13052
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/555516
Auto-Submit: Kevin Lubick <kjlubick@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Herb Derby <herb@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2022-07-06 14:52:55 +00:00

88 lines
3.3 KiB
C++

/*
* Copyright (C) 2014 Google Inc. All rights reserved.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkEventTracer_DEFINED
#define SkEventTracer_DEFINED
// The class in this header defines the interface between Skia's internal
// tracing macros and an external entity (e.g., Chrome) that will consume them.
// Such an entity should subclass SkEventTracer and provide an instance of
// that event to SkEventTracer::SetInstance.
// If you're looking for the tracing macros to instrument Skia itself, those
// live in src/core/SkTraceEvent.h
#include "include/core/SkTypes.h"
#include <cstdint>
class SK_API SkEventTracer {
public:
typedef uint64_t Handle;
/**
* If this is the first call to SetInstance or GetInstance then the passed instance is
* installed and true is returned. Otherwise, false is returned. In either case ownership of the
* tracer is transferred and it will be deleted when no longer needed.
*
* Not deleting the tracer on process exit should not cause problems as
* the whole heap is about to go away with the process. This can also
* improve performance by reducing the amount of work needed.
*
* @param leakTracer Do not delete tracer on process exit.
*/
static bool SetInstance(SkEventTracer*, bool leakTracer = false);
/**
* Gets the event tracer. If this is the first call to SetInstance or GetIntance then a default
* event tracer is installed and returned.
*/
static SkEventTracer* GetInstance();
virtual ~SkEventTracer() = default;
// The pointer returned from GetCategoryGroupEnabled() points to a
// value with zero or more of the following bits. Used in this class only.
// The TRACE_EVENT macros should only use the value as a bool.
// These values must be in sync with macro values in trace_event.h in chromium.
enum CategoryGroupEnabledFlags {
// Category group enabled for the recording mode.
kEnabledForRecording_CategoryGroupEnabledFlags = 1 << 0,
// Category group enabled for the monitoring mode.
kEnabledForMonitoring_CategoryGroupEnabledFlags = 1 << 1,
// Category group enabled by SetEventCallbackEnabled().
kEnabledForEventCallback_CategoryGroupEnabledFlags = 1 << 2,
};
virtual const uint8_t* getCategoryGroupEnabled(const char* name) = 0;
virtual const char* getCategoryGroupName(const uint8_t* categoryEnabledFlag) = 0;
virtual SkEventTracer::Handle
addTraceEvent(char phase,
const uint8_t* categoryEnabledFlag,
const char* name,
uint64_t id,
int32_t numArgs,
const char** argNames,
const uint8_t* argTypes,
const uint64_t* argValues,
uint8_t flags) = 0;
virtual void
updateTraceEventDuration(const uint8_t* categoryEnabledFlag,
const char* name,
SkEventTracer::Handle handle) = 0;
protected:
SkEventTracer() = default;
SkEventTracer(const SkEventTracer&) = delete;
SkEventTracer& operator=(const SkEventTracer&) = delete;
};
#endif // SkEventTracer_DEFINED