Skip to content

Commit 2f3a8b0

Browse files
bweltonBenjamin Welton
andauthored
Use fixed size array for serialization (#906)
Co-authored-by: Benjamin Welton <ben@amd.com>
1 parent b0c4182 commit 2f3a8b0

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

source/lib/rocprofiler-sdk-tool/generateCSV.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <rocprofiler-sdk/marker/api_id.h>
3131
#include <unistd.h>
3232

33+
#include <cstdint>
3334
#include <iomanip>
3435
#include <string_view>
3536
#include <utility>
@@ -553,8 +554,9 @@ generate_csv(tool_table* too
553554
{
554555
auto kernel_id = record.dispatch_data.dispatch_info.kernel_id;
555556
auto counter_name_value = std::map<std::string, uint64_t>{};
556-
for(const auto& count : record.records)
557+
for(uint64_t i = 0; i < record.counter_count; i++)
557558
{
559+
const auto& count = record.records.at(i);
558560
auto rec = count.record_counter;
559561
std::string counter_name = tool_functions->tool_get_counter_info_name_fn(rec.id);
560562
auto search = counter_name_value.find(counter_name);

source/lib/rocprofiler-sdk-tool/helper.hpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <rocprofiler-sdk/fwd.h>
3636
#include <rocprofiler-sdk/registration.h>
3737
#include <rocprofiler-sdk/rocprofiler.h>
38+
#include <cstdint>
3839
#include <rocprofiler-sdk/cxx/name_info.hpp>
3940
#include <rocprofiler-sdk/cxx/serialization.hpp>
4041

@@ -270,18 +271,22 @@ struct rocprofiler_tool_record_counter_t
270271

271272
struct rocprofiler_tool_counter_collection_record_t
272273
{
273-
rocprofiler_profile_counting_dispatch_data_t dispatch_data = {};
274-
std::vector<rocprofiler_tool_record_counter_t> records = {};
275-
uint64_t thread_id = 0;
276-
uint64_t arch_vgpr_count = 0;
277-
uint64_t sgpr_count = 0;
278-
uint64_t lds_block_size_v = 0;
274+
rocprofiler_profile_counting_dispatch_data_t dispatch_data = {};
275+
std::array<rocprofiler_tool_record_counter_t, 256> records = {};
276+
uint64_t thread_id = 0;
277+
uint64_t arch_vgpr_count = 0;
278+
uint64_t sgpr_count = 0;
279+
uint64_t lds_block_size_v = 0;
280+
uint64_t counter_count = 0;
279281

280282
template <typename ArchiveT>
281283
void save(ArchiveT& ar) const
282284
{
283285
ar(cereal::make_nvp("dispatch_data", dispatch_data));
284-
ar(cereal::make_nvp("records", records));
286+
// should be removed when moving to buffered tracing
287+
std::vector<rocprofiler_tool_record_counter_t> tmp{records.begin(),
288+
records.begin() + counter_count};
289+
ar(cereal::make_nvp("records", tmp));
285290
ar(cereal::make_nvp("thread_id", thread_id));
286291
ar(cereal::make_nvp("arch_vgpr_count", arch_vgpr_count));
287292
ar(cereal::make_nvp("sgpr_count", sgpr_count));

source/lib/rocprofiler-sdk-tool/tool.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -941,11 +941,19 @@ counter_record_callback(rocprofiler_profile_counting_dispatch_data_t dispatch_da
941941

942942
for(size_t count = 0; count < record_count; count++)
943943
{
944+
// Unlikely to trigger, temporary until we move to buffered callbacks
945+
if(count >= counter_record.records.size())
946+
{
947+
ROCP_WARNING << "Exceeded maximum counter capacity, skipping remaining";
948+
break;
949+
}
950+
944951
auto _counter_id = rocprofiler_counter_id_t{};
945952
ROCPROFILER_CALL(rocprofiler_query_record_counter_id(record_data[count].id, &_counter_id),
946953
"query record counter id");
947-
counter_record.records.emplace_back(
948-
rocprofiler_tool_record_counter_t{_counter_id, record_data[count]});
954+
counter_record.records[count] =
955+
rocprofiler_tool_record_counter_t{_counter_id, record_data[count]};
956+
counter_record.counter_count++;
949957
}
950958

951959
write_ring_buffer(counter_record, domain_type::COUNTER_COLLECTION);

tests/counter-collection/validate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def test_counter_values(input_data):
2828
counter_data = data["buffer_records"]["counter_collection"]
2929

3030
for itr in counter_info:
31-
if itr["is_constant"] == 1 and itr["name"] == "size":
31+
if itr["is_constant"] == 1:
3232
continue
3333
assert itr["id"]["handle"] > 0, f"{itr}"
3434
assert itr["is_constant"] in (0, 1), f"{itr}"

0 commit comments

Comments
 (0)