Skip to content

Commit 109c03d

Browse files
andrewharptensorflower-gardener
authored andcommitted
Android: add Timer utility class for measuring cpu and wall time.
Change: 143498460
1 parent 35f8b1f commit 109c03d

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/* Copyright 2016 The TensorFlow Authors. All Rights Reserved.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
==============================================================================*/
15+
16+
package org.tensorflow.demo.env;
17+
18+
import android.os.SystemClock;
19+
20+
/**
21+
* A simple utility timer for measuring CPU time and wall-clock splits.
22+
*/
23+
public class SplitTimer {
24+
private final Logger logger;
25+
26+
private long lastWallTime;
27+
private long lastCpuTime;
28+
29+
public SplitTimer(final String name) {
30+
logger = new Logger(name);
31+
newSplit();
32+
}
33+
34+
public void newSplit() {
35+
lastWallTime = SystemClock.uptimeMillis();
36+
lastCpuTime = SystemClock.currentThreadTimeMillis();
37+
}
38+
39+
public void endSplit(final String splitName) {
40+
final long currWallTime = SystemClock.uptimeMillis();
41+
final long currCpuTime = SystemClock.currentThreadTimeMillis();
42+
43+
logger.i(
44+
"%s: cpu=%dms wall=%dms",
45+
splitName, currCpuTime - lastCpuTime, currWallTime - lastWallTime);
46+
47+
lastWallTime = currWallTime;
48+
lastCpuTime = currCpuTime;
49+
}
50+
}

0 commit comments

Comments
 (0)