Move BenchTimer to tools as Timer
authormtklein <mtklein@chromium.org>
Fri, 20 Jun 2014 18:29:20 +0000 (11:29 -0700)
committerCommit bot <commit-bot@chromium.org>
Fri, 20 Jun 2014 18:29:21 +0000 (11:29 -0700)
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

50 files changed:
bench/BenchGpuTimer_gl.cpp [deleted file]
bench/BenchGpuTimer_gl.h [deleted file]
bench/BenchSysTimer_c.cpp [deleted file]
bench/BenchSysTimer_c.h [deleted file]
bench/BenchSysTimer_mach.cpp [deleted file]
bench/BenchSysTimer_mach.h [deleted file]
bench/BenchSysTimer_posix.cpp [deleted file]
bench/BenchSysTimer_posix.h [deleted file]
bench/BenchSysTimer_windows.cpp [deleted file]
bench/BenchSysTimer_windows.h [deleted file]
bench/BenchTimer.cpp [deleted file]
bench/BenchTimer.h [deleted file]
bench/TimerData.cpp [deleted file]
bench/TimerData.h [deleted file]
bench/benchmain.cpp
debugger/QT/SkDebuggerGUI.cpp
gyp/SampleApp.gyp
gyp/apptype_console.gypi
gyp/bench.gyp
gyp/crash_handler.gyp [deleted file]
gyp/debugger.gyp
gyp/dm.gyp
gyp/gm.gyp
gyp/resources.gyp [deleted file]
gyp/skia_launcher.gyp [new file with mode: 0644]
gyp/tests.gyp
gyp/tests.gypi
gyp/tools.gyp
platform_tools/android/gyp/skia_android.gypi
platform_tools/android/gyp/skia_launcher.gypi [new file with mode: 0644]
tools/DumpRecord.cpp
tools/PictureBenchmark.cpp
tools/PictureBenchmark.h
tools/bbh_shootout.cpp
tools/bench_pictures_main.cpp
tools/bench_playback.cpp
tools/bench_record.cpp
tools/skpdiff/skpdiff_util.cpp
tools/timer/GpuTimer.cpp [new file with mode: 0644]
tools/timer/GpuTimer.h [new file with mode: 0644]
tools/timer/SysTimer_mach.cpp [new file with mode: 0644]
tools/timer/SysTimer_mach.h [new file with mode: 0644]
tools/timer/SysTimer_posix.cpp [new file with mode: 0644]
tools/timer/SysTimer_posix.h [new file with mode: 0644]
tools/timer/SysTimer_windows.cpp [new file with mode: 0644]
tools/timer/SysTimer_windows.h [new file with mode: 0644]
tools/timer/Timer.cpp [new file with mode: 0644]
tools/timer/Timer.h [new file with mode: 0644]
tools/timer/TimerData.cpp [new file with mode: 0644]
tools/timer/TimerData.h [new file with mode: 0644]

