Commit ae2d8a3a by Jamie Madill

Add Platform methods for event tracing.

Event tracing requires pulling in timing counters, so we can sync with Chromium's timestamps. It may require a bit more tricky stuff to sync ANGLE's GPU timestamps with trace timestamps, but should allow us to add GPU trace events in the future. BUG=chromium:436191 BUG=angleproject:966 Change-Id: Ie1dc2981650d96888f988fa74b6fa435fbe8edc2 Reviewed-on: https://chromium-review.googlesource.com/263781Reviewed-by: 's avatarBrandon Jones <bajones@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent fbfa47c4
......@@ -20,8 +20,24 @@ class Platform
{
public:
// System --------------------------------------------------------------
// Monotonically increasing time in seconds from an arbitrary fixed point in the past.
// This function is expected to return at least millisecond-precision values. For this reason,
// it is recommended that the fixed point be no further in the past than the epoch.
virtual double monotonicallyIncreasingTime() { return 0; }
// Tracing --------
// Get a pointer to the enabled state of the given trace category. The
// embedder can dynamically change the enabled state as trace event
// recording is started and stopped by the application. Only long-lived
// literal strings should be given as the category name. The implementation
// expects the returned pointer to be held permanently in a local static. If
// the unsigned char is non-zero, tracing is enabled. If tracing is enabled,
// addTraceEvent is expected to be called by the trace event macros.
virtual const unsigned char *getTraceCategoryEnabledFlag(const char *categoryName) { return 0; }
typedef uint64_t TraceEventHandle;
// Add a trace event to the platform tracing system. Depending on the actual
......@@ -47,6 +63,7 @@ class Platform
// - id optionally allows events of the same name to be distinguished from
// each other. For example, to trace the consutruction and destruction of
// objects, specify the pointer as the id parameter.
// - timestamp should be a time value returned from monotonicallyIncreasingTime.
// - numArgs specifies the number of elements in argNames, argTypes, and
// argValues.
// - argNames is the array of argument names. Use long-lived literal strings
......@@ -84,15 +101,15 @@ class Platform
}
// Set the duration field of a COMPLETE trace event.
virtual void updateTraceEventDuration(const unsigned char* categoryEnabledFlag, const char* name, TraceEventHandle) { }
virtual void updateTraceEventDuration(const unsigned char *categoryEnabledFlag, const char *name, TraceEventHandle eventHandle) { }
// Callbacks for reporting histogram data.
// CustomCounts histogram has exponential bucket sizes, so that min=1, max=1000000, bucketCount=50 would do.
virtual void histogramCustomCounts(const char* name, int sample, int min, int max, int bucketCount) { }
virtual void histogramCustomCounts(const char *name, int sample, int min, int max, int bucketCount) { }
// Enumeration histogram buckets are linear, boundaryValue should be larger than any possible sample value.
virtual void histogramEnumeration(const char* name, int sample, int boundaryValue) { }
virtual void histogramEnumeration(const char *name, int sample, int boundaryValue) { }
// Unlike enumeration histograms, sparse histograms only allocate memory for non-empty buckets.
virtual void histogramSparse(const char* name, int sample) { }
virtual void histogramSparse(const char *name, int sample) { }
protected:
virtual ~Platform() { }
......
......@@ -4,6 +4,9 @@
#include "common/event_tracer.h"
#include "common/debug.h"
#include "platform/Platform.h"
namespace gl
{
......@@ -15,8 +18,18 @@ AddTraceEventFunc g_addTraceEvent;
namespace gl
{
const unsigned char* TraceGetTraceCategoryEnabledFlag(const char* name)
const unsigned char *TraceGetTraceCategoryEnabledFlag(const char *name)
{
angle::Platform *platform = ANGLEPlatformCurrent();
ASSERT(platform);
// TODO(jmadill): only use platform once it's working
const unsigned char *categoryEnabledFlag = platform->getTraceCategoryEnabledFlag(name);
if (categoryEnabledFlag != nullptr)
{
return categoryEnabledFlag;
}
if (g_getCategoryEnabledFlag)
{
return g_getCategoryEnabledFlag(name);
......@@ -29,7 +42,29 @@ void TraceAddTraceEvent(char phase, const unsigned char* categoryGroupEnabled, c
int numArgs, const char** argNames, const unsigned char* argTypes,
const unsigned long long* argValues, unsigned char flags)
{
if (g_addTraceEvent)
angle::Platform *platform = ANGLEPlatformCurrent();
ASSERT(platform);
// TODO(jmadill): only use platform once it's working
double timestamp = platform->monotonicallyIncreasingTime();
if (timestamp != 0)
{
angle::Platform::TraceEventHandle handle =
platform->addTraceEvent(phase,
categoryGroupEnabled,
name,
id,
timestamp,
numArgs,
argNames,
argTypes,
argValues,
flags);
ASSERT(handle != 0);
UNUSED_ASSERTION_VARIABLE(handle);
}
else if (g_addTraceEvent)
{
g_addTraceEvent(phase, categoryGroupEnabled, name, id, numArgs, argNames, argTypes, argValues, flags);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment