aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/examples/android
diff options
context:
space:
mode:
authorGravatar Andrew Harp <andrewharp@google.com>2017-01-03 16:20:40 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2017-01-03 16:28:45 -0800
commit109c03d94b50d7da10fa0ccefab8110072f8e583 (patch)
treed32097747cff73b19a6750225339f4c4261a3bfe /tensorflow/examples/android
parent35f8b1fe2c097ce97b5b465a67f312e92a62f162 (diff)
Android: add Timer utility class for measuring cpu and wall time.
Change: 143498460
Diffstat (limited to 'tensorflow/examples/android')
-rw-r--r--tensorflow/examples/android/src/org/tensorflow/demo/env/SplitTimer.java50
1 files changed, 50 insertions, 0 deletions
diff --git a/tensorflow/examples/android/src/org/tensorflow/demo/env/SplitTimer.java b/tensorflow/examples/android/src/org/tensorflow/demo/env/SplitTimer.java
new file mode 100644
index 0000000000..459b0a0d4d
--- /dev/null
+++ b/tensorflow/examples/android/src/org/tensorflow/demo/env/SplitTimer.java
@@ -0,0 +1,50 @@
+/* Copyright 2016 The TensorFlow Authors. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+==============================================================================*/
+
+package org.tensorflow.demo.env;
+
+import android.os.SystemClock;
+
+/**
+ * A simple utility timer for measuring CPU time and wall-clock splits.
+ */
+public class SplitTimer {
+ private final Logger logger;
+
+ private long lastWallTime;
+ private long lastCpuTime;
+
+ public SplitTimer(final String name) {
+ logger = new Logger(name);
+ newSplit();
+ }
+
+ public void newSplit() {
+ lastWallTime = SystemClock.uptimeMillis();
+ lastCpuTime = SystemClock.currentThreadTimeMillis();
+ }
+
+ public void endSplit(final String splitName) {
+ final long currWallTime = SystemClock.uptimeMillis();
+ final long currCpuTime = SystemClock.currentThreadTimeMillis();
+
+ logger.i(
+ "%s: cpu=%dms wall=%dms",
+ splitName, currCpuTime - lastCpuTime, currWallTime - lastWallTime);
+
+ lastWallTime = currWallTime;
+ lastCpuTime = currCpuTime;
+ }
+}