diff --git a/bench/BenchGpuTimer_gl.cpp b/bench/BenchGpuTimer_gl.cpp
deleted file mode 100644 (file)
index 349fc15..0000000
+++ /dev/null
@@ -1,74 +0,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.
- */
-#include "BenchGpuTimer_gl.h"
-#include "gl/SkGLContextHelper.h"
-#include "gl/GrGLUtil.h"
-
-BenchGpuTimer::BenchGpuTimer(const SkGLContextHelper* glctx) {
-    fContext = glctx;
-    glctx->ref();
-    glctx->makeCurrent();
-    fStarted = false;
-    fSupported = GrGLGetVersion(glctx->gl()) > GR_GL_VER(3,3) ||
-                 glctx->hasExtension("GL_ARB_timer_query") ||
-                 glctx->hasExtension("GL_EXT_timer_query");
-
-    if (fSupported) {
-        SK_GL(*glctx, GenQueries(1, &fQuery));
-    }
-}
-
-BenchGpuTimer::~BenchGpuTimer() {
-    if (fSupported) {
-        fContext->makeCurrent();
-        SK_GL(*fContext, DeleteQueries(1, &fQuery));
-    }
-    fContext->unref();
-}
-
-void BenchGpuTimer::startGpu() {
-    if (fSupported) {
-        fContext->makeCurrent();
-        fStarted = true;
-        SK_GL(*fContext, BeginQuery(GR_GL_TIME_ELAPSED, fQuery));
-    }
-}
-
-/**
- * It is important to stop the cpu clocks first,
- * as this will cpu wait for the gpu to finish.
- */
-double BenchGpuTimer::endGpu() {
-    if (fSupported) {
-        fStarted = false;
-        fContext->makeCurrent();
-        SK_GL(*fContext, EndQuery(GR_GL_TIME_ELAPSED));
-
-        GrGLint available = 0;
-        while (!available) {
-            SK_GL_NOERRCHECK(*fContext, GetQueryObjectiv(fQuery,
-                                             GR_GL_QUERY_RESULT_AVAILABLE,
-                                             &available));
-            // If GetQueryObjectiv is erroring out we need some alternative
-            // means of breaking out of this loop
-            GrGLenum error;
-            SK_GL_RET_NOERRCHECK(*fContext, error, GetError());
-            if (GR_GL_NO_ERROR != error) {
-                break;
-            }
-        }
-        GrGLuint64 totalGPUTimeElapsed = 0;
-        SK_GL(*fContext, GetQueryObjectui64v(fQuery,
-                                             GR_GL_QUERY_RESULT,
-                                             &totalGPUTimeElapsed));
-
-        return totalGPUTimeElapsed / 1000000.0;
-    } else {
-        return 0;
-    }
-}
diff --git a/bench/BenchGpuTimer_gl.h b/bench/BenchGpuTimer_gl.h
deleted file mode 100644 (file)
index e472a4c..0000000
+++ /dev/null
@@ -1,26 +0,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 SkBenchGpuTimer_DEFINED
-#define SkBenchGpuTimer_DEFINED
-
-class SkGLContextHelper;
-
-class BenchGpuTimer {
-public:
-    BenchGpuTimer(const SkGLContextHelper* glctx);
-    ~BenchGpuTimer();
-    void startGpu();
-    double endGpu();
-private:
-    unsigned fQuery;
-    int fStarted;
-    const SkGLContextHelper* fContext;
-    bool fSupported;
-};
-
-#endif
diff --git a/bench/BenchSysTimer_c.cpp b/bench/BenchSysTimer_c.cpp
deleted file mode 100644 (file)
index f4cbd39..0000000
+++ /dev/null
@@ -1,27 +0,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.
- */
-#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;
-}
diff --git a/bench/BenchSysTimer_c.h b/bench/BenchSysTimer_c.h
deleted file mode 100644 (file)
index 586f0b4..0000000
+++ /dev/null
@@ -1,26 +0,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
diff --git a/bench/BenchSysTimer_mach.cpp b/bench/BenchSysTimer_mach.cpp
deleted file mode 100644 (file)
index 1f0a6b9..0000000
+++ /dev/null
@@ -1,76 +0,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.
- */
-#include "BenchSysTimer_mach.h"
-
-//Time
-#include <mach/mach.h>
-#include <mach/mach_time.h>
-
-static time_value_t macCpuTime() {
-    mach_port_t task = mach_task_self();
-    if (task == MACH_PORT_NULL) {
-        time_value_t none = {0, 0};
-        return none;
-    }
-
-    task_thread_times_info thread_info_data;
-    mach_msg_type_number_t thread_info_count = TASK_THREAD_TIMES_INFO_COUNT;
-    if (KERN_SUCCESS != task_info(task,
-                 TASK_THREAD_TIMES_INFO,
-                 reinterpret_cast<task_info_t>(&thread_info_data),
-                 &thread_info_count))
-    {
-        time_value_t none = {0, 0};
-        return none;
-    }
-
-    time_value_add(&thread_info_data.user_time, &thread_info_data.system_time)
-    return thread_info_data.user_time;
-}
-
-static double intervalInMSec(const time_value_t start_clock
-                           , const time_value_t end_clock)
-{
-    double duration_clock;
-    if ((end_clock.microseconds - start_clock.microseconds) < 0) {
-        duration_clock = (end_clock.seconds - start_clock.seconds-1)*1000;
-        duration_clock += (1000000
-                           + end_clock.microseconds
-                           - start_clock.microseconds) / 1000.0;
-    } else {
-        duration_clock = (end_clock.seconds - start_clock.seconds)*1000;
-        duration_clock += (end_clock.microseconds - start_clock.microseconds)
-                           / 1000.0;
-    }
-    return duration_clock;
-}
-
-void BenchSysTimer::startWall() {
-    this->fStartWall = mach_absolute_time();
-}
-void BenchSysTimer::startCpu() {
-    this->fStartCpu = macCpuTime();
-}
-
-double BenchSysTimer::endCpu() {
-    time_value_t end_cpu = macCpuTime();
-    return intervalInMSec(this->fStartCpu, end_cpu);
-}
-double BenchSysTimer::endWall() {
-    uint64_t end_wall = mach_absolute_time();
-
-    uint64_t elapsed = end_wall - this->fStartWall;
-    mach_timebase_info_data_t sTimebaseInfo;
-    if (KERN_SUCCESS != mach_timebase_info(&sTimebaseInfo)) {
-        return 0;
-    } else {
-        uint64_t elapsedNano = elapsed * sTimebaseInfo.numer
-                               / sTimebaseInfo.denom;
-        return elapsedNano / 1000000.0;
-    }
-}
diff --git a/bench/BenchSysTimer_mach.h b/bench/BenchSysTimer_mach.h
deleted file mode 100644 (file)
index 44d0e5e..0000000
+++ /dev/null
@@ -1,26 +0,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 <mach/mach.h>
-#include <mach/mach_time.h>
-
-class BenchSysTimer {
-public:
-    void startWall();
-    void startCpu();
-    double endCpu();
-    double endWall();
-private:
-    time_value_t fStartCpu;
-    uint64_t fStartWall;
-};
-
-#endif
diff --git a/bench/BenchSysTimer_posix.cpp b/bench/BenchSysTimer_posix.cpp
deleted file mode 100644 (file)
index e6767e5..0000000
+++ /dev/null
@@ -1,57 +0,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.
- */
-#include "BenchSysTimer_posix.h"
-
-//Time
-#include <time.h>
-
-static double intervalInMSec(const timespec start_clock
-                           , const timespec end_clock)
-{
-    double duration_clock;
-    if ((end_clock.tv_nsec - start_clock.tv_nsec) < 0) {
-        duration_clock = (end_clock.tv_sec - start_clock.tv_sec-1)*1000;
-        duration_clock += (1000000000 + end_clock.tv_nsec - start_clock.tv_nsec)
-                           / 1000000.0;
-    } else {
-        duration_clock = (end_clock.tv_sec - start_clock.tv_sec)*1000;
-        duration_clock += (end_clock.tv_nsec - start_clock.tv_nsec) / 1000000.0;
-    }
-    return duration_clock;
-}
-
-void BenchSysTimer::startWall() {
-    if (-1 == clock_gettime(CLOCK_MONOTONIC, &this->fWall)) {
-        timespec none = {0, 0};
-        this->fWall = none;
-    }
-}
-void BenchSysTimer::startCpu() {
-    if (-1 == clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &this->fCpu)) {
-        timespec none = {0, 0};
-        this->fCpu = none;
-    }
-}
-
-double BenchSysTimer::endCpu() {
-    timespec end_cpu;
-    if (-1 == clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end_cpu)) {
-        timespec none = {0, 0};
-        end_cpu = none;
-    }
-    return intervalInMSec(this->fCpu, end_cpu);
-}
-
-double BenchSysTimer::endWall() {
-    timespec end_wall;
-    if (-1 == clock_gettime(CLOCK_MONOTONIC, &end_wall)) {
-        timespec none = {0, 0};
-        end_wall = none;
-    }
-    return intervalInMSec(this->fWall, end_wall);
-}
diff --git a/bench/BenchSysTimer_posix.h b/bench/BenchSysTimer_posix.h
deleted file mode 100644 (file)
index 8fd9706..0000000
+++ /dev/null
@@ -1,25 +0,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>
-
-class BenchSysTimer {
-public:
-    void startWall();
-    void startCpu();
-    double endCpu();
-    double endWall();
-private:
-    timespec fCpu;
-    timespec fWall;
-};
-
-#endif
diff --git a/bench/BenchSysTimer_windows.cpp b/bench/BenchSysTimer_windows.cpp
deleted file mode 100644 (file)
index fab657a..0000000
+++ /dev/null
@@ -1,64 +0,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.
- */
-#include "BenchSysTimer_windows.h"
-
-//Time
-#define WIN32_LEAN_AND_MEAN 1
-#include <windows.h>
-
-static ULONGLONG winCpuTime() {
-    FILETIME createTime;
-    FILETIME exitTime;
-    FILETIME usrTime;
-    FILETIME sysTime;
-    if (0 == GetProcessTimes(GetCurrentProcess()
-                           , &createTime, &exitTime
-                           , &sysTime, &usrTime))
-    {
-        return 0;
-    }
-    ULARGE_INTEGER start_cpu_sys;
-    ULARGE_INTEGER start_cpu_usr;
-    start_cpu_sys.LowPart  = sysTime.dwLowDateTime;
-    start_cpu_sys.HighPart = sysTime.dwHighDateTime;
-    start_cpu_usr.LowPart  = usrTime.dwLowDateTime;
-    start_cpu_usr.HighPart = usrTime.dwHighDateTime;
-    return start_cpu_sys.QuadPart + start_cpu_usr.QuadPart;
-}
-
-void BenchSysTimer::startWall() {
-    if (0 == ::QueryPerformanceCounter(&this->fStartWall)) {
-        this->fStartWall.QuadPart = 0;
-    }
-}
-void BenchSysTimer::startCpu() {
-    this->fStartCpu = winCpuTime();
-}
-
-double BenchSysTimer::endCpu() {
-    ULONGLONG end_cpu = winCpuTime();
-    return static_cast<double>((end_cpu - this->fStartCpu)) / 10000.0L;
-}
-double BenchSysTimer::endWall() {
-    LARGE_INTEGER end_wall;
-    if (0 == ::QueryPerformanceCounter(&end_wall)) {
-        end_wall.QuadPart = 0;
-    }
-
-    LARGE_INTEGER ticks_elapsed;
-    ticks_elapsed.QuadPart = end_wall.QuadPart - this->fStartWall.QuadPart;
-
-    LARGE_INTEGER frequency;
-    if (0 == ::QueryPerformanceFrequency(&frequency)) {
-        return 0.0L;
-    } else {
-        return static_cast<double>(ticks_elapsed.QuadPart)
-             / static_cast<double>(frequency.QuadPart)
-             * 1000.0L;
-    }
-}
diff --git a/bench/BenchSysTimer_windows.h b/bench/BenchSysTimer_windows.h
deleted file mode 100644 (file)
index 469332e..0000000
+++ /dev/null
@@ -1,26 +0,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
-#define WIN32_LEAN_AND_MEAN 1
-#include <windows.h>
-
-class BenchSysTimer {
-public:
-    void startWall();
-    void startCpu();
-    double endCpu();
-    double endWall();
-private:
-    ULONGLONG fStartCpu;
-    LARGE_INTEGER fStartWall;
-};
-
-#endif
diff --git a/bench/BenchTimer.cpp b/bench/BenchTimer.cpp
deleted file mode 100644 (file)
index f3e8e3b..0000000
+++ /dev/null
@@ -1,94 +0,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.
- */
-#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;
-}
-
diff --git a/bench/BenchTimer.h b/bench/BenchTimer.h
deleted file mode 100644 (file)
index 2abf10b..0000000
+++ /dev/null
@@ -1,67 +0,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 SkBenchTimer_DEFINED
-#define SkBenchTimer_DEFINED
-
-#include <SkTypes.h>
-
-
-class BenchSysTimer;
-class BenchGpuTimer;
-
-class SkGLContextHelper;
-
-/**
- * SysTimers and GpuTimers are implemented orthogonally.
- * 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.
- */
-class BenchTimer {
-public:
-    BenchTimer(SkGLContextHelper* gl = NULL);
-    ~BenchTimer();
-    void start(double durationScale = 1);
-    void end();
-    void truncatedEnd();
-    double fCpu;
-    double fWall;
-    double fTruncatedCpu;
-    double fTruncatedWall;
-    double fGpu;
-
-private:
-    BenchSysTimer* fSysTimer;
-    BenchSysTimer* fTruncatedSysTimer;
-#if SK_SUPPORT_GPU
-    BenchGpuTimer* fGpuTimer;
-#endif
-    double fDurationScale;  // for this start/end session
-};
-
-// Same as BenchTimer above, supporting only fWall but with much lower overhead.
-// (Typically, ~30ns instead of BenchTimer's ~1us.)
-class WallTimer {
-public:
-    WallTimer();
-    ~WallTimer();
-
-    void start(double durationScale = 1);
-    void end();
-
-    double fWall;
-
-private:
-    BenchSysTimer* fSysTimer;
-    double fDurationScale;
-};
-
-#endif
diff --git a/bench/TimerData.cpp b/bench/TimerData.cpp
deleted file mode 100644 (file)
index 0cb0002..0000000
+++ /dev/null
@@ -1,224 +0,0 @@
-
-/*
- * Copyright 2012 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-#include "TimerData.h"
-
-#include "BenchTimer.h"
-#include <limits>
-
-using namespace std;
-
-TimerData::TimerData(int maxNumTimings)
-: fMaxNumTimings(maxNumTimings)
-, fCurrTiming(0)
-, fWallTimes(maxNumTimings)
-, fTruncatedWallTimes(maxNumTimings)
-, fCpuTimes(maxNumTimings)
-, fTruncatedCpuTimes(maxNumTimings)
-, fGpuTimes(maxNumTimings){
-}
-
-bool TimerData::appendTimes(BenchTimer* timer) {
-    SkASSERT(timer != NULL);
-    if (fCurrTiming >= fMaxNumTimings) {
-        return false;
-    }
-
-    fWallTimes[fCurrTiming] = timer->fWall;
-    fTruncatedWallTimes[fCurrTiming] = timer->fTruncatedWall;
-    fCpuTimes[fCurrTiming] = timer->fCpu;
-    fTruncatedCpuTimes[fCurrTiming] = timer->fTruncatedCpu;
-    fGpuTimes[fCurrTiming] = timer->fGpu;
-
-    ++fCurrTiming;
-
-    return true;
-}
-
-SkString TimerData::getResult(const char* doubleFormat,
-                              Result result,
-                              const char *configName,
-                              uint32_t timerFlags,
-                              int itersPerTiming) {
-    SkASSERT(itersPerTiming >= 1);
-
-    if (!fCurrTiming) {
-        return SkString("");
-    }
-
-    int numTimings = fCurrTiming;
-
-    SkString wallStr(" msecs = ");
-    SkString truncWallStr(" Wmsecs = ");
-    SkString cpuStr(" cmsecs = ");
-    SkString truncCpuStr(" Cmsecs = ");
-    SkString gpuStr(" gmsecs = ");
-
-    double wallMin = std::numeric_limits<double>::max();
-    double truncWallMin = std::numeric_limits<double>::max();
-    double cpuMin = std::numeric_limits<double>::max();
-    double truncCpuMin = std::numeric_limits<double>::max();
-    double gpuMin = std::numeric_limits<double>::max();
-
-    double wallSum = 0;
-    double truncWallSum = 0;
-    double cpuSum = 0;
-    double truncCpuSum = 0;
-    double gpuSum = 0;
-
-    for (int i = 0; i < numTimings; ++i) {
-        if (kPerIter_Result == result) {
-            wallStr.appendf(doubleFormat, fWallTimes[i] / itersPerTiming);
-            truncWallStr.appendf(doubleFormat, fTruncatedWallTimes[i] / itersPerTiming);
-            cpuStr.appendf(doubleFormat, fCpuTimes[i] / itersPerTiming);
-            truncCpuStr.appendf(doubleFormat, fTruncatedCpuTimes[i] / itersPerTiming);
-            gpuStr.appendf(doubleFormat, fGpuTimes[i] / itersPerTiming);
-
-            if (i != numTimings - 1) {
-                static const char kSep[] = ", ";
-                wallStr.append(kSep);
-                truncWallStr.append(kSep);
-                cpuStr.append(kSep);
-                truncCpuStr.append(kSep);
-                gpuStr.append(kSep);
-            }
-        } else if (kMin_Result == result) {
-            wallMin = SkTMin(wallMin, fWallTimes[i]);
-            truncWallMin = SkTMin(truncWallMin, fTruncatedWallTimes[i]);
-            cpuMin = SkTMin(cpuMin, fCpuTimes[i]);
-            truncCpuMin = SkTMin(truncCpuMin, fTruncatedCpuTimes[i]);
-            gpuMin = SkTMin(gpuMin, fGpuTimes[i]);
-        } else {
-            SkASSERT(kAvg_Result == result);
-            wallSum += fWallTimes[i];
-            truncWallSum += fTruncatedWallTimes[i];
-            cpuSum += fCpuTimes[i];
-            truncCpuSum += fTruncatedCpuTimes[i];
-        }
-
-        // We always track the GPU sum because whether it is non-zero indicates if valid gpu times
-        // were recorded at all.
-        gpuSum += fGpuTimes[i];
-    }
-
-    if (kMin_Result == result) {
-        wallStr.appendf(doubleFormat, wallMin / itersPerTiming);
-        truncWallStr.appendf(doubleFormat, truncWallMin / itersPerTiming);
-        cpuStr.appendf(doubleFormat, cpuMin / itersPerTiming);
-        truncCpuStr.appendf(doubleFormat, truncCpuMin / itersPerTiming);
-        gpuStr.appendf(doubleFormat, gpuMin / itersPerTiming);
-    } else if (kAvg_Result == result) {
-        int divisor = numTimings * itersPerTiming;
-        wallStr.appendf(doubleFormat, wallSum / divisor);
-        truncWallStr.appendf(doubleFormat, truncWallSum / divisor);
-        cpuStr.appendf(doubleFormat, cpuSum / divisor);
-        truncCpuStr.appendf(doubleFormat, truncCpuSum / divisor);
-        gpuStr.appendf(doubleFormat, gpuSum / divisor);
-    }
-
-    SkString str;
-    str.printf("  %4s:", configName);
-    if (timerFlags & kWall_Flag) {
-        str += wallStr;
-    }
-    if (timerFlags & kTruncatedWall_Flag) {
-        str += truncWallStr;
-    }
-    if (timerFlags & kCpu_Flag) {
-        str += cpuStr;
-    }
-    if (timerFlags & kTruncatedCpu_Flag) {
-        str += truncCpuStr;
-    }
-    if ((timerFlags & kGpu_Flag) && gpuSum > 0) {
-        str += gpuStr;
-    }
-    return str;
-}
-
-Json::Value TimerData::getJSON(uint32_t timerFlags,
-                               Result result,
-                               int itersPerTiming) {
-    SkASSERT(itersPerTiming >= 1);
-    Json::Value dataNode;
-    Json::Value wallNode, truncWall, cpuNode, truncCpu, gpuNode;
-    if (!fCurrTiming) {
-        return dataNode;
-    }
-
-    int numTimings = fCurrTiming;
-
-    double wallMin = std::numeric_limits<double>::max();
-    double truncWallMin = std::numeric_limits<double>::max();
-    double cpuMin = std::numeric_limits<double>::max();
-    double truncCpuMin = std::numeric_limits<double>::max();
-    double gpuMin = std::numeric_limits<double>::max();
-
-    double wallSum = 0;
-    double truncWallSum = 0;
-    double cpuSum = 0;
-    double truncCpuSum = 0;
-    double gpuSum = 0;
-
-    for (int i = 0; i < numTimings; ++i) {
-        if (kPerIter_Result == result) {
-            wallNode.append(fWallTimes[i] / itersPerTiming);
-            truncWall.append(fTruncatedWallTimes[i] / itersPerTiming);
-            cpuNode.append(fCpuTimes[i] / itersPerTiming);
-            truncCpu.append(fTruncatedCpuTimes[i] / itersPerTiming);
-            gpuNode.append(fGpuTimes[i] / itersPerTiming);
-        } else if (kMin_Result == result) {
-            wallMin = SkTMin(wallMin, fWallTimes[i]);
-            truncWallMin = SkTMin(truncWallMin, fTruncatedWallTimes[i]);
-            cpuMin = SkTMin(cpuMin, fCpuTimes[i]);
-            truncCpuMin = SkTMin(truncCpuMin, fTruncatedCpuTimes[i]);
-            gpuMin = SkTMin(gpuMin, fGpuTimes[i]);
-        } else {
-            SkASSERT(kAvg_Result == result);
-            wallSum += fWallTimes[i];
-            truncWallSum += fTruncatedWallTimes[i];
-            cpuSum += fCpuTimes[i];
-            truncCpuSum += fTruncatedCpuTimes[i];
-        }
-
-        // We always track the GPU sum because whether it is non-zero indicates if valid gpu times
-        // were recorded at all.
-        gpuSum += fGpuTimes[i];
-    }
-
-    if (kMin_Result == result) {
-        wallNode.append(wallMin / itersPerTiming);
-        truncWall.append(truncWallMin / itersPerTiming);
-        cpuNode.append(cpuMin / itersPerTiming);
-        truncCpu.append(truncCpuMin / itersPerTiming);
-        gpuNode.append(gpuMin / itersPerTiming);
-    } else if (kAvg_Result == result) {
-        int divisor = numTimings * itersPerTiming;
-        wallNode.append(wallSum / divisor);
-        truncWall.append(truncWallSum / divisor);
-        cpuNode.append(cpuSum / divisor);
-        truncCpu.append(truncCpuSum / divisor);
-        gpuNode.append(gpuSum / divisor);
-    }
-
-    if (timerFlags & kWall_Flag) {
-        dataNode["wall"] = wallNode;
-    }
-    if (timerFlags & kTruncatedWall_Flag) {
-        dataNode["truncWall"] = truncWall;
-    }
-    if (timerFlags & kCpu_Flag) {
-        dataNode["cpu"] = cpuNode;
-    }
-    if (timerFlags & kTruncatedCpu_Flag) {
-        dataNode["trucCpu"] = truncCpu;
-    }
-    if ((timerFlags & kGpu_Flag) && gpuSum > 0) {
-        dataNode["gpu"] = gpuNode;
-    }
-    return dataNode;
-}
diff --git a/bench/TimerData.h b/bench/TimerData.h
deleted file mode 100644 (file)
index fb84df1..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-
-/*
- * Copyright 2012 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef TimerData_DEFINED
-#define TimerData_DEFINED
-
-#include "SkString.h"
-#include "SkTemplates.h"
-
-#ifdef SK_BUILD_FOR_WIN
-    #pragma warning(push)
-    #pragma warning(disable : 4530)
-#endif
-
-#include "SkJSONCPP.h"
-
-#ifdef SK_BUILD_FOR_WIN
-    #pragma warning(pop)
-#endif
-
-class BenchTimer;
-
-class TimerData {
-public:
-    /**
-     * Constructs a TimerData to hold at most maxNumTimings sets of elapsed timer values.
-     **/
-    explicit TimerData(int maxNumTimings);
-
-    /**
-     * Collect times from the BenchTimer for an iteration. It will fail if called more often than
-     * indicated in the constructor.
-     *
-     * @param BenchTimer Must not be null.
-     */
-    bool appendTimes(BenchTimer*);
-
-    enum Result {
-        kMin_Result,
-        kAvg_Result,
-        kPerIter_Result
-    };
-
-    enum TimerFlags {
-        kWall_Flag              = 0x1,
-        kTruncatedWall_Flag     = 0x2,
-        kCpu_Flag               = 0x4,
-        kTruncatedCpu_Flag      = 0x8,
-        kGpu_Flag               = 0x10
-    };
-
-    /**
-     * Gets the timer data results as a string.
-     * @param doubleFormat printf-style format for doubles (e.g. "%02d")
-     * @param result the type of result desired
-     * @param the name of the config being timed (prepended to results string)
-     * @param timerFlags bitfield of TimerFlags values indicating which timers should be reported.
-     * @param itersPerTiming the number of test/bench iterations that correspond to each
-     *        appendTimes() call, 1 when appendTimes is called for each iteration.
-     */
-    SkString getResult(const char* doubleFormat,
-                       Result result,
-                       const char* configName,
-                       uint32_t timerFlags,
-                       int itersPerTiming = 1);
-    Json::Value getJSON(uint32_t timerFlags,
-                        Result result,
-                        int itersPerTiming = 1);
-
-private:
-    int fMaxNumTimings;
-    int fCurrTiming;
-
-    SkAutoTArray<double> fWallTimes;
-    SkAutoTArray<double> fTruncatedWallTimes;
-    SkAutoTArray<double> fCpuTimes;
-    SkAutoTArray<double> fTruncatedCpuTimes;
-    SkAutoTArray<double> fGpuTimes;
-};
-
-#endif // TimerData_DEFINED
index 6b3f5872f2c37dcc453aebef1ecc3c165861d965..5c3b7901afc913131a84ccdd7a51a6f8199159de 100644 (file)
@@ -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();
index 1873afca678d972cf7f68e9ccc125916041736c9..5cecba273c4ce9a7722161be94e05678690be7fd 100644 (file)
 __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)
