Commit ef41279c 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/289995Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent ea1be878
......@@ -241,8 +241,7 @@ Error Display::initialize()
// Re-initialize default platform if it's needed
InitDefaultPlatformImpl();
double createDeviceBegin = ANGLEPlatformCurrent()->currentTime();
SCOPED_ANGLE_HISTOGRAM_TIMER("GPU.ANGLE.DisplayInitializeMS");
TRACE_EVENT0("gpu.angle", "egl::Display::initialize");
ASSERT(mImplementation != nullptr);
......@@ -292,10 +291,6 @@ Error Display::initialize()
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);
}
......
......@@ -63,4 +63,45 @@
#define ANGLE_HISTOGRAM_SPARSE_SLOWLY(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_
......@@ -352,11 +352,10 @@ Renderer11::~Renderer11()
egl::Error Renderer11::initialize()
{
double loadDLLsBegin = ANGLEPlatformCurrent()->currentTime();
#if !defined(ANGLE_ENABLE_WINDOWS_STORE)
PFN_D3D11_CREATE_DEVICE D3D11CreateDevice = nullptr;
{
SCOPED_ANGLE_HISTOGRAM_TIMER("GPU.ANGLE.Renderer11InitializeDLLsMS");
TRACE_EVENT0("gpu.angle", "Renderer11::initialize (Load DLLs)");
mDxgiModule = LoadLibrary(TEXT("dxgi.dll"));
mD3d11Module = LoadLibrary(TEXT("d3d11.dll"));
......@@ -381,10 +380,6 @@ egl::Error Renderer11::initialize()
}
#endif
double loadDLLsSec = ANGLEPlatformCurrent()->currentTime() - loadDLLsBegin;
int loadDLLsMS = static_cast<int>(loadDLLsSec * 1000);
ANGLE_HISTOGRAM_TIMES("GPU.ANGLE.Renderer11InitializeDLLsMS", loadDLLsMS);
HRESULT result = S_OK;
#ifdef _DEBUG
{
......@@ -409,9 +404,9 @@ egl::Error Renderer11::initialize()
if (!mDevice || FAILED(result))
#endif
{
double createDeviceBegin = ANGLEPlatformCurrent()->currentTime();
SCOPED_ANGLE_HISTOGRAM_TIMER("GPU.ANGLE.D3D11CreateDeviceMS");
TRACE_EVENT0("gpu.angle", "D3D11CreateDevice");
result = D3D11CreateDevice(NULL,
mDriverType,
NULL,
......@@ -431,10 +426,6 @@ egl::Error Renderer11::initialize()
D3D11_INIT_CREATEDEVICE_ERROR,
"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)
......@@ -588,8 +579,7 @@ egl::Error Renderer11::initialize()
// to reset the scene status and ensure the default states are reset.
void Renderer11::initializeDevice()
{
double startTimeSeconds = ANGLEPlatformCurrent()->currentTime();
SCOPED_ANGLE_HISTOGRAM_TIMER("GPU.ANGLE.Renderer11InitializeDeviceMS");
TRACE_EVENT0("gpu.angle", "Renderer11::initializeDevice");
populateRenderer11DeviceCaps();
......@@ -658,10 +648,6 @@ void Renderer11::initializeDevice()
// TODO(jmadill): use context caps, and place in common D3D location
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()
......
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