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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
78d08e1
summarize Events in PerfEvent & PerfEventInstance class
Jun 25, 2024
8c7bd3b
implement suggested changes in PerfEvent
Jul 23, 2024
4379a92
completely remove config() dependency, use event_provider as Event fa…
Jul 29, 2024
80bb194
fix build tests
Aug 6, 2024
37e03d5
rephrase ExecutionScope name() msg, fix typo
Aug 8, 2024
77df695
EventGuard: set_id() -> get_id()
Aug 8, 2024
dd05e7b
add/remove const& where needed
Aug 23, 2024
3c2811b
refactor event getter & setter
Aug 23, 2024
1770f37
remove overloaded helper for std::visit
Aug 23, 2024
25a6e0c
remove ret var in enable() and diable() method
Aug 23, 2024
0e1d88f
combine each tracepoint & sysfs event factory functions
Aug 23, 2024
acb9c59
no c-style casting
Aug 23, 2024
833089f
implement and use |= operator for Availability enum
Aug 23, 2024
ef4525c
check for error in get_id()
Aug 23, 2024
cc25f5f
remove Event attribute from EventGuard
Aug 23, 2024
bb92d40
move time event constructor into factory function, generalize create_…
Sep 2, 2024
5d2643f
init fd_ in EventGuard constructor
Sep 2, 2024
eea1bee
replace bit with (1ull << x)
Sep 2, 2024
205279b
include sorting
Sep 2, 2024
50a50d2
fix build tests
Sep 2, 2024
449bccd
let read_file_or_else return an std::optional, rename to try_read_file
Sep 2, 2024
d68aea3
replace default constructed EventGuard instances with std::optional<E…
Sep 2, 2024
fbc55bd
use move explicitly for EventGuard instances
Sep 16, 2024
fbce3ca
fix build tests
Sep 17, 2024
31ae04c
fix -Wmaybe-uninitialized for group and userspace EventGuards
Oct 14, 2024
a26b574
fix comparison operators of Event
Oct 14, 2024
2c88278
name time events "Time"
Nov 12, 2024
a04153f
remove default constructors of Events, use std::optional instead
Nov 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ set(SOURCE_FILES
src/process_controller.cpp

src/perf/event_provider.cpp
src/perf/event.cpp

src/perf/bio/block_device.cpp
src/perf/counter/counter_provider.cpp
Expand All @@ -196,8 +197,8 @@ set(SOURCE_FILES

src/perf/sample/writer.cpp
src/perf/time/converter.cpp src/perf/time/reader.cpp
src/perf/tracepoint/format.cpp
src/perf/tracepoint/writer.cpp
src/perf/tracepoint/event.cpp
src/perf/syscall/writer.cpp

src/time/time.cpp
Expand Down
8 changes: 8 additions & 0 deletions include/lo2s/measurement_scope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ enum class MeasurementScopeType
BIO,
SYSCALL,
CUDA,
TRACEPOINT,
UNKNOWN
};

Expand Down Expand Up @@ -85,6 +86,11 @@ struct MeasurementScope
return { MeasurementScopeType::CUDA, s };
}

static MeasurementScope tracepoint(ExecutionScope s)
{
return { MeasurementScopeType::TRACEPOINT, s };
}

friend bool operator==(const MeasurementScope& lhs, const MeasurementScope& rhs)
{
return (lhs.scope == rhs.scope) && lhs.type == rhs.type;
Expand Down Expand Up @@ -119,6 +125,8 @@ struct MeasurementScope
return fmt::format("syscall events for {}", scope.name());
case lo2s::MeasurementScopeType::CUDA:
return fmt::format("cuda kernel events for {}", scope.name());
case MeasurementScopeType::TRACEPOINT:
return fmt::format("tracepoint events for {}", scope.name());
default:
throw new std::runtime_error("Unknown ExecutionScopeType!");
}
Expand Down
32 changes: 18 additions & 14 deletions include/lo2s/perf/bio/writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class Writer

void write(IoReaderIdentity& identity, TracepointSampleType* header)
{
if (identity.tracepoint == bio_queue_)
if (identity.tracepoint() == bio_queue_)
{
struct RecordBioQueue* event = (RecordBioQueue*)header;

Expand Down Expand Up @@ -112,7 +112,7 @@ class Writer
time_converter_(event->header.time), handle, mode,
otf2::common::io_operation_flag_type::non_blocking, size, event->sector);
}
else if (identity.tracepoint == bio_issue_)
else if (identity.tracepoint() == bio_issue_)
{
struct RecordBlock* event = (RecordBlock*)header;

Expand All @@ -129,7 +129,7 @@ class Writer
writer << otf2::event::io_operation_issued(time_converter_(event->header.time), handle,
event->sector);
}
else if (identity.tracepoint == bio_complete_)
else if (identity.tracepoint() == bio_complete_)
{
struct RecordBlock* event = (RecordBlock*)header;

Expand All @@ -150,19 +150,21 @@ class Writer
}
else
{
throw std::runtime_error("tracepoint " + identity.tracepoint.name() +
throw std::runtime_error("tracepoint " + identity.tracepoint().name() +
" not valid for block I/O");
}
}

