Commit Graph

28 Commits

Author SHA1 Message Date
Nico Weber b50431defb fix some typos to cycle bots 2020-02-10 13:51:23 -05:00
Petr Hosek d3db13af7e [profile] Support counter relocation at runtime
This is an alternative to the continous mode that was implemented in
D68351. This mode relies on padding and the ability to mmap a file over
the existing mapping which is generally only available on POSIX systems
and isn't suitable for other platforms.

This change instead introduces the ability to relocate counters at
runtime using a level of indirection. On every counter access, we add a
bias to the counter address. This bias is stored in a symbol that's
provided by the profile runtime and is initially set to zero, meaning no
relocation. The runtime can mmap the profile into memory at abitrary
location, and set bias to the offset between the original and the new
counter location, at which point every subsequent counter access will be
to the new location, which allows updating profile directly akin to the
continous mode.

The advantage of this implementation is that doesn't require any special
OS support. The disadvantage is the extra overhead due to additional
instructions required for each counter access (overhead both in terms of
binary size and performance) plus duplication of counters (i.e. one copy
in the binary itself and another copy that's mmapped).

Differential Revision: https://reviews.llvm.org/D69740
2020-01-17 15:02:23 -08:00
Vedant Kumar 859bf4d2be [Coverage] Emit a gap region to cover switch bodies
Emit a gap region beginning where the switch body begins. This sets line
execution counts in the areas between non-overlapping cases to 0.

This also removes some special handling of the first case in a switch:
these are now treated like any other case.

This does not resolve an outstanding issue with case statement regions
that do not end when a region is terminated. But it should address
llvm.org/PR44011.

Differential Revision: https://reviews.llvm.org/D70571
2019-12-03 12:35:54 -08:00
Vedant Kumar 2492b5a125 [profile] Support online merging with continuous sync mode
Make it possible to use online profile merging ("%m" mode) with
continuous sync ("%c" mode).

To implement this, the merged profile is locked in the runtime
initialization step and either a) filled out for the first time or b)
checked for compatibility. Then, the profile can simply be mmap()'d with
MAP_SHARED set. With the mmap() in place, counter updates from every
process which uses an image are mapped onto the same set of physical
pages assigned by the filesystem cache. After the mmap() is set up, the
profile is unlocked.

Differential Revision: https://reviews.llvm.org/D69586
2019-11-18 12:56:58 -08:00
Vedant Kumar d889d1efef [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
2019-10-31 16:04:09 -07:00
Sylvestre Ledru bc5c3f5727 Update our URLs in clang doc to use https
llvm-svn: 346101
2018-11-04 17:02:00 +00:00
Vedant Kumar 1c5f312c70 [docs] Coverage: Improve the wording a bit
llvm-svn: 305745
2017-06-19 21:26:04 +00:00
Vedant Kumar 82cd770914 [docs] Coverage: document issue with the BFD linker
llvm-svn: 305743
2017-06-19 21:22:05 +00:00
Vedant Kumar 6eed0d5bb5 [docs] coverage: Clarify which flags enable gcov-style profiling (NFC)
Point out that --coverage and -ftest-coverage, which is what most people
are used to, do not enable clang's frontend based coverage pass.

Suggested by Benn Bolay!

llvm-svn: 294626
2017-02-09 21:33:21 +00:00
Nico Weber b1706ca107 Clarify how to forward-declare __llvm_profile symbols.
llvm-svn: 293065
2017-01-25 16:01:32 +00:00
Vedant Kumar 74c3fd1798 [docs] Touch up the coverage docs some more
llvm-svn: 282169
2016-09-22 15:34:33 +00:00
Vedant Kumar 6fe6eae7f7 [docs] Extend the code coverage docs some more
Flesh out the section on interpreting coverage reports, mention the
coverage export feature, and add notes on how to build llvm with
coverage turned on.

llvm-svn: 281988
2016-09-20 17:11:18 +00:00
Vedant Kumar 9ed5802680 [docs] Touch up the code coverage doc
llvm-svn: 281881
2016-09-19 01:42:38 +00:00
Vedant Kumar ae00885108 [docs] Coverage: Reference the new -output-dir option
llvm-svn: 277081
2016-07-28 23:22:42 +00:00
Vedant Kumar 3f42b13c20 [docs] Mention some new options in llvm-cov
llvm-svn: 277080
2016-07-28 23:18:48 +00:00
Sylvestre Ledru c0a3d717c7 fix two typos in the doc
llvm-svn: 274447
2016-07-02 19:17:58 +00:00
George Burgess IV bc8cc5ac9c [Docs] More warning fixes to unbreak the docs buildbot.
A number of warnings still remain, but these were the last of the
"unlexable code"-related ones (AFAICT).

I changed a few examples in docs/UsersManual.rst to showcase
-Wextra-tokens because it's already documented (-Wmultichar isn't), and
the sphinx C lexer apparently can't handle char literals like 'ab'. It
seemed like a better overall approach than just marking the code blocks
as none or console.

llvm-svn: 273232
2016-06-21 02:19:43 +00:00
Vedant Kumar f3300c9f74 [docs] Coverage: Document the profile merge pool specifier
llvm-svn: 272604
2016-06-14 00:42:12 +00:00
Vedant Kumar 89262b6928 [docs] Coverage: Clarify return value of __llvm_profile_write_file
llvm-svn: 272215
2016-06-08 22:32:03 +00:00
Vedant Kumar 32a9bfa42a [docs] Coverage: Flesh out instructions for avoiding static initializeres
llvm-svn: 272214
2016-06-08 22:24:52 +00:00
Vedant Kumar b06294da84 [docs] Coverage: Explain how to avoid static initializers
llvm-svn: 272067
2016-06-07 22:25:29 +00:00
Vedant Kumar 62baa4c752 [docs] Clarify limitations section of SourceBasedCodeCoverage.rst
Mention that the code coverage tool becomes less precise whenever
unpredictable changes in control flow occur.

Thanks to Sean Silva for pointing this out!

llvm-svn: 271902
2016-06-06 15:44:40 +00:00
Vedant Kumar 553a0d62f2 [docs] Add a limitations section to SourceBasedCodeCoverage.rst
llvm-svn: 271544
2016-06-02 17:19:45 +00:00
Vedant Kumar 6c53d8f94c [docs] Fix misplaced comma
llvm-svn: 271472
2016-06-02 02:45:59 +00:00
Vedant Kumar 0819f36ddd [docs] Minor formatting changes and typo fixes
llvm-svn: 271471
2016-06-02 02:25:13 +00:00
Vedant Kumar 4c1112c3b7 [docs] Use cpp code-blocks where appropriate
llvm-svn: 271461
2016-06-02 01:15:59 +00:00
Vedant Kumar 01d91eeac5 [docs] Add missing newline to console section
llvm-svn: 271457
2016-06-02 01:01:48 +00:00
Vedant Kumar a530a3615e [docs] Document the source-based code coverage feature
Differential Revision: http://reviews.llvm.org/D20715

llvm-svn: 271454
2016-06-02 00:51:50 +00:00