From 9cb75351c6bc8bf60d2bddb71ec039197e869b0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alf-Andr=C3=A9=20Walla?= Date: Sun, 3 Nov 2024 13:35:13 +0100 Subject: [PATCH] Remove elf_hint argument to get_hotspots() and make total first argument --- src/sandbox.cpp | 2 +- src/sandbox.h | 5 ++--- src/sandbox_profiling.cpp | 9 ++++----- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/sandbox.cpp b/src/sandbox.cpp index 73826dd..32713f6 100644 --- a/src/sandbox.cpp +++ b/src/sandbox.cpp @@ -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. diff --git a/src/sandbox.h b/src/sandbox.h index eddea87..7f62d3e 100644 --- a/src/sandbox.h +++ b/src/sandbox.h @@ -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(); diff --git a/src/sandbox_profiling.cpp b/src/sandbox_profiling.cpp index 2fcdf4d..b278c35 100644 --- a/src/sandbox_profiling.cpp +++ b/src/sandbox_profiling.cpp @@ -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 -f -C 0x
@@ -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); @@ -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> visited; { std::scoped_lock lock(profiling_mutex); @@ -146,7 +146,6 @@ Array Sandbox::get_hotspots(const String &elf_hint, const Callable &callable, un // Gather information about the hotspots std::vector results; - std::string std_elf_hint = std::string(elf_hint.utf8().ptr()); unsigned total_measurements = 0; for (const auto &path : visited) { @@ -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)); }