index abfc8b77f9ac26ffaa207584bdf75c18adfe00f7..9ced81b98f57149e31f009c53ebc538467ffaf99 100644 (file)
         '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',
index cde87792c77dd1c844a494e3878b3d909f1568b3..b9939987b8bf764238f48f6886c55f4c7a27121a 100644 (file)
@@ -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"', {
index 15927e641300d012b57ded829cbfbad7fe72958b..1c1943705fcdd10ed7d3131f71380568243b3dc8 100644 (file)
@@ -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',
         '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',
-          ],
-        }],
-      ],
-    }
   ],
 }
diff --git a/gyp/crash_handler.gyp b/gyp/crash_handler.gyp
deleted file mode 100644 (file)
index 7e3599c..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-{
-  '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' ],
-                  }
-              },
-          }
-  }]
-}
index 84f03972df504a36f39f6598ef6f6aeb951d27b5..4add7439a8866fad8c6f4d93aa0d326b419846be 100644 (file)
@@ -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"', {
index f69ffe5f4b7192b02073971739daf9d7cf4b28e4..2d02796b457657ac512fc160626844710c12f7ba 100644 (file)
             '../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', {
index 0b0054b7018072eb41c59808809c04fd05bce0da..fd56e7eebef52890c848bc266fe7108de816662c 100644 (file)
@@ -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',
       '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', {
diff --git a/gyp/resources.gyp b/gyp/resources.gyp
deleted file mode 100644 (file)
index 48e96c3..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-# 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/',
-        ],
-      },
-    },
-  ]
-}
diff --git a/gyp/skia_launcher.gyp b/gyp/skia_launcher.gyp
new file mode 100644 (file)
index 0000000..d9970b4
--- /dev/null
@@ -0,0 +1,3 @@
+{
+  'includes': [ '../platform_tools/android/gyp/skia_launcher.gypi' ]
+}
index 80768efa35ac041f0fe98802a0a888b6da73ddba..155207ed6f38703360ecf7c448f9ce9022b32e77 100644 (file)
@@ -11,7 +11,7 @@
         'pathops_unittest.gypi',
         'tests.gypi',
       ],