std::vector<tracepoint::EventFormat> get_tracepoints()
std::vector<perf::tracepoint::TracepointEvent> get_tracepoints()
{

bio_queue_ = tracepoint::EventFormat("block:block_bio_queue");
bio_issue_ = tracepoint::EventFormat("block:block_rq_issue");
bio_complete_ = tracepoint::EventFormat("block:block_rq_complete");

return { bio_queue_, bio_issue_, bio_complete_ };
bio_queue_ =
perf::EventProvider::instance().create_tracepoint_event("block:block_bio_queue");
bio_issue_ =
perf::EventProvider::instance().create_tracepoint_event("block:block_rq_issue");
bio_complete_ =
perf::EventProvider::instance().create_tracepoint_event("block:block_rq_complete");

return { bio_queue_.value(), bio_issue_.value(), bio_complete_.value() };
}

private:
Expand All @@ -182,9 +184,11 @@ class Writer
trace::Trace& trace_;
time::Converter& time_converter_;

tracepoint::EventFormat bio_queue_;
tracepoint::EventFormat bio_issue_;
tracepoint::EventFormat bio_complete_;
// Unavailable until get_tracepoints() is called
std::optional<perf::tracepoint::TracepointEvent> bio_queue_;
std::optional<perf::tracepoint::TracepointEvent> bio_issue_;
std::optional<perf::tracepoint::TracepointEvent> bio_complete_;

// The unit "sector" is always 512 bit large, regardless of the actual sector size of the device
static constexpr int SECTOR_SIZE = 512;
};
Expand Down
22 changes: 14 additions & 8 deletions include/lo2s/perf/counter/counter_collection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@

#pragma once

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

#include <optional>
#include <vector>

namespace lo2s
Expand All @@ -33,24 +34,29 @@ namespace counter
{
struct CounterCollection
{
EventDescription leader;
std::vector<EventDescription> counters;
std::optional<Event> leader_;
std::vector<Event> counters;

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

Event& leader() const
{
return const_cast<Event&>(leader_.value());
}

friend bool operator==(const CounterCollection& lhs, const CounterCollection& rhs)
{
if (lhs.leader == rhs.leader)
if (lhs.leader_.value() == rhs.leader_.value())
{
return lhs.counters == rhs.counters;
}
Expand All @@ -59,11 +65,11 @@ struct CounterCollection

friend bool operator<(const CounterCollection& lhs, const CounterCollection& rhs)
{
if (lhs.leader == rhs.leader)
if (lhs.leader_.value() == rhs.leader_.value())
{
return lhs.counters < rhs.counters;
}
return lhs.leader < rhs.leader;
return lhs.leader_.value() < rhs.leader_.value();
}
};

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

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

#include <optional>
#include <vector>

namespace lo2s
Expand All @@ -49,16 +50,19 @@ class CounterProvider
void initialize_group_counters(const std::string& leader,
const std::vector<std::string>& counters);
void initialize_userspace_counters(const std::vector<std::string>& counters);
void initialize_tracepoints(const std::vector<std::string>& tracepoints);

bool has_group_counters(ExecutionScope scope);
bool has_userspace_counters(ExecutionScope scope);

CounterCollection collection_for(MeasurementScope scope);
std::vector<std::string> get_tracepoint_event_names();

private:
EventDescription group_leader_;
std::vector<EventDescription> group_events_;
std::vector<EventDescription> userspace_events_;
std::optional<Event> group_leader_;
std::vector<Event> group_events_;
std::vector<Event> userspace_events_;
std::vector<tracepoint::TracepointEvent> tracepoint_events_;
};
} // namespace counter
} // namespace perf
Expand Down
18 changes: 4 additions & 14 deletions include/lo2s/perf/counter/group/reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@

#include <lo2s/perf/counter/counter_collection.hpp>
#include <lo2s/perf/counter/group/group_counter_buffer.hpp>
#include <lo2s/perf/event.hpp>
#include <lo2s/perf/event_reader.hpp>

#include <optional>
#include <vector>

extern "C"
Expand Down Expand Up @@ -58,21 +60,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_;
std::optional<EventGuard> counter_leader_;
std::vector<EventGuard> 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/event_provider.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<EventGuard> counters_;
std::vector<UserspaceReadFormat> data_;
};
} // namespace userspace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ namespace userspace
{
struct UserspaceReadFormat
{
UserspaceReadFormat() : value(0), time_enabled(0), time_running(0)
{
}

uint64_t value;
uint64_t time_enabled;
uint64_t time_running;
Expand Down
Loading
Loading