aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/examples/android/jni/tensorflow_jni.cc
diff options
context:
space:
mode:
authorGravatar Andrew Harp <andrew.harp@gmail.com>2016-03-23 11:51:46 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2016-03-23 13:38:06 -0700
commitbc0754d59dbb038a86e16cb592f9b716aaebfc0d (patch)
tree16456e9a7a657a92105c3ea435e3cb8461a5cb1c /tensorflow/examples/android/jni/tensorflow_jni.cc
parent62df5bef660a3b56fcabf7d8266b62b48fb4425b (diff)
Print per-node step stats from Android demo for better benchmarking.
Change: 117958944
Diffstat (limited to 'tensorflow/examples/android/jni/tensorflow_jni.cc')
-rw-r--r--tensorflow/examples/android/jni/tensorflow_jni.cc45
1 files changed, 40 insertions, 5 deletions
diff --git a/tensorflow/examples/android/jni/tensorflow_jni.cc b/tensorflow/examples/android/jni/tensorflow_jni.cc
index ae0634f4fd..a6f6174664 100644
--- a/tensorflow/examples/android/jni/tensorflow_jni.cc
+++ b/tensorflow/examples/android/jni/tensorflow_jni.cc
@@ -36,6 +36,7 @@ limitations under the License.
#include "tensorflow/core/platform/mutex.h"
#include "tensorflow/core/platform/types.h"
#include "tensorflow/core/public/session.h"
+#include "tensorflow/core/util/stat_summarizer.h"
#include "tensorflow/examples/android/jni/jni_utils.h"
using namespace tensorflow;
@@ -49,10 +50,19 @@ static bool g_compute_graph_initialized = false;
static int g_tensorflow_input_size; // The image size for the mognet input.
static int g_image_mean; // The image mean.
+static StatSummarizer g_stats;
// For basic benchmarking.
static int g_num_runs = 0;
static int64 g_timing_total_us = 0;
+static Stat<int64> g_frequency_start;
+static Stat<int64> g_frequency_end;
+
+#ifdef LOG_DETAILED_STATS
+static const bool kLogDetailedStats = true;
+#else
+static const bool kLogDetailedStats = false;
+#endif
// Improve benchmarking by limiting runs to predefined amount.
// 0 (default) denotes infinite runs.
@@ -79,6 +89,9 @@ TENSORFLOW_METHOD(initializeTensorflow)(
jint num_classes, jint mognet_input_size, jint image_mean) {
g_num_runs = 0;
g_timing_total_us = 0;
+ g_stats.Reset();
+ g_frequency_start.Reset();
+ g_frequency_end.Reset();
//MutexLock input_lock(&g_compute_graph_mutex);
if (g_compute_graph_initialized) {
@@ -179,6 +192,17 @@ static void GetTopN(
std::reverse(top_results->begin(), top_results->end());
}
+static int64 GetCpuSpeed() {
+ string scaling_contents;
+ ReadFileToString(nullptr,
+ "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq",
+ &scaling_contents);
+ std::stringstream ss(scaling_contents);
+ int64 result;
+ ss >> result;
+ return result;
+}
+
static std::string ClassifyImage(const RGBA* const bitmap_src,
const int in_stride,
const int width, const int height) {
@@ -227,22 +251,33 @@ static std::string ClassifyImage(const RGBA* const bitmap_src,
tensorflow::Status s;
int64 start_time, end_time;
- if (kSaveStepStats) {
+ if (kLogDetailedStats || kSaveStepStats) {
RunOptions run_options;
run_options.set_trace_level(RunOptions::FULL_TRACE);
RunMetadata run_metadata;
+ g_frequency_start.UpdateStat(GetCpuSpeed());
start_time = CurrentThreadTimeUs();
s = session->Run(run_options, input_tensors, output_names, {},
&output_tensors, &run_metadata);
end_time = CurrentThreadTimeUs();
+ g_frequency_end.UpdateStat(GetCpuSpeed());
assert(run_metadata.has_step_stats());
const StepStats& stats = run_metadata.step_stats();
- mkdir("/sdcard/tf/", 0755);
- const string filename =
- strings::Printf("/sdcard/tf/stepstats%05d.pb", g_num_runs);
- WriteProtoToFile(filename.c_str(), stats);
+ if (kLogDetailedStats) {
+ LOG(INFO) << "CPU frequency start: " << g_frequency_start;
+ LOG(INFO) << "CPU frequency end: " << g_frequency_end;
+ g_stats.ProcessStepStats(stats);
+ g_stats.PrintStepStats();
+ }
+
+ if (kSaveStepStats) {
+ mkdir("/sdcard/tf/", 0755);
+ const string filename =
+ strings::Printf("/sdcard/tf/stepstats%05d.pb", g_num_runs);
+ WriteProtoToFile(filename.c_str(), stats);
+ }
} else {
start_time = CurrentThreadTimeUs();
s = session->Run(input_tensors, output_names, {}, &output_tensors);