diff options
author | MacDue <macdue@dueutil.tech> | 2023-04-15 01:04:28 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-04-15 06:37:51 +0200 |
commit | 0329ddf46a0d24303fac5954bf3c70d5f3fe577c (patch) | |
tree | 83ca60d767bfde06438e191fe4b0a4c7b0da10aa /Userland | |
parent | 5db1eb996173b34960f48c7ea8ce4fd33acde157 (diff) | |
download | serenity-0329ddf46a0d24303fac5954bf3c70d5f3fe577c.zip |
Ladybird+LibWebView: Add -P/--enable-callgrind-profiling option
This adds a -P option to run Ladybird under callgrind. It starts with
instrumentation disabled. To start capturing a profile (once Ladybird
has launched) run `callgrind_control -i on` and to stop it again run
`callgrind_control -i off`.
P.s. This is pretty much stolen from Andreas (and is based on the patch
everyone [that wants a profile] have been manually applying).
Diffstat (limited to 'Userland')
5 files changed, 34 insertions, 13 deletions
diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp index cee2b51ba1..52a1185550 100644 --- a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp +++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp @@ -59,7 +59,7 @@ void OutOfProcessWebView::handle_web_content_process_crash() load_html(builder.to_deprecated_string(), m_url); } -void OutOfProcessWebView::create_client() +void OutOfProcessWebView::create_client(EnableCallgrindProfiling) { m_client_state = {}; diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.h b/Userland/Libraries/LibWebView/OutOfProcessWebView.h index e521b29751..1e66ecd62c 100644 --- a/Userland/Libraries/LibWebView/OutOfProcessWebView.h +++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.h @@ -121,7 +121,7 @@ private: virtual void did_scroll() override; // ^WebView::ViewImplementation - virtual void create_client() override; + virtual void create_client(EnableCallgrindProfiling = EnableCallgrindProfiling::No) override; virtual void update_zoom() override; virtual void notify_server_did_layout(Badge<WebContentClient>, Gfx::IntSize content_size) override; virtual void notify_server_did_paint(Badge<WebContentClient>, i32 bitmap_id) override; diff --git a/Userland/Libraries/LibWebView/ViewImplementation.cpp b/Userland/Libraries/LibWebView/ViewImplementation.cpp index c77b8c27f9..0686544921 100644 --- a/Userland/Libraries/LibWebView/ViewImplementation.cpp +++ b/Userland/Libraries/LibWebView/ViewImplementation.cpp @@ -126,7 +126,7 @@ void ViewImplementation::run_javascript(StringView js_source) #if !defined(AK_OS_SERENITY) -ErrorOr<NonnullRefPtr<WebView::WebContentClient>> ViewImplementation::launch_web_content_process(ReadonlySpan<String> candidate_web_content_paths) +ErrorOr<NonnullRefPtr<WebView::WebContentClient>> ViewImplementation::launch_web_content_process(ReadonlySpan<String> candidate_web_content_paths, EnableCallgrindProfiling enable_callgrind_profiling) { int socket_fds[2] {}; TRY(Core::System::socketpair(AF_LOCAL, SOCK_STREAM, 0, socket_fds)); @@ -149,15 +149,22 @@ ErrorOr<NonnullRefPtr<WebView::WebContentClient>> ViewImplementation::launch_web auto webcontent_fd_passing_socket_string = TRY(String::number(wc_fd_passing_fd)); - auto arguments = Array { - "WebContent"sv, - "--webcontent-fd-passing-socket"sv, - webcontent_fd_passing_socket_string - }; - ErrorOr<void> result; for (auto const& path : candidate_web_content_paths) { - result = Core::System::exec(path, arguments, Core::System::SearchInPath::Yes); + constexpr auto callgrind_prefix_length = 3; + auto arguments_with_callgrind_prefix = Array { + "valgrind"sv, + "--tool=callgrind"sv, + "--instr-atstart=no"sv, + path.bytes_as_string_view(), + "--webcontent-fd-passing-socket"sv, + webcontent_fd_passing_socket_string + }; + auto arguments = arguments_with_callgrind_prefix.span(); + if (enable_callgrind_profiling == EnableCallgrindProfiling::No) + arguments = arguments.slice(callgrind_prefix_length); + + result = Core::System::exec(arguments[0], arguments, Core::System::SearchInPath::Yes); if (!result.is_error()) break; } @@ -176,6 +183,13 @@ ErrorOr<NonnullRefPtr<WebView::WebContentClient>> ViewImplementation::launch_web auto new_client = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) WebView::WebContentClient(move(socket), *this))); new_client->set_fd_passing_socket(TRY(Core::LocalSocket::adopt_fd(ui_fd_passing_fd))); + if (enable_callgrind_profiling == EnableCallgrindProfiling::Yes) { + dbgln(); + dbgln("\033[1;45mLaunched WebContent process under callgrind!\033[0m"); + dbgln("\033[100mRun `\033[4mcallgrind_control -i on\033[24m` to start instrumentation and `\033[4mcallgrind_control -i off\033[24m` stop it again.\033[0m"); + dbgln(); + } + return new_client; } diff --git a/Userland/Libraries/LibWebView/ViewImplementation.h b/Userland/Libraries/LibWebView/ViewImplementation.h index 0aa276da80..a7342a3cb8 100644 --- a/Userland/Libraries/LibWebView/ViewImplementation.h +++ b/Userland/Libraries/LibWebView/ViewImplementation.h @@ -18,6 +18,12 @@ namespace WebView { +// Note: This only exists inside Serenity to avoid #ifdefs in all implementors of ViewImplementation. +enum class EnableCallgrindProfiling { + No, + Yes +}; + class ViewImplementation { public: virtual ~ViewImplementation() { } @@ -120,11 +126,12 @@ protected: WebContentClient& client(); WebContentClient const& client() const; - virtual void create_client() = 0; virtual void update_zoom() = 0; + virtual void create_client(EnableCallgrindProfiling = EnableCallgrindProfiling::No) {}; + #if !defined(AK_OS_SERENITY) - ErrorOr<NonnullRefPtr<WebView::WebContentClient>> launch_web_content_process(ReadonlySpan<String> candidate_web_content_paths); + ErrorOr<NonnullRefPtr<WebView::WebContentClient>> launch_web_content_process(ReadonlySpan<String> candidate_web_content_paths, EnableCallgrindProfiling = EnableCallgrindProfiling::No); #endif struct SharedBitmap { diff --git a/Userland/Utilities/headless-browser.cpp b/Userland/Utilities/headless-browser.cpp index 2dfca6f1ee..8c6420aca6 100644 --- a/Userland/Utilities/headless-browser.cpp +++ b/Userland/Utilities/headless-browser.cpp @@ -157,7 +157,7 @@ private: void notify_server_did_finish_handling_input_event(bool) override { } void update_zoom() override { } - void create_client() override { } + void create_client(WebView::EnableCallgrindProfiling) override { } }; static ErrorOr<NonnullRefPtr<Core::Timer>> load_page_for_screenshot_and_exit(Core::EventLoop& event_loop, HeadlessWebContentView& view, int screenshot_timeout) |