Skip to content

Commit

Permalink
Revert "summarize Events in PerfEvent & PerfEventInstance class"
Browse files Browse the repository at this point in the history
This reverts commit c30368a.
  • Loading branch information
cvonelm authored Dec 8, 2024
1 parent 32cb5cc commit 34b512c
Show file tree
Hide file tree
Showing 27 changed files with 792 additions and 996 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ 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/reader.hpp>
#include <lo2s/perf/event_description.hpp>

#include <vector>

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

double get_scale(int index) const
{
if (index == 0)
{
return leader.get_scale();
return leader.scale;
}
else
{
return counters[index - 1].get_scale();
return counters[index - 1].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/reader.hpp>
#include <lo2s/perf/event_description.hpp>

#include <vector>

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

private:
SysfsEvent group_leader_;
std::vector<SysfsEvent> group_events_;
std::vector<SysfsEvent> userspace_events_;
EventDescription group_leader_;
std::vector<EventDescription> group_events_;
std::vector<EventDescription> userspace_events_;
};
} // namespace counter
} // namespace perf
Expand Down
17 changes: 14 additions & 3 deletions include/lo2s/perf/counter/group/reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#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 @@ -59,9 +58,21 @@ class Reader : public EventReader<T>
struct GroupReadFormat v;
};

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

protected:
PerfEventInstance counter_leader_;
std::vector<PerfEventInstance> counters_;
int group_leader_fd_;
std::vector<int> counter_fds_;
CounterCollection counter_collection_;
GroupCounterBuffer counter_buffer_;
};
Expand Down
3 changes: 1 addition & 2 deletions include/lo2s/perf/counter/userspace/reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#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 @@ -56,11 +55,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: 110 additions & 0 deletions include/lo2s/perf/event_description.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* This file is part of the lo2s software.
* Linux OTF2 sampling
*
* Copyright (c) 2017,
* Technische Universitaet Dresden, Germany
*
* lo2s is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* lo2s is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with lo2s. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include <lo2s/execution_scope.hpp>
#include <lo2s/topology.hpp>

#include <set>
#include <string>

extern "C"
{
#include <linux/perf_event.h>
}

namespace lo2s
{
namespace perf
{
enum class Availability
{
UNAVAILABLE,
SYSTEM_MODE,
PROCESS_MODE,
UNIVERSAL
};

struct EventDescription
{
EventDescription(const std::string& name, perf_type_id type, std::uint64_t config,
std::uint64_t config1 = 0, std::set<Cpu> cpus = std::set<Cpu>(),
double scale = 1, std::string unit = "#",
Availability availability = Availability::UNAVAILABLE)
: name(name), type(type), config(config), config1(config1), scale(scale), unit(unit),
availability(availability), cpus_(cpus)
{
}

EventDescription()
: name(""), type(static_cast<perf_type_id>(-1)), config(0), config1(0), scale(1), unit("#"),
availability(Availability::UNAVAILABLE)
{
}

const std::set<Cpu>& supported_cpus() const
{
if (cpus_.empty())
{
return Topology::instance().cpus();
}
return cpus_;
}

bool is_supported_in(ExecutionScope scope) const
{
// per-process should always work. the counter will just not count if the process is
// scheduled on a core that is not supprted by that counter
return scope.is_thread() || cpus_.empty() || cpus_.count(scope.as_cpu());
}

friend bool operator==(const EventDescription& lhs, const EventDescription& rhs)
{
return (lhs.type == rhs.type) && (lhs.config == rhs.config) && (lhs.config1 == rhs.config1);
}

friend bool operator<(const EventDescription& lhs, const EventDescription& rhs)
{
if (lhs.type == rhs.type)
{
if (lhs.config == rhs.config)
{
return lhs.config1 < rhs.config1;
}
return lhs.config < rhs.config;
}
return lhs.type < rhs.type;
}

std::string name;
perf_type_id type;
std::uint64_t config;
std::uint64_t config1;
double scale;
std::string unit;
Availability availability;

private:
std::set<Cpu> cpus_;
};
} // namespace perf
} // namespace lo2s
52 changes: 45 additions & 7 deletions include/lo2s/perf/event_provider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#pragma once

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

#include <stdexcept>
#include <string>
Expand All @@ -36,6 +36,43 @@ 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 @@ -45,14 +82,14 @@ class EventProvider
return instance_mutable();
}

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

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

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

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

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

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

std::unordered_map<std::string, SysfsEvent> event_map_;
EventMap event_map_;
};

bool event_is_openable(EventDescription& ev);
} // namespace perf
} // namespace lo2s
Loading

0 comments on commit 34b512c

Please sign in to comment.