1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-08 02:27:35 +00:00

ProfileViewer: Add a timeline widget for a visual view of the profile

Userspace stack frames are in blue, kernel stack frames in red :^)
This commit is contained in:
Andreas Kling 2019-12-14 18:44:29 +01:00
parent 46a57c7f59
commit a3e7c99ffe
6 changed files with 121 additions and 16 deletions

View file

@ -4,9 +4,11 @@
#include <LibCore/CFile.h>
#include <stdio.h>
Profile::Profile(const JsonArray& json, Vector<NonnullRefPtr<ProfileNode>>&& roots)
Profile::Profile(const JsonArray& json, Vector<NonnullRefPtr<ProfileNode>>&& roots, u64 first_timestamp, u64 last_timestamp)
: m_json(json)
, m_roots(move(roots))
, m_first_timestamp(first_timestamp)
, m_last_timestamp(last_timestamp)
{
m_model = ProfileModel::create(*this);
}
@ -34,22 +36,27 @@ OwnPtr<Profile> Profile::load_from_file(const StringView& path)
return nullptr;
}
auto samples = json.as_array();
auto& samples = json.as_array();
if (samples.is_empty())
return nullptr;
NonnullRefPtrVector<ProfileNode> roots;
auto find_or_create_root = [&roots](const String& symbol, u32 address, u32 offset) -> ProfileNode& {
auto find_or_create_root = [&roots](const String& symbol, u32 address, u32 offset, u64 timestamp) -> ProfileNode& {
for (int i = 0; i < roots.size(); ++i) {
auto& root = roots[i];
if (root.symbol() == symbol) {
return root;
}
}
auto new_root = ProfileNode::create(symbol, address, offset);
auto new_root = ProfileNode::create(symbol, address, offset, timestamp);
roots.append(new_root);
return new_root;
};
u64 first_timestamp = samples.at(0).as_object().get("timestamp").to_number<u64>();
u64 last_timestamp = samples.at(samples.size() - 1).as_object().get("timestamp").to_number<u64>();
samples.for_each([&](const JsonValue& sample) {
auto frames_value = sample.as_object().get("frames");
auto& frames = frames_value.as_array();
@ -60,14 +67,15 @@ OwnPtr<Profile> Profile::load_from_file(const StringView& path)
auto symbol = frame.as_object().get("symbol").as_string_or({});
auto address = frame.as_object().get("address").as_u32();
auto offset = frame.as_object().get("offset").as_u32();
auto timestamp = frame.as_object().get("timestamp").to_number<u64>();
if (symbol.is_empty())
break;
if (!node)
node = &find_or_create_root(symbol, address, offset);
node = &find_or_create_root(symbol, address, offset, timestamp);
else
node = &node->find_or_create_child(symbol, address, offset);
node = &node->find_or_create_child(symbol, address, offset, timestamp);
node->increment_sample_count();
}
@ -77,7 +85,7 @@ OwnPtr<Profile> Profile::load_from_file(const StringView& path)
root.sort_children();
}
return NonnullOwnPtr<Profile>(NonnullOwnPtr<Profile>::Adopt, *new Profile(move(samples), move(roots)));
return NonnullOwnPtr<Profile>(NonnullOwnPtr<Profile>::Adopt, *new Profile(move(samples), move(roots), first_timestamp, last_timestamp));
}
void ProfileNode::sort_children()