Skip to content

Commit

Permalink
Remove elf_hint argument to get_hotspots() and make total first argument
Browse files Browse the repository at this point in the history
  • Loading branch information
fwsGonzo committed Nov 3, 2024
1 parent 71dc876 commit 9cb7535
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/sandbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void Sandbox::_bind_methods() {
ClassDB::bind_static_method("Sandbox", D_METHOD("generate_api", "language", "header_extra", "use_argument_names"), &Sandbox::generate_api, DEFVAL("cpp"), DEFVAL(""), DEFVAL(false));

// Profiling.
ClassDB::bind_static_method("Sandbox", D_METHOD("get_hotspots", "elf_hint", "callable", "total"), &Sandbox::get_hotspots, DEFVAL(""), DEFVAL(Callable()), DEFVAL(6));
ClassDB::bind_static_method("Sandbox", D_METHOD("get_hotspots", "total", "callable"), &Sandbox::get_hotspots, DEFVAL(6), DEFVAL(Callable()));
ClassDB::bind_static_method("Sandbox", D_METHOD("clear_hotspots"), &Sandbox::clear_hotspots);

// Binary translation.
Expand Down
5 changes: 2 additions & 3 deletions src/sandbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,10 @@ class Sandbox : public Node {
// -= Profiling & Hotspots =-

/// @brief Generate the top N hotspots from profiling recorded so far.
/// @param elf_hint A hint used when the path to the ELF file is not available. It can be passed to the callback.
/// @param lookup A callback that must resolve an address of an unknown program, given elf_hint and an address as arguments.
/// @param total The maximum number of hotspots to generate.
/// @param callable A callback that must resolve an address of an unknown program, given elf_hint and an address as arguments.
/// @return The top hotspots recorded globally so far, sorted by the number of hits.
static Array get_hotspots(const String &elf_hint, const Callable &lookup, unsigned total = 10);
static Array get_hotspots(unsigned total = 10, const Callable &callable = {});

/// @brief Clear all recorded hotspots.
static void clear_hotspots();
Expand Down
9 changes: 4 additions & 5 deletions src/sandbox_profiling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static ProfilingMachine *requisition(const std::string &elf) {
return &it->second;
}

static void resolve(Result &res, std::string_view fallback_filename, const Callable &callback) {
static void resolve(Result &res, const Callable &callback) {
#ifdef __linux__
if (USE_ADDR2LINE && !res.elf.empty()) {
// execute riscv64-linux-gnu-addr2line -e <binary> -f -C 0x<address>
Expand Down Expand Up @@ -113,7 +113,7 @@ static void resolve(Result &res, std::string_view fallback_filename, const Calla
}
#endif
// Fallback to the callback
res.file = String::utf8(fallback_filename.data(), fallback_filename.size());
res.file = "(unknown)";
res.function = "??";
if (!res.elf.empty()) {
ProfilingMachine *pm = requisition(res.elf);
Expand All @@ -129,7 +129,7 @@ static void resolve(Result &res, std::string_view fallback_filename, const Calla
}
}

Array Sandbox::get_hotspots(const String &elf_hint, const Callable &callable, unsigned total) {
Array Sandbox::get_hotspots(unsigned total, const Callable &callable) {
std::unordered_map<std::string_view, std::unordered_map<gaddr_t, int>> visited;
{
std::scoped_lock lock(profiling_mutex);
Expand All @@ -146,7 +146,6 @@ Array Sandbox::get_hotspots(const String &elf_hint, const Callable &callable, un

// Gather information about the hotspots
std::vector<Result> results;
std::string std_elf_hint = std::string(elf_hint.utf8().ptr());
unsigned total_measurements = 0;

for (const auto &path : visited) {
Expand All @@ -160,7 +159,7 @@ Array Sandbox::get_hotspots(const String &elf_hint, const Callable &callable, un
res.count = entry.second;
total_measurements += res.count;

resolve(res, std_elf_hint, callable);
resolve(res, callable);

results.push_back(std::move(res));
}
Expand Down

0 comments on commit 9cb7535

Please sign in to comment.