Skip to content

Commit 4be9ba7

Browse files
committed
Code cleanup and extended changelog for v0.12.4
1 parent 7ad7364 commit 4be9ba7

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
## v0.12.4
44
This update enables exporting sampled data to the standard perf format for analysis with existing tools.
55

6-
- **Perf Data Export**: Samples can now be written as *perf data files* using `Sampler::to_perf_file()`, enabling analysis with standard perf ecosystem tools like perf report (see the [documentation](docs/analyzing-samples-with-perf-report.md)).
6+
- **Bugfix**: The library crashed when events loaded from an external CSV file contained empty spaces (see [#8](https://github.com/jmuehlig/perf-cpp/issues/8)). Thanks to [@Liteom](https://github.com/Liteom).
7+
- **Bugfix**: The library could not compile for specific Linux kernels not providing `PERF_MEM_LVLNUM_UNC` and `PERF_MEM_SNOOPX_PEER` (see [#7](https://github.com/jmuehlig/perf-cpp/issues/7)). Thanks to [@Raphalex46](https://github.com/Raphalex46) for pointing out.
8+
- **Perf Data Export**: Samples can now be written as *perf data files* using `Sampler::to_perf_file()`, enabling analysis with standard perf ecosystem tools like perf report (see the [documentation](docs/analyzing-samples-with-perf-report.md)). **Note that this feature is experimental.**
9+
710

811
## v0.12.3
912
This update simplifies the handling of counter definitions by introducing a default instance.

docs/analyzing-samples-with-perf-report.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ This gives you the best of both worlds:
1111

1212
→ [For a practical implementation, check out our perf data export example.](../examples/sampling/perf_record.cpp)
1313

14+
> [!IMPORTANT]
15+
> This feature is considered as being **experimental**.
16+
17+
1418
---
1519
## Table of Contents
1620
- [Overview](#overview)

src/event_provider.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -332,21 +332,25 @@ perf::SystemSpecificEventProvider::parse_event_file_descriptor_format(std::files
332332
std::optional<std::uint64_t>
333333
perf::SystemSpecificEventProvider::parse_integer(const std::string& value)
334334
{
335-
std::string copied_str = value;
336-
copied_str.erase(std::remove_if(copied_str.begin(), copied_str.end(), [](unsigned char c){return std::isspace(c);}), copied_str.end());
337-
338-
if (copied_str.empty()) {
335+
if (value.empty()) {
339336
return std::nullopt;
340337
}
341338

339+
/// Remove all whitespaces if the value has at least one.
340+
if (value.find_first_of(' ') != std::string::npos) {
341+
auto value_without_leading_whitespace = value;
342+
value_without_leading_whitespace.erase(std::remove_if(value_without_leading_whitespace.begin(), value_without_leading_whitespace.end(), ::isspace), value_without_leading_whitespace.end());
343+
return SystemSpecificEventProvider::parse_integer(value_without_leading_whitespace);
344+
}
345+
342346
/// Strings starting with '0x' are considered hex numbers.
343-
if (copied_str.rfind("0x", 0ULL) == 0ULL) {
344-
return std::stoull(copied_str.substr(2ULL), nullptr, 16);
347+
if (value.rfind("0x", 0ULL) == 0ULL) {
348+
return std::stoull(value.substr(2ULL), nullptr, 16);
345349
}
346350

347351
/// Strings containing digits are considered dec numbers.
348-
if (std::all_of(copied_str.begin(), copied_str.end(), [](const auto c) { return std::isdigit(c); })) {
349-
return std::stoull(copied_str, nullptr, 0);
352+
if (std::all_of(value.begin(), value.end(), [](const auto c) { return std::isdigit(c); })) {
353+
return std::stoull(value, nullptr, 0);
350354
}
351355

352356
return std::nullopt;

src/record_file_writer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ perf::RecordFileWriter::write(const Sampler::Values& sampler_values,
7575

7676
/// Write attributes with proper file structure.
7777
for (const auto& counter : sample_counters) {
78-
const auto& perf_event_attribute = counter.group().member(0U).perf_event_attribute();
78+
const auto event_index = 0U + static_cast<std::uint8_t>(counter.has_intel_auxiliary_event());
79+
const auto& perf_event_attribute = counter.group().member(event_index).perf_event_attribute();
7980

8081
/// Create attribute file section (offset and size are empty by default).
8182
auto attribute_section = AttributeFileSection{};

0 commit comments

Comments
 (0)