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

Turn EventDescription into class #340

Open
wants to merge 26 commits into
base: master
Choose a base branch
from

Conversation

teto519f
Copy link

This addresses issue #224

This PR creates a PerfEvent and a PerfEventInstance class, which can handle every type of event in lo2s. It aims to remove redundant code for event creation and to simplify their handling.

@teto519f teto519f force-pushed the issue-224-EventDescription-into-class branch from 36ca29e to e66d04a Compare July 23, 2024 08:00
include/lo2s/perf/counter/counter_collection.hpp Outdated Show resolved Hide resolved
include/lo2s/perf/counter/counter_provider.hpp Outdated Show resolved Hide resolved
include/lo2s/perf/event_provider.hpp Outdated Show resolved Hide resolved
include/lo2s/perf/io_reader.hpp Outdated Show resolved Hide resolved
src/platform.cpp Outdated Show resolved Hide resolved
src/perf/reader.cpp Outdated Show resolved Hide resolved
include/lo2s/perf/bio/writer.hpp Outdated Show resolved Hide resolved
include/lo2s/perf/reader.hpp Outdated Show resolved Hide resolved
include/lo2s/perf/reader.hpp Outdated Show resolved Hide resolved
include/lo2s/perf/reader.hpp Outdated Show resolved Hide resolved
include/lo2s/perf/reader.hpp Outdated Show resolved Hide resolved
src/perf/reader.cpp Outdated Show resolved Hide resolved
include/lo2s/perf/reader.hpp Outdated Show resolved Hide resolved
src/perf/reader.cpp Outdated Show resolved Hide resolved
include/lo2s/perf/reader.hpp Outdated Show resolved Hide resolved
include/lo2s/perf/reader.hpp Outdated Show resolved Hide resolved
include/lo2s/perf/reader.hpp Outdated Show resolved Hide resolved
include/lo2s/perf/reader.hpp Outdated Show resolved Hide resolved
include/lo2s/perf/reader.hpp Outdated Show resolved Hide resolved
* Contains an opened instance of PerfEvent.
* Use PerfEvent.open() to construct an object
*/
class PerfEventInstance
Copy link
Member

Choose a reason for hiding this comment

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

I don't like the Instance postfix for a class name. Nobody does that. In C++ we would call these things "guard", like std::lock_guard. Hence, I propose EventGuard instead.

Copy link
Member

Choose a reason for hiding this comment

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

Also, I have the feeling, that it might be good to have a template argument to this class, which is the actual event used, e.g., EventGuard<TracepointEvent> event_;.

Copy link
Author

Choose a reason for hiding this comment

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

But the type of Event in EventGuard isn't being checked anywhere. Is there even a use for this information in EventGuard?

include/lo2s/perf/reader.hpp Outdated Show resolved Hide resolved
src/perf/counter/group/reader.cpp Outdated Show resolved Hide resolved
src/perf/counter/group/reader.cpp Outdated Show resolved Hide resolved
include/lo2s/perf/syscall/reader.hpp Outdated Show resolved Hide resolved
src/perf/reader.cpp Outdated Show resolved Hide resolved
include/lo2s/perf/reader.hpp Outdated Show resolved Hide resolved
@teto519f teto519f force-pushed the issue-224-EventDescription-into-class branch 3 times, most recently from 6e7e736 to 820daaa Compare August 6, 2024 11:28
include/lo2s/measurement_scope.hpp Outdated Show resolved Hide resolved
include/lo2s/perf/bio/writer.hpp Outdated Show resolved Hide resolved
include/lo2s/perf/event.hpp Outdated Show resolved Hide resolved
include/lo2s/perf/event.hpp Outdated Show resolved Hide resolved
include/lo2s/perf/event.hpp Outdated Show resolved Hide resolved
include/lo2s/perf/event.hpp Outdated Show resolved Hide resolved
include/lo2s/perf/event.hpp Outdated Show resolved Hide resolved
include/lo2s/perf/event.hpp Outdated Show resolved Hide resolved
Comment on lines +133 to +144
Event::Event() : name_("")
{
memset(&attr_, 0, sizeof(attr_));
attr_.size = sizeof(attr_);
attr_.type = PERF_TYPE_RAW;

attr_.config = 0;
attr_.config1 = 0;

attr_.sample_period = 0;
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.

I don't think a default constructed event should be possible.

Copy link
Author

Choose a reason for hiding this comment

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

Why not? This way you can say that a reader holds an event without needing to know the specifics.

Copy link
Member

Choose a reason for hiding this comment

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

Because of the unknown specifics, you end up with an object that cannot be used. It's not initialized, a constructor should never give an ususable object.

attr_.exclude_kernel = 1;
}

Event::Event([[maybe_unused]] uint64_t addr, bool enable_on_exec)
Copy link
Member

Choose a reason for hiding this comment

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

this does not set the name_ I don't want Event instances without a name.
The real issue is that this constructor is used for some special task and should better be a factory function

Copy link
Author

Choose a reason for hiding this comment

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

Which name should a time event get? Or in other words: From where should the event take its name?

Copy link
Member

Choose a reason for hiding this comment

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

"Time" sounds as good to me as anything else.

src/perf/event.cpp Outdated Show resolved Hide resolved
src/perf/event.cpp Outdated Show resolved Hide resolved
src/perf/event.cpp Outdated Show resolved Hide resolved
@teto519f teto519f force-pushed the issue-224-EventDescription-into-class branch 4 times, most recently from 3601ca0 to 7798068 Compare September 17, 2024 08:29
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.

3 participants