2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2014-06-20 18:29:20 +00:00
|
|
|
#ifndef Timer_DEFINED
|
|
|
|
#define Timer_DEFINED
|
2011-06-07 19:16:02 +00:00
|
|
|
|
2014-06-20 18:29:20 +00:00
|
|
|
#include "SkTypes.h"
|
2015-01-15 18:56:12 +00:00
|
|
|
#include "SkString.h"
|
2011-10-19 20:43:20 +00:00
|
|
|
|
2014-06-20 18:29:20 +00:00
|
|
|
#if defined(SK_BUILD_FOR_WIN32)
|
|
|
|
#include "SysTimer_windows.h"
|
|
|
|
#elif defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
|
|
|
|
#include "SysTimer_mach.h"
|
|
|
|
#elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID)
|
|
|
|
#include "SysTimer_posix.h"
|
|
|
|
#endif
|
2011-10-19 20:43:20 +00:00
|
|
|
|
2014-06-20 18:29:20 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
#include "GpuTimer.h"
|
|
|
|
#endif
|
2011-06-07 19:16:02 +00:00
|
|
|
|
2014-10-09 12:24:15 +00:00
|
|
|
class SkGLContext;
|
2011-10-19 20:43:20 +00:00
|
|
|
|
2011-06-07 19:16:02 +00:00
|
|
|
/**
|
|
|
|
* SysTimers and GpuTimers are implemented orthogonally.
|
2012-08-28 12:18:40 +00:00
|
|
|
* This class combines 2 SysTimers and a GpuTimer into one single,
|
|
|
|
* platform specific Timer with a simple interface. The truncated
|
|
|
|
* timer doesn't include the time required for the GPU to finish
|
|
|
|
* its rendering. It should always be <= the un-truncated system
|
|
|
|
* times and (for GPU configurations) can be used to roughly (very
|
|
|
|
* roughly) gauge the GPU load/backlog.
|
2011-06-07 19:16:02 +00:00
|
|
|
*/
|
2014-06-20 18:29:20 +00:00
|
|
|
class Timer {
|
2011-06-07 19:16:02 +00:00
|
|
|
public:
|
2014-10-09 12:24:15 +00:00
|
|
|
explicit Timer(SkGLContext* gl = NULL);
|
2014-06-20 18:29:20 +00:00
|
|
|
|
|
|
|
void start();
|
2014-06-20 17:43:07 +00:00
|
|
|
void truncatedEnd();
|
2014-06-20 18:29:20 +00:00
|
|
|
void end();
|
|
|
|
|
|
|
|
// All times in milliseconds.
|
2011-06-07 19:16:02 +00:00
|
|
|
double fCpu;
|
|
|
|
double fWall;
|
2012-08-28 12:18:40 +00:00
|
|
|
double fTruncatedCpu;
|
|
|
|
double fTruncatedWall;
|
2011-06-07 19:16:02 +00:00
|
|
|
double fGpu;
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2011-06-07 19:16:02 +00:00
|
|
|
private:
|
2014-06-20 18:29:20 +00:00
|
|
|
SysTimer fSysTimer;
|
|
|
|
SysTimer fTruncatedSysTimer;
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2014-06-20 18:29:20 +00:00
|
|
|
GpuTimer fGpuTimer;
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif
|
2011-06-07 19:16:02 +00:00
|
|
|
};
|
|
|
|
|
2014-06-20 18:29:20 +00:00
|
|
|
// Same as Timer above, supporting only fWall but with much lower overhead.
|
|
|
|
// (Typically, ~30ns instead of Timer's ~1us.)
|
2014-06-16 21:04:32 +00:00
|
|
|
class WallTimer {
|
|
|
|
public:
|
|
|
|
WallTimer();
|
|
|
|
|
2014-06-20 18:29:20 +00:00
|
|
|
void start();
|
2014-06-16 21:04:32 +00:00
|
|
|
void end();
|
|
|
|
|
2014-06-20 18:29:20 +00:00
|
|
|
double fWall; // Milliseconds.
|
2014-06-16 21:04:32 +00:00
|
|
|
|
|
|
|
private:
|
2014-06-20 18:29:20 +00:00
|
|
|
SysTimer fSysTimer;
|
2014-06-16 21:04:32 +00:00
|
|
|
};
|
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
SkString HumanizeMs(double);
|
|
|
|
|
2011-06-07 19:16:02 +00:00
|
|
|
#endif
|