diff options
author | Andreas Kling <kling@serenityos.org> | 2021-08-11 20:29:34 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-12 00:03:39 +0200 |
commit | 3ed6c137df73b816216472834f4836d290df6c6a (patch) | |
tree | a853017a5d09a9e52b76072ee9d90b179e8b1b3f /Userland/DevTools/Profiler/Profile.cpp | |
parent | 4657c791433a5d5e3e286fd1a4b85a2478c6356e (diff) | |
download | serenity-3ed6c137df73b816216472834f4836d290df6c6a.zip |
Profiler: Parse and render signpost strings
The first perf_event argument to a PERF_EVENT_SIGNPOST is now
interpreted as a string ID (in the profile strings set.)
This allows us to generate signposts with custom strings. :^)
Diffstat (limited to 'Userland/DevTools/Profiler/Profile.cpp')
-rw-r--r-- | Userland/DevTools/Profiler/Profile.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/Userland/DevTools/Profiler/Profile.cpp b/Userland/DevTools/Profiler/Profile.cpp index 640636a5c4..61f0f0524a 100644 --- a/Userland/DevTools/Profiler/Profile.cpp +++ b/Userland/DevTools/Profiler/Profile.cpp @@ -208,6 +208,17 @@ Result<NonnullOwnPtr<Profile>, String> Profile::load_from_perfcore_file(const St if (!file_or_error.is_error()) kernel_elf = make<ELF::Image>(file_or_error.value()->bytes()); + auto strings_value = object.get_ptr("strings"sv); + if (!strings_value || !strings_value->is_object()) + return String { "Malformed profile (strings is not an object)" }; + + HashMap<FlatPtr, String> profile_strings; + strings_value->as_object().for_each_member([&](String const& key, JsonValue const& value) { + auto string_id = key.to_uint(); + VERIFY(string_id.has_value()); + profile_strings.set(string_id.value(), value.to_string()); + }); + auto events_value = object.get_ptr("events"); if (!events_value || !events_value->is_array()) return String { "Malformed profile (events is not an array)" }; @@ -242,7 +253,8 @@ Result<NonnullOwnPtr<Profile>, String> Profile::load_from_perfcore_file(const St event.ptr = perf_event.get("ptr").to_number<FlatPtr>(); } else if (event.type == "signpost"sv) { is_signpost = true; - event.arg1 = perf_event.get("arg1").to_number<FlatPtr>(); + auto string_id = perf_event.get("arg1").to_number<FlatPtr>(); + event.signpost_string = profile_strings.get(string_id).value_or(String::formatted("Signpost #{}", string_id)); event.arg2 = perf_event.get("arg2").to_number<FlatPtr>(); } else if (event.type == "mmap"sv) { event.ptr = perf_event.get("ptr").to_number<FlatPtr>(); |