mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:57:45 +00:00
Profiler: Use CoreDumpReader::library_containing
This commit is contained in:
parent
65ffd8de69
commit
1af2f65df5
2 changed files with 10 additions and 50 deletions
|
@ -32,7 +32,6 @@
|
||||||
#include <AK/QuickSort.h>
|
#include <AK/QuickSort.h>
|
||||||
#include <AK/RefPtr.h>
|
#include <AK/RefPtr.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
#include <LibCoreDump/Reader.h>
|
|
||||||
#include <LibELF/Image.h>
|
#include <LibELF/Image.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
@ -47,61 +46,19 @@ static void sort_profile_nodes(Vector<NonnullRefPtr<ProfileNode>>& nodes)
|
||||||
child->sort_children();
|
child->sort_children();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CachedLibData {
|
|
||||||
OwnPtr<MappedFile> file;
|
|
||||||
ELF::Image lib_elf;
|
|
||||||
};
|
|
||||||
|
|
||||||
static String symbolicate(FlatPtr eip, const ELF::Core::MemoryRegionInfo* region, u32& offset)
|
|
||||||
{
|
|
||||||
|
|
||||||
static HashMap<String, OwnPtr<CachedLibData>> 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<MappedFile>(path);
|
|
||||||
if (!lib_file->is_valid())
|
|
||||||
return {};
|
|
||||||
auto image = ELF::Image((const u8*)lib_file->data(), lib_file->size());
|
|
||||||
cached_libs.set(path, make<CachedLibData>(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)
|
static String symbolicate_from_coredump(CoreDump::Reader& coredump, u32 ptr, [[maybe_unused]] u32& offset)
|
||||||
{
|
{
|
||||||
auto* region = coredump.region_containing((FlatPtr)ptr);
|
auto library_data = coredump.library_containing(ptr);
|
||||||
if (!region) {
|
if (!library_data) {
|
||||||
dbgln("did not find region for eip: {:p}", ptr);
|
|
||||||
return "??";
|
|
||||||
}
|
|
||||||
|
|
||||||
auto name = symbolicate((FlatPtr)ptr, region, offset);
|
|
||||||
if (name.is_null()) {
|
|
||||||
dbgln("could not symbolicate: {:p}", ptr);
|
dbgln("could not symbolicate: {:p}", ptr);
|
||||||
return "??";
|
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<Event> events)
|
Profile::Profile(String executable_path, NonnullOwnPtr<CoreDump::Reader>&& coredump, Vector<Event> events)
|
||||||
: m_executable_path(move(executable_path))
|
: m_executable_path(move(executable_path))
|
||||||
|
, m_coredump(move(coredump))
|
||||||
, m_events(move(events))
|
, m_events(move(events))
|
||||||
{
|
{
|
||||||
m_first_timestamp = m_events.first().timestamp;
|
m_first_timestamp = m_events.first().timestamp;
|
||||||
|
@ -332,7 +289,7 @@ Result<NonnullOwnPtr<Profile>, String> Profile::load_from_perfcore_file(const St
|
||||||
events.append(move(event));
|
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()
|
void ProfileNode::sort_children()
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
#include <AK/NonnullRefPtrVector.h>
|
#include <AK/NonnullRefPtrVector.h>
|
||||||
#include <AK/OwnPtr.h>
|
#include <AK/OwnPtr.h>
|
||||||
#include <AK/Result.h>
|
#include <AK/Result.h>
|
||||||
|
#include <LibCoreDump/Reader.h>
|
||||||
#include <LibGUI/Forward.h>
|
#include <LibGUI/Forward.h>
|
||||||
#include <LibGUI/ModelIndex.h>
|
#include <LibGUI/ModelIndex.h>
|
||||||
|
|
||||||
|
@ -176,13 +177,15 @@ public:
|
||||||
void set_show_percentages(bool);
|
void set_show_percentages(bool);
|
||||||
|
|
||||||
const String& executable_path() const { return m_executable_path; }
|
const String& executable_path() const { return m_executable_path; }
|
||||||
|
const CoreDump::Reader& coredump() const { return *m_coredump; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Profile(String executable_path, Vector<Event>);
|
Profile(String executable_path, NonnullOwnPtr<CoreDump::Reader>&&, Vector<Event>);
|
||||||
|
|
||||||
void rebuild_tree();
|
void rebuild_tree();
|
||||||
|
|
||||||
String m_executable_path;
|
String m_executable_path;
|
||||||
|
NonnullOwnPtr<CoreDump::Reader> m_coredump;
|
||||||
|
|
||||||
RefPtr<ProfileModel> m_model;
|
RefPtr<ProfileModel> m_model;
|
||||||
RefPtr<DisassemblyModel> m_disassembly_model;
|
RefPtr<DisassemblyModel> m_disassembly_model;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue