Commit 964248a8 by Jamie Madill

Add scoped timer histogram helper macros.

These macros replace a lot of repeated timing code, and mirror how Chromium operates. BUG=516027 Change-Id: Ib03e35d0f3b8638b9b0e8785c397c8381f16b041 Reviewed-on: https://chromium-review.googlesource.com/290840Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 2bde736f
...@@ -235,8 +235,7 @@ Error Display::initialize() ...@@ -235,8 +235,7 @@ Error Display::initialize()
// Re-initialize default platform if it's needed // Re-initialize default platform if it's needed
InitDefaultPlatformImpl(); InitDefaultPlatformImpl();
double createDeviceBegin = ANGLEPlatformCurrent()->currentTime(); SCOPED_ANGLE_HISTOGRAM_TIMER("GPU.ANGLE.DisplayInitializeMS");
TRACE_EVENT0("gpu.angle", "egl::Display::initialize"); TRACE_EVENT0("gpu.angle", "egl::Display::initialize");
ASSERT(mImplementation != nullptr); ASSERT(mImplementation != nullptr);
...@@ -281,10 +280,6 @@ Error Display::initialize() ...@@ -281,10 +280,6 @@ Error Display::initialize()
mInitialized = true; mInitialized = true;
double displayInitializeSec = ANGLEPlatformCurrent()->currentTime() - createDeviceBegin;
int displayInitializeMS = static_cast<int>(displayInitializeSec * 1000);
ANGLE_HISTOGRAM_TIMES("GPU.ANGLE.DisplayInitializeMS", displayInitializeMS);
return Error(EGL_SUCCESS); return Error(EGL_SUCCESS);
} }
......
...@@ -63,4 +63,45 @@ ...@@ -63,4 +63,45 @@
#define ANGLE_HISTOGRAM_SPARSE_SLOWLY(name, sample) \ #define ANGLE_HISTOGRAM_SPARSE_SLOWLY(name, sample) \
ANGLEPlatformCurrent()->histogramSparse(name, sample) ANGLEPlatformCurrent()->histogramSparse(name, sample)
// Scoped class which logs its time on this earth as a UMA statistic. This is
// recommended for when you want a histogram which measures the time it takes
// for a method to execute. This measures up to 10 seconds.
#define SCOPED_ANGLE_HISTOGRAM_TIMER(name) \
SCOPED_ANGLE_HISTOGRAM_TIMER_EXPANDER(name, false, __COUNTER__)
// Similar scoped histogram timer, but this uses ANGLE_HISTOGRAM_LONG_TIMES_100,
// which measures up to an hour, and uses 100 buckets. This is more expensive
// to store, so only use if this often takes >10 seconds.
#define SCOPED_ANGLE_HISTOGRAM_LONG_TIMER(name) \
SCOPED_ANGLE_HISTOGRAM_TIMER_EXPANDER(name, true, __COUNTER__)
// This nested macro is necessary to expand __COUNTER__ to an actual value.
#define SCOPED_ANGLE_HISTOGRAM_TIMER_EXPANDER(name, is_long, key) \
SCOPED_ANGLE_HISTOGRAM_TIMER_UNIQUE(name, is_long, key)
#define SCOPED_ANGLE_HISTOGRAM_TIMER_UNIQUE(name, is_long, key) \
class ScopedHistogramTimer##key \
{ \
public: \
ScopedHistogramTimer##key() : constructed_(ANGLEPlatformCurrent()->currentTime()) {} \
~ScopedHistogramTimer##key() \
{ \
if (constructed_ == 0) \
return; \
double elapsed = ANGLEPlatformCurrent()->currentTime() - constructed_; \
int elapsedMS = static_cast<int>(elapsed * 1000.0); \
if (is_long) \
{ \
ANGLE_HISTOGRAM_LONG_TIMES_100(name, elapsedMS); \
} \
else \
{ \
ANGLE_HISTOGRAM_TIMES(name, elapsedMS); \
} \
} \
\
private: \
double constructed_; \
} scoped_histogram_timer_##key
#endif // BASE_METRICS_HISTOGRAM_MACROS_H_ #endif // BASE_METRICS_HISTOGRAM_MACROS_H_
...@@ -405,9 +405,9 @@ egl::Error Renderer11::initialize() ...@@ -405,9 +405,9 @@ egl::Error Renderer11::initialize()
if (!mDevice || FAILED(result)) if (!mDevice || FAILED(result))
#endif #endif
{ {
double createDeviceBegin = ANGLEPlatformCurrent()->currentTime(); SCOPED_ANGLE_HISTOGRAM_TIMER("GPU.ANGLE.D3D11CreateDeviceMS");
TRACE_EVENT0("gpu.angle", "D3D11CreateDevice"); TRACE_EVENT0("gpu.angle", "D3D11CreateDevice");
result = D3D11CreateDevice(NULL, result = D3D11CreateDevice(NULL,
mDriverType, mDriverType,
NULL, NULL,
...@@ -427,10 +427,6 @@ egl::Error Renderer11::initialize() ...@@ -427,10 +427,6 @@ egl::Error Renderer11::initialize()
D3D11_INIT_CREATEDEVICE_ERROR, D3D11_INIT_CREATEDEVICE_ERROR,
"Could not create D3D11 device."); "Could not create D3D11 device.");
} }
double createDeviceSec = ANGLEPlatformCurrent()->currentTime() - createDeviceBegin;
int createDeviceMS = static_cast<int>(createDeviceSec * 1000);
ANGLE_HISTOGRAM_TIMES("GPU.ANGLE.D3D11CreateDeviceMS", createDeviceMS);
} }
#if !defined(ANGLE_ENABLE_WINDOWS_STORE) #if !defined(ANGLE_ENABLE_WINDOWS_STORE)
...@@ -584,8 +580,7 @@ egl::Error Renderer11::initialize() ...@@ -584,8 +580,7 @@ egl::Error Renderer11::initialize()
// to reset the scene status and ensure the default states are reset. // to reset the scene status and ensure the default states are reset.
void Renderer11::initializeDevice() void Renderer11::initializeDevice()
{ {
double startTimeSeconds = ANGLEPlatformCurrent()->currentTime(); SCOPED_ANGLE_HISTOGRAM_TIMER("GPU.ANGLE.Renderer11InitializeDeviceMS");
TRACE_EVENT0("gpu.angle", "Renderer11::initializeDevice"); TRACE_EVENT0("gpu.angle", "Renderer11::initializeDevice");
populateRenderer11DeviceCaps(); populateRenderer11DeviceCaps();
...@@ -654,10 +649,6 @@ void Renderer11::initializeDevice() ...@@ -654,10 +649,6 @@ void Renderer11::initializeDevice()
// TODO(jmadill): use context caps, and place in common D3D location // TODO(jmadill): use context caps, and place in common D3D location
mTranslatedAttribCache.resize(getRendererCaps().maxVertexAttributes); mTranslatedAttribCache.resize(getRendererCaps().maxVertexAttributes);
double elapsedTimeSeconds = ANGLEPlatformCurrent()->currentTime() - startTimeSeconds;
int initializeDeviceMS = static_cast<int>(elapsedTimeSeconds * 1000);
ANGLE_HISTOGRAM_TIMES("GPU.ANGLE.Renderer11InitializeDeviceMS", initializeDeviceMS);
} }
void Renderer11::populateRenderer11DeviceCaps() void Renderer11::populateRenderer11DeviceCaps()
......
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