mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:28:10 +00:00
ProfileViewer: Rename Profile::Sample => Profile::Event
This commit is contained in:
parent
251b7f3776
commit
8eaac171d7
4 changed files with 44 additions and 44 deletions
|
@ -36,7 +36,7 @@
|
||||||
static void sort_profile_nodes(Vector<NonnullRefPtr<ProfileNode>>& nodes)
|
static void sort_profile_nodes(Vector<NonnullRefPtr<ProfileNode>>& nodes)
|
||||||
{
|
{
|
||||||
quick_sort(nodes.begin(), nodes.end(), [](auto& a, auto& b) {
|
quick_sort(nodes.begin(), nodes.end(), [](auto& a, auto& b) {
|
||||||
return a->sample_count() >= b->sample_count();
|
return a->event_count() >= b->event_count();
|
||||||
});
|
});
|
||||||
|
|
||||||
for (auto& child : nodes)
|
for (auto& child : nodes)
|
||||||
|
@ -51,30 +51,30 @@ Profile::Profile(const JsonArray& json)
|
||||||
|
|
||||||
m_model = ProfileModel::create(*this);
|
m_model = ProfileModel::create(*this);
|
||||||
|
|
||||||
m_samples.ensure_capacity(m_json.size());
|
m_events.ensure_capacity(m_json.size());
|
||||||
for (auto& sample_value : m_json.values()) {
|
for (auto& event_value : m_json.values()) {
|
||||||
|
|
||||||
auto& sample_object = sample_value.as_object();
|
auto& event_object = event_value.as_object();
|
||||||
|
|
||||||
Sample sample;
|
Event event;
|
||||||
sample.timestamp = sample_object.get("timestamp").to_number<u64>();
|
event.timestamp = event_object.get("timestamp").to_number<u64>();
|
||||||
sample.type = sample_object.get("type").to_string();
|
event.type = event_object.get("type").to_string();
|
||||||
|
|
||||||
if (sample.type == "malloc") {
|
if (event.type == "malloc") {
|
||||||
sample.ptr = sample_object.get("ptr").to_number<u32>();
|
event.ptr = event_object.get("ptr").to_number<u32>();
|
||||||
sample.size = sample_object.get("size").to_number<u32>();
|
event.size = event_object.get("size").to_number<u32>();
|
||||||
} else if (sample.type == "free") {
|
} else if (event.type == "free") {
|
||||||
sample.ptr = sample_object.get("ptr").to_number<u32>();
|
event.ptr = event_object.get("ptr").to_number<u32>();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto frames_value = sample_object.get("frames");
|
auto frames_value = event_object.get("frames");
|
||||||
auto& frames_array = frames_value.as_array();
|
auto& frames_array = frames_value.as_array();
|
||||||
|
|
||||||
if (frames_array.size() < 2)
|
if (frames_array.size() < 2)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
u32 innermost_frame_address = frames_array.at(1).as_object().get("address").to_number<u32>();
|
u32 innermost_frame_address = frames_array.at(1).as_object().get("address").to_number<u32>();
|
||||||
sample.in_kernel = innermost_frame_address >= 0xc0000000;
|
event.in_kernel = innermost_frame_address >= 0xc0000000;
|
||||||
|
|
||||||
for (int i = frames_array.size() - 1; i >= 1; --i) {
|
for (int i = frames_array.size() - 1; i >= 1; --i) {
|
||||||
auto& frame_value = frames_array.at(i);
|
auto& frame_value = frames_array.at(i);
|
||||||
|
@ -83,12 +83,12 @@ Profile::Profile(const JsonArray& json)
|
||||||
frame.symbol = frame_object.get("symbol").as_string_or({});
|
frame.symbol = frame_object.get("symbol").as_string_or({});
|
||||||
frame.address = frame_object.get("address").as_u32();
|
frame.address = frame_object.get("address").as_u32();
|
||||||
frame.offset = frame_object.get("offset").as_u32();
|
frame.offset = frame_object.get("offset").as_u32();
|
||||||
sample.frames.append(move(frame));
|
event.frames.append(move(frame));
|
||||||
};
|
};
|
||||||
|
|
||||||
m_deepest_stack_depth = max((u32)frames_array.size(), m_deepest_stack_depth);
|
m_deepest_stack_depth = max((u32)frames_array.size(), m_deepest_stack_depth);
|
||||||
|
|
||||||
m_samples.append(move(sample));
|
m_events.append(move(event));
|
||||||
}
|
}
|
||||||
|
|
||||||
rebuild_tree();
|
rebuild_tree();
|
||||||
|
@ -121,30 +121,30 @@ void Profile::rebuild_tree()
|
||||||
|
|
||||||
HashTable<uintptr_t> live_allocations;
|
HashTable<uintptr_t> live_allocations;
|
||||||
|
|
||||||
for (auto& sample : m_samples) {
|
for (auto& event : m_events) {
|
||||||
if (has_timestamp_filter_range()) {
|
if (has_timestamp_filter_range()) {
|
||||||
auto timestamp = sample.timestamp;
|
auto timestamp = event.timestamp;
|
||||||
if (timestamp < m_timestamp_filter_range_start || timestamp > m_timestamp_filter_range_end)
|
if (timestamp < m_timestamp_filter_range_start || timestamp > m_timestamp_filter_range_end)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sample.type == "malloc")
|
if (event.type == "malloc")
|
||||||
live_allocations.set(sample.ptr);
|
live_allocations.set(event.ptr);
|
||||||
else if (sample.type == "free")
|
else if (event.type == "free")
|
||||||
live_allocations.remove(sample.ptr);
|
live_allocations.remove(event.ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& sample : m_samples) {
|
for (auto& event : m_events) {
|
||||||
if (has_timestamp_filter_range()) {
|
if (has_timestamp_filter_range()) {
|
||||||
auto timestamp = sample.timestamp;
|
auto timestamp = event.timestamp;
|
||||||
if (timestamp < m_timestamp_filter_range_start || timestamp > m_timestamp_filter_range_end)
|
if (timestamp < m_timestamp_filter_range_start || timestamp > m_timestamp_filter_range_end)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sample.type == "malloc" && !live_allocations.contains(sample.ptr))
|
if (event.type == "malloc" && !live_allocations.contains(event.ptr))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (sample.type == "free")
|
if (event.type == "free")
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
ProfileNode* node = nullptr;
|
ProfileNode* node = nullptr;
|
||||||
|
@ -152,13 +152,13 @@ void Profile::rebuild_tree()
|
||||||
auto for_each_frame = [&]<typename Callback>(Callback callback)
|
auto for_each_frame = [&]<typename Callback>(Callback callback)
|
||||||
{
|
{
|
||||||
if (!m_inverted) {
|
if (!m_inverted) {
|
||||||
for (size_t i = 0; i < sample.frames.size(); ++i) {
|
for (size_t i = 0; i < event.frames.size(); ++i) {
|
||||||
if (callback(sample.frames.at(i)) == IterationDecision::Break)
|
if (callback(event.frames.at(i)) == IterationDecision::Break)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (ssize_t i = sample.frames.size() - 1; i >= 0; --i) {
|
for (ssize_t i = event.frames.size() - 1; i >= 0; --i) {
|
||||||
if (callback(sample.frames.at(i)) == IterationDecision::Break)
|
if (callback(event.frames.at(i)) == IterationDecision::Break)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -173,11 +173,11 @@ void Profile::rebuild_tree()
|
||||||
return IterationDecision::Break;
|
return IterationDecision::Break;
|
||||||
|
|
||||||
if (!node)
|
if (!node)
|
||||||
node = &find_or_create_root(symbol, address, offset, sample.timestamp);
|
node = &find_or_create_root(symbol, address, offset, event.timestamp);
|
||||||
else
|
else
|
||||||
node = &node->find_or_create_child(symbol, address, offset, sample.timestamp);
|
node = &node->find_or_create_child(symbol, address, offset, event.timestamp);
|
||||||
|
|
||||||
node->increment_sample_count();
|
node->increment_event_count();
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ public:
|
||||||
u32 offset() const { return m_offset; }
|
u32 offset() const { return m_offset; }
|
||||||
u64 timestamp() const { return m_timestamp; }
|
u64 timestamp() const { return m_timestamp; }
|
||||||
|
|
||||||
u32 sample_count() const { return m_sample_count; }
|
u32 event_count() const { return m_event_count; }
|
||||||
|
|
||||||
int child_count() const { return m_children.size(); }
|
int child_count() const { return m_children.size(); }
|
||||||
const Vector<NonnullRefPtr<ProfileNode>>& children() const { return m_children; }
|
const Vector<NonnullRefPtr<ProfileNode>>& children() const { return m_children; }
|
||||||
|
@ -77,7 +77,7 @@ public:
|
||||||
ProfileNode* parent() { return m_parent; }
|
ProfileNode* parent() { return m_parent; }
|
||||||
const ProfileNode* parent() const { return m_parent; }
|
const ProfileNode* parent() const { return m_parent; }
|
||||||
|
|
||||||
void increment_sample_count() { ++m_sample_count; }
|
void increment_event_count() { ++m_event_count; }
|
||||||
|
|
||||||
void sort_children();
|
void sort_children();
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ private:
|
||||||
String m_symbol;
|
String m_symbol;
|
||||||
u32 m_address { 0 };
|
u32 m_address { 0 };
|
||||||
u32 m_offset { 0 };
|
u32 m_offset { 0 };
|
||||||
u32 m_sample_count { 0 };
|
u32 m_event_count { 0 };
|
||||||
u64 m_timestamp { 0 };
|
u64 m_timestamp { 0 };
|
||||||
Vector<NonnullRefPtr<ProfileNode>> m_children;
|
Vector<NonnullRefPtr<ProfileNode>> m_children;
|
||||||
};
|
};
|
||||||
|
@ -114,7 +114,7 @@ public:
|
||||||
u32 offset { 0 };
|
u32 offset { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Sample {
|
struct Event {
|
||||||
u64 timestamp { 0 };
|
u64 timestamp { 0 };
|
||||||
String type;
|
String type;
|
||||||
uintptr_t ptr { 0 };
|
uintptr_t ptr { 0 };
|
||||||
|
@ -123,7 +123,7 @@ public:
|
||||||
Vector<Frame> frames;
|
Vector<Frame> frames;
|
||||||
};
|
};
|
||||||
|
|
||||||
const Vector<Sample>& samples() const { return m_samples; }
|
const Vector<Event>& events() const { return m_events; }
|
||||||
|
|
||||||
u64 length_in_ms() const { return m_last_timestamp - m_first_timestamp; }
|
u64 length_in_ms() const { return m_last_timestamp - m_first_timestamp; }
|
||||||
u64 first_timestamp() const { return m_first_timestamp; }
|
u64 first_timestamp() const { return m_first_timestamp; }
|
||||||
|
@ -148,7 +148,7 @@ private:
|
||||||
u64 m_first_timestamp { 0 };
|
u64 m_first_timestamp { 0 };
|
||||||
u64 m_last_timestamp { 0 };
|
u64 m_last_timestamp { 0 };
|
||||||
|
|
||||||
Vector<Sample> m_samples;
|
Vector<Event> m_events;
|
||||||
|
|
||||||
bool m_has_timestamp_filter_range { false };
|
bool m_has_timestamp_filter_range { false };
|
||||||
u64 m_timestamp_filter_range_start { 0 };
|
u64 m_timestamp_filter_range_start { 0 };
|
||||||
|
|
|
@ -126,7 +126,7 @@ GUI::Variant ProfileModel::data(const GUI::ModelIndex& index, Role role) const
|
||||||
}
|
}
|
||||||
if (role == Role::Display) {
|
if (role == Role::Display) {
|
||||||
if (index.column() == Column::SampleCount)
|
if (index.column() == Column::SampleCount)
|
||||||
return node->sample_count();
|
return node->event_count();
|
||||||
if (index.column() == Column::StackFrame)
|
if (index.column() == Column::StackFrame)
|
||||||
return node->symbol();
|
return node->symbol();
|
||||||
return {};
|
return {};
|
||||||
|
|
|
@ -51,14 +51,14 @@ void ProfileTimelineWidget::paint_event(GUI::PaintEvent& event)
|
||||||
float column_width = (float)frame_inner_rect().width() / (float)m_profile.length_in_ms();
|
float column_width = (float)frame_inner_rect().width() / (float)m_profile.length_in_ms();
|
||||||
float frame_height = (float)frame_inner_rect().height() / (float)m_profile.deepest_stack_depth();
|
float frame_height = (float)frame_inner_rect().height() / (float)m_profile.deepest_stack_depth();
|
||||||
|
|
||||||
for (auto& sample : m_profile.samples()) {
|
for (auto& event : m_profile.events()) {
|
||||||
u64 t = sample.timestamp - m_profile.first_timestamp();
|
u64 t = event.timestamp - m_profile.first_timestamp();
|
||||||
int x = (int)((float)t * column_width);
|
int x = (int)((float)t * column_width);
|
||||||
int cw = max(1, (int)column_width);
|
int cw = max(1, (int)column_width);
|
||||||
|
|
||||||
int column_height = frame_inner_rect().height() - (int)((float)sample.frames.size() * frame_height);
|
int column_height = frame_inner_rect().height() - (int)((float)event.frames.size() * frame_height);
|
||||||
|
|
||||||
bool in_kernel = sample.in_kernel;
|
bool in_kernel = event.in_kernel;
|
||||||
Color color = in_kernel ? Color::from_rgb(0xc25e5a) : Color::from_rgb(0x5a65c2);
|
Color color = in_kernel ? Color::from_rgb(0xc25e5a) : Color::from_rgb(0x5a65c2);
|
||||||
for (int i = 0; i < cw; ++i)
|
for (int i = 0; i < cw; ++i)
|
||||||
painter.draw_line({ x + i, frame_thickness() + column_height }, { x + i, height() - frame_thickness() * 2 }, color);
|
painter.draw_line({ x + i, frame_thickness() + column_height }, { x + i, height() - frame_thickness() * 2 }, color);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue