aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-10-18 01:25:59 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-10-18 01:25:59 +0000
commite6c70d8d1b55feb7e1a79624f37cda239821c997 (patch)
treed20815695f142998aee97ccdff682da9aff8ff85
parent4fe7b03311ee08d79429452776c7032e64193e66 (diff)
parent8677ccf70152c9002996132edfeb90787afd7fba (diff)
downloaddittosuite-e6c70d8d1b55feb7e1a79624f37cda239821c997.tar.gz
Snap for 10963245 from 8677ccf70152c9002996132edfeb90787afd7fba to 24Q1-release
Change-Id: I6e04c2c20b3616de085cbc6abde3162fb63f78d1
-rw-r--r--dittobench.cpp8
-rw-r--r--example/memory.ditto37
-rw-r--r--include/ditto/instruction.h2
-rw-r--r--include/ditto/memory_allocation.h35
-rw-r--r--include/ditto/tracer.h13
-rw-r--r--schema/benchmark.proto5
-rw-r--r--src/instruction.cpp3
-rw-r--r--src/instruction_factory.cpp6
-rw-r--r--src/memory_allocation.cpp39
-rw-r--r--src/tracer.cpp47
10 files changed, 170 insertions, 25 deletions
diff --git a/dittobench.cpp b/dittobench.cpp
index b64812a..3b6fc63 100644
--- a/dittobench.cpp
+++ b/dittobench.cpp
@@ -24,11 +24,11 @@
#include <ditto/tracer.h>
int main(int argc, char** argv) {
+ dittosuite::Tracer tracer;
dittosuite::CmdArguments arguments = dittosuite::ParseArguments(argc, argv);
auto benchmark = dittosuite::Parser::GetParser().Parse(arguments.file_path, arguments.parameters);
- auto &tracer = dittosuite::Tracer::GetTracer();
- tracer.Start(std::move(benchmark));
+ tracer.StartSession(std::move(benchmark));
auto init = dittosuite::Parser::GetParser().GetInit();
if (init != nullptr) {
@@ -39,9 +39,9 @@ int main(int argc, char** argv) {
auto main = dittosuite::Parser::GetParser().GetMain();
main->SetUp();
- tracer.StartBenchmark();
+ tracer.Start("Benchmark");
main->Run();
- tracer.EndBenchmark();
+ tracer.End("Benchmark");
main->TearDown();
auto result = main->CollectResults("");
diff --git a/example/memory.ditto b/example/memory.ditto
new file mode 100644
index 0000000..797178f
--- /dev/null
+++ b/example/memory.ditto
@@ -0,0 +1,37 @@
+main: {
+ multithreading: {
+ fork: true,
+ threads: [
+ {
+ name: "Memory"
+ instruction: {
+ mem_alloc: {
+ size: 5000000000
+ }
+ }
+ },
+ {
+ name: "Util"
+ instruction: {
+ cpu_work: {
+ utilization: 0.3,
+ }
+ repeat: 300,
+ period_us: 100000
+ },
+ spawn: 2
+ },
+ {
+ name: "MemGrow"
+ instruction: {
+ mem_alloc: {
+ size: 5000000
+ }
+ repeat: 300,
+ period_us: 100000
+ }
+ }
+ ]
+ }
+}
+global: {}
diff --git a/include/ditto/instruction.h b/include/ditto/instruction.h
index b043639..c4bdb09 100644
--- a/include/ditto/instruction.h
+++ b/include/ditto/instruction.h
@@ -24,6 +24,7 @@
#include <ditto/result.h>
#include <ditto/sampler.h>
#include <ditto/syscall.h>
+#include <ditto/tracer.h>
namespace dittosuite {
@@ -72,6 +73,7 @@ class Instruction {
int repeat_;
uint64_t period_us_;
TimeSampler time_sampler_;
+ Tracer tracer_;
private:
timespec next_awake_time_;
diff --git a/include/ditto/memory_allocation.h b/include/ditto/memory_allocation.h
new file mode 100644
index 0000000..af32220
--- /dev/null
+++ b/include/ditto/memory_allocation.h
@@ -0,0 +1,35 @@
+// 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 <ditto/instruction.h>
+
+namespace dittosuite {
+
+class MemoryAllocation : public Instruction {
+ public:
+ inline static const std::string kName = "memory_allocation";
+
+ explicit MemoryAllocation(const Params& params, const uint64_t size);
+ ~MemoryAllocation();
+
+ private:
+ size_t size_;
+ char* allocated_memory_;
+
+ void RunSingle();
+};
+
+} // namespace dittosuite
diff --git a/include/ditto/tracer.h b/include/ditto/tracer.h
index 2658eed..0832950 100644
--- a/include/ditto/tracer.h
+++ b/include/ditto/tracer.h
@@ -28,18 +28,17 @@ namespace dittosuite {
class Tracer {
public:
+ Tracer();
+ ~Tracer();
Tracer(Tracer& other) = delete;
- static Tracer& GetTracer();
- void Start(std::unique_ptr<dittosuiteproto::Benchmark> benchmark);
- void StartBenchmark();
- void EndBenchmark();
+
+ void StartSession(std::unique_ptr<dittosuiteproto::Benchmark> benchmark);
+ void Start(const std::string &splice);
+ void End(const std::string &splice);
private:
std::ofstream trace_marker_;
std::string id_;
-
- Tracer();
- ~Tracer();
};
template <class T>
diff --git a/schema/benchmark.proto b/schema/benchmark.proto
index ef0052e..197c1d7 100644
--- a/schema/benchmark.proto
+++ b/schema/benchmark.proto
@@ -19,6 +19,10 @@ enum AccessMode {
READ_WRITE = 3;
}
+message MemoryAllocate {
+ optional uint64 size = 1;
+}
+
message CpuWork {
oneof type {
uint64 cycles = 1;
@@ -176,6 +180,7 @@ message Instruction {
BinderRequest binder_request = 13;
BinderService binder_service = 14;
CpuWork cpu_work = 16;
+ MemoryAllocate mem_alloc = 17;
};
optional uint64 period_us = 15 [default = 0];
}
diff --git a/src/instruction.cpp b/src/instruction.cpp
index 9e1260f..3ea0025 100644
--- a/src/instruction.cpp
+++ b/src/instruction.cpp
@@ -16,6 +16,7 @@
#include <ditto/shared_variables.h>
#include <ditto/logger.h>
+#include <ditto/tracer.h>
namespace dittosuite {
@@ -69,11 +70,13 @@ std::thread Instruction::SpawnThread(pthread_barrier_t* barrier,
void Instruction::TearDown() {}
void Instruction::SetUpSingle() {
+ tracer_.Start(name_);
time_sampler_.MeasureStart();
}
void Instruction::TearDownSingle(bool /*is_last*/) {
time_sampler_.MeasureEnd();
+ tracer_.End(name_);
if (!period_us_) {
return;
diff --git a/src/instruction_factory.cpp b/src/instruction_factory.cpp
index 6d9cead..cef9c1b 100644
--- a/src/instruction_factory.cpp
+++ b/src/instruction_factory.cpp
@@ -27,6 +27,7 @@
#include <ditto/instruction_set.h>
#include <ditto/invalidate_cache.h>
#include <ditto/logger.h>
+#include <ditto/memory_allocation.h>
#include <ditto/multiprocessing.h>
#include <ditto/multithreading.h>
#include <ditto/multithreading_utils.h>
@@ -287,6 +288,11 @@ std::unique_ptr<Instruction> InstructionFactory::CreateFromProtoInstruction(
}
}
}
+ case InstructionType::kMemAlloc: {
+ const auto& options = proto_instruction.mem_alloc();
+ return std::make_unique<MemoryAllocation>(instruction_params, options.size());
+ break;
+ }
case InstructionType::INSTRUCTION_ONEOF_NOT_SET: {
LOGF("Instruction was not set in .ditto file");
}
diff --git a/src/memory_allocation.cpp b/src/memory_allocation.cpp
new file mode 100644
index 0000000..d54c64a
--- /dev/null
+++ b/src/memory_allocation.cpp
@@ -0,0 +1,39 @@
+// 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/memory_allocation.h>
+
+#include <ditto/logger.h>
+
+#include <unistd.h>
+
+namespace dittosuite {
+
+MemoryAllocation::MemoryAllocation(const Params& params, const uint64_t size)
+ : Instruction(kName, params), size_(size), allocated_memory_(nullptr) {}
+
+MemoryAllocation::~MemoryAllocation() {
+ free(allocated_memory_);
+}
+
+void MemoryAllocation::RunSingle() {
+ int page_size = getpagesize();
+ allocated_memory_ = static_cast<char*>(malloc(size_));
+
+ for (size_t i = 0; i < size_; i += page_size) {
+ allocated_memory_[i] = 1;
+ }
+}
+
+} // namespace dittosuite
diff --git a/src/tracer.cpp b/src/tracer.cpp
index b89018d..d70ea80 100644
--- a/src/tracer.cpp
+++ b/src/tracer.cpp
@@ -44,12 +44,11 @@ std::string random_string(int len) {
return ret;
}
-Tracer& Tracer::GetTracer() {
- static Tracer tracer;
- return tracer;
-}
+void Tracer::StartSession(std::unique_ptr<dittosuiteproto::Benchmark> benchmark) {
+ if (!trace_marker_.good()) {
+ return;
+ }
-void Tracer::Start(std::unique_ptr<dittosuiteproto::Benchmark> benchmark) {
std::string benchmark_dump;
google::protobuf::util::JsonPrintOptions options;
@@ -61,27 +60,47 @@ void Tracer::Start(std::unique_ptr<dittosuiteproto::Benchmark> benchmark) {
id_ = random_string(16);
- trace_marker_ << trace_format("B", std::to_string(gettid()), "Session", id_, benchmark_dump) << std::endl;
+ trace_marker_ << trace_format("B", std::to_string(getpid()), "Session", benchmark_dump, id_);
+ trace_marker_.write("\0", 1);
+ trace_marker_.flush();
}
-void Tracer::StartBenchmark() {
- trace_marker_ << trace_format("B", std::to_string(gettid()), "Benchmark", id_) << std::endl;
-}
+void Tracer::Start(const std::string& splice) {
+ if (!trace_marker_.good()) {
+ return;
+ }
-void Tracer::EndBenchmark() {
- trace_marker_ << trace_format("E", std::to_string(gettid())) << std::endl;
+ trace_marker_ << trace_format("B", std::to_string(getpid()), splice);
+ trace_marker_.write("\0", 1);
+ trace_marker_.flush();
}
+void Tracer::End(const std::string& splice) {
+ if (!trace_marker_.good()) {
+ return;
+ }
+
+ trace_marker_ << trace_format("E", std::to_string(getpid()), splice);
+ trace_marker_.write("\0", 1);
+ trace_marker_.flush();
+}
Tracer::Tracer() {
- trace_marker_.open("/sys/kernel/tracing/trace_marker", std::ofstream::out);
+ trace_marker_.open("/sys/kernel/tracing/trace_marker",
+ std::ofstream::out | std::ofstream::binary);
if (!trace_marker_.good()) {
- LOGF("Unable to open trace_marker");
+ LOGW("Unable to open trace_marker");
}
}
Tracer::~Tracer() {
- trace_marker_ << trace_format("E", std::to_string(gettid())) << std::endl;
+ if (!trace_marker_.good()) {
+ return;
+ }
+
+ trace_marker_ << trace_format("E", std::to_string(getpid()), "Session", id_);
+ trace_marker_.write("\0", 1);
+ trace_marker_.flush();
trace_marker_.close();
}