1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:27:44 +00:00

Profiler: Store signposts in the main event stream

Instead of keeping a separate Vector<Event> for signposts, let them live
in the main event stream. For fast iteration, we instead keep a cache of
the signpost event indices.
This commit is contained in:
Andreas Kling 2021-08-13 21:55:14 +02:00
parent f5db92448d
commit 2da817615e
3 changed files with 26 additions and 20 deletions

View file

@ -31,11 +31,15 @@ static void sort_profile_nodes(Vector<NonnullRefPtr<ProfileNode>>& nodes)
child->sort_children();
}
Profile::Profile(Vector<Process> processes, Vector<Event> events, Vector<Event> signposts)
Profile::Profile(Vector<Process> processes, Vector<Event> events)
: m_processes(move(processes))
, m_events(move(events))
, m_signposts(move(signposts))
{
for (size_t i = 0; i < m_events.size(); ++i) {
if (m_events[i].data.has<Event::SignpostData>())
m_signpost_indices.append(i);
}
m_first_timestamp = m_events.first().timestamp;
m_last_timestamp = m_events.last().timestamp;
@ -231,7 +235,6 @@ Result<NonnullOwnPtr<Profile>, String> Profile::load_from_perfcore_file(const St
NonnullOwnPtrVector<Process> all_processes;
HashMap<pid_t, Process*> current_processes;
Vector<Event> events;
Vector<Event> signposts;
EventSerialNumber next_serial;
for (auto& perf_event_value : perf_events.values()) {
@ -393,12 +396,7 @@ Result<NonnullOwnPtr<Profile>, String> Profile::load_from_perfcore_file(const St
FlatPtr innermost_frame_address = event.frames.at(1).address;
event.in_kernel = maybe_kernel_base.has_value() && innermost_frame_address >= maybe_kernel_base.value();
dbgln("size: {}", sizeof(Event));
if (event.data.has<Event::SignpostData>())
signposts.append(move(event));
else
events.append(move(event));
events.append(move(event));
}
if (events.is_empty())
@ -415,7 +413,7 @@ Result<NonnullOwnPtr<Profile>, String> Profile::load_from_perfcore_file(const St
for (auto& it : all_processes)
processes.append(move(it));
return adopt_own(*new Profile(move(processes), move(events), move(signposts)));
return adopt_own(*new Profile(move(processes), move(events)));
}
void ProfileNode::sort_children()

View file

@ -217,8 +217,7 @@ public:
Variant<std::nullptr_t, SampleData, MallocData, FreeData, SignpostData, MmapData, MunmapData, ProcessCreateData, ProcessExecData, ThreadCreateData> data { nullptr };
};
const Vector<Event>& events() const { return m_events; }
Vector<Event> const& signposts() const { return m_signposts; }
Vector<Event> const& events() const { return m_events; }
const Vector<size_t>& filtered_event_indices() const { return m_filtered_event_indices; }
u64 length_in_ms() const { return m_last_timestamp - m_first_timestamp; }
@ -258,8 +257,18 @@ public:
}
}
template<typename Callback>
void for_each_signpost(Callback callback) const
{
for (auto index : m_signpost_indices) {
auto& event = m_events[index];
if (callback(event) == IterationDecision::Break)
break;
}
}
private:
Profile(Vector<Process>, Vector<Event> events, Vector<Event> signposts);
Profile(Vector<Process>, Vector<Event>);
void rebuild_tree();
@ -276,7 +285,7 @@ private:
Vector<Process> m_processes;
Vector<Event> m_events;
Vector<Event> m_signposts;
Vector<size_t> m_signpost_indices;
bool m_has_timestamp_filter_range { false };
u64 m_timestamp_filter_range_start { 0 };

View file

@ -113,16 +113,15 @@ void TimelineTrack::paint_event(GUI::PaintEvent& event)
template<typename Callback>
void TimelineTrack::for_each_signpost(Callback callback)
{
for (auto& signpost : m_profile.signposts()) {
m_profile.for_each_signpost([&](auto& signpost) {
if (signpost.pid != m_process.pid)
continue;
return IterationDecision::Continue;
if (!m_process.valid_at(signpost.serial))
continue;
return IterationDecision::Continue;
if (callback(signpost) == IterationDecision::Break)
break;
}
return callback(signpost);
});
}
void TimelineTrack::mousemove_event(GUI::MouseEvent& event)