Skip to content

Commit

Permalink
refactor event getter & setter
Browse files Browse the repository at this point in the history
  • Loading branch information
Tessa Todorowski committed Aug 23, 2024
1 parent a729250 commit 60fe8b7
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 73 deletions.
4 changes: 2 additions & 2 deletions include/lo2s/perf/counter/counter_collection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ struct CounterCollection
{
if (index == 0)
{
return leader.get_scale();
return leader.scale();
}
else
{
return counters[index - 1].get_scale();
return counters[index - 1].scale();
}
}

Expand Down
31 changes: 18 additions & 13 deletions include/lo2s/perf/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,47 +82,52 @@ class Event
*/
EventGuard open_as_group_leader(ExecutionScope location, int cgroup_fd = -1);

const Availability& get_availability() const
const Availability& availability() const
{
return availability_;
};

std::string get_name() const
std::string name() const
{
return name_;
}

std::set<Cpu> get_cpus() const
std::set<Cpu> cpus() const
{
return cpus_;
}

std::string get_unit() const
std::string unit() const
{
return unit_;
}

perf_event_attr& get_attr()
const perf_event_attr& attr() const
{
return attr_;
}

double get_scale() const
perf_event_attr& mut_attr()
{
return attr_;
}

double scale() const
{
return scale_;
}

void set_scale(double scale)
void scale(double scale)
{
scale_ = scale;
}

void set_unit(const std::string& unit)
void unit(const std::string& unit)
{
unit_ = unit;
}

void set_clock_attrs([[maybe_unused]] bool use_clockid, [[maybe_unused]] clockid_t clockid)
void clock_attrs([[maybe_unused]] bool use_clockid, [[maybe_unused]] clockid_t clockid)
{
#ifndef USE_HW_BREAKPOINT_COMPAT
attr_.use_clockid = use_clockid;
Expand All @@ -132,19 +137,19 @@ class Event

// 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
void set_watermark(size_t mmap_pages)
void watermark(size_t mmap_pages)
{
attr_.watermark = 1;
attr_.wakeup_watermark = static_cast<uint32_t>(0.8 * mmap_pages * sysconf(_SC_PAGESIZE));
}

void set_exclude_kernel(bool exclude_kernel)
void exclude_kernel(bool exclude_kernel)
{
attr_.exclude_kernel = exclude_kernel;
}

void set_sample_period(const int& period);
void set_sample_freq(const uint64_t& freq);
void sample_period(const int& period);
void sample_freq(const uint64_t& freq);
void event_attr_update(std::uint64_t value, const std::string& format);

void parse_pmu_path(const std::string& ev_name);
Expand Down
8 changes: 4 additions & 4 deletions include/lo2s/perf/sample/reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ class Reader : public EventReader<T>
}
catch (const std::system_error& e)
{
if (e.code().value() == EACCES && !event.get_attr().exclude_kernel &&
if (e.code().value() == EACCES && !event.attr().exclude_kernel &&
perf_event_paranoid() > 1)
{
event.get_attr().exclude_kernel = 1;
event.mut_attr().exclude_kernel = 1;
perf_warn_paranoid();
continue;
}
Expand All @@ -106,7 +106,7 @@ class Reader : public EventReader<T>
{
Log::error() << "perf_event_open for sampling failed: " << e.what();

if (event.get_attr().use_clockid)
if (event.attr().use_clockid)
{
Log::error() << "maybe the specified clock is unavailable?";
}
Expand All @@ -115,7 +115,7 @@ class Reader : public EventReader<T>
}
} while (!event_.is_valid());

Log::debug() << "Using precise_ip level: " << event.get_attr().precise_ip;
Log::debug() << "Using precise_ip level: " << event.attr().precise_ip;

// Exception safe, so much wow!
try
Expand Down
5 changes: 2 additions & 3 deletions include/lo2s/trace/trace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,9 @@ class Trace
otf2::definition::metric_member& get_event_metric_member(perf::Event event)
{
return registry_.emplace<otf2::definition::metric_member>(
BySamplingEvent(event), intern(event.get_name()), intern(event.get_name()),
BySamplingEvent(event), intern(event.name()), intern(event.name()),
otf2::common::metric_type::other, otf2::common::metric_mode::accumulated_start,
otf2::common::type::Double, otf2::common::base_type::decimal, 0,
intern(event.get_unit()));
otf2::common::type::Double, otf2::common::base_type::decimal, 0, intern(event.unit()));
}

