Skip to content

Commit

Permalink
fofoo
Browse files Browse the repository at this point in the history
  • Loading branch information
cvonelm committed Feb 10, 2025
1 parent 47b00bd commit 9c3d43f
Show file tree
Hide file tree
Showing 33 changed files with 915 additions and 586 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ add_subdirectory(lib/otf2xx)
mark_as_advanced(OTF2XX_WITH_MPI OTF2_CONFIG OTF2_PRINT)

# configure fmtlib submodule
set(BUILD_SHARED_LIBS ON)
add_subdirectory(lib/fmt)

# configure Nitro submodule
Expand Down Expand Up @@ -349,7 +350,7 @@ if (USE_LIBAUDIT)
endif()
endif()

add_executable(rb_test src/cupti/test.cpp)
add_executable(rb_test src/cupti/test.cpp src/types.cpp)
target_include_directories(rb_test PRIVATE include ${CMAKE_CURRENT_BINARY_DIR}/include)
target_link_libraries(rb_test PRIVATE fmt::fmt
Nitro::log
Expand Down
48 changes: 0 additions & 48 deletions include/lo2s/cupti/events.hpp

This file was deleted.

8 changes: 6 additions & 2 deletions include/lo2s/dwarf_resolve.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ class DwarfFunctionResolver : public FunctionResolver
public:
DwarfFunctionResolver(std::string name);

static FunctionResolver& cache(std::string name)
static std::shared_ptr<FunctionResolver> cache(std::string name)
{
return StringCache<DwarfFunctionResolver>::instance()[name];
return BinaryCache<DwarfFunctionResolver>::instance()[name];
}

DwarfFunctionResolver(DwarfFunctionResolver&) = delete;
DwarfFunctionResolver& operator=(DwarfFunctionResolver&) = delete;
DwarfFunctionResolver(DwarfFunctionResolver&&) = delete;
DwarfFunctionResolver& operator=(DwarfFunctionResolver&&) = delete;
~DwarfFunctionResolver();
virtual LineInfo lookup_line_info(Address addr) override;

Expand Down
2 changes: 1 addition & 1 deletion include/lo2s/execution_scope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class ExecutionScope
case ExecutionScopeType::THREAD:
return fmt::format("thread {}", id);
case ExecutionScopeType::PROCESS:
return fmt::format("process {}");
return fmt::format("process {}", id);
case ExecutionScopeType::CPU:
return fmt::format("cpu {}", id);
default:
Expand Down
65 changes: 59 additions & 6 deletions include/lo2s/function_resolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class FunctionResolver
{
}

static FunctionResolver& cache(const std::string& name)
static std::shared_ptr<FunctionResolver> cache(const std::string& name)
{
return StringCache<FunctionResolver>::instance()[name];
return BinaryCache<FunctionResolver>::instance()[name];
}

virtual LineInfo lookup_line_info(Address)
Expand All @@ -51,18 +51,71 @@ class FunctionResolver
return name_;
}

virtual void insert(std::map<Address, std::string>& functions [[maybe_unused]])
{
throw std::runtime_error("Class does not support inserting elements");
}

virtual ~FunctionResolver()
{
}

protected:
std::string name_;
};

class ManualFunctionResolver : public FunctionResolver
{
public:
ManualFunctionResolver(const std::string& name) : FunctionResolver(name)
{
}

static std::shared_ptr<ManualFunctionResolver> cache(const std::string& name)
{
return BinaryCache<ManualFunctionResolver>::instance()[name];
}

virtual LineInfo lookup_line_info(Address address) override
{
if (functions_.count(address))
{
return LineInfo::for_function("", functions_.at(address).c_str(), 1, "");
}
return LineInfo::for_unknown_function();
}

void insert(std::map<Address, std::string>& functions) override
{
for (auto& function : functions)
{
functions_.insert(function);
}
}

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

protected:
std::map<Address, std::string> functions_;
std::string name_;
};

Check failure on line 104 in include/lo2s/function_resolver.hpp

View check run for this annotation

Code Style Turtle / Code Formatting Test

include/lo2s/function_resolver.hpp#L104

+
class Kallsyms : public FunctionResolver
{
public:
Kallsyms() : FunctionResolver("[kernel]")
{
std::map<Address, std::string> entries;
std::ifstream ksyms_file("/proc/kallsyms");
std::ifstream ksyms_file;
ksyms_file.exceptions(std::ifstream::badbit);
ksyms_file.open("/proc/kallsyms");

if (!ksyms_file.good())
{
return;
}
std::regex ksym_regex("([0-9a-f]+) (?:t|T) ([^[:space:]]+)");
std::smatch ksym_match;

Expand Down Expand Up @@ -107,9 +160,9 @@ class Kallsyms : public FunctionResolver
}
}

static Kallsyms& cache()
static std::shared_ptr<Kallsyms> cache()
{
static Kallsyms k;
static std::shared_ptr<Kallsyms> k = std::make_shared<Kallsyms>();
return k;
}

Expand All @@ -125,6 +178,6 @@ class Kallsyms : public FunctionResolver

private:
std::map<Range, std::string> kallsyms_;
uint64_t start_;
uint64_t start_ = UINT64_MAX;
};
} // namespace lo2s
8 changes: 6 additions & 2 deletions include/lo2s/instruction_resolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ class InstructionResolver
{
return "";
}

virtual ~InstructionResolver()
{
}
};
#ifdef HAVE_RADARE
class RadareInstructionResolver : public InstructionResolver
Expand All @@ -57,9 +61,9 @@ class RadareInstructionResolver : public InstructionResolver
{
}

