1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:58:12 +00:00

ProfileViewer: Only show live allocations by default

For memory profiles, we now keep track of which allocations are still
live at the end of the selected timeline range and only show those.

This is really cool, I have to admit. :^)
This commit is contained in:
Andreas Kling 2020-02-02 20:59:26 +01:00
parent 266d7ca268
commit 9dc78338ad
2 changed files with 37 additions and 0 deletions

View file

@ -26,6 +26,7 @@
#include "Profile.h"
#include "ProfileModel.h"
#include <AK/HashTable.h>
#include <AK/MappedFile.h>
#include <AK/QuickSort.h>
#include <LibCore/CFile.h>
@ -57,6 +58,15 @@ Profile::Profile(const JsonArray& json)
Sample sample;
sample.timestamp = sample_object.get("timestamp").to_number<u64>();
sample.type = sample_object.get("type").to_string();
if (sample.type == "malloc") {
sample.ptr = sample_object.get("ptr").to_number<u32>();
sample.size = sample_object.get("size").to_number<u32>();
} else if (sample.type == "free") {
sample.ptr = sample_object.get("ptr").to_number<u32>();
}
auto frames_value = sample_object.get("frames");
auto& frames_array = frames_value.as_array();
@ -110,6 +120,8 @@ void Profile::rebuild_tree()
return new_root;
};
HashTable<uintptr_t> live_allocations;
for (auto& sample : m_samples) {
if (has_timestamp_filter_range()) {
auto timestamp = sample.timestamp;
@ -117,6 +129,25 @@ void Profile::rebuild_tree()
continue;
}
if (sample.type == "malloc")
live_allocations.set(sample.ptr);
else if (sample.type == "free")
live_allocations.remove(sample.ptr);
}
for (auto& sample : m_samples) {
if (has_timestamp_filter_range()) {
auto timestamp = sample.timestamp;
if (timestamp < m_timestamp_filter_range_start || timestamp > m_timestamp_filter_range_end)
continue;
}
if (sample.type == "malloc" && !live_allocations.contains(sample.ptr))
continue;
if (sample.type == "free")
continue;
ProfileNode* node = nullptr;
auto for_each_frame = [&]<typename Callback>(Callback callback)
@ -198,6 +229,9 @@ OwnPtr<Profile> Profile::load_from_perfcore_file(const StringView& path)
JsonObject object;
object.set("timestamp", perf_event.get("timestamp"));
object.set("type", perf_event.get("type"));
object.set("ptr", perf_event.get("ptr"));
object.set("size", perf_event.get("size"));
JsonArray frames_array;
auto stack_array = perf_event.get("stack").as_array();