[webkit-changes] [WebKit/WebKit] 6fc61a: [PGO] Fix sandboxing issues and simplify collection

Elliott Williams noreply at github.com
Thu Sep 7 11:03:26 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 6fc61a30ebc7388f132ccd447db31ed6c04612cc
      https://github.com/WebKit/WebKit/commit/6fc61a30ebc7388f132ccd447db31ed6c04612cc
  Author: Elliott Williams <emw at apple.com>
  Date:   2023-09-07 (Thu, 07 Sep 2023)

  Changed paths:
    M Source/JavaScriptCore/runtime/InitializeThreading.cpp
    M Source/WTF/WTF.xcodeproj/project.pbxproj
    M Source/WTF/wtf/CMakeLists.txt
    R Source/WTF/wtf/GenerateProfiles.h
    M Source/WebCore/bindings/js/ScriptController.cpp
    M Source/WebKit/GPUProcess/mac/com.apple.WebKit.GPUProcess.sb.in
    M Source/WebKit/NetworkProcess/mac/com.apple.WebKit.NetworkProcess.sb.in
    M Source/WebKit/Shared/Cocoa/WebKit2InitializeCocoa.mm
    M Source/WebKit/Shared/WebKit2Initialize.cpp
    M Source/WebKit/WebProcess/com.apple.WebProcess.sb.in
    M Tools/Scripts/webkitpy/benchmark_runner/benchmark_runner.py
    M Tools/Scripts/webkitpy/benchmark_runner/run_benchmark.py
    M Tools/Scripts/webkitpy/benchmark_runner/webserver_benchmark_runner.py
    M Tools/TestWebKitAPI/Configurations/TestIPC.xcconfig

  Log Message:
  -----------
  [PGO] Fix sandboxing issues and simplify collection
https://bugs.webkit.org/show_bug.cgi?id=261014
rdar://113870737

Reviewed by Justin Michaud and Alexey Proskuryakov.

Make a number of simplifications to our PGO instrumentation logic
to fix instances where profile collection would fail silently due to
sandboxing:

Instead of initializing and writing out instrumented profiles ourselves,
use LLVM's built-in logic. We bake in a default profile path into
instrumented binaries, which tells the instrumentation machinery to
write profiles to /private/tmp/WebKitPGO. This is done by declaring
__llvm_profile_filename in each instrumented binary, rather than using
the -fprofile-generate=<name> compiler argument, because there is no
Xcode build setting to easily set it, see rdar://114792050. At process
launch, profiling begins via a static initializer compiled in to each
instrumented binary from LLVM.

Auto-initalization works great for starting PGO collection in a
predictably, across all WebKit processes, but termination requires extra
care. On Darwin-based platforms, we kill WebKit XPC processes via _exit,
without running atexit handlers, which is normally when profiles would
be written. To accomodate this, run profile collection in "continuous
mode", denoted by a %c in the profile string. LLVM mmaps the profile
file and records function calls directly in the mapped file, with no
writeback step needed.

Add sandbox rules to permit writing to the WebKitPGO directory when
built for instrumentation. Teach the benchmark runner to copy from
WebKitPGO when Safari exits, instead of parsing the system log to find
written profiles.

* Source/JavaScriptCore/runtime/InitializeThreading.cpp: Declare default
  profile name for JSC.
* Source/WTF/WTF.xcodeproj/project.pbxproj: Remove GenerateProfiles.h.
* Source/WTF/wtf/CMakeLists.txt: Remove GenerateProfiles.h.
* Source/WTF/wtf/GenerateProfiles.h: Removed.
* Source/WebCore/bindings/js/ScriptController.cpp: Declare default
  profile name for WebCore.
* Source/WebKit/Configurations/BaseXPCService.xcconfig: XPC executables
  (i.e. the binary that contains XPCServiceMain) were being
  instrumented, but the profiles were being discarded due to sandboxing.
  We can safely turn off instrumentation -- the only binaries we care
  about are the executables in the WebKit framework stack.
* Source/WebKit/GPUProcess/mac/com.apple.WebKit.GPUProcess.sb.in: Allow
  access to the WebKitPGO directory.
* Source/WebKit/NetworkProcess/mac/com.apple.WebKit.NetworkProcess.sb.in: Ditto.
* Source/WebKit/Shared/Cocoa/WebKit2InitializeCocoa.mm: Declare default
  profile name for WebKit.
* Source/WebKit/Shared/WebKit2Initialize.cpp: Remove spurious include.
* Source/WebKit/WebProcess/com.apple.WebProcess.sb.in: Ditto above.

* Tools/Scripts/webkitpy/benchmark_runner/benchmark_runner.py: When
  collecting profiles, each invocation will populate /tmp/WebKitPGO.
  Ensure the directory is empty before launching the browser, and copy
  its contents to the diagnostic directory upon exit.
(BenchmarkRunner._run_benchmark):
* Tools/Scripts/webkitpy/benchmark_runner/run_benchmark.py:
(run_benchmark_plan): Use a fixed path for writing profiles to.
* Tools/Scripts/webkitpy/benchmark_runner/webserver_benchmark_runner.py:
(WebServerBenchmarkRunner._get_result): Remove the logic that listened
  to the system log for profiling messages and moved profiles out ad hoc.
* Tools/TestWebKitAPI/Configurations/TestIPC.xcconfig: It static-links
  libWebKitPlatform.a, so when that library is compiled with profiling
  it needs it too. This has likely always been broken, and not been an
  issue since we never attempt to build for profiling with tools.

Canonical link: https://commits.webkit.org/267741@main




More information about the webkit-changes mailing list