static RadareInstructionResolver& cache(const std::string& name)
static std::shared_ptr<RadareInstructionResolver> cache(const std::string& name)
{
return StringCache<RadareInstructionResolver>::instance()[name];
return BinaryCache<RadareInstructionResolver>::instance()[name];
}

virtual std::string lookup_instruction(Address ip)
Expand Down
41 changes: 32 additions & 9 deletions include/lo2s/measurement_scope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ enum class MeasurementScopeType
NEC_METRIC,
BIO,
SYSCALL,
CUDA,
RB,
TRACEPOINT,
UNKNOWN
};
Expand All @@ -42,12 +42,14 @@ struct MeasurementScope
{
MeasurementScopeType type;
ExecutionScope scope;
std::string rb_name = "";

MeasurementScope() : type(MeasurementScopeType::UNKNOWN), scope()
{
}

MeasurementScope(MeasurementScopeType type, ExecutionScope s) : type(type), scope(s)
MeasurementScope(MeasurementScopeType type, ExecutionScope s, std::string name = "")
: type(type), scope(s), rb_name(name)
{
}

Expand Down Expand Up @@ -81,9 +83,9 @@ struct MeasurementScope
return { MeasurementScopeType::SYSCALL, s };
}

static MeasurementScope cuda(ExecutionScope s)
static MeasurementScope rb(ExecutionScope s, std::string name)
{
return { MeasurementScopeType::CUDA, s };
return { MeasurementScopeType::RB, s, name };
}

static MeasurementScope tracepoint(ExecutionScope s)
Expand All @@ -93,19 +95,40 @@ struct MeasurementScope

friend bool operator==(const MeasurementScope& lhs, const MeasurementScope& rhs)
{
if (lhs.type == MeasurementScopeType::RB && rhs.type == MeasurementScopeType::RB)
{
return lhs.scope == rhs.scope && lhs.rb_name == rhs.rb_name;
}

return (lhs.scope == rhs.scope) && lhs.type == rhs.type;
}

MeasurementScope from_ex_scope(ExecutionScope new_scope)
{
return MeasurementScope(type, new_scope, rb_name);
}

friend bool operator<(const MeasurementScope& lhs, const MeasurementScope& rhs)
{
if (lhs.type != rhs.type)
if (lhs.type == MeasurementScopeType::RB && rhs.type == MeasurementScopeType::RB)
{
return lhs.type < rhs.type;
if (lhs.scope == rhs.scope)
{
return lhs.rb_name < rhs.rb_name;
}
else
{
return lhs.scope < rhs.scope;
}
}
else
if (lhs.type == rhs.type)
{
return lhs.scope < rhs.scope;
}
else
{
return lhs.type < rhs.type;
}
}

std::string name() const
Expand All @@ -123,8 +146,8 @@ struct MeasurementScope
return fmt::format("block layer I/O events for {}", scope.name());
case MeasurementScopeType::SYSCALL:
return fmt::format("syscall events for {}", scope.name());
case lo2s::MeasurementScopeType::CUDA:
return fmt::format("cuda kernel events for {}", scope.name());
case lo2s::MeasurementScopeType::RB:
return fmt::format("{} events for {}", rb_name, scope.name());
case MeasurementScopeType::TRACEPOINT:
return fmt::format("tracepoint events for {}", scope.name());
default:
Expand Down
2 changes: 2 additions & 0 deletions include/lo2s/monitor/main_monitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class MainMonitor
void insert_cached_events(const RawMemoryMapCache& cached_events,
const RawCommCache& cached_comms);

void
insert_cached_cctx(std::map<MeasurementScope, std::map<Address, std::string>>& cached_cctx);

Check failure on line 68 in include/lo2s/monitor/main_monitor.hpp

View check run for this annotation

Code Style Turtle / Code Formatting Test

include/lo2s/monitor/main_monitor.hpp#L68

+
ProcessMap& get_process_infos()
{
return process_infos_;
Expand Down
13 changes: 10 additions & 3 deletions include/lo2s/monitor/ringbuf_monitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace monitor
class RingbufMonitor : public PollMonitor
{
public:
RingbufMonitor(trace::Trace& trace, int fd);
RingbufMonitor(trace::Trace& trace, MainMonitor& main_monitor, int fd);

void initialize_thread() override;
void finalize_thread() override;
Expand All @@ -45,9 +45,16 @@ class RingbufMonitor : public PollMonitor
}

private:
trace::Trace& trace_;
perf::time::Converter& time_converter_;
RingBufReader ringbuf_reader_;
RingbufReader ringbuf_reader_;
MeasurementScope scope_;
otf2::writer::local& rb_writer_;
std::optional<otf2::definition::calling_context> last_cctx_ref_;
MainMonitor& main_monitor_ [[maybe_unused]];
LocalCctxMap& local_cctx_map_;
std::map<MeasurementScope, std::map<Address, std::string>> functions_;
otf2::chrono::time_point last_;
bool entered_ = false;
};
} // namespace monitor
} // namespace lo2s
3 changes: 2 additions & 1 deletion include/lo2s/monitor/socket_monitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace monitor
class SocketMonitor : public PollMonitor
{
public:
SocketMonitor(trace::Trace& trace);
SocketMonitor(trace::Trace& trace, MainMonitor& main_monitor);

void initialize_thread() override;
void finalize_thread() override;
Expand All @@ -53,6 +53,7 @@ class SocketMonitor : public PollMonitor

private:
trace::Trace& trace_;
MainMonitor& main_monitor_;
std::map<int, RingbufMonitor> monitors_;
int socket = -1;
};
Expand Down
Loading

0 comments on commit 9c3d43f

Please sign in to comment.