Skip to content

Commit

Permalink
summarize Events in PerfEvent & PerfEventInstance class
Browse files Browse the repository at this point in the history
  • Loading branch information
Tessa Todorowski committed Jul 23, 2024
1 parent 038b75a commit e66d04a
Show file tree
Hide file tree
Showing 27 changed files with 998 additions and 775 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ set(SOURCE_FILES
src/process_controller.cpp

src/perf/event_provider.cpp
src/perf/reader.cpp

src/perf/bio/block_device.cpp
src/perf/counter/counter_provider.cpp
Expand Down
10 changes: 5 additions & 5 deletions include/lo2s/perf/counter/counter_collection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#pragma once

#include <lo2s/perf/event_description.hpp>
#include <lo2s/perf/reader.hpp>

#include <vector>

Expand All @@ -33,18 +33,18 @@ namespace counter
{
struct CounterCollection
{
EventDescription leader;
std::vector<EventDescription> counters;
SysfsEvent leader;
std::vector<SysfsEvent> counters;

double get_scale(int index) const
{
if (index == 0)
{
return leader.scale;
return leader.get_scale();
}
else
{
return counters[index - 1].scale;
return counters[index - 1].get_scale();
}
}

Expand Down
8 changes: 4 additions & 4 deletions include/lo2s/perf/counter/counter_provider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#include <lo2s/measurement_scope.hpp>
#include <lo2s/perf/counter/counter_collection.hpp>
#include <lo2s/perf/event_description.hpp>
#include <lo2s/perf/reader.hpp>

#include <vector>

Expand Down Expand Up @@ -56,9 +56,9 @@ class CounterProvider
CounterCollection collection_for(MeasurementScope scope);

private:
EventDescription group_leader_;
std::vector<EventDescription> group_events_;
std::vector<EventDescription> userspace_events_;
SysfsEvent group_leader_;
std::vector<SysfsEvent> group_events_;
std::vector<SysfsEvent> userspace_events_;
};
} // namespace counter
} // namespace perf
Expand Down
17 changes: 3 additions & 14 deletions include/lo2s/perf/counter/group/reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <lo2s/perf/counter/counter_collection.hpp>
#include <lo2s/perf/counter/group/group_counter_buffer.hpp>
#include <lo2s/perf/event_reader.hpp>
#include <lo2s/perf/reader.hpp>

#include <vector>

Expand Down Expand Up @@ -58,21 +59,9 @@ class Reader : public EventReader<T>
struct GroupReadFormat v;
};

~Reader()
{
for (int fd : counter_fds_)
{
if (fd != -1)
{
::close(fd);
}
}
::close(group_leader_fd_);
}

protected:
int group_leader_fd_;
std::vector<int> counter_fds_;
PerfEventInstance counter_leader_;
std::vector<PerfEventInstance> counters_;
CounterCollection counter_collection_;
GroupCounterBuffer counter_buffer_;
};
Expand Down
3 changes: 2 additions & 1 deletion include/lo2s/perf/counter/userspace/reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <lo2s/execution_scope.hpp>
#include <lo2s/perf/counter/counter_collection.hpp>
#include <lo2s/perf/counter/userspace/userspace_counter_buffer.hpp>
#include <lo2s/perf/reader.hpp>
#include <lo2s/trace/trace.hpp>

#include <cstdint>
Expand Down Expand Up @@ -55,11 +56,11 @@ class Reader
}

protected:
std::vector<int> counter_fds_;
CounterCollection counter_collection_;
UserspaceCounterBuffer counter_buffer_;
int timer_fd_;

std::vector<PerfEventInstance> counters_;
std::vector<UserspaceReadFormat> data_;
};
} // namespace userspace
Expand Down
110 changes: 0 additions & 110 deletions include/lo2s/perf/event_description.hpp

This file was deleted.

51 changes: 7 additions & 44 deletions include/lo2s/perf/event_provider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <unordered_map>
#include <vector>

#include <lo2s/perf/event_description.hpp>
#include <lo2s/perf/reader.hpp>

namespace lo2s
{
Expand All @@ -36,43 +36,6 @@ namespace perf
class EventProvider
{
public:
struct DescriptionCache
{
private:
DescriptionCache()
: description(std::string(), static_cast<perf_type_id>(-1), 0, 0), valid_(false)
{
}

public:
DescriptionCache(const EventDescription& description)
: description(description), valid_(true)
{
}

DescriptionCache(EventDescription&& description)
: description(std::move(description)), valid_(true)
{
}

static DescriptionCache make_invalid()
{
return DescriptionCache();
}

bool is_valid() const
{
return valid_;
}

EventDescription description;

private:
bool valid_;
};

using EventMap = std::unordered_map<std::string, DescriptionCache>;

EventProvider();
EventProvider(const EventProvider&) = delete;
void operator=(const EventProvider&) = delete;
Expand All @@ -82,14 +45,14 @@ class EventProvider
return instance_mutable();
}

static EventDescription get_event_by_name(const std::string& name);
static SysfsEvent get_event_by_name(const std::string& name);

static bool has_event(const std::string& name);

static std::vector<EventDescription> get_predefined_events();
static std::vector<EventDescription> get_pmu_events();
static std::vector<SysfsEvent> get_predefined_events();
static std::vector<SysfsEvent> get_pmu_events();

static EventDescription fallback_metric_leader_event();
static SysfsEvent fallback_metric_leader_event();

class InvalidEvent : public std::runtime_error
{
Expand All @@ -107,9 +70,9 @@ class EventProvider
return e;
}

EventDescription cache_event(const std::string& name);
SysfsEvent cache_event(const std::string& name);

EventMap event_map_;
std::unordered_map<std::string, SysfsEvent> event_map_;
};
} // namespace perf
} // namespace lo2s
Loading

0 comments on commit e66d04a

Please sign in to comment.