[PATCH] D155290: [PGO] Use Unique Profile Files when New Processes are Forked

Qiongsi Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 14 06:25:58 PDT 2023


qiongsiwu1 created this revision.
qiongsiwu1 added reviewers: w2yehia, davidxl, vsk, ellis.
Herald added subscribers: wlei, Enna1, wenlei.
Herald added a project: All.
qiongsiwu1 requested review of this revision.
Herald added subscribers: Sanitizers, cfe-commits, MaskRay.
Herald added projects: clang, Sanitizers.

Currently, the PGO runtime only creates unique per process profile files when both of the following conditions are true

1. __llvm_profile_initialize is triggered through global variable initialization (e.g. when exec starts an instrumented binary).
2. When there are no existing file patterns set. See https://github.com/llvm/llvm-project/blob/bb6d60bf9dfea82814d9e50c5bb457c47d010611/compiler-rt/lib/profile/InstrProfilingFile.c#L795

This patch changes the behaviour so that a new profile file name is generate as soon as a fork system call generates a new process from an instrumented binary. The patch uses the `pthread_atfork` hook to register the initialization code, and modifies the file name pattern parsing logic so that when `%p` is present in the pattern, a unique file name can be generated even though the pattern already exists.

Additionally, the unique profile files are created before the profiling starts. If a process is not terminated gracefully by calling `exit`, an empty profile file for that process will exist, indicating that the profiling may be incomplete due to the process's abnormal termination.

Note that the unique profile per process is only generated when `%p` is present in the profile file name pattern. Additionally, this patch does not support Windows because the implementation relies on `pthread`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155290

Files:
  clang/lib/Driver/ToolChains/AIX.cpp
  compiler-rt/lib/profile/InstrProfilingFile.c
  compiler-rt/test/profile/Posix/instrprof-fork-int.c
  compiler-rt/test/profile/Posix/instrprof-fork.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155290.540393.patch
Type: text/x-patch
Size: 6535 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230714/a0fc37e1/attachment-0001.bin>


More information about the cfe-commits mailing list