mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-23 17:52:26 -05:00
Profiler: Let the user select more than one process
This commit is contained in:
parent
325d9445fd
commit
210d2d270d
Notes:
sideshowbarker
2024-07-18 18:33:28 +09:00
Author: https://github.com/gunnarbeutner Commit: https://github.com/SerenityOS/serenity/commit/210d2d270d3 Pull-request: https://github.com/SerenityOS/serenity/pull/6932
3 changed files with 47 additions and 21 deletions
|
@ -376,26 +376,39 @@ void Profile::clear_timestamp_filter_range()
|
|||
m_samples_model->update();
|
||||
}
|
||||
|
||||
void Profile::set_process_filter(pid_t pid, u64 start_valid, u64 end_valid)
|
||||
void Profile::add_process_filter(pid_t pid, u64 start_valid, u64 end_valid)
|
||||
{
|
||||
if (m_has_process_filter && m_process_filter_pid == pid && m_process_filter_start_valid == start_valid && m_process_filter_end_valid == end_valid)
|
||||
auto filter = ProcessFilter { pid, start_valid, end_valid };
|
||||
if (m_process_filters.contains_slow(filter))
|
||||
return;
|
||||
m_has_process_filter = true;
|
||||
|
||||
m_process_filter_pid = pid;
|
||||
m_process_filter_start_valid = start_valid;
|
||||
m_process_filter_end_valid = end_valid;
|
||||
m_process_filters.append(move(filter));
|
||||
|
||||
rebuild_tree();
|
||||
if (m_disassembly_model)
|
||||
m_disassembly_model->update();
|
||||
m_samples_model->update();
|
||||
}
|
||||
|
||||
void Profile::remove_process_filter(pid_t pid, u64 start_valid, u64 end_valid)
|
||||
{
|
||||
auto filter = ProcessFilter { pid, start_valid, end_valid };
|
||||
if (!m_process_filters.contains_slow(filter))
|
||||
return;
|
||||
m_process_filters.remove_first_matching([&filter](ProcessFilter const& other_filter) {
|
||||
return other_filter == filter;
|
||||
});
|
||||
|
||||
rebuild_tree();
|
||||
if (m_disassembly_model)
|
||||
m_disassembly_model->update();
|
||||
m_samples_model->update();
|
||||
}
|
||||
|
||||
void Profile::clear_process_filter()
|
||||
{
|
||||
if (!m_has_process_filter)
|
||||
if (m_process_filters.is_empty())
|
||||
return;
|
||||
m_has_process_filter = false;
|
||||
m_process_filters.clear();
|
||||
rebuild_tree();
|
||||
if (m_disassembly_model)
|
||||
m_disassembly_model->update();
|
||||
|
@ -407,7 +420,11 @@ bool Profile::process_filter_contains(pid_t pid, u32 timestamp)
|
|||
if (!has_process_filter())
|
||||
return true;
|
||||
|
||||
return (pid == m_process_filter_pid && timestamp >= m_process_filter_start_valid && timestamp <= m_process_filter_end_valid);
|
||||
for (auto const& process_filter : m_process_filters)
|
||||
if (pid == process_filter.pid && timestamp >= process_filter.start_valid && timestamp <= process_filter.end_valid)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Profile::set_inverted(bool inverted)
|
||||
|
|
|
@ -116,6 +116,17 @@ private:
|
|||
Bitmap m_seen_events;
|
||||
};
|
||||
|
||||
struct ProcessFilter {
|
||||
pid_t pid { 0 };
|
||||
u64 start_valid { 0 };
|
||||
u64 end_valid { 0 };
|
||||
|
||||
bool operator==(ProcessFilter const& rhs) const
|
||||
{
|
||||
return pid == rhs.pid && start_valid == rhs.start_valid && end_valid == rhs.end_valid;
|
||||
}
|
||||
};
|
||||
|
||||
class Profile {
|
||||
public:
|
||||
static Result<NonnullOwnPtr<Profile>, String> load_from_perfcore_file(const StringView& path);
|
||||
|
@ -171,9 +182,10 @@ public:
|
|||
void clear_timestamp_filter_range();
|
||||
bool has_timestamp_filter_range() const { return m_has_timestamp_filter_range; }
|
||||
|
||||
void set_process_filter(pid_t pid, u64 start_valid, u64 end_valid);
|
||||
void add_process_filter(pid_t pid, u64 start_valid, u64 end_valid);
|
||||
void remove_process_filter(pid_t pid, u64 start_valid, u64 end_valid);
|
||||
void clear_process_filter();
|
||||
bool has_process_filter() const { return m_has_process_filter; }
|
||||
bool has_process_filter() const { return !m_process_filters.is_empty(); }
|
||||
bool process_filter_contains(pid_t pid, u32 timestamp);
|
||||
|
||||
bool is_inverted() const { return m_inverted; }
|
||||
|
@ -222,10 +234,7 @@ private:
|
|||
u64 m_timestamp_filter_range_start { 0 };
|
||||
u64 m_timestamp_filter_range_end { 0 };
|
||||
|
||||
bool m_has_process_filter { false };
|
||||
pid_t m_process_filter_pid { 0 };
|
||||
u64 m_process_filter_start_valid { 0 };
|
||||
u64 m_process_filter_end_valid { 0 };
|
||||
Vector<ProcessFilter> m_process_filters;
|
||||
|
||||
u32 m_deepest_stack_depth { 0 };
|
||||
bool m_inverted { false };
|
||||
|
|
|
@ -110,11 +110,11 @@ int main(int argc, char** argv)
|
|||
auto& timeline_header = timeline_header_container->add<TimelineHeader>(*profile, process);
|
||||
timeline_header.set_shrink_to_fit(true);
|
||||
timeline_header.on_selection_change = [&](bool selected) {
|
||||
if (selected) {
|
||||
auto end_valid = process.end_valid == 0 ? profile->last_timestamp() : process.end_valid;
|
||||
profile->set_process_filter(process.pid, process.start_valid, end_valid);
|
||||
} else
|
||||
profile->clear_process_filter();
|
||||
auto end_valid = process.end_valid == 0 ? profile->last_timestamp() : process.end_valid;
|
||||
if (selected)
|
||||
profile->add_process_filter(process.pid, process.start_valid, end_valid);
|
||||
else
|
||||
profile->remove_process_filter(process.pid, process.start_valid, end_valid);
|
||||
|
||||
timeline_header_container->for_each_child_widget([](auto& other_timeline_header) {
|
||||
static_cast<TimelineHeader&>(other_timeline_header).update_selection();
|
||||
|
|
Loading…
Add table
Reference in a new issue