[PATCH] D68351: [profile] Add a mode to continuously sync counter updates to a file

Vedant Kumar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 2 11:39:25 PDT 2019


vsk created this revision.
vsk added reviewers: ejvaughan, davidxl.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.

Add support for continuously syncing profile counter updates to a file.

The motivation for this is that programs do not always exit cleanly. On
iOS, for example, programs are usually killed via a signal from the OS.
Running atexit() handlers after catching a signal is unreliable, so some
method for progressively writing out profile data is necessary.

The approach taken here is to mmap() the `__llvm_prf_cnts` section onto
a raw profile. To do this, the linker must page-align the counter and
data sections, and the runtime must ensure that counters are mapped to a
page-aligned offset within a raw profile.

Continuous mode is (for the moment) incompatible with the online merging
mode. The merging mode needs to take a lock while updating a profile: it
may become very slow if the lock needs to be held for the entire process
lifetime. Continuous mode is also (for the moment) incompatible with
value profiling, as I'm not sure whether there is interest in this and
the implementation may be tricky.

As I have not been able to test extensively on non-Darwin platforms,
only Darwin support is included for the moment. However, continuous mode
may "just work" without modification on Linux and other UNIX-likes. AIUI
the default value for the GNU linker's `--section-alignment` flag is set
to the page size on many systems. This appears to be true for LLD as
well, as its `no_nmagic` option is on by default.

rdar://54210980


https://reviews.llvm.org/D68351

Files:
  clang/docs/SourceBasedCodeCoverage.rst
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/darwin-ld.c
  compiler-rt/lib/profile/InstrProfData.inc
  compiler-rt/lib/profile/InstrProfiling.h
  compiler-rt/lib/profile/InstrProfilingBuffer.c
  compiler-rt/lib/profile/InstrProfilingFile.c
  compiler-rt/lib/profile/InstrProfilingPort.h
  compiler-rt/lib/profile/InstrProfilingRuntime.cpp
  compiler-rt/lib/profile/InstrProfilingWriter.c
  compiler-rt/test/profile/ContinuousSyncMode/basic.c
  compiler-rt/test/profile/ContinuousSyncMode/darwin-proof-of-concept.c
  compiler-rt/test/profile/ContinuousSyncMode/lit.local.cfg.py
  compiler-rt/test/profile/ContinuousSyncMode/multiple-DSOs.c
  compiler-rt/test/profile/ContinuousSyncMode/pid-substitution.c
  compiler-rt/test/profile/ContinuousSyncMode/set-file-object.c
  compiler-rt/test/profile/ContinuousSyncMode/set-filename.c
  llvm/include/llvm/ProfileData/InstrProfData.inc
  llvm/lib/ProfileData/InstrProfReader.cpp
  llvm/test/tools/llvm-profdata/Inputs/c-general.profraw
  llvm/test/tools/llvm-profdata/Inputs/malformed-ptr-to-counter-array.profraw
  llvm/test/tools/llvm-profdata/c-general.test
  llvm/test/tools/llvm-profdata/raw-32-bits-be.test
  llvm/test/tools/llvm-profdata/raw-32-bits-le.test
  llvm/test/tools/llvm-profdata/raw-64-bits-be.test
  llvm/test/tools/llvm-profdata/raw-64-bits-le.test
  llvm/test/tools/llvm-profdata/raw-two-profiles.test

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68351.222885.patch
Type: text/x-patch
Size: 45542 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191002/3d297333/attachment-0001.bin>


More information about the llvm-commits mailing list