-      'dependencies': [ 'crash_handler.gyp:CrashHandler' ],
+      'dependencies': [ 'tools.gyp:crash_handler' ],
       'sources': [
         '../tests/skia_test.cpp',
       ],
index 2a7dddd4ff02882b6d7196d64694533254be7dc7..f135107c34e6e21d42af97172fa673e2562fd951 100644 (file)
@@ -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',
index 5ea127296ae495935da7b0fc984ead95cda3ef51..eeb210a4970a3d15e81acff02a9c58f3d8874a97 100644 (file)
         ],
       ],
     },
+    {  # 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',
         '../src/utils/',
       ],
       'dependencies': [
+        'gm_expectations',
         'flags.gyp:flags',
-        'gm.gyp:gm_expectations',
         'jsoncpp.gyp:jsoncpp',
         'skia_lib.gyp:skia_lib',
       ],
         '../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',
       ],
     },
     {
         '../src/lazy',
       ],
       'dependencies': [
-        'bench.gyp:bench_timer',
+        'timer',
         'flags.gyp:flags',
         'skia_lib.gyp:skia_lib',
       ],
         '../src/images',
       ],
       'dependencies': [
-        'bench.gyp:bench_timer',
+        'timer',
         'flags.gyp:flags',
         'skia_lib.gyp:skia_lib',
       ],
         '../src/lazy',
       ],
       'dependencies': [
-        'bench.gyp:bench_timer',
+        'timer',
         'flags.gyp:flags',
         'skia_lib.gyp:skia_lib',
       ],
         # 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',
         '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',
index 9ebee7cc6d9a55aeeb2627dd0de69ccb9027f352..624b599bd6770687655c851fb4adb2f974161360 100644 (file)
         },
       ],
     },