otf2::definition::metric_class& perf_metric_class(MeasurementScope scope)
Expand Down
8 changes: 4 additions & 4 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ static inline void print_availability(std::ostream& os, const std::string& descr

std::string availability = "";
std::string cpu = "";
if (ev.get_availability() == perf::Availability::PROCESS_MODE)
if (ev.availability() == perf::Availability::PROCESS_MODE)
{
availability = " *";
}
else if (ev.get_availability() == perf::Availability::SYSTEM_MODE)
else if (ev.availability() == perf::Availability::SYSTEM_MODE)
{
availability = " #";
}
Expand All @@ -100,7 +100,7 @@ static inline void print_availability(std::ostream& os, const std::string& descr
std::max_element(cpus.begin(), cpus.end())->as_int());
}

event_names.push_back(ev.get_name() + availability + cpu);
event_names.push_back(ev.name() + availability + cpu);
}
list_arguments_sorted(os, description, event_names);
}
Expand Down Expand Up @@ -731,7 +731,7 @@ void parse_program_options(int argc, const char** argv)
{
for (const auto& mem_event : platform::get_mem_events())
{
perf_group_events.emplace_back(mem_event.get_name());
perf_group_events.emplace_back(mem_event.name());
}
perf_group_events.emplace_back("instructions");
perf_group_events.emplace_back("cpu-cycles");
Expand Down
4 changes: 2 additions & 2 deletions src/monitor/tracepoint_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ TracepointMonitor::TracepointMonitor(trace::Trace& trace, Cpu cpu)

for (const auto& event : tracepoint_collection.counters)
{
auto& mc = trace.tracepoint_metric_class(event.get_name());
auto& mc = trace.tracepoint_metric_class(event.name());
std::unique_ptr<perf::tracepoint::Writer> writer =
std::make_unique<perf::tracepoint::Writer>(cpu, event.get_name(), trace, mc);
std::make_unique<perf::tracepoint::Writer>(cpu, event.name(), trace, mc);

add_fd(writer->fd());
perf_writers_.emplace(std::piecewise_construct, std::forward_as_tuple(writer->fd()),
Expand Down
8 changes: 4 additions & 4 deletions src/perf/counter/counter_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void CounterProvider::initialize_userspace_counters(const std::vector<std::strin
try
{
userspace_events_.emplace_back(perf::EventProvider::get_event_by_name(ev));
userspace_events_.back().set_sample_period(0);
userspace_events_.back().sample_period(0);
}
catch (const perf::EventProvider::InvalidEvent& e)
{
Expand Down Expand Up @@ -115,14 +115,14 @@ void CounterProvider::initialize_group_counters(const std::string& leader,
}
}

// DONT do group_leader_.set_sample_freq() here, since it requires config() to be complete
// DONT do group_leader_.sample_freq() here, since it requires config() to be complete

for (const auto& ev : counters)
{
try
{
// skip event if it has already been declared as group leader
if (ev == group_leader_.get_name())
if (ev == group_leader_.name())
{
Log::info() << "'" << ev
<< "' has been requested as both the metric leader event and a regular "
Expand All @@ -131,7 +131,7 @@ void CounterProvider::initialize_group_counters(const std::string& leader,
}

group_events_.emplace_back(perf::EventProvider::get_event_by_name(ev));
group_events_.back().set_sample_period(0);
group_events_.back().sample_period(0);
}
catch (const perf::EventProvider::InvalidEvent& e)
{
Expand Down
16 changes: 7 additions & 9 deletions src/perf/counter/group/reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ Reader<T>::Reader(ExecutionScope scope, bool enable_on_exec)
{
if (config().metric_use_frequency)
{
counter_collection_.leader.set_sample_freq(config().metric_frequency);
counter_collection_.leader.sample_freq(config().metric_frequency);
}
else
{
counter_collection_.leader.set_sample_period(config().metric_count);
counter_collection_.leader.sample_period(config().metric_count);
}

do
Expand All @@ -73,9 +73,9 @@ Reader<T>::Reader(ExecutionScope scope, bool enable_on_exec)
{
// perf_try_event_open was used here before
if (counter_leader_.get_fd() < 0 && errno == EACCES &&
!counter_collection_.leader.get_attr().exclude_kernel && perf_event_paranoid() > 1)
!counter_collection_.leader.attr().exclude_kernel && perf_event_paranoid() > 1)
{
counter_collection_.leader.get_attr().exclude_kernel = 1;
counter_collection_.leader.mut_attr().exclude_kernel = 1;
perf_warn_paranoid();

continue;
Expand All @@ -89,16 +89,14 @@ Reader<T>::Reader(ExecutionScope scope, bool enable_on_exec)
}
} while (!counter_leader_.is_valid());

Log::debug() << "counter::Reader: leader event: '" << counter_collection_.leader.get_name()
<< "'";
Log::debug() << "counter::Reader: leader event: '" << counter_collection_.leader.name() << "'";

for (auto& counter_ev : counter_collection_.counters)
{
if (counter_ev.is_available_in(scope))
{
EventGuard counter;
counter_ev.get_attr().exclude_kernel =
counter_collection_.leader.get_attr().exclude_kernel;
counter_ev.mut_attr().exclude_kernel = counter_collection_.leader.attr().exclude_kernel;
do
{
try
Expand All @@ -109,7 +107,7 @@ Reader<T>::Reader(ExecutionScope scope, bool enable_on_exec)
{
if (!counter.is_valid())
{
Log::error() << "failed to add counter '" << counter_ev.get_name()
Log::error() << "failed to add counter '" << counter_ev.name()
<< "': " << e.code().message();

if (e.code().value() == EINVAL)
Expand Down
4 changes: 2 additions & 2 deletions src/perf/counter/userspace/reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ Reader<T>::Reader(ExecutionScope scope)
catch (const std::system_error& e)
{
// perf_try_event_open was used here before
if (counter.get_fd() < 0 && errno == EACCES && !event.get_attr().exclude_kernel &&
if (counter.get_fd() < 0 && errno == EACCES && !event.attr().exclude_kernel &&
perf_event_paranoid() > 1)
{
event.get_attr().exclude_kernel = 1;
event.mut_attr().exclude_kernel = 1;
perf_warn_paranoid();

counter = event.open(scope);
Expand Down
10 changes: 5 additions & 5 deletions src/perf/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,13 @@ void Event::parse_cpus()
[](uint32_t cpuid) { return Cpu(cpuid); });
}

void Event::set_sample_period(const int& period)
void Event::sample_period(const int& period)
{
Log::debug() << "counter::Reader: sample_period: " << period;
attr_.sample_period = period;
}

void Event::set_sample_freq(const uint64_t& freq)
void Event::sample_freq(const uint64_t& freq)
{
Log::debug() << "counter::Reader: sample_freq: " << freq;
attr_.sample_freq = freq;
Expand Down Expand Up @@ -495,8 +495,8 @@ SysfsEvent::SysfsEvent(const std::string& ev_name, bool enable_on_exec) : Event(
<< name_ << "/type=" << attr_.type << ",config=" << attr_.config
<< ",config1=" << attr_.config1 << std::dec << std::noshowbase << "/";

set_scale(read_file_or_else<double>(event_path.replace_extension(".scale"), 1.0));
set_unit(read_file_or_else<std::string>(event_path.replace_extension(".unit"), "#"));
scale(read_file_or_else<double>(event_path.replace_extension(".scale"), 1.0));
unit(read_file_or_else<std::string>(event_path.replace_extension(".unit"), "#"));

if (!event_is_openable())
{
Expand Down Expand Up @@ -596,7 +596,7 @@ EventGuard::EventGuard(Event& ev, std::variant<Cpu, Thread> location, int group_
[&](Thread thread) { scope = thread.as_scope(); } },
location);

fd_ = perf_event_open(&ev_.get_attr(), scope, group_fd, 0, cgroup_fd);
fd_ = perf_event_open(&ev_.mut_attr(), scope, group_fd, 0, cgroup_fd);

if (fd_ < 0)
{
Expand Down
Loading

0 comments on commit 60fe8b7

Please sign in to comment.