Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(442)

Side by Side Diff: tools/timer/Timer.cpp

Issue 1422513003: SkTime::GetNSecs() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: #else std::chrono Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/timer/Timer.h ('k') | tools/timer/TimerData.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 #include "Timer.h" 7 #include "Timer.h"
8 8
9 Timer::Timer(SkGLContext* gl)
10 : fCpu(-1.0)
11 , fWall(-1.0)
12 , fTruncatedCpu(-1.0)
13 , fTruncatedWall(-1.0)
14 , fGpu(-1.0)
15 #if SK_SUPPORT_GPU
16 , fGpuTimer(gl)
17 #endif
18 {}
19
20 void Timer::start() {
21 fSysTimer.startWall();
22 fTruncatedSysTimer.startWall();
23 #if SK_SUPPORT_GPU
24 fGpuTimer.start();
25 #endif
26 fSysTimer.startCpu();
27 fTruncatedSysTimer.startCpu();
28 }
29
30 void Timer::end() {
31 fCpu = fSysTimer.endCpu();
32 #if SK_SUPPORT_GPU
33 //It is important to stop the cpu clocks first,
34 //as the following will cpu wait for the gpu to finish.
35 fGpu = fGpuTimer.end();
36 #endif
37 fWall = fSysTimer.endWall();
38 }
39
40 void Timer::truncatedEnd() {
41 fTruncatedCpu = fTruncatedSysTimer.endCpu();
42 fTruncatedWall = fTruncatedSysTimer.endWall();
43 }
44
45 WallTimer::WallTimer() : fWall(-1.0) {}
46
47 void WallTimer::start() {
48 fSysTimer.startWall();
49 }
50
51 void WallTimer::end() {
52 fWall = fSysTimer.endWall();
53 }
54
55 SkString HumanizeMs(double ms) { 9 SkString HumanizeMs(double ms) {
56 if (ms > 60e+3) return SkStringPrintf("%.3gm", ms/60e+3); 10 if (ms > 60e+3) return SkStringPrintf("%.3gm", ms/60e+3);
57 if (ms > 1e+3) return SkStringPrintf("%.3gs", ms/1e+3); 11 if (ms > 1e+3) return SkStringPrintf("%.3gs", ms/1e+3);
58 if (ms < 1e-3) return SkStringPrintf("%.3gns", ms*1e+6); 12 if (ms < 1e-3) return SkStringPrintf("%.3gns", ms*1e+6);
59 #ifdef SK_BUILD_FOR_WIN 13 #ifdef SK_BUILD_FOR_WIN
60 if (ms < 1) return SkStringPrintf("%.3gus", ms*1e+3); 14 if (ms < 1) return SkStringPrintf("%.3gus", ms*1e+3);
61 #else 15 #else
62 if (ms < 1) return SkStringPrintf("%.3gµs", ms*1e+3); 16 if (ms < 1) return SkStringPrintf("%.3gµs", ms*1e+3);
63 #endif 17 #endif
64 return SkStringPrintf("%.3gms", ms); 18 return SkStringPrintf("%.3gms", ms);
65 } 19 }
OLDNEW
« no previous file with comments | « tools/timer/Timer.h ('k') | tools/timer/TimerData.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698