-    {
-      'target_name': 'skia_launcher',
-      'type': 'executable',
-      'sources': [
-        '../launcher/skia_launcher.cpp',
-      ],
-    },
     {
       'target_name': 'SampleApp_APK',
       'type': 'none',
diff --git a/platform_tools/android/gyp/skia_launcher.gypi b/platform_tools/android/gyp/skia_launcher.gypi
new file mode 100644 (file)
index 0000000..f8b5dfd
--- /dev/null
@@ -0,0 +1,7 @@
+{
+    'targets': [{
+        'target_name': 'skia_launcher',
+        'type': 'executable',
+        'sources': [ '../launcher/skia_launcher.cpp' ],
+    }]
+}
index 2376fb9cf08b5d6edb1663d9b7e2456d8b89c752..6e679a5430a4269855c905b1e18a4b7680bd1398 100644 (file)
@@ -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();
index 30967c738141d83f3583f4e257ce089e38931e40..85a49f4e5e748c7c66cb0ab5100e0a8924ea23ac 100644 (file)
@@ -5,7 +5,7 @@
  * found in the LICENSE file.
  */
 
-#include "BenchTimer.h"
+#include "Timer.h"
 #include "PictureBenchmark.h"
 #include "SkCanvas.h"
 #include "SkPicture.h"
@@ -42,13 +42,13 @@ void PictureBenchmark::setTimersToShow(bool wall,
     fTimerTypes |= gpu ? TimerData::kGpu_Flag : 0;
 }
 
-BenchTimer* PictureBenchmark::setupTimer(bool useGLTimer) {
+Timer* PictureBenchmark::setupTimer(bool useGLTimer) {
 #if SK_SUPPORT_GPU
     if (useGLTimer && fRenderer != NULL && fRenderer->isUsingGpuDevice()) {
-        return SkNEW_ARGS(BenchTimer, (fRenderer->getGLContext()));
+        return SkNEW_ARGS(Timer, (fRenderer->getGLContext()));
     }
 #endif
-    return SkNEW_ARGS(BenchTimer, (NULL));
+    return SkNEW_ARGS(Timer, (NULL));
 }
 
 PictureRenderer* PictureBenchmark::setRenderer(sk_tools::PictureRenderer* renderer) {
@@ -147,11 +147,11 @@ void PictureBenchmark::run(SkPicture* pict) {
             // seems to cause problems (i.e., INVALID_OPERATIONs) on several
             // platforms. To work around this, we disable the gpu timer on the
             // long running timer.
-            SkAutoTDelete<BenchTimer> longRunningTimer(this->setupTimer());
+            SkAutoTDelete<Timer> longRunningTimer(this->setupTimer());
             TimerData longRunningTimerData(numOuterLoops);
 
             for (int outer = 0; outer < numOuterLoops; ++outer) {
-                SkAutoTDelete<BenchTimer> perTileTimer(this->setupTimer(false));
+                SkAutoTDelete<Timer> perTileTimer(this->setupTimer(false));
                 TimerData perTileTimerData(numInnerLoops);
 
                 longRunningTimer->start();
@@ -201,11 +201,11 @@ void PictureBenchmark::run(SkPicture* pict) {
                 numInnerLoops);
         }
     } else {
-        SkAutoTDelete<BenchTimer> longRunningTimer(this->setupTimer());
+        SkAutoTDelete<Timer> longRunningTimer(this->setupTimer());
         TimerData longRunningTimerData(numOuterLoops);
 
         for (int outer = 0; outer < numOuterLoops; ++outer) {
-            SkAutoTDelete<BenchTimer> perRunTimer(this->setupTimer(false));
+            SkAutoTDelete<Timer> perRunTimer(this->setupTimer(false));
             TimerData perRunTimerData(numInnerLoops);
 
             longRunningTimer->start();
index 142d52685e0e8b161b1de470786ac54b82cd41eb..1ddd18ea16358634a19c31fd625983402d976082 100644 (file)
@@ -13,8 +13,8 @@
 #include "SkTypes.h"
 #include "TimerData.h"
 
-class BenchTimer;
 class SkPicture;
+class Timer;
 
 namespace sk_tools {
 
@@ -67,7 +67,7 @@ private:
 
     PictureResultsWriter* fWriter;
 
-    BenchTimer* setupTimer(bool useGLTimer = true);
+    Timer* setupTimer(bool useGLTimer = true);
 };
 
 }
index e657917aad9029bf7945e76aa3bb7f92423366f0..64fc6d87d8cd52db37a54c55d33c1d259570f661 100644 (file)
@@ -5,7 +5,7 @@
  * found in the LICENSE file.
  */
 
-#include "BenchTimer.h"
+#include "Timer.h"
 #include "Benchmark.h"
 #include "LazyDecodeBitmap.h"
 #include "PictureBenchmark.h"
@@ -64,7 +64,7 @@ static void do_benchmark_work(sk_tools::PictureRenderer* renderer,
         BBoxType bBoxType,
         SkPicture* pic,
         const int numRepeats,
-        BenchTimer* timer) {
+        Timer* timer) {
     renderer->setBBoxHierarchyType(bBoxType);
     renderer->setGridSize(FLAGS_tilesize, FLAGS_tilesize);
     renderer->init(pic, NULL, NULL, NULL, false);
@@ -106,14 +106,14 @@ int tool_main(int argc, char** argv) {
             if (!includeBBoxType[bBoxType]) { continue; }
             if (FLAGS_playback > 0) {
                 sk_tools::TiledPictureRenderer playbackRenderer;
-                BenchTimer playbackTimer;
+                Timer playbackTimer;
                 do_benchmark_work(&playbackRenderer, (BBoxType)bBoxType,
                                   picture, FLAGS_playback, &playbackTimer);
                 measurement.fPlaybackAverage[bBoxType] = playbackTimer.fCpu;
             }
             if (FLAGS_record > 0) {
                 sk_tools::RecordPictureRenderer recordRenderer;
-                BenchTimer recordTimer;
+                Timer recordTimer;
                 do_benchmark_work(&recordRenderer, (BBoxType)bBoxType,
                                   picture, FLAGS_record, &recordTimer);
                 measurement.fRecordAverage[bBoxType] = recordTimer.fCpu;
index d9b767b2aa5de522911d9cab70ee7f52d7d3c9ab..503269af6a7c8a3e3bfb5388eb6de6c8c4782293 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #include "BenchLogger.h"
-#include "BenchTimer.h"
+#include "Timer.h"
 #include "CopyTilesRenderer.h"
 #include "CrashHandler.h"
 #include "LazyDecodeBitmap.h"
index 26fa1c7ee8dfa595680808f7dcb5858c7cf911b5..6ebe19d36f78e72da44b6510e96ab7bc7a08e103 100644 (file)
 
 #include "../include/record/SkRecording.h"
 
-#include "BenchTimer.h"
 #include "Stats.h"
-
-typedef WallTimer Timer;
+#include "Timer.h"
 
 __SK_FORCE_IMAGE_DECODER_LINKING;
 
@@ -78,15 +76,16 @@ static void bench(SkPMColor* scratch, SkPicture& src, const char* name) {
     // Draw once to warm any caches.  The first sample otherwise can be very noisy.
     draw(*record, *picture, canvas.get());
 
-    Timer timer;
+    WallTimer timer;
+    const double scale = timescale();
     SkAutoTMalloc<double> samples(FLAGS_samples);
     for (int i = 0; i < FLAGS_samples; i++) {
         // We assume timer overhead (typically, ~30ns) is insignificant
         // compared to draw runtime (at least ~100us, usually several ms).
-        timer.start(timescale());
+        timer.start();
         draw(*record, *picture, canvas.get());
         timer.end();
-        samples[i] = timer.fWall;
+        samples[i] = timer.fWall * scale;
     }
 
     Stats stats(samples.get(), FLAGS_samples);
index 0024c2ccdbea644eb600efec04e39672d9f76f0a..545731900bcfc288d17d564d91f0a228547171a9 100644 (file)
 #include "SkStream.h"
 #include "SkString.h"
 
-#include "BenchTimer.h"
 #include "LazyDecodeBitmap.h"
 #include "Stats.h"
-
-typedef WallTimer Timer;
+#include "Timer.h"
 
 __SK_FORCE_IMAGE_DECODER_LINKING;
 
@@ -81,12 +79,13 @@ static void bench_record(const SkPicture& src,
     rerecord(src, bbhFactory);
 
     // Rerecord once to see how many times we should loop to make timer overhead insignificant.
-    Timer timer;
+    WallTimer timer;
+    const double scale = timescale();
     do {
-        timer.start(timescale());
+        timer.start();
         rerecord(src, bbhFactory);
         timer.end();
-    } while (timer.fWall < timerOverhead);   // Loop just in case something bizarre happens.
+    } while (timer.fWall * scale < timerOverhead);  // Loop just in case something bizarre happens.
 
     // We want (timer overhead / measurement) to be less than FLAGS_overheadGoal.
     // So in each sample, we'll loop enough times to have made that true for our first measurement.
@@ -94,12 +93,12 @@ static void bench_record(const SkPicture& src,
 
     SkAutoTMalloc<double> samples(FLAGS_samples);
     for (int i = 0; i < FLAGS_samples; i++) {
-        timer.start(timescale());
+        timer.start();
         for (int j = 0; j < loops; j++) {
             rerecord(src, bbhFactory);
         }
         timer.end();
-        samples[i] = timer.fWall / loops;
+        samples[i] = timer.fWall * scale / loops;
     }
 
     Stats stats(samples.get(), FLAGS_samples);
@@ -132,12 +131,13 @@ int tool_main(int argc, char** argv) {
 
     // Each run will use this timer overhead estimate to guess how many times it should run.
     static const int kOverheadLoops = 10000000;
-    Timer timer;
+    WallTimer timer;
     double overheadEstimate = 0.0;
+    const double scale = timescale();
     for (int i = 0; i < kOverheadLoops; i++) {
-        timer.start(timescale());
+        timer.start();
         timer.end();
-        overheadEstimate += timer.fWall;
+        overheadEstimate += timer.fWall * scale;
     }
     overheadEstimate /= kOverheadLoops;
 
index 171721c3be91f105d1c175356bd891961de799da..983bee20b3a2f96234db62495d564de5e2bdcd27 100644 (file)
@@ -83,7 +83,7 @@ const char* cl_error_to_string(cl_int err) {
 }
 #endif
 
-// TODO refactor BenchTimer to be used here
+// TODO refactor Timer to be used here
 double get_seconds() {
 #if SK_BUILD_FOR_WIN32
     LARGE_INTEGER currentTime;
diff --git a/tools/timer/GpuTimer.cpp b/tools/timer/GpuTimer.cpp
new file mode 100644 (file)
index 0000000..aac10a3
--- /dev/null
@@ -0,0 +1,77 @@
+
+/*
+ * 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 "GpuTimer.h"
+#include "gl/SkGLContextHelper.h"
+#include "gl/GrGLUtil.h"
+
+GpuTimer::GpuTimer(const SkGLContextHelper* glctx) : fContext(glctx) {
+    if (fContext) {
+        fContext->ref();
+        fContext->makeCurrent();
+        fStarted = false;
+        fSupported = GrGLGetVersion(fContext->gl()) > GR_GL_VER(3,3) ||
+                     fContext->hasExtension("GL_ARB_timer_query") ||
+                     fContext->hasExtension("GL_EXT_timer_query");
+
+        if (fSupported) {
+            SK_GL(*fContext, GenQueries(1, &fQuery));
+        }
+    }
+}
+
+GpuTimer::~GpuTimer() {
+    if (fContext) {
+        if (fSupported) {
+            fContext->makeCurrent();
+            SK_GL(*fContext, DeleteQueries(1, &fQuery));
+        }
+        fContext->unref();
+    }
+}
+
+void GpuTimer::start() {
+    if (fContext && fSupported) {
+        fContext->makeCurrent();
+        fStarted = true;
+        SK_GL(*fContext, BeginQuery(GR_GL_TIME_ELAPSED, fQuery));
+    }
+}
+
+/**
+ * It is important to stop the cpu clocks first,
+ * as this will cpu wait for the gpu to finish.
+ */
+double GpuTimer::end() {
+    if (fContext && fSupported) {
+        fStarted = false;
+        fContext->makeCurrent();
+        SK_GL(*fContext, EndQuery(GR_GL_TIME_ELAPSED));
+
+        GrGLint available = 0;
+        while (!available) {
+            SK_GL_NOERRCHECK(*fContext, GetQueryObjectiv(fQuery,
+                                                         GR_GL_QUERY_RESULT_AVAILABLE,
+                                                         &available));
+            // If GetQueryObjectiv is erroring out we need some alternative
+            // means of breaking out of this loop
+            GrGLenum error;
+            SK_GL_RET_NOERRCHECK(*fContext, error, GetError());
+            if (GR_GL_NO_ERROR != error) {
+                break;
+            }
+        }
+        GrGLuint64 totalGPUTimeElapsed = 0;
+        SK_GL(*fContext, GetQueryObjectui64v(fQuery,
+                                             GR_GL_QUERY_RESULT,
+                                             &totalGPUTimeElapsed));
+
+        return totalGPUTimeElapsed / 1000000.0;
+    } else {
+        return 0;
+    }
+}
diff --git a/tools/timer/GpuTimer.h b/tools/timer/GpuTimer.h
new file mode 100644 (file)
index 0000000..2100312
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * 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 GpuTimer_DEFINED
+#define GpuTimer_DEFINED
+
+class SkGLContextHelper;
+
+class GpuTimer {
+public:
+    GpuTimer(const SkGLContextHelper*);
+    ~GpuTimer();
+    void start();
+    double end();
+private:
+    unsigned fQuery;
+    int fStarted;
+    const SkGLContextHelper* fContext;
+    bool fSupported;
+};
+
+#endif
diff --git a/tools/timer/SysTimer_mach.cpp b/tools/timer/SysTimer_mach.cpp
new file mode 100644 (file)
index 0000000..aca12de
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * 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 "SysTimer_mach.h"
+
+static time_value_t mac_cpu_time() {
+    mach_port_t task = mach_task_self();
+    if (task == MACH_PORT_NULL) {
+        time_value_t none = {0, 0};
+        return none;
+    }
+
+    task_thread_times_info thread_info_data;
+    mach_msg_type_number_t thread_info_count = TASK_THREAD_TIMES_INFO_COUNT;
+    if (KERN_SUCCESS != task_info(task,
+                                  TASK_THREAD_TIMES_INFO,
+                                  reinterpret_cast<task_info_t>(&thread_info_data),
+                                  &thread_info_count)) {
+        time_value_t none = {0, 0};
+        return none;
+    }
+
+    time_value_add(&thread_info_data.user_time, &thread_info_data.system_time)
+    return thread_info_data.user_time;
+}
+
+static double interval_in_ms(time_value_t start_clock, time_value_t end_clock) {
+    double duration_clock;
+    if ((end_clock.microseconds - start_clock.microseconds) < 0) {
+        duration_clock = (end_clock.seconds - start_clock.seconds-1) * 1000;
+        duration_clock += (1000000 + end_clock.microseconds - start_clock.microseconds) / 1000.0;
+    } else {
+        duration_clock = (end_clock.seconds - start_clock.seconds) * 1000;
+        duration_clock += (end_clock.microseconds - start_clock.microseconds) / 1000.0;
+    }
+    return duration_clock;
+}
+
+void SysTimer::startWall() {
+    fStartWall = mach_absolute_time();
+}
+
+void SysTimer::startCpu() {
+    fStartCpu = mac_cpu_time();
+}
+
+double SysTimer::endCpu() {
+    time_value_t end_cpu = mac_cpu_time();
+    return interval_in_ms(fStartCpu, end_cpu);
+}
+
+double SysTimer::endWall() {
+    uint64_t end_wall = mach_absolute_time();
+
+    uint64_t elapsed = end_wall - fStartWall;
+    mach_timebase_info_data_t sTimebaseInfo;
+    if (KERN_SUCCESS != mach_timebase_info(&sTimebaseInfo)) {
+        return 0;
+    } else {
+        uint64_t elapsedNano = elapsed * sTimebaseInfo.numer / sTimebaseInfo.denom;
+        return elapsedNano / 1000000.0;
+    }
+}
diff --git a/tools/timer/SysTimer_mach.h b/tools/timer/SysTimer_mach.h
new file mode 100644 (file)
index 0000000..8c21d57
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * 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 SysTimer_DEFINED
+#define SysTimer_DEFINED
+
+#include <mach/mach.h>
+#include <mach/mach_time.h>
+
+class SysTimer {
+public:
+    void startWall();
+    void startCpu();
+    double endCpu();
+    double endWall();
+private:
+    time_value_t fStartCpu;
+    uint64_t fStartWall;
+};
+
+#endif
diff --git a/tools/timer/SysTimer_posix.cpp b/tools/timer/SysTimer_posix.cpp
new file mode 100644 (file)
index 0000000..4b7d708
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * 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 "SysTimer_posix.h"
+
+static double interval_in_ms(timespec start_clock, timespec end_clock)
+{
+    double duration_clock;
+    if ((end_clock.tv_nsec - start_clock.tv_nsec) < 0) {
+        duration_clock = (end_clock.tv_sec - start_clock.tv_sec - 1) * 1000;
+        duration_clock += (1000000000 + end_clock.tv_nsec - start_clock.tv_nsec) / 1000000.0;
+    } else {
+        duration_clock = (end_clock.tv_sec - start_clock.tv_sec) * 1000;
+        duration_clock += (end_clock.tv_nsec - start_clock.tv_nsec) / 1000000.0;
+    }
+    return duration_clock;
+}
+
+void SysTimer::startWall() {
+    if (-1 == clock_gettime(CLOCK_MONOTONIC, &fWall)) {
+        timespec none = {0, 0};
+        fWall = none;
+    }
+}
+void SysTimer::startCpu() {
+    if (-1 == clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &fCpu)) {
+        timespec none = {0, 0};
+        fCpu = none;
+    }
+}
+
+double SysTimer::endCpu() {
+    timespec end_cpu;
+    if (-1 == clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end_cpu)) {
+        timespec none = {0, 0};
+        end_cpu = none;
+    }
+    return interval_in_ms(fCpu, end_cpu);
+}
+
+double SysTimer::endWall() {
+    timespec end_wall;
+    if (-1 == clock_gettime(CLOCK_MONOTONIC, &end_wall)) {
+        timespec none = {0, 0};
+        end_wall = none;
+    }
+    return interval_in_ms(fWall, end_wall);
+}
diff --git a/tools/timer/SysTimer_posix.h b/tools/timer/SysTimer_posix.h
new file mode 100644 (file)
index 0000000..1eca909
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * 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 SysTimer_DEFINED
+#define SysTimer_DEFINED
+
+#include <time.h>
+
+class SysTimer {
+public:
+    void startWall();
+    void startCpu();
+    double endCpu();
+    double endWall();
+private:
+    timespec fCpu;
+    timespec fWall;
+};
+
+#endif
diff --git a/tools/timer/SysTimer_windows.cpp b/tools/timer/SysTimer_windows.cpp
new file mode 100644 (file)
index 0000000..2f9d0a5
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * 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 "SysTimer_windows.h"
+
+static ULONGLONG win_cpu_time() {
+    FILETIME createTime;
+    FILETIME exitTime;
+    FILETIME usrTime;
+    FILETIME sysTime;
+    if (0 == GetProcessTimes(GetCurrentProcess(), &createTime, &exitTime, &sysTime, &usrTime)) {
+        return 0;
+    }
+    ULARGE_INTEGER start_cpu_sys;
+    ULARGE_INTEGER start_cpu_usr;
+    start_cpu_sys.LowPart  = sysTime.dwLowDateTime;
+    start_cpu_sys.HighPart = sysTime.dwHighDateTime;
+    start_cpu_usr.LowPart  = usrTime.dwLowDateTime;
+    start_cpu_usr.HighPart = usrTime.dwHighDateTime;
+    return start_cpu_sys.QuadPart + start_cpu_usr.QuadPart;
+}
+
+void SysTimer::startWall() {
+    if (0 == ::QueryPerformanceCounter(&fStartWall)) {
+        fStartWall.QuadPart = 0;
+    }
+}
+void SysTimer::startCpu() {
+    fStartCpu = win_cpu_time();
+}
+
+double SysTimer::endCpu() {
+    ULONGLONG end_cpu = win_cpu_time();
+    return static_cast<double>(end_cpu - fStartCpu) / 10000.0L;
+}
+double SysTimer::endWall() {
+    LARGE_INTEGER end_wall;
+    if (0 == ::QueryPerformanceCounter(&end_wall)) {
+        end_wall.QuadPart = 0;
+    }
+
+    LARGE_INTEGER ticks_elapsed;
+    ticks_elapsed.QuadPart = end_wall.QuadPart - fStartWall.QuadPart;
+
+    LARGE_INTEGER frequency;
+    if (0 == ::QueryPerformanceFrequency(&frequency)) {
+        return 0.0L;
+    } else {
+        return static_cast<double>(ticks_elapsed.QuadPart)
+             / static_cast<double>(frequency.QuadPart)
+             * 1000.0L;
+    }
+}
diff --git a/tools/timer/SysTimer_windows.h b/tools/timer/SysTimer_windows.h
new file mode 100644 (file)
index 0000000..62a9445
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * 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 SysTimer_DEFINED
+#define SysTimer_DEFINED
+
+//Time
+#define WIN32_LEAN_AND_MEAN 1
+#include <windows.h>
+
+class SysTimer {
+public:
+    void startWall();
+    void startCpu();
+    double endCpu();
+    double endWall();
+private:
+    ULONGLONG fStartCpu;
+    LARGE_INTEGER fStartWall;
+};
+
+#endif
diff --git a/tools/timer/Timer.cpp b/tools/timer/Timer.cpp
new file mode 100644 (file)
index 0000000..4f3fc85
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * 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 "Timer.h"
+
+Timer::Timer(SkGLContextHelper* gl)
+        : fCpu(-1.0)
+        , fWall(-1.0)
+        , fTruncatedCpu(-1.0)
+        , fTruncatedWall(-1.0)
+        , fGpu(-1.0)
+#if SK_SUPPORT_GPU
+        , fGpuTimer(gl)
+#endif
+        {}
+
+void Timer::start() {
+    fSysTimer.startWall();
+    fTruncatedSysTimer.startWall();
+#if SK_SUPPORT_GPU
+    fGpuTimer.start();
+#endif
+    fSysTimer.startCpu();
+    fTruncatedSysTimer.startCpu();
+}
+
+void Timer::end() {
+    fCpu = fSysTimer.endCpu();
+#if SK_SUPPORT_GPU
+    //It is important to stop the cpu clocks first,
+    //as the following will cpu wait for the gpu to finish.
+    fGpu = fGpuTimer.end();
+#endif
+    fWall = fSysTimer.endWall();
+}
+
+void Timer::truncatedEnd() {
+    fTruncatedCpu = fTruncatedSysTimer.endCpu();
+    fTruncatedWall = fTruncatedSysTimer.endWall();
+}
+
+WallTimer::WallTimer() : fWall(-1.0) {}
+
+void WallTimer::start() {
+    fSysTimer.startWall();
+}
+
+void WallTimer::end() {
+    fWall = fSysTimer.endWall();
+}
diff --git a/tools/timer/Timer.h b/tools/timer/Timer.h
new file mode 100644 (file)
index 0000000..15c93f5
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * 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 Timer_DEFINED
+#define Timer_DEFINED
+
+#include "SkTypes.h"
+
+#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
+
+#if SK_SUPPORT_GPU
+    #include "GpuTimer.h"
+#endif
+
+class SkGLContextHelper;
+
+/**
+ * SysTimers and GpuTimers are implemented orthogonally.
+ * 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.
+ */
+class Timer {
+public:
+    explicit Timer(SkGLContextHelper* gl = NULL);
+
+    void start();
+    void truncatedEnd();
+    void end();
+
+    // All times in milliseconds.
+    double fCpu;
+    double fWall;
+    double fTruncatedCpu;
+    double fTruncatedWall;
+    double fGpu;
+
+private:
+    SysTimer fSysTimer;
+    SysTimer fTruncatedSysTimer;
+#if SK_SUPPORT_GPU
+    GpuTimer fGpuTimer;
+#endif
+};
+
+// Same as Timer above, supporting only fWall but with much lower overhead.
+// (Typically, ~30ns instead of Timer's ~1us.)
+class WallTimer {
+public:
+    WallTimer();
+
+    void start();
+    void end();
+
+    double fWall;  // Milliseconds.
+
+private:
+    SysTimer fSysTimer;
+};
+
+#endif
diff --git a/tools/timer/TimerData.cpp b/tools/timer/TimerData.cpp
new file mode 100644 (file)
index 0000000..21529bc
--- /dev/null
@@ -0,0 +1,220 @@
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include "TimerData.h"
+
+#include "Timer.h"
+#include <limits>
+
+TimerData::TimerData(int maxNumTimings)
+    : fMaxNumTimings(maxNumTimings)
+    , fCurrTiming(0)
+    , fWallTimes(maxNumTimings)
+    , fTruncatedWallTimes(maxNumTimings)
+    , fCpuTimes(maxNumTimings)
+    , fTruncatedCpuTimes(maxNumTimings)
+    , fGpuTimes(maxNumTimings) {}
+
+bool TimerData::appendTimes(Timer* timer) {
+    SkASSERT(timer != NULL);
+    if (fCurrTiming >= fMaxNumTimings) {
+        return false;
+    }
+
+    fWallTimes[fCurrTiming] = timer->fWall;
+    fTruncatedWallTimes[fCurrTiming] = timer->fTruncatedWall;
+    fCpuTimes[fCurrTiming] = timer->fCpu;
+    fTruncatedCpuTimes[fCurrTiming] = timer->fTruncatedCpu;
+    fGpuTimes[fCurrTiming] = timer->fGpu;
+
+    ++fCurrTiming;
+
+    return true;
+}
+
+SkString TimerData::getResult(const char* doubleFormat,
+                              Result result,
+                              const char *configName,
+                              uint32_t timerFlags,
+                              int itersPerTiming) {
+    SkASSERT(itersPerTiming >= 1);
+
+    if (!fCurrTiming) {
+        return SkString("");
+    }
+
+    int numTimings = fCurrTiming;
+
+    SkString wallStr(" msecs = ");
+    SkString truncWallStr(" Wmsecs = ");
+    SkString cpuStr(" cmsecs = ");
+    SkString truncCpuStr(" Cmsecs = ");
+    SkString gpuStr(" gmsecs = ");
+
+    double wallMin = std::numeric_limits<double>::max();
+    double truncWallMin = std::numeric_limits<double>::max();
+    double cpuMin = std::numeric_limits<double>::max();
+    double truncCpuMin = std::numeric_limits<double>::max();
+    double gpuMin = std::numeric_limits<double>::max();
+
+    double wallSum = 0;
+    double truncWallSum = 0;
+    double cpuSum = 0;
+    double truncCpuSum = 0;
+    double gpuSum = 0;
+
+    for (int i = 0; i < numTimings; ++i) {
+        if (kPerIter_Result == result) {
+            wallStr.appendf(doubleFormat, fWallTimes[i] / itersPerTiming);
+            truncWallStr.appendf(doubleFormat, fTruncatedWallTimes[i] / itersPerTiming);
+            cpuStr.appendf(doubleFormat, fCpuTimes[i] / itersPerTiming);
+            truncCpuStr.appendf(doubleFormat, fTruncatedCpuTimes[i] / itersPerTiming);
+            gpuStr.appendf(doubleFormat, fGpuTimes[i] / itersPerTiming);
+
+            if (i != numTimings - 1) {
+                static const char kSep[] = ", ";
+                wallStr.append(kSep);
+                truncWallStr.append(kSep);
+                cpuStr.append(kSep);
+                truncCpuStr.append(kSep);
+                gpuStr.append(kSep);
+            }
+        } else if (kMin_Result == result) {
+            wallMin = SkTMin(wallMin, fWallTimes[i]);
+            truncWallMin = SkTMin(truncWallMin, fTruncatedWallTimes[i]);
+            cpuMin = SkTMin(cpuMin, fCpuTimes[i]);
+            truncCpuMin = SkTMin(truncCpuMin, fTruncatedCpuTimes[i]);
+            gpuMin = SkTMin(gpuMin, fGpuTimes[i]);
+        } else {
+            SkASSERT(kAvg_Result == result);
+            wallSum += fWallTimes[i];
+            truncWallSum += fTruncatedWallTimes[i];
+            cpuSum += fCpuTimes[i];
+            truncCpuSum += fTruncatedCpuTimes[i];
+        }
+
+        // We always track the GPU sum because whether it is non-zero indicates if valid gpu times
+        // were recorded at all.
+        gpuSum += fGpuTimes[i];
+    }
+
+    if (kMin_Result == result) {
+        wallStr.appendf(doubleFormat, wallMin / itersPerTiming);
+        truncWallStr.appendf(doubleFormat, truncWallMin / itersPerTiming);
+        cpuStr.appendf(doubleFormat, cpuMin / itersPerTiming);
+        truncCpuStr.appendf(doubleFormat, truncCpuMin / itersPerTiming);
+        gpuStr.appendf(doubleFormat, gpuMin / itersPerTiming);
+    } else if (kAvg_Result == result) {
+        int divisor = numTimings * itersPerTiming;
+        wallStr.appendf(doubleFormat, wallSum / divisor);
+        truncWallStr.appendf(doubleFormat, truncWallSum / divisor);
+        cpuStr.appendf(doubleFormat, cpuSum / divisor);
+        truncCpuStr.appendf(doubleFormat, truncCpuSum / divisor);
+        gpuStr.appendf(doubleFormat, gpuSum / divisor);
+    }
+
+    SkString str;
+    str.printf("  %4s:", configName);
+    if (timerFlags & kWall_Flag) {
+        str += wallStr;
+    }
+    if (timerFlags & kTruncatedWall_Flag) {
+        str += truncWallStr;
+    }
+    if (timerFlags & kCpu_Flag) {
+        str += cpuStr;
+    }
+    if (timerFlags & kTruncatedCpu_Flag) {
+        str += truncCpuStr;
+    }
+    if ((timerFlags & kGpu_Flag) && gpuSum > 0) {
+        str += gpuStr;
+    }
+    return str;
+}
+
+Json::Value TimerData::getJSON(uint32_t timerFlags,
+                               Result result,
+                               int itersPerTiming) {
+    SkASSERT(itersPerTiming >= 1);
+    Json::Value dataNode;
+    Json::Value wallNode, truncWall, cpuNode, truncCpu, gpuNode;
+    if (!fCurrTiming) {
+        return dataNode;
+    }
+
+    int numTimings = fCurrTiming;
+
+    double wallMin = std::numeric_limits<double>::max();
+    double truncWallMin = std::numeric_limits<double>::max();
+    double cpuMin = std::numeric_limits<double>::max();
+    double truncCpuMin = std::numeric_limits<double>::max();
+    double gpuMin = std::numeric_limits<double>::max();
+
+    double wallSum = 0;
+    double truncWallSum = 0;
+    double cpuSum = 0;
+    double truncCpuSum = 0;
+    double gpuSum = 0;
+
+    for (int i = 0; i < numTimings; ++i) {
+        if (kPerIter_Result == result) {
+            wallNode.append(fWallTimes[i] / itersPerTiming);
+            truncWall.append(fTruncatedWallTimes[i] / itersPerTiming);
+            cpuNode.append(fCpuTimes[i] / itersPerTiming);
+            truncCpu.append(fTruncatedCpuTimes[i] / itersPerTiming);
+            gpuNode.append(fGpuTimes[i] / itersPerTiming);
+        } else if (kMin_Result == result) {
+            wallMin = SkTMin(wallMin, fWallTimes[i]);
+            truncWallMin = SkTMin(truncWallMin, fTruncatedWallTimes[i]);
+            cpuMin = SkTMin(cpuMin, fCpuTimes[i]);
+            truncCpuMin = SkTMin(truncCpuMin, fTruncatedCpuTimes[i]);
+            gpuMin = SkTMin(gpuMin, fGpuTimes[i]);
+        } else {
+            SkASSERT(kAvg_Result == result);
+            wallSum += fWallTimes[i];
+            truncWallSum += fTruncatedWallTimes[i];
+            cpuSum += fCpuTimes[i];
+            truncCpuSum += fTruncatedCpuTimes[i];
+        }
+
+        // We always track the GPU sum because whether it is non-zero indicates if valid gpu times
+        // were recorded at all.
+        gpuSum += fGpuTimes[i];
+    }
+
+    if (kMin_Result == result) {
+        wallNode.append(wallMin / itersPerTiming);
+        truncWall.append(truncWallMin / itersPerTiming);
+        cpuNode.append(cpuMin / itersPerTiming);
+        truncCpu.append(truncCpuMin / itersPerTiming);
+        gpuNode.append(gpuMin / itersPerTiming);
+    } else if (kAvg_Result == result) {
+        int divisor = numTimings * itersPerTiming;
+        wallNode.append(wallSum / divisor);
+        truncWall.append(truncWallSum / divisor);
+        cpuNode.append(cpuSum / divisor);
+        truncCpu.append(truncCpuSum / divisor);
+        gpuNode.append(gpuSum / divisor);
+    }
+
+    if (timerFlags & kWall_Flag) {
+        dataNode["wall"] = wallNode;
+    }
+    if (timerFlags & kTruncatedWall_Flag) {
+        dataNode["truncWall"] = truncWall;
+    }
+    if (timerFlags & kCpu_Flag) {
+        dataNode["cpu"] = cpuNode;
+    }
+    if (timerFlags & kTruncatedCpu_Flag) {
+        dataNode["trucCpu"] = truncCpu;
+    }
+    if ((timerFlags & kGpu_Flag) && gpuSum > 0) {
+        dataNode["gpu"] = gpuNode;
+    }
+    return dataNode;
+}
diff --git a/tools/timer/TimerData.h b/tools/timer/TimerData.h
new file mode 100644 (file)
index 0000000..35e94dc
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef TimerData_DEFINED
+#define TimerData_DEFINED
+
+#include "SkString.h"
+#include "SkTemplates.h"
+
+#ifdef SK_BUILD_FOR_WIN
+    #pragma warning(push)
+    #pragma warning(disable : 4530)
+#endif
+
+#include "SkJSONCPP.h"
+
+#ifdef SK_BUILD_FOR_WIN
+    #pragma warning(pop)
+#endif
+
+class Timer;
+
+class TimerData {
+public:
+    /**
+     * Constructs a TimerData to hold at most maxNumTimings sets of elapsed timer values.
+     **/
+    explicit TimerData(int maxNumTimings);
+
+    /**
+     * Collect times from the Timer for an iteration. It will fail if called more often than
+     * indicated in the constructor.
+     *
+     * @param Timer Must not be null.
+     */
+    bool appendTimes(Timer*);
+
+    enum Result {
+        kMin_Result,
+        kAvg_Result,
+        kPerIter_Result
+    };
+
+    enum TimerFlags {
+        kWall_Flag              = 0x1,
+        kTruncatedWall_Flag     = 0x2,
+        kCpu_Flag               = 0x4,
+        kTruncatedCpu_Flag      = 0x8,
+        kGpu_Flag               = 0x10
+    };
+
+    /**
+     * Gets the timer data results as a string.
+     * @param doubleFormat printf-style format for doubles (e.g. "%02d")
+     * @param result the type of result desired
+     * @param the name of the config being timed (prepended to results string)
+     * @param timerFlags bitfield of TimerFlags values indicating which timers should be reported.
+     * @param itersPerTiming the number of test/bench iterations that correspond to each
+     *        appendTimes() call, 1 when appendTimes is called for each iteration.
+     */
+    SkString getResult(const char* doubleFormat,
+                       Result result,
+                       const char* configName,
+                       uint32_t timerFlags,
+                       int itersPerTiming = 1);
+    Json::Value getJSON(uint32_t timerFlags,
+                        Result result,
+                        int itersPerTiming = 1);
+
+private:
+    int fMaxNumTimings;
+    int fCurrTiming;
+
+    SkAutoTArray<double> fWallTimes;
+    SkAutoTArray<double> fTruncatedWallTimes;
+    SkAutoTArray<double> fCpuTimes;
+    SkAutoTArray<double> fTruncatedCpuTimes;
+    SkAutoTArray<double> fGpuTimes;
+};
+
+#endif // TimerData_DEFINED