File tree Expand file tree Collapse file tree 3 files changed +19
-6
lines changed
Expand file tree Collapse file tree 3 files changed +19
-6
lines changed Original file line number Diff line number Diff line change @@ -116,8 +116,15 @@ ETDumpGen::ETDumpGen(Span<uint8_t> buffer) {
116116 builder_ = (struct flatcc_builder *)alignPointer (buffer.data (), 64 );
117117 uintptr_t buffer_with_builder =
118118 (uintptr_t )alignPointer (builder_ + sizeof (struct flatcc_builder ), 64 );
119- size_t buffer_size = buffer. size () -
119+ size_t builder_size =
120120 (size_t )(buffer_with_builder - (uintptr_t )buffer.data ());
121+ size_t min_buf_size = max_alloc_buf_size + builder_size;
122+ ET_CHECK_MSG (
123+ buffer.size () > min_buf_size,
124+ " Static buffer size provided to ETDumpGen is %zu, which is less than or equal to the minimum size of %zu" ,
125+ buffer.size (),
126+ min_buf_size);
127+ size_t buffer_size = buffer.size () - builder_size;
121128 alloc_.set_buffer (
122129 (uint8_t *)buffer_with_builder,
123130 buffer_size,
Original file line number Diff line number Diff line change @@ -31,8 +31,11 @@ struct ETDumpStaticAllocator {
3131 data_size = alloc_buf_size;
3232 allocated = 0 ;
3333 out_size = total_buf_size - alloc_buf_size;
34- front_cursor = &buffer[alloc_buf_size];
35- front_left = out_size / 2 ;
34+ // The front of the buffer is the end of the allocation buffer.
35+ // We start writing from the end of the allocation buffer, and
36+ // move backwards.
37+ front_cursor = &buffer[alloc_buf_size + out_size];
38+ front_left = out_size;
3639 }
3740
3841 // Pointer to backing buffer to allocate from.
Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ class ProfilerETDumpTest : public ::testing::Test {
4040 void SetUp () override {
4141 torch::executor::runtime_init ();
4242 etdump_gen[0 ] = new ETDumpGen ();
43- const size_t buf_size = 1024 * 1024 ;
43+ const size_t buf_size = 512 * 1024 ;
4444 buf = (uint8_t *)malloc (buf_size * sizeof (uint8_t ));
4545 etdump_gen[1 ] = new ETDumpGen (Span<uint8_t >(buf, buf_size));
4646 }
@@ -58,8 +58,11 @@ class ProfilerETDumpTest : public ::testing::Test {
5858TEST_F (ProfilerETDumpTest, SingleProfileEvent) {
5959 for (size_t i = 0 ; i < 2 ; i++) {
6060 etdump_gen[i]->create_event_block (" test_block" );
61- EventTracerEntry entry = etdump_gen[i]->start_profiling (" test_event" , 0 , 1 );
62- etdump_gen[i]->end_profiling (entry);
61+ for (size_t j = 0 ; j < 2048 ; j++) {
62+ EventTracerEntry entry =
63+ etdump_gen[i]->start_profiling (" test_event" , 0 , 1 );
64+ etdump_gen[i]->end_profiling (entry);
65+ }
6366
6467 ETDumpResult result = etdump_gen[i]->get_etdump_data ();
6568 ASSERT_TRUE (result.buf != nullptr );
You can’t perform that action at this time.
0 commit comments