Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(EventDescription): Turn EventDescription into real class #276

Closed
wants to merge 2 commits into from

Conversation

cvonelm
Copy link
Member

@cvonelm cvonelm commented Apr 19, 2023

The current EventDescription is a mere struct with exposed struct members etc. This PR attempts to rework the EventDescription into a proper class while integrating some of the Event Handling Code into this new class.

This fixes #224

This also fixes #275, a bug that prevents events from showing if they could only be opened with exclude_kernel=1

@cvonelm cvonelm force-pushed the issue-224-decify-event-description branch from 838638e to dc2d7bf Compare April 27, 2023 11:19
@bmario
Copy link
Member

bmario commented Apr 27, 2023

I'm out of the loop about this. Can you extend the PR description (and commit message) and elaborate on what this PR tries to achieve?

@cvonelm
Copy link
Member Author

cvonelm commented Apr 27, 2023

I will be updating the commit message once this is ready for merging and squashed.

Copy link
Member

@bmario bmario left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really dislike, how this copies perf initialization code everywhere, but only in half of the cases. The other half has a new method as sane replacement.

else
{
availability_ = Availability::UNIVERSAL;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need an Fd RAII object. sys_fd and proc_fd are never closed, if they succeed in opening.


if (sys_fd == -1 && proc_fd == -1)
{
attr.exclude_kernel = 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we just open it with exclude_kernel, if it's for testing only anyways?

struct perf_event_attr perf_event_attr() const
{
struct perf_event_attr attr;
memset(&attr, 0, sizeof(struct perf_event_attr));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
memset(&attr, 0, sizeof(struct perf_event_attr));
std::memset(&attr, 0, sizeof(struct perf_event_attr));

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, missing header: <cstring>

return attr;
}

std::string name() const
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::string name() const
const& std::string name() const

return scale_;
}

std::string unit() const
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::string unit() const
const& std::string unit() const

Comment on lines +460 to +478
static constexpr auto npos = std::string::npos;
const auto colon = format.find_first_of(':');
if (colon == npos)
{
throw EventProvider::InvalidEvent("invalid format description: missing colon");
}

const auto target_config = format.substr(0, colon);
const auto mask = parse_bitmask(format.substr(colon + 1));

if (target_config == "config")
{
config |= apply_mask(val, mask);
}

if (target_config == "config1")
{
config1 |= apply_mask(val, mask);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🍝

Comment on lines +357 to +363
std::underlying_type<perf_type_id>::type type;
uint64_t config = 0;
uint64_t config1 = 0;
std::set<Cpu> cpus;
double scale;
std::string unit;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this here?
Seems to be unused for another 100 lines of code.

constexpr std::uint64_t bit(int bitnumber)
{
return static_cast<std::uint64_t>(1_u64 << bitnumber);
return static_cast<std::uint64_t>(1ULL << bitnumber);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return static_cast<std::uint64_t>(1ULL << bitnumber);
return 1ull << bitnumber;

Comment on lines +460 to +462
static constexpr auto npos = std::string::npos;
const auto colon = format.find_first_of(':');
if (colon == npos)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static constexpr auto npos = std::string::npos;
const auto colon = format.find_first_of(':');
if (colon == npos)
const auto colon = format.find_first_of(':');
if (colon == std::string::npos)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be have been a regex in the first place. What about format == "foo:"?

Comment on lines +58 to +68
leader_attr.disabled = 1;

#ifndef USE_HW_BREAKPOINT_COMPAT
leader_attr.use_clockid = config().use_clockid;
leader_attr.clockid = config().clockid;
#endif
// When we poll on the fd given by perf_event_open, wakeup, when our buffer is 80% full
// Default behaviour is to wakeup on every event, which is horrible performance wise
leader_attr.watermark = 1;
leader_attr.wakeup_watermark =
static_cast<uint32_t>(0.8 * config().mmap_pages * get_page_size());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks oddly familiar. 🍝

@cvonelm
Copy link
Member Author

cvonelm commented Sep 15, 2023

Dropping this PR in favour of a more thorough refactoring based on the raii-fd branch.

@cvonelm cvonelm closed this Sep 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rework EventDescription to be less C-struct like. Events will be marked as unopenable if exclude_kernel=1
2 participants