aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessio Balsini <balsini@google.com>2023-10-13 22:31:12 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2023-10-13 22:31:12 +0000
commit0436aa0b9d11b7903e85a6c843e94af6e78a634a (patch)
treec5f667008df69cc108ea00dd4e04ea9c24a23318
parent0279f043ff79c94ab11debfd2c4b6917bf2e496a (diff)
parentbe36c5e83cee1a259d6e0f017d73c5ab46c5f734 (diff)
downloaddittosuite-0436aa0b9d11b7903e85a6c843e94af6e78a634a.tar.gz
Write benchmark stages in trace_marker am: dc5f7e2521 am: 24c8570302 am: daf479da6c am: dd6fdba431 am: be36c5e83c
Original change: https://android-review.googlesource.com/c/platform/test/dittosuite/+/2787079 Change-Id: I614adcc7c7db11f05be6bc77e44a9e5bbbaffdfd Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--dittobench.cpp7
-rw-r--r--include/ditto/parser.h9
-rw-r--r--include/ditto/tracer.h70
-rw-r--r--src/parser.cpp9
-rw-r--r--src/tracer.cpp89
-rw-r--r--test/tracer_test.cpp34
6 files changed, 209 insertions, 9 deletions
diff --git a/dittobench.cpp b/dittobench.cpp
index 5371d0c..b64812a 100644
--- a/dittobench.cpp
+++ b/dittobench.cpp
@@ -21,11 +21,14 @@
#include <ditto/arg_parser.h>
#include <ditto/logger.h>
#include <ditto/parser.h>
+#include <ditto/tracer.h>
int main(int argc, char** argv) {
dittosuite::CmdArguments arguments = dittosuite::ParseArguments(argc, argv);
- dittosuite::Parser::GetParser().Parse(arguments.file_path, arguments.parameters);
+ auto benchmark = dittosuite::Parser::GetParser().Parse(arguments.file_path, arguments.parameters);
+ auto &tracer = dittosuite::Tracer::GetTracer();
+ tracer.Start(std::move(benchmark));
auto init = dittosuite::Parser::GetParser().GetInit();
if (init != nullptr) {
@@ -36,7 +39,9 @@ int main(int argc, char** argv) {
auto main = dittosuite::Parser::GetParser().GetMain();
main->SetUp();
+ tracer.StartBenchmark();
main->Run();
+ tracer.EndBenchmark();
main->TearDown();
auto result = main->CollectResults("");
diff --git a/include/ditto/parser.h b/include/ditto/parser.h
index fd9ada2..8c7a767 100644
--- a/include/ditto/parser.h
+++ b/include/ditto/parser.h
@@ -15,9 +15,14 @@
#pragma once
#include <string>
-
#include <ditto/instruction_set.h>
+#ifdef __ANDROID__
+#include <benchmark.pb.h>
+#else
+#include "schema/benchmark.pb.h"
+#endif
+
namespace dittosuite {
class Parser {
@@ -26,7 +31,7 @@ class Parser {
void operator=(const Parser&) = delete;
static Parser& GetParser();
- void Parse(const std::string& file_path, const std::vector<std::string>& parameters);
+ std::unique_ptr<dittosuiteproto::Benchmark> Parse(const std::string& file_path, const std::vector<std::string>& parameters);
std::unique_ptr<Instruction> GetInit();
std::unique_ptr<Instruction> GetMain();
std::unique_ptr<Instruction> GetCleanUp();
diff --git a/include/ditto/tracer.h b/include/ditto/tracer.h
new file mode 100644
index 0000000..2658eed
--- /dev/null
+++ b/include/ditto/tracer.h
@@ -0,0 +1,70 @@
+// Copyright (C) 2023 The Android Open Source Project
+//
+// 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.
+
+#pragma once
+
+#include <memory>
+#include <fstream>
+
+#ifdef __ANDROID__
+#include <benchmark.pb.h>
+#else
+#include "schema/benchmark.pb.h"
+#endif
+
+
+namespace dittosuite {
+
+class Tracer {
+ public:
+ Tracer(Tracer& other) = delete;
+ static Tracer& GetTracer();
+ void Start(std::unique_ptr<dittosuiteproto::Benchmark> benchmark);
+ void StartBenchmark();
+ void EndBenchmark();
+
+ private:
+ std::ofstream trace_marker_;
+ std::string id_;
+
+ Tracer();
+ ~Tracer();
+};
+
+template <class T>
+std::string trace_format__(const T& id) {
+ return std::string("|") + id;
+}
+
+template <class T, class... Args>
+std::string trace_format__(const T& id, Args... vars) {
+ return std::string("|") + id + trace_format__(vars...);
+}
+
+template <class T>
+std::string trace_format(const T& id) {
+ return id;
+}
+
+template <class T, class... Args>
+std::string trace_format(const T& id, Args... vars) {
+ std::string result;
+
+ result = trace_format(id);
+
+ return result + trace_format__(vars...);
+}
+
+
+} // namespace dittosuite
diff --git a/src/parser.cpp b/src/parser.cpp
index f0e98ec..5360cfe 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -25,11 +25,6 @@
#include <google/protobuf/text_format.h>
-#ifdef __ANDROID__
-#include <benchmark.pb.h>
-#else
-#include "schema/benchmark.pb.h"
-#endif
namespace dittosuite {
@@ -38,7 +33,7 @@ Parser& Parser::GetParser() {
return parser;
}
-void Parser::Parse(const std::string& file_path, const std::vector<std::string>& parameters) {
+std::unique_ptr<dittosuiteproto::Benchmark> Parser::Parse(const std::string& file_path, const std::vector<std::string>& parameters) {
std::unique_ptr<dittosuiteproto::Benchmark> benchmark =
std::make_unique<dittosuiteproto::Benchmark>();
@@ -78,6 +73,8 @@ void Parser::Parse(const std::string& file_path, const std::vector<std::string>&
}
SharedVariables::ClearKeys();
+
+ return benchmark;
}
std::unique_ptr<Instruction> Parser::GetInit() {
diff --git a/src/tracer.cpp b/src/tracer.cpp
new file mode 100644
index 0000000..b89018d
--- /dev/null
+++ b/src/tracer.cpp
@@ -0,0 +1,89 @@
+// Copyright (C) 2023 The Android Open Source Project
+//
+// 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 <ditto/logger.h>
+#include <ditto/tracer.h>
+
+#include <google/protobuf/util/json_util.h>
+
+#include <cstdarg>
+#include <unistd.h>
+
+namespace dittosuite {
+
+std::string random_string(int len) {
+ std::string char_set;
+ for (char c = '0'; c <= '9'; ++c) {
+ char_set += c;
+ }
+ for (char c = 'a'; c <= 'z'; ++c) {
+ char_set += c;
+ }
+ for (char c = 'A'; c <= 'Z'; ++c) {
+ char_set += c;
+ }
+
+ std::string ret;
+
+ ret.reserve(len);
+ for (int i = 0; i < len; ++i) {
+ ret += char_set[rand() % (char_set.length())];
+ }
+
+ return ret;
+}
+
+Tracer& Tracer::GetTracer() {
+ static Tracer tracer;
+ return tracer;
+}
+
+void Tracer::Start(std::unique_ptr<dittosuiteproto::Benchmark> benchmark) {
+ std::string benchmark_dump;
+ google::protobuf::util::JsonPrintOptions options;
+
+ auto status = google::protobuf::util::MessageToJsonString(*benchmark, &benchmark_dump, options);
+
+ if (!status.ok()) {
+ LOGF("Unable to dump benchmark into string");
+ }
+
+ id_ = random_string(16);
+
+ trace_marker_ << trace_format("B", std::to_string(gettid()), "Session", id_, benchmark_dump) << std::endl;
+}
+
+void Tracer::StartBenchmark() {
+ trace_marker_ << trace_format("B", std::to_string(gettid()), "Benchmark", id_) << std::endl;
+}
+
+void Tracer::EndBenchmark() {
+ trace_marker_ << trace_format("E", std::to_string(gettid())) << std::endl;
+}
+
+
+Tracer::Tracer() {
+ trace_marker_.open("/sys/kernel/tracing/trace_marker", std::ofstream::out);
+ if (!trace_marker_.good()) {
+ LOGF("Unable to open trace_marker");
+ }
+}
+
+Tracer::~Tracer() {
+ trace_marker_ << trace_format("E", std::to_string(gettid())) << std::endl;
+
+ trace_marker_.close();
+}
+
+} // namespace dittosuite
diff --git a/test/tracer_test.cpp b/test/tracer_test.cpp
new file mode 100644
index 0000000..1a86c63
--- /dev/null
+++ b/test/tracer_test.cpp
@@ -0,0 +1,34 @@
+// Copyright (C) 2023 The Android Open Source Project
+//
+// 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 <ditto/tracer.h>
+#include <gtest/gtest.h>
+
+#include <vector>
+
+namespace dittosuite {
+
+TEST(DittoTracer, OneVar) {
+ ASSERT_EQ(trace_format("ABC"), std::string("ABC"));
+}
+
+TEST(DittoTracer, TwoVars) {
+ ASSERT_EQ(trace_format("ABC", "DEF"), std::string("ABC|DEF"));
+}
+
+TEST(DittoTracer, ThreeVar) {
+ ASSERT_EQ(trace_format("ABC", "DEF", "GHI"), std::string("ABC|DEF|GHI"));
+}
+
+} // namespace dittosuite