blob: 4e0484459d1b9c926446a4c75613251ec008d65d [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
bungeman@google.combe9ad4e2011-06-07 19:16:02 +00008#include "BenchTimer.h"
9#if defined(SK_BUILD_FOR_WIN32)
10 #include "BenchSysTimer_windows.h"
11#elif defined(SK_BUILD_FOR_MAC)
12 #include "BenchSysTimer_mach.h"
djsollen@google.com58629292011-11-03 13:08:29 +000013#elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID)
bungeman@google.combe9ad4e2011-06-07 19:16:02 +000014 #include "BenchSysTimer_posix.h"
15#else
16 #include "BenchSysTimer_c.h"
17#endif
18
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000019#if SK_SUPPORT_GPU
bsalomon@google.com373a6632011-10-19 20:43:20 +000020#include "BenchGpuTimer_gl.h"
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000021#endif
bungeman@google.combe9ad4e2011-06-07 19:16:02 +000022
bsalomon@google.com373a6632011-10-19 20:43:20 +000023BenchTimer::BenchTimer(SkGLContext* gl)
bungeman@google.combe9ad4e2011-06-07 19:16:02 +000024 : fCpu(-1.0)
25 , fWall(-1.0)
robertphillips@google.com91ee3a12012-08-28 12:18:40 +000026 , fTruncatedCpu(-1.0)
27 , fTruncatedWall(-1.0)
bungeman@google.combe9ad4e2011-06-07 19:16:02 +000028 , fGpu(-1.0)
29{
bsalomon@google.com373a6632011-10-19 20:43:20 +000030 fSysTimer = new BenchSysTimer();
robertphillips@google.com91ee3a12012-08-28 12:18:40 +000031 fTruncatedSysTimer = new BenchSysTimer();
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000032#if SK_SUPPORT_GPU
bsalomon@google.com373a6632011-10-19 20:43:20 +000033 if (gl) {
34 fGpuTimer = new BenchGpuTimer(gl);
35 } else {
36 fGpuTimer = NULL;
37 }
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000038#endif
bungeman@google.combe9ad4e2011-06-07 19:16:02 +000039}
40
41BenchTimer::~BenchTimer() {
bsalomon@google.com373a6632011-10-19 20:43:20 +000042 delete fSysTimer;
robertphillips@google.com91ee3a12012-08-28 12:18:40 +000043 delete fTruncatedSysTimer;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000044#if SK_SUPPORT_GPU
bsalomon@google.com373a6632011-10-19 20:43:20 +000045 delete fGpuTimer;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000046#endif
bungeman@google.combe9ad4e2011-06-07 19:16:02 +000047}
48
49void BenchTimer::start() {
bsalomon@google.com373a6632011-10-19 20:43:20 +000050 fSysTimer->startWall();
robertphillips@google.com91ee3a12012-08-28 12:18:40 +000051 fTruncatedSysTimer->startWall();
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000052#if SK_SUPPORT_GPU
bsalomon@google.com373a6632011-10-19 20:43:20 +000053 if (fGpuTimer) {
54 fGpuTimer->startGpu();
55 }
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000056#endif
bsalomon@google.com373a6632011-10-19 20:43:20 +000057 fSysTimer->startCpu();
robertphillips@google.com91ee3a12012-08-28 12:18:40 +000058 fTruncatedSysTimer->startCpu();
bungeman@google.combe9ad4e2011-06-07 19:16:02 +000059}
60
61void BenchTimer::end() {
bsalomon@google.com373a6632011-10-19 20:43:20 +000062 fCpu = fSysTimer->endCpu();
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000063#if SK_SUPPORT_GPU
bungeman@google.combe9ad4e2011-06-07 19:16:02 +000064 //It is important to stop the cpu clocks first,
65 //as the following will cpu wait for the gpu to finish.
bsalomon@google.com373a6632011-10-19 20:43:20 +000066 if (fGpuTimer) {
67 fGpu = fGpuTimer->endGpu();
68 }
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000069#endif
bsalomon@google.com373a6632011-10-19 20:43:20 +000070 fWall = fSysTimer->endWall();
bungeman@google.combe9ad4e2011-06-07 19:16:02 +000071}
robertphillips@google.com91ee3a12012-08-28 12:18:40 +000072
73void BenchTimer::truncatedEnd() {
74 fTruncatedCpu = fTruncatedSysTimer->endCpu();
75 fTruncatedWall = fTruncatedSysTimer->endWall();
76}