Skip to content

Commit

Permalink
Merge branch 'v0.8' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
jmuehlig committed Nov 11, 2024
2 parents a3be4cc + 25f9ca0 commit f9a9e41
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
* New feature: Access interim results from counters without stopping the counter using [live counters](docs/recording-live-events.md).
* New feature: Sampling the user stack (see [documentation](docs/sampling.md#user-stack)).

## v0.8.3
* Fixed multiple compatibility issues where the code relied on Linux kernel features that might not available on different versions.

## v0.8.2
* Fixed compatibility for older Linux versions that don't provide `PERF_MEM_BLK`, `PERF_MEM_LVLNUM`, and `PERF_MEM_REMOTE`.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ git clone https://github.com/jmuehlig/perf-cpp.git
cd perf-cpp

# Optional: Switch to the latest stable version
git checkout v0.8.2
git checkout v0.8.3

# Build the library (in build/)
cmake . -B build -DBUILD_EXAMPLES=1
Expand Down
6 changes: 3 additions & 3 deletions docs/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ git clone git clone https://github.com/jmuehlig/perf-cpp.git
cd perf-cpp

# Optional: switch to latest stable version
git checkout v0.8.2
git checkout v0.8.3
```

#### Generate the Makefile and Build
Expand Down Expand Up @@ -74,7 +74,7 @@ include(ExternalProject)
ExternalProject_Add(
perf-cpp-external
GIT_REPOSITORY "https://github.com/jmuehlig/perf-cpp"
GIT_TAG "v0.8.2"
GIT_TAG "v0.8.3"
PREFIX "lib/perf-cpp"
INSTALL_COMMAND cmake -E echo ""
)
Expand All @@ -92,7 +92,7 @@ include(FetchContent)
FetchContent_Declare(
perf-cpp-external
GIT_REPOSITORY "https://github.com/jmuehlig/perf-cpp"
GIT_TAG "v0.8.2"
GIT_TAG "v0.8.3"
)
FetchContent_MakeAvailable(perf-cpp-external)
```
Expand Down
6 changes: 5 additions & 1 deletion include/perfcpp/branch.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ enum BranchType : std::uint64_t
#ifndef PERFCPP_NO_SAMPLE_BRANCH_CALL
Call = PERF_SAMPLE_BRANCH_ANY_CALL,
#else
Call = 1ULL << 62,
Call = 1ULL << 61,
#endif
#ifndef PERFCPP_NO_SAMPLE_BRANCH_CALL
DirectCall = PERF_SAMPLE_BRANCH_CALL,
#else
DirectCall = 1ULL << 62,
#endif
IndirectCall = PERF_SAMPLE_BRANCH_IND_CALL,
Return = PERF_SAMPLE_BRANCH_ANY_RETURN,
#ifndef PERFCPP_NO_SAMPLE_BRANCH_IND_JUMP
Expand Down
1 change: 1 addition & 0 deletions include/perfcpp/data_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <cstdint>
#include <linux/perf_event.h>
#include "feature.h"

namespace perf {
class DataSource
Expand Down
2 changes: 2 additions & 0 deletions include/perfcpp/feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 2, 0)
#define PERFCPP_NO_SAMPLE_BRANCH_IND_JUMP
#define PERFCPP_NO_RECORD_LOST_SAMPLES
#endif

#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 3, 0)
Expand All @@ -24,6 +25,7 @@

#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 4, 0)
#define PERFCPP_NO_SAMPLE_BRANCH_CALL
#define PERFCPP_NO_COUNT_SW_BPF_OUTPUT
#endif

#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 8, 0)
Expand Down
9 changes: 8 additions & 1 deletion include/perfcpp/sampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,14 @@ class Sampler
[[nodiscard]] Sample::Mode mode() const noexcept;

[[nodiscard]] bool is_sample_event() const noexcept { return _type == PERF_RECORD_SAMPLE; }
[[nodiscard]] bool is_loss_event() const noexcept { return _type == PERF_RECORD_LOST_SAMPLES; }
[[nodiscard]] bool is_loss_event() const noexcept
{
#ifndef PERFCPP_NO_RECORD_LOST_SAMPLES /// PERF_RECORD_LOST_SAMPLES is supported since Linux 4.2
return _type == PERF_RECORD_LOST_SAMPLES;
#else
return false;
#endif
}
[[nodiscard]] bool is_context_switch_event() const noexcept
{
#ifndef PERFCPP_NO_RECORD_SWITCH /// Switch events are supported since Linux 4.3
Expand Down
7 changes: 6 additions & 1 deletion src/counter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,10 +617,11 @@ perf::Counter::to_string(const std::optional<bool> is_group_leader,

stream << "\n";
}

#ifndef PERFCPP_NO_SAMPLE_MAX_STACK
if (this->_event_attribute.sample_max_stack > 0U) {
stream << " sample_max_stack: " << this->_event_attribute.sample_max_stack << "\n";
}
#endif

if (this->_event_attribute.sample_regs_user > 0U) {
stream << " sample_regs_user: " << this->_event_attribute.sample_regs_user << "\n";
Expand Down Expand Up @@ -657,12 +658,16 @@ perf::Counter::to_string(const std::optional<bool> is_group_leader,
if (this->_event_attribute.exclude_guest > 0U) {
stream << " exclude_guest: " << this->_event_attribute.exclude_guest << "\n";
}
#ifndef PERFCPP_NO_RECORD_SWITCH
if (this->_event_attribute.context_switch > 0U) {
stream << " context_switch: " << this->_event_attribute.context_switch << "\n";
}
#endif
#ifndef PERFCPP_NO_RECORD_CGROUP
if (this->_event_attribute.cgroup > 0U) {
stream << " cgroup: " << this->_event_attribute.cgroup << "\n";
}
#endif

return stream.str();
}
Expand Down
4 changes: 3 additions & 1 deletion src/counter_definition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ perf::CounterDefinition::initialize_generalized_counters()
this->add("alignment-faults", PERF_TYPE_SOFTWARE, PERF_COUNT_SW_ALIGNMENT_FAULTS);
this->add("emulation-faults", PERF_TYPE_SOFTWARE, PERF_COUNT_SW_EMULATION_FAULTS);
this->add("context-switches", PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CONTEXT_SWITCHES);
#ifndef PERFCPP_NO_COUNT_SW_BPF_OUTPUT /// PERF_COUNT_SW_BPF_OUTPUT is supported since Linux Kernel 4.4
this->add("bpf-output", PERF_TYPE_SOFTWARE, PERF_COUNT_SW_BPF_OUTPUT);
#ifndef PERFCPP_NO_CGROUP_SWITCHES /// PERF_COUNT_SW_CGROUP_SWITCHES is provided since Linux Kernel 5.13
#endif
#ifndef PERFCPP_NO_CGROUP_SWITCHES /// PERF_COUNT_SW_CGROUP_SWITCHES is supported since Linux Kernel 5.13
this->add("cgroup-switches", PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CGROUP_SWITCHES);
#endif
this->add("cpu-migrations", PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_MIGRATIONS);
Expand Down

0 comments on commit f9a9e41

Please sign in to comment.