diff --git a/DevTools/Profiler/Profile.cpp b/DevTools/Profiler/Profile.cpp index 548d719477..11cb49f50e 100644 --- a/DevTools/Profiler/Profile.cpp +++ b/DevTools/Profiler/Profile.cpp @@ -32,7 +32,6 @@ #include #include #include -#include #include #include #include @@ -47,61 +46,19 @@ static void sort_profile_nodes(Vector>& nodes) child->sort_children(); } -struct CachedLibData { - OwnPtr file; - ELF::Image lib_elf; -}; - -static String symbolicate(FlatPtr eip, const ELF::Core::MemoryRegionInfo* region, u32& offset) -{ - - static HashMap> cached_libs; - - auto name = region->object_name(); - - String path; - if (name.contains(".so")) - path = String::format("/usr/lib/%s", name.characters()); - else { - path = name; - } - - struct stat st; - if (stat(path.characters(), &st)) { - return {}; - } - - if (!cached_libs.contains(path)) { - auto lib_file = make(path); - if (!lib_file->is_valid()) - return {}; - auto image = ELF::Image((const u8*)lib_file->data(), lib_file->size()); - cached_libs.set(path, make(move(lib_file), move(image))); - } - - auto lib_data = cached_libs.get(path).value(); - - return String::format("[%s] %s", name.characters(), lib_data->lib_elf.symbolicate(eip - region->region_start, &offset).characters()); -} - static String symbolicate_from_coredump(CoreDump::Reader& coredump, u32 ptr, [[maybe_unused]] u32& offset) { - auto* region = coredump.region_containing((FlatPtr)ptr); - if (!region) { - dbgln("did not find region for eip: {:p}", ptr); - return "??"; - } - - auto name = symbolicate((FlatPtr)ptr, region, offset); - if (name.is_null()) { + auto library_data = coredump.library_containing(ptr); + if (!library_data) { dbgln("could not symbolicate: {:p}", ptr); return "??"; } - return name; + return String::formatted("[{}] {}", library_data->name, library_data->lib_elf.symbolicate(ptr - library_data->base_address, &offset)); } -Profile::Profile(String executable_path, Vector events) +Profile::Profile(String executable_path, NonnullOwnPtr&& coredump, Vector events) : m_executable_path(move(executable_path)) + , m_coredump(move(coredump)) , m_events(move(events)) { m_first_timestamp = m_events.first().timestamp; @@ -332,7 +289,7 @@ Result, String> Profile::load_from_perfcore_file(const St events.append(move(event)); } - return adopt_own(*new Profile(executable_path, move(events))); + return adopt_own(*new Profile(executable_path, coredump.release_nonnull(), move(events))); } void ProfileNode::sort_children() diff --git a/DevTools/Profiler/Profile.h b/DevTools/Profiler/Profile.h index 24740434f2..79c618a306 100644 --- a/DevTools/Profiler/Profile.h +++ b/DevTools/Profiler/Profile.h @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -176,13 +177,15 @@ public: void set_show_percentages(bool); const String& executable_path() const { return m_executable_path; } + const CoreDump::Reader& coredump() const { return *m_coredump; } private: - Profile(String executable_path, Vector); + Profile(String executable_path, NonnullOwnPtr&&, Vector); void rebuild_tree(); String m_executable_path; + NonnullOwnPtr m_coredump; RefPtr m_model; RefPtr m_disassembly_model;