Skip to content

Commit

Permalink
ProfileView: Show "self" sample counts in profiles
Browse files Browse the repository at this point in the history
The "self" sample count is the number of samples that had this specific
frame as its innermost stack frame (leaf nodes in the profile tree.)
  • Loading branch information
awesomekling committed Mar 2, 2020
1 parent 8e8e8c8 commit 8effe0b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
8 changes: 5 additions & 3 deletions DevTools/ProfileViewer/Profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,18 @@ void Profile::rebuild_tree()
{
if (!m_inverted) {
for (size_t i = 0; i < event.frames.size(); ++i) {
if (callback(event.frames.at(i)) == IterationDecision::Break)
if (callback(event.frames.at(i), i == event.frames.size() - 1) == IterationDecision::Break)
break;
}
} else {
for (ssize_t i = event.frames.size() - 1; i >= 0; --i) {
if (callback(event.frames.at(i)) == IterationDecision::Break)
if (callback(event.frames.at(i), static_cast<size_t>(i) == event.frames.size() - 1) == IterationDecision::Break)
break;
}
}
};

for_each_frame([&](const Frame& frame) {
for_each_frame([&](const Frame& frame, bool is_innermost_frame) {
auto& symbol = frame.symbol;
auto& address = frame.address;
auto& offset = frame.offset;
Expand All @@ -142,6 +142,8 @@ void Profile::rebuild_tree()
node = &node->find_or_create_child(symbol, address, offset, event.timestamp);

node->increment_event_count();
if (is_innermost_frame)
node->increment_self_count();
return IterationDecision::Continue;
});
}
Expand Down
3 changes: 3 additions & 0 deletions DevTools/ProfileViewer/Profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class ProfileNode : public RefCounted<ProfileNode> {
u64 timestamp() const { return m_timestamp; }

u32 event_count() const { return m_event_count; }
u32 self_count() const { return m_self_count; }

int child_count() const { return m_children.size(); }
const Vector<NonnullRefPtr<ProfileNode>>& children() const { return m_children; }
Expand Down Expand Up @@ -78,6 +79,7 @@ class ProfileNode : public RefCounted<ProfileNode> {
const ProfileNode* parent() const { return m_parent; }

void increment_event_count() { ++m_event_count; }
void increment_self_count() { ++m_self_count; }

void sort_children();

Expand All @@ -95,6 +97,7 @@ class ProfileNode : public RefCounted<ProfileNode> {
u32 m_address { 0 };
u32 m_offset { 0 };
u32 m_event_count { 0 };
u32 m_self_count { 0 };
u64 m_timestamp { 0 };
Vector<NonnullRefPtr<ProfileNode>> m_children;
};
Expand Down
6 changes: 5 additions & 1 deletion DevTools/ProfileViewer/ProfileModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ String ProfileModel::column_name(int column) const
switch (column) {
case Column::SampleCount:
return "# Samples";
case Column::SelfCount:
return "# Self";
case Column::StackFrame:
return "Stack Frame";
default:
Expand All @@ -108,7 +110,7 @@ String ProfileModel::column_name(int column) const

GUI::Model::ColumnMetadata ProfileModel::column_metadata(int column) const
{
if (column == Column::SampleCount)
if (column == Column::SampleCount || column == Column::SelfCount)
return ColumnMetadata { 0, Gfx::TextAlignment::CenterRight };
return {};
}
Expand All @@ -127,6 +129,8 @@ GUI::Variant ProfileModel::data(const GUI::ModelIndex& index, Role role) const
if (role == Role::Display) {
if (index.column() == Column::SampleCount)
return node->event_count();
if (index.column() == Column::SelfCount)
return node->self_count();
if (index.column() == Column::StackFrame)
return node->symbol();
return {};
Expand Down
1 change: 1 addition & 0 deletions DevTools/ProfileViewer/ProfileModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class ProfileModel final : public GUI::Model {

enum Column {
SampleCount,
SelfCount,
StackFrame,
__Count
};
Expand Down

0 comments on commit 8effe0b

Please sign in to comment.