diff options
author | Brian Gianforcaro <bgianf@serenityos.org> | 2021-05-14 08:21:25 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-14 10:21:25 +0200 |
commit | c63761a3419781dc4e1b22f5586a2a908877463a (patch) | |
tree | 45c74a227fcfa08c34d2d033bef8a0ccd60e7e2f /Userland/DevTools | |
parent | 5a7db74c52d95f59e2972ed255407e75fd338ed8 (diff) | |
download | serenity-c63761a3419781dc4e1b22f5586a2a908877463a.zip |
Profiler: Avoid copies / String construction when parsing profile (#7096)
Use sv literal suffix to construct StringViews at compile time,
and make sure to reference array items by const reference.
Diffstat (limited to 'Userland/DevTools')
-rw-r--r-- | Userland/DevTools/Profiler/Profile.cpp | 32 | ||||
-rw-r--r-- | Userland/DevTools/Profiler/TimelineTrack.cpp | 4 |
2 files changed, 18 insertions, 18 deletions
diff --git a/Userland/DevTools/Profiler/Profile.cpp b/Userland/DevTools/Profiler/Profile.cpp index 0a7249dcee..b422531869 100644 --- a/Userland/DevTools/Profiler/Profile.cpp +++ b/Userland/DevTools/Profiler/Profile.cpp @@ -79,9 +79,9 @@ void Profile::rebuild_tree() HashTable<FlatPtr> live_allocations; for_each_event_in_filter_range([&](auto& event) { - if (event.type == "malloc") + if (event.type == "malloc"sv) live_allocations.set(event.ptr); - else if (event.type == "free") + else if (event.type == "free"sv) live_allocations.remove(event.ptr); }); @@ -100,17 +100,17 @@ void Profile::rebuild_tree() continue; if (!m_show_scheduler && !event.frames.is_empty()) { - auto top_frame = event.frames[event.frames.size() - 1]; - if (top_frame.symbol == "Kernel::Scheduler::yield()") + const auto& top_frame = event.frames[event.frames.size() - 1]; + if (top_frame.symbol == "Kernel::Scheduler::yield()"sv) continue; } m_filtered_event_indices.append(event_index); - if (event.type == "malloc" && !live_allocations.contains(event.ptr)) + if (event.type == "malloc"sv && !live_allocations.contains(event.ptr)) continue; - if (event.type == "free") + if (event.type == "free"sv) continue; auto for_each_frame = [&]<typename Callback>(Callback callback) { @@ -233,12 +233,12 @@ Result<NonnullOwnPtr<Profile>, String> Profile::load_from_perfcore_file(const St event.pid = perf_event.get("pid").to_i32(); event.tid = perf_event.get("tid").to_i32(); - if (event.type == "malloc") { + if (event.type == "malloc"sv) { event.ptr = perf_event.get("ptr").to_number<FlatPtr>(); event.size = perf_event.get("size").to_number<size_t>(); - } else if (event.type == "free") { + } else if (event.type == "free"sv) { event.ptr = perf_event.get("ptr").to_number<FlatPtr>(); - } else if (event.type == "mmap") { + } else if (event.type == "mmap"sv) { event.ptr = perf_event.get("ptr").to_number<FlatPtr>(); event.size = perf_event.get("size").to_number<size_t>(); event.name = perf_event.get("name").to_string(); @@ -247,11 +247,11 @@ Result<NonnullOwnPtr<Profile>, String> Profile::load_from_perfcore_file(const St if (it != current_processes.end()) it->value->library_metadata.handle_mmap(event.ptr, event.size, event.name); continue; - } else if (event.type == "munmap") { + } else if (event.type == "munmap"sv) { event.ptr = perf_event.get("ptr").to_number<FlatPtr>(); event.size = perf_event.get("size").to_number<size_t>(); continue; - } else if (event.type == "process_create") { + } else if (event.type == "process_create"sv) { event.parent_pid = perf_event.get("parent_pid").to_number<FlatPtr>(); event.executable = perf_event.get("executable").to_string(); @@ -264,7 +264,7 @@ Result<NonnullOwnPtr<Profile>, String> Profile::load_from_perfcore_file(const St current_processes.set(sampled_process->pid, sampled_process); all_processes.append(move(sampled_process)); continue; - } else if (event.type == "process_exec") { + } else if (event.type == "process_exec"sv) { event.executable = perf_event.get("executable").to_string(); auto old_process = current_processes.get(event.pid).value(); @@ -280,19 +280,19 @@ Result<NonnullOwnPtr<Profile>, String> Profile::load_from_perfcore_file(const St current_processes.set(sampled_process->pid, sampled_process); all_processes.append(move(sampled_process)); continue; - } else if (event.type == "process_exit") { + } else if (event.type == "process_exit"sv) { auto old_process = current_processes.get(event.pid).value(); old_process->end_valid = event.timestamp - 1; current_processes.remove(event.pid); continue; - } else if (event.type == "thread_create") { + } else if (event.type == "thread_create"sv) { event.parent_tid = perf_event.get("parent_tid").to_i32(); auto it = current_processes.find(event.pid); if (it != current_processes.end()) it->value->handle_thread_create(event.tid, event.timestamp); continue; - } else if (event.type == "thread_exit") { + } else if (event.type == "thread_exit"sv) { auto it = current_processes.find(event.pid); if (it != current_processes.end()) it->value->handle_thread_exit(event.tid, event.timestamp); @@ -488,7 +488,7 @@ ProfileNode::ProfileNode(const String& object_name, String symbol, u32 address, , m_timestamp(timestamp) { String object; - if (object_name.ends_with(": .text")) { + if (object_name.ends_with(": .text"sv)) { object = object_name.view().substring_view(0, object_name.length() - 7); } else { object = object_name; diff --git a/Userland/DevTools/Profiler/TimelineTrack.cpp b/Userland/DevTools/Profiler/TimelineTrack.cpp index ae096f23b1..6f430bed36 100644 --- a/Userland/DevTools/Profiler/TimelineTrack.cpp +++ b/Userland/DevTools/Profiler/TimelineTrack.cpp @@ -72,8 +72,8 @@ void TimelineTrack::paint_event(GUI::PaintEvent& event) continue; if (!m_profile.show_scheduler() && !event.frames.is_empty()) { - auto top_frame = event.frames[event.frames.size() - 1]; - if (top_frame.symbol == "Kernel::Scheduler::yield()") + const auto& top_frame = event.frames[event.frames.size() - 1]; + if (top_frame.symbol == "Kernel::Scheduler::yield()"sv) continue; } |