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) {
116
116
builder_ = (struct flatcc_builder *)alignPointer (buffer.data (), 64 );
117
117
uintptr_t buffer_with_builder =
118
118
(uintptr_t )alignPointer (builder_ + sizeof (struct flatcc_builder ), 64 );
119
- size_t buffer_size = buffer. size () -
119
+ size_t builder_size =
120
120
(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;
121
128
alloc_.set_buffer (
122
129
(uint8_t *)buffer_with_builder,
123
130
buffer_size,
Original file line number Diff line number Diff line change @@ -31,8 +31,11 @@ struct ETDumpStaticAllocator {
31
31
data_size = alloc_buf_size;
32
32
allocated = 0 ;
33
33
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;
36
39
}
37
40
38
41
// 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 {
40
40
void SetUp () override {
41
41
torch::executor::runtime_init ();
42
42
etdump_gen[0 ] = new ETDumpGen ();
43
- const size_t buf_size = 1024 * 1024 ;
43
+ const size_t buf_size = 512 * 1024 ;
44
44
buf = (uint8_t *)malloc (buf_size * sizeof (uint8_t ));
45
45
etdump_gen[1 ] = new ETDumpGen (Span<uint8_t >(buf, buf_size));
46
46
}
@@ -58,8 +58,11 @@ class ProfilerETDumpTest : public ::testing::Test {
58
58
TEST_F (ProfilerETDumpTest, SingleProfileEvent) {
59
59
for (size_t i = 0 ; i < 2 ; i++) {
60
60
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
+ }
63
66
64
67
ETDumpResult result = etdump_gen[i]->get_etdump_data ();
65
68
ASSERT_TRUE (result.buf != nullptr );
You can’t perform that action at this time.
0 commit comments