diff options
author | Eugene Brevdo <ebrevdo@gmail.com> | 2016-02-25 12:12:47 -0800 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2016-02-25 13:19:20 -0800 |
commit | ad3ef4c05b2fab077ce7fb56a4927100fed239e9 (patch) | |
tree | 6468847604c82f7b4f3c5a16f197f031c4fffbcf /tensorflow/core/util/reporter.cc | |
parent | b97931cb933d546b578a17d3454e9f4eb3b91cad (diff) |
TestReporter is back in. Maybe also fixed the Android build.
Change: 115589642
Diffstat (limited to 'tensorflow/core/util/reporter.cc')
-rw-r--r-- | tensorflow/core/util/reporter.cc | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/tensorflow/core/util/reporter.cc b/tensorflow/core/util/reporter.cc new file mode 100644 index 0000000000..1fe25afa66 --- /dev/null +++ b/tensorflow/core/util/reporter.cc @@ -0,0 +1,75 @@ +/* Copyright 2016 Google Inc. 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. +==============================================================================*/ + +#include "tensorflow/core/util/reporter.h" + +#include "tensorflow/core/lib/core/errors.h" +#include "tensorflow/core/lib/strings/str_util.h" +#include "tensorflow/core/platform/mutex.h" + +namespace tensorflow { + +TestReporter::TestReporter(const string& fname, const string& test_name) + : closed_(true), fname_(fname), test_name_(test_name) {} + +Status TestReporter::Close() { + if (closed_) return Status::OK(); + + string entry_string; + if (!protobuf::TextFormat::PrintToString(benchmark_entry_, &entry_string)) { + return errors::Internal("Could not serialize to string: ", + benchmark_entry_.DebugString()); + } + + TF_RETURN_IF_ERROR(log_file_->Append(entry_string)); + benchmark_entry_.Clear(); + + closed_ = true; + + return log_file_->Close(); +} + +Status TestReporter::Benchmark(int64 iters, double cpu_time, double wall_time, + double throughput) { + if (closed_) return Status::OK(); + benchmark_entry_.set_iters(iters); + benchmark_entry_.set_cpu_time(cpu_time); + benchmark_entry_.set_wall_time(wall_time); + benchmark_entry_.set_throughput(throughput); + return Status::OK(); +} + +Status TestReporter::Initialize() { + if (fname_.empty()) { + return Status::OK(); + } + string mangled_fname = strings::StrCat( + fname_, str_util::Join(str_util::Split(test_name_, '/'), "__")); + Env* env = Env::Default(); + if (env->FileExists(mangled_fname)) { + return errors::InvalidArgument("Cannot create TestReporter, file exists: ", + mangled_fname); + } + WritableFile* log_file; + TF_RETURN_IF_ERROR(env->NewWritableFile(mangled_fname, &log_file)); + log_file_.reset(log_file); + TF_RETURN_IF_ERROR(log_file->Flush()); + + benchmark_entry_.set_name(test_name_); + closed_ = false; + return Status::OK(); +} + +} // namespace tensorflow |