From d889d1efefe9f97507e3eafa85a2e3939df9750f Mon Sep 17 00:00:00 2001 From: Vedant Kumar Date: Thu, 19 Sep 2019 11:56:43 -0700 Subject: [profile] Add a mode to continuously sync counter updates to a file 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. This limitation is lifted in https://reviews.llvm.org/D69586. 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 some 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. Continuous mode will not "just work" on Fuchsia or Windows, as it's not possible to mmap() a section on these platforms. There is a proposal to add a layer of indirection to the profile instrumentation to support these platforms. rdar://54210980 Differential Revision: https://reviews.llvm.org/D68351 --- clang/docs/SourceBasedCodeCoverage.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'clang/docs/SourceBasedCodeCoverage.rst') diff --git a/clang/docs/SourceBasedCodeCoverage.rst b/clang/docs/SourceBasedCodeCoverage.rst index 27a1950a1602..0beb284e475e 100644 --- a/clang/docs/SourceBasedCodeCoverage.rst +++ b/clang/docs/SourceBasedCodeCoverage.rst @@ -87,6 +87,16 @@ directory structure will be created. Additionally, the following special be between 1 and 9. The merge pool specifier can only occur once per filename pattern. +* "%c" expands out to nothing, but enables a mode in which profile counter + updates are continuously synced to a file. This means that if the + instrumented program crashes, or is killed by a signal, perfect coverage + information can still be recovered. Continuous mode is not yet compatible with + the "%Nm" merging mode described above, does not support value profiling for + PGO, and is only supported on Darwin. Support for Linux may be mostly + complete but requires testing, and support for Fuchsia/Windows may require + more extensive changes: please get involved if you are interested in porting + this feature. + .. code-block:: console # Step 2: Run the program. -- cgit v1.2.3