Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion devtools/etdump/etdump_flatcc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,15 @@ ETDumpGen::ETDumpGen(Span<uint8_t> buffer) {
builder_ = (struct flatcc_builder*)alignPointer(buffer.data(), 64);
uintptr_t buffer_with_builder =
(uintptr_t)alignPointer(builder_ + sizeof(struct flatcc_builder), 64);
size_t buffer_size = buffer.size() -
size_t builder_size =
(size_t)(buffer_with_builder - (uintptr_t)buffer.data());
size_t min_buf_size = max_alloc_buf_size + builder_size;
ET_CHECK_MSG(
buffer.size() > min_buf_size,
"Static buffer size provided to ETDumpGen is %zu, which is less than or equal to the minimum size of %zu",
buffer.size(),
min_buf_size);
size_t buffer_size = buffer.size() - builder_size;
alloc_.set_buffer(
(uint8_t*)buffer_with_builder,
buffer_size,
Expand Down
7 changes: 5 additions & 2 deletions devtools/etdump/etdump_flatcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ struct ETDumpStaticAllocator {
data_size = alloc_buf_size;
allocated = 0;
out_size = total_buf_size - alloc_buf_size;
front_cursor = &buffer[alloc_buf_size];
front_left = out_size / 2;
// The front of the buffer is the end of the allocation buffer.
// We start writing from the end of the allocation buffer, and
// move backwards.
front_cursor = &buffer[alloc_buf_size + out_size];
front_left = out_size;
}

// Pointer to backing buffer to allocate from.
Expand Down
9 changes: 6 additions & 3 deletions devtools/etdump/tests/etdump_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ProfilerETDumpTest : public ::testing::Test {
void SetUp() override {
torch::executor::runtime_init();
etdump_gen[0] = new ETDumpGen();
const size_t buf_size = 1024 * 1024;
const size_t buf_size = 512 * 1024;
buf = (uint8_t*)malloc(buf_size * sizeof(uint8_t));
etdump_gen[1] = new ETDumpGen(Span<uint8_t>(buf, buf_size));
}
Expand All @@ -58,8 +58,11 @@ class ProfilerETDumpTest : public ::testing::Test {
TEST_F(ProfilerETDumpTest, SingleProfileEvent) {
for (size_t i = 0; i < 2; i++) {
etdump_gen[i]->create_event_block("test_block");
EventTracerEntry entry = etdump_gen[i]->start_profiling("test_event", 0, 1);
etdump_gen[i]->end_profiling(entry);
for (size_t j = 0; j < 2048; j++) {
EventTracerEntry entry =
etdump_gen[i]->start_profiling("test_event", 0, 1);
etdump_gen[i]->end_profiling(entry);
}

ETDumpResult result = etdump_gen[i]->get_etdump_data();
ASSERT_TRUE(result.buf != nullptr);
Expand Down