diff options
author | Vedant Kumar <vsk@apple.com> | 2019-09-19 11:56:43 -0700 |
---|---|---|
committer | Vedant Kumar <vsk@apple.com> | 2019-10-31 16:04:09 -0700 |
commit | d889d1efefe9f97507e3eafa85a2e3939df9750f (patch) | |
tree | 3b0b092d7b64e5f1620b7eef3b0282d214663e95 /compiler-rt/test/profile/ContinuousSyncMode/basic.c | |
parent | ade776b5845384bb45fcd2f7919d80f4101971a7 (diff) | |
download | bcm5719-llvm-d889d1efefe9f97507e3eafa85a2e3939df9750f.tar.gz bcm5719-llvm-d889d1efefe9f97507e3eafa85a2e3939df9750f.zip |
[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
Diffstat (limited to 'compiler-rt/test/profile/ContinuousSyncMode/basic.c')
-rw-r--r-- | compiler-rt/test/profile/ContinuousSyncMode/basic.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/compiler-rt/test/profile/ContinuousSyncMode/basic.c b/compiler-rt/test/profile/ContinuousSyncMode/basic.c new file mode 100644 index 00000000000..9e29a0b0477 --- /dev/null +++ b/compiler-rt/test/profile/ContinuousSyncMode/basic.c @@ -0,0 +1,32 @@ +// RUN: %clang -fprofile-instr-generate -fcoverage-mapping -o %t.exe %s +// RUN: echo "garbage" > %t.profraw +// RUN: env LLVM_PROFILE_FILE="%c%t.profraw" %run %t.exe +// RUN: llvm-profdata show --counts --all-functions %t.profraw | FileCheck %s -check-prefix=CHECK-COUNTS +// RUN: llvm-profdata merge -o %t.profdata %t.profraw +// RUN: llvm-cov report %t.exe -instr-profile %t.profdata | FileCheck %s -check-prefix=CHECK-COVERAGE + +// CHECK-COUNTS: Counters: +// CHECK-COUNTS-NEXT: main: +// CHECK-COUNTS-NEXT: Hash: 0x{{.*}} +// CHECK-COUNTS-NEXT: Counters: 2 +// CHECK-COUNTS-NEXT: Function count: 1 +// CHECK-COUNTS-NEXT: Block counts: [1] +// CHECK-COUNTS-NEXT: Instrumentation level: Front-end +// CHECK-COUNTS-NEXT: Functions shown: 1 +// CHECK-COUNTS-NEXT: Total functions: 1 +// CHECK-COUNTS-NEXT: Maximum function count: 1 +// CHECK-COUNTS-NEXT: Maximum internal block count: 1 + +// CHECK-COVERAGE: Filename Regions Missed Regions Cover Functions Missed Functions Executed Lines Missed Lines Cover +// CHECK-COVERAGE-NEXT: --- +// CHECK-COVERAGE-NEXT: basic.c 4 1 75.00% 1 0 100.00% 5 2 60.00% +// CHECK-COVERAGE-NEXT: --- +// CHECK-COVERAGE-NEXT: TOTAL 4 1 75.00% 1 0 100.00% 5 2 60.00% + +extern int __llvm_profile_is_continuous_mode_enabled(void); + +int main() { + if (__llvm_profile_is_continuous_mode_enabled()) + return 0; + return 1; +} |