Commit 9ac68ee2 authored by mtklein's avatar mtklein Committed by Commit bot
Browse files

Move BenchTimer to tools as Timer

This breaks a bunch of circular dependencies between tools and gm and bench.

BUG=skia:

Committed: https://skia.googlesource.com/skia/+/4ed75287aed6371c6e4a41ffcc78c8a49c9810ed

CQ_EXTRA_TRYBOTS=tryserver.skia:Build-Mac10.7-Clang-Arm7-Debug-iOS-Trybot,Test-Ubuntu12-ShuttleA-GTX660-x86-Debug-Trybot
R=tfarina@chromium.org, mtklein@google.com

Author: mtklein@chromium.org

Review URL: https://codereview.chromium.org/344213003
parent 24480bc7
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "BenchSysTimer_c.h"
//Time
#include <time.h>
void BenchSysTimer::startWall() {
this->fStartWall = time();
}
void BenchSysTimer::startCpu() {
this->fStartCpu = clock();
}
double BenchSysTimer::endCpu() {
clock_t end_cpu = clock();
this->fCpu = (end_cpu - this->fStartCpu) * CLOCKS_PER_SEC / 1000.0;
}
double BenchSysTimer::endWall() {
time_t end_wall = time();
this->fWall = difftime(end_wall, this->fstartWall) / 1000.0;
}
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkBenchSysTimer_DEFINED
#define SkBenchSysTimer_DEFINED
//Time
#include <time.h>
// Beware: this timer uses standard (as opposed to high precision) clocks
class BenchSysTimer {
public:
void startWall();
void startCpu();
double endCpu();
double endWall();
private:
clock_t start_cpu;
time_t fStartWall;
};
#endif
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "BenchTimer.h"
#if defined(SK_BUILD_FOR_WIN32)
#include "BenchSysTimer_windows.h"
#elif defined(SK_BUILD_FOR_MAC)
#include "BenchSysTimer_mach.h"
#elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID)
#include "BenchSysTimer_posix.h"
#else
#include "BenchSysTimer_c.h"
#endif
#if SK_SUPPORT_GPU
#include "BenchGpuTimer_gl.h"
#endif
BenchTimer::BenchTimer(SkGLContextHelper* gl)
: fCpu(-1.0)
, fWall(-1.0)
, fTruncatedCpu(-1.0)
, fTruncatedWall(-1.0)
, fGpu(-1.0)
{
fSysTimer = new BenchSysTimer();
fTruncatedSysTimer = new BenchSysTimer();
#if SK_SUPPORT_GPU
if (gl) {
fGpuTimer = new BenchGpuTimer(gl);
} else {
fGpuTimer = NULL;
}
#endif
}
BenchTimer::~BenchTimer() {
delete fSysTimer;
delete fTruncatedSysTimer;
#if SK_SUPPORT_GPU
delete fGpuTimer;
#endif
}
void BenchTimer::start(double durationScale) {
fDurationScale = durationScale;
fSysTimer->startWall();
fTruncatedSysTimer->startWall();
#if SK_SUPPORT_GPU
if (fGpuTimer) {
fGpuTimer->startGpu();
}
#endif
fSysTimer->startCpu();
fTruncatedSysTimer->startCpu();
}
void BenchTimer::end() {
fCpu = fSysTimer->endCpu() * fDurationScale;
#if SK_SUPPORT_GPU
//It is important to stop the cpu clocks first,
//as the following will cpu wait for the gpu to finish.
if (fGpuTimer) {
fGpu = fGpuTimer->endGpu() * fDurationScale;
}
#endif
fWall = fSysTimer->endWall() * fDurationScale;
}
void BenchTimer::truncatedEnd() {
fTruncatedCpu = fTruncatedSysTimer->endCpu() * fDurationScale;
fTruncatedWall = fTruncatedSysTimer->endWall() * fDurationScale;
}
WallTimer::WallTimer() : fWall(-1.0), fSysTimer(new BenchSysTimer) {}
WallTimer::~WallTimer() {
delete fSysTimer;
}
void WallTimer::start(double durationScale) {
fDurationScale = durationScale;
fSysTimer->startWall();
}
void WallTimer::end() {
fWall = fSysTimer->endWall() * fDurationScale;
}
......@@ -6,7 +6,6 @@
*/
#include "BenchLogger.h"
#include "BenchTimer.h"
#include "Benchmark.h"
#include "CrashHandler.h"
#include "GMBench.h"
......@@ -24,6 +23,7 @@
#include "SkPictureRecorder.h"
#include "SkString.h"
#include "SkSurface.h"
#include "Timer.h"
#if SK_SUPPORT_GPU
#include "GrContext.h"
......@@ -530,9 +530,9 @@ int tool_main(int argc, char** argv) {
if (Benchmark::kGPU_Backend == config.backend) {
contextHelper = gContextFactory.getGLContext(config.contextType);
}
BenchTimer timer(contextHelper);
Timer timer(contextHelper);
#else
BenchTimer timer;
Timer timer;
#endif
double previous = std::numeric_limits<double>::infinity();
......
......@@ -17,13 +17,13 @@
__SK_FORCE_IMAGE_DECODER_LINKING;
#if defined(SK_BUILD_FOR_WIN32)
#include "BenchSysTimer_windows.h"
#include "SysTimer_windows.h"
#elif defined(SK_BUILD_FOR_MAC)
#include "BenchSysTimer_mach.h"
#include "SysTimer_mach.h"
#elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID)
#include "BenchSysTimer_posix.h"
#include "SysTimer_posix.h"
#else
#include "BenchSysTimer_c.h"
#include "SysTimer_c.h"
#endif
......@@ -202,7 +202,7 @@ public:
double totTime() const { return fTot; }
protected:
BenchSysTimer fTimer;
SysTimer fTimer;
SkTDArray<bool> fSkipCommands; // has the command been deleted in the GUI?
SkTDArray<double> fTimes; // sum of time consumed for each command
SkTDArray<double> fTypeTimes; // sum of time consumed for each type of command (e.g., drawPath)
......
......@@ -150,8 +150,8 @@
'flags.gyp:flags',
'lua.gyp:lua',
'pdf.gyp:pdf',
'resources.gyp:resources',
'skia_lib.gyp:skia_lib',
'tools.gyp:resources',
'views.gyp:views',
'views_animated.gyp:views_animated',
'xml.gyp:xml',
......
......@@ -15,7 +15,7 @@
[ 'skia_os == "android" and not skia_android_framework', {
'dependencies': [
'android_deps.gyp:Android_EntryPoint',
'android_system.gyp:skia_launcher',
'skia_launcher.gyp:skia_launcher',
],
}],
[ 'skia_os == "nacl"', {
......
......@@ -9,13 +9,13 @@
'target_name': 'bench',
'type': 'executable',
'dependencies': [
'bench_timer',
'crash_handler.gyp:CrashHandler',
'etc1.gyp:libetc1',
'flags.gyp:flags',
'jsoncpp.gyp:jsoncpp',
'resources.gyp:resources',
'skia_lib.gyp:skia_lib',
'tools.gyp:crash_handler',
'tools.gyp:resources',
'tools.gyp:timer',
],
'sources': [
'../bench/BenchLogger.cpp',
......@@ -50,63 +50,5 @@
'gmslides.gypi',
],
},
{
'target_name' : 'bench_timer',
'type': 'static_library',
'sources': [
'../bench/BenchTimer.h',
'../bench/BenchTimer.cpp',
'../bench/BenchSysTimer_mach.h',
'../bench/BenchSysTimer_mach.cpp',
'../bench/BenchSysTimer_posix.h',
'../bench/BenchSysTimer_posix.cpp',
'../bench/BenchSysTimer_windows.h',
'../bench/BenchSysTimer_windows.cpp',
],
'include_dirs': [
'../src/core',
'../src/gpu',
'../tools',
],
'direct_dependent_settings': {
'include_dirs': ['../bench'],
},
'dependencies': [
'skia_lib.gyp:skia_lib',
],
'conditions': [
[ 'skia_os not in ["mac", "ios"]', {
'sources!': [
'../bench/BenchSysTimer_mach.h',
'../bench/BenchSysTimer_mach.cpp',
],
}],
[ 'skia_os not in ["linux", "freebsd", "openbsd", "solaris", "android", "chromeos"]', {
'sources!': [
'../bench/BenchSysTimer_posix.h',
'../bench/BenchSysTimer_posix.cpp',
],
}],
[ 'skia_os in ["linux", "freebsd", "openbsd", "solaris", "chromeos"]', {
'link_settings': {
'libraries': [
'-lrt',
],
},
}],
[ 'skia_os != "win"', {
'sources!': [
'../bench/BenchSysTimer_windows.h',
'../bench/BenchSysTimer_windows.cpp',
],
}],
['skia_gpu == 1', {
'sources': [
'../bench/BenchGpuTimer_gl.h',
'../bench/BenchGpuTimer_gl.cpp',
],
}],
],
}
],
}
{
'targets': [{
'target_name': 'CrashHandler',
'type': 'static_library',
'sources': [ '../tools/CrashHandler.cpp' ],
'dependencies': [ 'skia_lib.gyp:skia_lib' ],
'direct_dependent_settings': {
'include_dirs': [ '../tools' ],
},
'all_dependent_settings': {
'msvs_settings': {
'VCLinkerTool': {
'AdditionalDependencies': [ 'Dbghelp.lib' ],
}
},
}
}]
}
......@@ -96,8 +96,8 @@
],
'dependencies': [
'skia_lib.gyp:skia_lib',
'bench.gyp:bench_timer',
'tools.gyp:picture_renderer',
'tools.gyp:timer',
],
'conditions': [
[ 'skia_os == "nacl"', {
......
......@@ -55,12 +55,12 @@
'../src/utils/debugger/SkObjectParser.cpp',
],
'dependencies': [
'crash_handler.gyp:CrashHandler',
'etc1.gyp:libetc1',
'flags.gyp:flags',
'gputest.gyp:skgputest',
'jsoncpp.gyp:jsoncpp',
'skia_lib.gyp:skia_lib',
'tools.gyp:crash_handler',
],
'conditions': [
['skia_android_framework', {
......
......@@ -4,28 +4,6 @@
'apptype_console.gypi',
],
'targets': [
{
'target_name': 'gm_expectations',
'type': 'static_library',
'include_dirs' : [
'../src/utils/',
],
'sources': [
'../gm/gm_expectations.h',
'../gm/gm_expectations.cpp',
'../tools/sk_tool_utils.cpp',
],
'dependencies': [
'crash_handler.gyp:CrashHandler',
'jsoncpp.gyp:jsoncpp',
'skia_lib.gyp:skia_lib',
],
'direct_dependent_settings': {
'include_dirs': [
'../gm/',
],
},
},
{
'target_name': 'gm',
'type': 'executable',
......@@ -49,11 +27,12 @@
'dependencies': [
'etc1.gyp:libetc1',
'flags.gyp:flags',
'gm.gyp:gm_expectations',
'jsoncpp.gyp:jsoncpp',
'pdf.gyp:pdf',
'resources.gyp:resources',
'skia_lib.gyp:skia_lib',
'tools.gyp:crash_handler',
'tools.gyp:gm_expectations',
'tools.gyp:resources',
],
'conditions': [
['skia_android_framework', {
......
# Copyright 2014 Google Inc.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
{
'targets': [
{
'target_name': 'resources',
'type': 'static_library',
'sources': [
'../tools/Resources.cpp',
'../tools/Resources.h',
],
'dependencies': [
'flags.gyp:flags',
'skia_lib.gyp:skia_lib',
],
'direct_dependent_settings': {
'include_dirs': [
'../tools/',
],
},
},
]
}
{
'includes': [ '../platform_tools/android/gyp/skia_launcher.gypi' ]
}
......@@ -11,7 +11,7 @@
'pathops_unittest.gypi',
'tests.gypi',
],
'dependencies': [ 'crash_handler.gyp:CrashHandler' ],
'dependencies': [ 'tools.gyp:crash_handler' ],
'sources': [
'../tests/skia_test.cpp',
],
......
......@@ -20,9 +20,9 @@
'experimental.gyp:experimental',
'flags.gyp:flags',
'pdf.gyp:pdf',
'resources.gyp:resources',
'skia_lib.gyp:skia_lib',
'tools.gyp:picture_utils',
'tools.gyp:resources',
],
'sources': [
'../tests/Test.cpp',
......
......@@ -43,6 +43,86 @@
],
],
},
{ # This would go in gm.gyp, but it's also used by skimage below.
'target_name': 'gm_expectations',
'type': 'static_library',
'include_dirs' : [ '../src/utils/' ],
'sources': [
'../gm/gm_expectations.cpp',
'../tools/sk_tool_utils.cpp',
],
'dependencies': [
'jsoncpp.gyp:jsoncpp',
'skia_lib.gyp:skia_lib',
],
'direct_dependent_settings': {
'include_dirs': [ '../gm/' ],
},
},
{
'target_name': 'crash_handler',
'type': 'static_library',
'sources': [ '../tools/CrashHandler.cpp' ],
'dependencies': [ 'skia_lib.gyp:skia_lib' ],
'direct_dependent_settings': {
'include_dirs': [ '../tools' ],
},
'all_dependent_settings': {
'msvs_settings': {
'VCLinkerTool': {
'AdditionalDependencies': [ 'Dbghelp.lib' ],
}
},
}
},
{
'target_name': 'resources',
'type': 'static_library',
'sources': [ '../tools/Resources.cpp' ],
'dependencies': [
'flags.gyp:flags',
'skia_lib.gyp:skia_lib',
],
'direct_dependent_settings': {
'include_dirs': [ '../tools/', ],
},
},
{
'target_name' : 'timer',
'type': 'static_library',
'sources': [
'../tools/timer/Timer.cpp',
'../tools/timer/TimerData.cpp',
],
'include_dirs': [
'../src/core',
'../src/gpu',
],
'direct_dependent_settings': {
'include_dirs': ['../tools/timer'],
},
'dependencies': [
'skia_lib.gyp:skia_lib',
'jsoncpp.gyp:jsoncpp',
],
'conditions': [
['skia_gpu == 1', {
'sources': [ '../tools/timer/GpuTimer.cpp' ],
}],
[ 'skia_os in ["mac", "ios"]', {
'sources': [ '../tools/timer/SysTimer_mach.cpp' ],
}],
[ 'skia_os == "win"', {
'sources': [ '../tools/timer/SysTimer_windows.cpp' ],
}],
[ 'skia_os in ["linux", "freebsd", "openbsd", "solaris", "android", "chromeos"]', {
'sources': [ '../tools/timer/SysTimer_posix.cpp' ],
}],
[ 'skia_os in ["linux", "freebsd", "openbsd", "solaris", "chromeos"]', {
'link_settings': { 'libraries': [ '-lrt' ] },
}],
],
},
{
'target_name': 'skdiff',
'type': 'executable',
......@@ -178,8 +258,8 @@
'../src/utils/',
],
'dependencies': [
'gm_expectations',
'flags.gyp:flags',
'gm.gyp:gm_expectations',
'jsoncpp.gyp:jsoncpp',
'skia_lib.gyp:skia_lib',
],
......@@ -299,14 +379,13 @@
'../src/lazy/',
],
'dependencies': [
'bench.gyp:bench_timer',
'crash_handler.gyp:CrashHandler',
'timer',
'crash_handler',
'flags.gyp:flags',
'jsoncpp.gyp:jsoncpp',
'skia_lib.gyp:skia_lib',
'tools.gyp:picture_renderer',
'tools.gyp:picture_utils',
'tools.gyp:timer_data',
],
},
{
......@@ -322,7 +401,7 @@
'../src/lazy',
],
'dependencies': [
'bench.gyp:bench_timer',
'timer',
'flags.gyp:flags',
'skia_lib.gyp:skia_lib',
],
......@@ -338,7 +417,7 @@
'../src/images',
],
'dependencies': [
'bench.gyp:bench_timer',
'timer',
'flags.gyp:flags',
'skia_lib.gyp:skia_lib',
],
......@@ -357,7 +436,7 @@
'../src/lazy',
],
'dependencies': [
'bench.gyp:bench_timer',
'timer',
'flags.gyp:flags',
'skia_lib.gyp:skia_lib',
],
......@@ -505,9 +584,8 @@
# Bench code:
],
'dependencies': [
'bench.gyp:bench_timer',
'timer',
'flags.gyp:flags',
'tools.gyp:timer_data',
'skia_lib.gyp:skia_lib',
'tools.gyp:picture_renderer',
'tools.gyp:picture_utils',
......@@ -544,17 +622,6 @@
'skia_lib.gyp:skia_lib',
],
},
{
'target_name': 'timer_data',
'type': 'static_library',
'sources': [
'../bench/TimerData.cpp',
],
'dependencies': [
'skia_lib.gyp:skia_lib',
'jsoncpp.gyp:jsoncpp'
]
}
],
'conditions': [
['skia_shared_lib',
......
......@@ -44,13 +44,6 @@
},
],
},
{
'target_name': 'skia_launcher',
'type': 'executable',
'sources': [
'../launcher/skia_launcher.cpp',
],
},
{
'target_name': 'SampleApp_APK',
'type': 'none',
......
{
'targets': [{
'target_name': 'skia_launcher',
'type': 'executable',
'sources': [ '../launcher/skia_launcher.cpp' ],
}]
}
......@@ -10,8 +10,8 @@
#include "SkRecord.h"
#include "SkRecordDraw.h"
#include "BenchTimer.h"
#include "DumpRecord.h"
#include "Timer.h"
namespace {
......@@ -33,7 +33,7 @@ public:
template <typename T>
void operator()(const T& command) {
BenchTimer timer;
Timer timer;
timer.start();
fDraw(command);
timer.end();
......
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