Skip to content

Commit

Permalink
ProfileViewer: Rename Profile::Sample => Profile::Event
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomekling committed Mar 2, 2020
1 parent 251b7f3 commit 8eaac17
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 44 deletions.
66 changes: 33 additions & 33 deletions DevTools/ProfileViewer/Profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
static void sort_profile_nodes(Vector<NonnullRefPtr<ProfileNode>>& nodes)
{
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)
Expand All @@ -51,30 +51,30 @@ Profile::Profile(const JsonArray& json)

m_model = ProfileModel::create(*this);

m_samples.ensure_capacity(m_json.size());
for (auto& sample_value : m_json.values()) {
m_events.ensure_capacity(m_json.size());
for (auto& event_value : m_json.values()) {

auto& sample_object = sample_value.as_object();
auto& event_object = event_value.as_object();

Sample sample;
sample.timestamp = sample_object.get("timestamp").to_number<u64>();
sample.type = sample_object.get("type").to_string();
Event event;
event.timestamp = event_object.get("timestamp").to_number<u64>();
event.type = event_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>();
if (event.type == "malloc") {
event.ptr = event_object.get("ptr").to_number<u32>();
event.size = event_object.get("size").to_number<u32>();
} else if (event.type == "free") {
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();

if (frames_array.size() < 2)
continue;

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) {
auto& frame_value = frames_array.at(i);
Expand All @@ -83,12 +83,12 @@ Profile::Profile(const JsonArray& json)
frame.symbol = frame_object.get("symbol").as_string_or({});
frame.address = frame_object.get("address").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_samples.append(move(sample));
m_events.append(move(event));
}

rebuild_tree();
Expand Down Expand Up @@ -121,44 +121,44 @@ void Profile::rebuild_tree()

HashTable<uintptr_t> live_allocations;

for (auto& sample : m_samples) {
for (auto& event : m_events) {
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)
continue;
}

if (sample.type == "malloc")
live_allocations.set(sample.ptr);
else if (sample.type == "free")
live_allocations.remove(sample.ptr);
if (event.type == "malloc")
live_allocations.set(event.ptr);
else if (event.type == "free")
live_allocations.remove(event.ptr);
}

for (auto& sample : m_samples) {
for (auto& event : m_events) {
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)
continue;
}

if (sample.type == "malloc" && !live_allocations.contains(sample.ptr))
if (event.type == "malloc" && !live_allocations.contains(event.ptr))
continue;

if (sample.type == "free")
if (event.type == "free")
continue;

ProfileNode* node = nullptr;

auto for_each_frame = [&]<typename Callback>(Callback callback)
{
if (!m_inverted) {
for (size_t i = 0; i < sample.frames.size(); ++i) {
if (callback(sample.frames.at(i)) == IterationDecision::Break)
for (size_t i = 0; i < event.frames.size(); ++i) {
if (callback(event.frames.at(i)) == IterationDecision::Break)
break;
}
} else {
for (ssize_t i = sample.frames.size() - 1; i >= 0; --i) {
if (callback(sample.frames.at(i)) == IterationDecision::Break)
for (ssize_t i = event.frames.size() - 1; i >= 0; --i) {
if (callback(event.frames.at(i)) == IterationDecision::Break)
break;
}
}
Expand All @@ -173,11 +173,11 @@ void Profile::rebuild_tree()
return IterationDecision::Break;

if (!node)
node = &find_or_create_root(symbol, address, offset, sample.timestamp);
node = &find_or_create_root(symbol, address, offset, event.timestamp);
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;
});
}
Expand Down
12 changes: 6 additions & 6 deletions DevTools/ProfileViewer/Profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ProfileNode : public RefCounted<ProfileNode> {
u32 offset() const { return m_offset; }
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(); }
const Vector<NonnullRefPtr<ProfileNode>>& children() const { return m_children; }
Expand Down Expand Up @@ -77,7 +77,7 @@ class ProfileNode : public RefCounted<ProfileNode> {
ProfileNode* parent() { 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();

Expand All @@ -94,7 +94,7 @@ class ProfileNode : public RefCounted<ProfileNode> {
String m_symbol;
u32 m_address { 0 };
u32 m_offset { 0 };
u32 m_sample_count { 0 };
u32 m_event_count { 0 };
u64 m_timestamp { 0 };
Vector<NonnullRefPtr<ProfileNode>> m_children;
};
Expand All @@ -114,7 +114,7 @@ class Profile {
u32 offset { 0 };
};

struct Sample {
struct Event {
u64 timestamp { 0 };
String type;
uintptr_t ptr { 0 };
Expand All @@ -123,7 +123,7 @@ class Profile {
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 first_timestamp() const { return m_first_timestamp; }
Expand All @@ -148,7 +148,7 @@ class Profile {
u64 m_first_timestamp { 0 };
u64 m_last_timestamp { 0 };

Vector<Sample> m_samples;
Vector<Event> m_events;

bool m_has_timestamp_filter_range { false };
u64 m_timestamp_filter_range_start { 0 };
Expand Down
2 changes: 1 addition & 1 deletion DevTools/ProfileViewer/ProfileModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ GUI::Variant ProfileModel::data(const GUI::ModelIndex& index, Role role) const
}
if (role == Role::Display) {
if (index.column() == Column::SampleCount)
return node->sample_count();
return node->event_count();
if (index.column() == Column::StackFrame)
return node->symbol();
return {};
Expand Down
8 changes: 4 additions & 4 deletions DevTools/ProfileViewer/ProfileTimelineWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 frame_height = (float)frame_inner_rect().height() / (float)m_profile.deepest_stack_depth();

for (auto& sample : m_profile.samples()) {
u64 t = sample.timestamp - m_profile.first_timestamp();
for (auto& event : m_profile.events()) {
u64 t = event.timestamp - m_profile.first_timestamp();
int x = (int)((float)t * 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);
for (int i = 0; i < cw; ++i)
painter.draw_line({ x + i, frame_thickness() + column_height }, { x + i, height() - frame_thickness() * 2 }, color);
Expand Down

0 comments on commit 8eaac17

Please sign in to comment.