mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:27:35 +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:
parent
266d7ca268
commit
9dc78338ad
2 changed files with 37 additions and 0 deletions
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
#include "Profile.h"
|
#include "Profile.h"
|
||||||
#include "ProfileModel.h"
|
#include "ProfileModel.h"
|
||||||
|
#include <AK/HashTable.h>
|
||||||
#include <AK/MappedFile.h>
|
#include <AK/MappedFile.h>
|
||||||
#include <AK/QuickSort.h>
|
#include <AK/QuickSort.h>
|
||||||
#include <LibCore/CFile.h>
|
#include <LibCore/CFile.h>
|
||||||
|
@ -57,6 +58,15 @@ Profile::Profile(const JsonArray& json)
|
||||||
|
|
||||||
Sample sample;
|
Sample sample;
|
||||||
sample.timestamp = sample_object.get("timestamp").to_number<u64>();
|
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_value = sample_object.get("frames");
|
||||||
auto& frames_array = frames_value.as_array();
|
auto& frames_array = frames_value.as_array();
|
||||||
|
@ -110,6 +120,8 @@ void Profile::rebuild_tree()
|
||||||
return new_root;
|
return new_root;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
HashTable<uintptr_t> live_allocations;
|
||||||
|
|
||||||
for (auto& sample : m_samples) {
|
for (auto& sample : m_samples) {
|
||||||
if (has_timestamp_filter_range()) {
|
if (has_timestamp_filter_range()) {
|
||||||
auto timestamp = sample.timestamp;
|
auto timestamp = sample.timestamp;
|
||||||
|
@ -117,6 +129,25 @@ void Profile::rebuild_tree()
|
||||||
continue;
|
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;
|
ProfileNode* node = nullptr;
|
||||||
|
|
||||||
auto for_each_frame = [&]<typename Callback>(Callback callback)
|
auto for_each_frame = [&]<typename Callback>(Callback callback)
|
||||||
|
@ -198,6 +229,9 @@ OwnPtr<Profile> Profile::load_from_perfcore_file(const StringView& path)
|
||||||
|
|
||||||
JsonObject object;
|
JsonObject object;
|
||||||
object.set("timestamp", perf_event.get("timestamp"));
|
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;
|
JsonArray frames_array;
|
||||||
auto stack_array = perf_event.get("stack").as_array();
|
auto stack_array = perf_event.get("stack").as_array();
|
||||||
|
|
|
@ -120,6 +120,9 @@ public:
|
||||||
|
|
||||||
struct Sample {
|
struct Sample {
|
||||||
u64 timestamp { 0 };
|
u64 timestamp { 0 };
|
||||||
|
String type;
|
||||||
|
uintptr_t ptr { 0 };
|
||||||
|
size_t size { 0 };
|
||||||
bool in_kernel { false };
|
bool in_kernel { false };
|
||||||
Vector<Frame> frames;
|
Vector<Frame> frames;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue