return Status::OK();
}
+Status TestReporter::SetProperty(const string& name, const string& value) {
+ if (closed_) return Status::OK();
+ (*benchmark_entry_.mutable_extras())[name].set_string_value(value);
+ return Status::OK();
+}
+
+Status TestReporter::SetProperty(const string& name, double value) {
+ if (closed_) return Status::OK();
+ (*benchmark_entry_.mutable_extras())[name].set_double_value(value);
+ return Status::OK();
+}
+
Status TestReporter::Initialize() {
if (fname_.empty()) {
return Status::OK();
//
// If this environment variable is not defined, no logging is performed.
//
-// The intended use is via the following 4 lines:
+// The intended use is via the following lines:
//
// TestReporter reporter(test_name);
// TF_CHECK_OK(reporter.Initialize()));
// TF_CHECK_OK(reporter.Benchmark(iters, cpu_time, wall_time, throughput));
+// TF_CHECK_OK(reporter.SetProperty("some_string_property", "some_value");
+// TF_CHECK_OK(reporter.SetProperty("some_double_property", double_value);
// TF_CHECK_OK(reporter.Close());
//
// For example, if the environment variable
Status Benchmark(int64 iters, double cpu_time, double wall_time,
double throughput);
+ // Set property on Benchmark to the given value.
+ Status SetProperty(const string& name, double value);
+
+ // Set property on Benchmark to the given value.
+ Status SetProperty(const string& name, const string& value);
+
// TODO(b/32704451): Don't just ignore the ::tensorflow::Status object!
~TestReporter() { Close().IgnoreError(); } // Autoclose in destructor.
EXPECT_EQ(benchmark_entry.throughput(), 3.0);
}
+TEST(TestReporter, SetProperties) {
+ string fname =
+ strings::StrCat(testing::TmpDir(), "/test_reporter_benchmarks_");
+ TestReporter test_reporter(fname, "b2/3/4");
+ TF_EXPECT_OK(test_reporter.Initialize());
+ TF_EXPECT_OK(test_reporter.SetProperty("string_prop", "abc"));
+ TF_EXPECT_OK(test_reporter.SetProperty("double_prop", 4.0));
+
+ TF_EXPECT_OK(test_reporter.Close());
+ string expected_fname = strings::StrCat(fname, "b2__3__4");
+ string read;
+ TF_EXPECT_OK(ReadFileToString(Env::Default(), expected_fname, &read));
+
+ BenchmarkEntries benchmark_entries;
+ ASSERT_TRUE(benchmark_entries.ParseFromString(read));
+ ASSERT_EQ(1, benchmark_entries.entry_size());
+ const BenchmarkEntry& benchmark_entry = benchmark_entries.entry(0);
+ const auto& extras = benchmark_entry.extras();
+ ASSERT_EQ(2, extras.size());
+ EXPECT_EQ("abc", extras.at("string_prop").string_value());
+ EXPECT_EQ(4.0, extras.at("double_prop").double_value());
+}
+
} // namespace
} // namespace tensorflow