summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/profile/InstrProfilingFile.c
Commit message (Collapse)AuthorAgeFilesLines
* [profile] Support merge pool size >= 10Fangrui Song2020-01-121-19/+27
| | | | | | | | | | | The executable acquires an advisory record lock (`fcntl(fd, F_SETLKW, *)`) on a profile file. Merge pool size >= 10 may be beneficial when the concurrency is large. Also fix a small problem about snprintf. It can cause the filename to be truncated after %m. Reviewed By: davidxl Differential Revision: https://reviews.llvm.org/D71970
* [profile] Avoid allocating a page on the stack, NFCVedant Kumar2019-12-111-0/+12
| | | | | | | | | | | | | | | | | | | | | When writing out a profile, avoid allocating a page on the stack for the purpose of writing out zeroes, as some embedded environments do not have enough stack space to accomodate this. Instead, use a small, fixed-size zero buffer that can be written repeatedly. For a synthetic file with >100,000 functions, I did not measure a significant difference in profile write times. We are removing a page-length zero-fill `memset()` in favor of several smaller buffered `fwrite()` calls: in practice, I am not sure there is much of a difference. The performance impact is only expected to affect the continuous sync mode (%c) -- zero padding is less than 8 bytes in all other cases. rdar://57810014 Differential Revision: https://reviews.llvm.org/D71323
* [profile] Address unused function warnings on Windows after D69586Vedant Kumar2019-11-191-0/+2
| | | | | This '#ifdef's out two functions which are unused on Windows, to prevent -Wunused-function warnings.
* [profile] Unbreak Fuchsia/Windows after D68351Vedant Kumar2019-11-191-3/+3
| | | | | | Continuous mode is not yet supported on Fuchsia/Windows, however an error should not be reported unless the user attempted to actually enable continuous mode.
* [profile] Support online merging with continuous sync modeVedant Kumar2019-11-181-39/+92
| | | | | | | | | | | | | | | 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
* [profile] Factor out logic for mmap'ing merged profile, NFCVedant Kumar2019-11-131-22/+51
| | | | | | | | | | | Split out the logic to get the size of a merged profile and to do a compatibility check. This can be shared with both the continuous+merging mode implementation, as well as the runtime-allocated counters implementation planned for Fuchsia. Lifted out of D69586. Differential Revision: https://reviews.llvm.org/D70135
* [profile] Fifth speculative fix for Android after D68351Vedant Kumar2019-10-311-4/+4
| | | | | | | | | | | | | | | | | | | | | | Use the printf macros from inttypes.h to sidestep -Wformat issues: /var/lib/buildbot/sanitizer-buildbot6/sanitizer-x86_64-linux-android/build/llvm-project/compiler-rt/lib/profile/InstrProfilingFile.c:425:14: error: format specifies type 'long long' but the argument has type 'off_t' (aka 'long') [-Werror,-Wformat] CurrentFileOffset, PageSize); ^~~~~~~~~~~~~~~~~ /var/lib/buildbot/sanitizer-buildbot6/sanitizer-x86_64-linux-android/build/llvm-project/compiler-rt/lib/profile/InstrProfilingPort.h:114:50: note: expanded from macro 'PROF_ERR' fprintf(stderr, "LLVM Profile Error: " Format, __VA_ARGS__); ~~~~~~ ^~~~~~~~~~~ /var/lib/buildbot/sanitizer-buildbot6/sanitizer-x86_64-linux-android/build/llvm-project/compiler-rt/lib/profile/InstrProfilingFile.c:461:41: error: format specifies type 'unsigned long long' but the argument has type 'uint64_t' (aka 'unsigned long') [-Werror,-Wformat] strerror(errno), CountersBegin, PageAlignedCountersLength, Fileno, ^~~~~~~~~~~~~~~~~~~~~~~~~ /var/lib/buildbot/sanitizer-buildbot6/sanitizer-x86_64-linux-android/build/llvm-project/compiler-rt/lib/profile/InstrProfilingPort.h:114:50: note: expanded from macro 'PROF_ERR' fprintf(stderr, "LLVM Profile Error: " Format, __VA_ARGS__); ~~~~~~ ^~~~~~~~~~~ /var/lib/buildbot/sanitizer-buildbot6/sanitizer-x86_64-linux-android/build/llvm-project/compiler-rt/lib/profile/InstrProfilingFile.c:462:9: error: format specifies type 'unsigned long long' but the argument has type 'uint64_t' (aka 'unsigned long') [-Werror,-Wformat] FileOffsetToCounters); ^~~~~~~~~~~~~~~~~~~~ /var/lib/buildbot/sanitizer-buildbot6/sanitizer-x86_64-linux-android/build/llvm-project/compiler-rt/lib/profile/InstrProfilingPort.h:114:50: note: expanded from macro 'PROF_ERR' fprintf(stderr, "LLVM Profile Error: " Format, __VA_ARGS__);
* [profile] Third speculative fix for Windows after D68351Vedant Kumar2019-10-311-3/+8
| | | | | | | _putenv on Windows takes 1 argument, whereas setenv elsewhere takes 3. Just treat the two platforms differently. http://lab.llvm.org:8011/builders/sanitizer-windows/builds/53547
* [profile] Add a mode to continuously sync counter updates to a fileVedant Kumar2019-10-311-2/+137
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* [profile] Do not cache __llvm_profile_get_filename resultVedant Kumar2019-10-181-9/+2
| | | | | | | | | | | | | | | | | When the %m filename pattern is used, the filename is unique to each image, so the cached value is wrong. It struck me that the full filename isn't something that's recomputed often, so perhaps it doesn't need to be cached at all. David Li pointed out we can go further and just hide lprofCurFilename. This may regress workflows that depend on using the set-filename API to change filenames across all loaded DSOs, but this is expected to be very rare. rdar://55137071 Differential Revision: https://reviews.llvm.org/D69137 llvm-svn: 375301
* (Reland with changes) Adding a function for setting coverage output file.Sajjad Mirza2019-06-241-12/+52
| | | | | | | | | | | | | | | | | | | | | | | Summary: User code can open a file on its own and pass it to the runtime, rather than specifying a name and having the runtime open the file. This supports the use case where a process cannot open a file on its own but can receive a file descriptor from another process. Relanding https://reviews.llvm.org/D62541. The original revision unlocked the file before calling flush, this revision fixes that. Reviewers: Dor1s, davidxl Reviewed By: Dor1s Subscribers: #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D63581 llvm-svn: 364231
* Revert r362676 "[Profile]: Add runtime interface to specify file handle for ↵Hans Wennborg2019-06-121-52/+12
| | | | | | | | | | | | | | | profile data." This caused instrumented Clang to become crashy. See llvm-commits thread for repro steps. This also reverts follow-up r362716 which added test cases. > Author: Sajjad Mirza > > Differential Revision: http://reviews.llvm.org/D62541 llvm-svn: 363134
* [Profile]: Add runtime interface to specify file handle for profile data.Xinliang David Li2019-06-061-12/+52
| | | | | | | | Author: Sajjad Mirza Differential Revision: http://reviews.llvm.org/D62541 llvm-svn: 362676
* Reland compiler-rt support for order file instrumentation.Manman Ren2019-03-081-0/+86
| | | | | | | | | | | | | | r355343 was landed and was reverted in r355363 due to build breakage. This patch adds Linux/Windows support on top of r355343. In this patch, Darwin should be working with testing case. Linux should be working, I will enable the testing case in a follwup diff. Windows/Other should be building. Correct implementation for Other platforms will be added. Thanks David for reviewing the original diff, helping me with issues on Linux, and giving suggestions for adding support for Other platforms. llvm-svn: 355701
* Revert compiler-rt diffs for order file instrumentation to get bot green!Manman Ren2019-03-051-86/+0
| | | | | | | | This caused issues on Linux/Windows and other platforms. r355343 355350 355350 llvm-svn: 355363
* Order File Instrumentation: dump the data in compiler-rtManman Ren2019-03-041-0/+86
| | | | | | | | The profile data will be dumped in a file default_xxx.profraw.order. Differential Revision: https://reviews.llvm.org/D57530 llvm-svn: 355343
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* [profile] Support profiling runtime on FuchsiaPetr Hosek2018-07-251-0/+4
| | | | | | | | | | | | | This ports the profiling runtime on Fuchsia and enables the instrumentation. Unlike on other platforms, Fuchsia doesn't use files to dump the instrumentation data since on Fuchsia, filesystem may not be accessible to the instrumented process. We instead use the data sink to pass the profiling data to the system the same sanitizer runtimes do. Differential Revision: https://reviews.llvm.org/D47208 llvm-svn: 337881
* [profile] Fix a possible memory leak in parseFilenamePattern().Igor Kudrin2018-07-241-2/+2
| | | | | | Differential Revision: https://reviews.llvm.org/D49666 llvm-svn: 337823
* [profile] Add interface to get profile filenameTeresa Johnson2018-07-191-12/+47
| | | | | | | | | | | | | | | | Summary: Add __llvm_profile_get_filename interface to get the profile filename, which can be used for identifying which profile file belongs to an app when multiple binaries are instrumented and dumping profiles into the same directory. The filename includes the path. Reviewers: davidxl Subscribers: delcypher, #sanitizers, llvm-commits Differential Revision: https://reviews.llvm.org/D49529 llvm-svn: 337482
* Fix clang-cl warnings in compiler-rtReid Kleckner2018-04-231-1/+2
| | | | | | | | | The profile library was missing some includes and was erroneously using ftruncate. WinASan was using `= {0}` to initialize structs, which creates -Wmissing-field-initializers and -Wmissing-braces warnings with clang. Use `= {}` instead, since this is C++. llvm-svn: 330616
* [profile] Fix value profile runtime merging issuesRong Xu2018-04-021-1/+6
| | | | | | | | | | | | | | | | This patch fixes the following issues: (1) The strong definition of the merge hook function was not working which breaks the online value profile merging. This patch removes the weak attribute of VPMergeHook and assigns the value dynamically. (2) Truncate the proifle file so that we don't have garbage data at the end of the file. (3) Add new __llvm_profile_instrument_target_value() interface to do the value profile update in batch. This is needed as the original incremental by 1 in __llvm_profile_instrument_target() is too slow for online merge. Differential Revision: https://reviews.llvm.org/D44847 llvm-svn: 328987
* [profile] Port the runtime to Solaris (retry)Vedant Kumar2017-12-141-5/+5
| | | | | | | | | | | | | This includes a few nice bits of refactoring (e.g splitting out the exclusive locking code into a common utility). Hopefully the Windows support is fixed now. Patch by Rainer Orth! Differential Revision: https://reviews.llvm.org/D40944 llvm-svn: 320731
* Revert "(HEAD -> master, origin/master, origin/HEAD) [profile] Port the ↵Vedant Kumar2017-12-141-5/+5
| | | | | | | | | | | runtime to Solaris" This reverts commit r320726. It looks like flock isn't available on Windows: http://lab.llvm.org:8011/builders/sanitizer-windows/builds/21317/steps/build%20compiler-rt/logs/stdio llvm-svn: 320728
* [profile] Port the runtime to SolarisVedant Kumar2017-12-141-5/+5
| | | | | | | | | | | This includes a few nice bits of refactoring (e.g splitting out the exclusive locking code into a common utility). Patch by Rainer Orth! Differential Revision: https://reviews.llvm.org/D40944 llvm-svn: 320726
* Revert r312240Alex Lorenz2017-08-311-1/+1
| | | | | | | The buildbots have shown that -Wstrict-prototypes behaves differently in GCC and Clang so we should keep it disabled until Clang follows GCC's behaviour llvm-svn: 312246
* Build LLVM with -Wstrict-prototypes enabledAlex Lorenz2017-08-311-1/+1
| | | | | | | | | | | Clang 5 supports -Wstrict-prototypes. We should use it to catch any C declarations that declare a non-prototype function. rdar://33705313 Differential Revision: https://reviews.llvm.org/D36669 llvm-svn: 312240
* [Profile] create a copy of profile file name from environmentXinliang David Li2017-08-231-2/+4
| | | | | | | | Original patch by Max Moroz. Differential Revsion: http://reviews.llvm.org/D36903 llvm-svn: 311607
* Revert r310857 due to internal test failureXinliang David Li2017-08-151-17/+11
| | | | llvm-svn: 310907
* [PGO] Add support for relocate profile dumping directoryXinliang David Li2017-08-141-11/+17
| | | | | | Differential Revsion: http://reviews.llvm.org/D36648 llvm-svn: 310857
* [PGO] Reduce IO in profile dumping with mergingXinliang David Li2017-06-281-11/+19
| | | | | | Differential Revision: http://reviews.llvm.org/D34709 llvm-svn: 306561
* [Profile] Remove redundant callXinliang David Li2017-06-271-1/+0
| | | | llvm-svn: 306480
* [PGO] Refactor file/buffer writer callback interfaces /NFCXinliang David Li2017-06-271-5/+18
| | | | | | | | | | Introduces a 'owner' struct to include the overridable write method and the write context in C. This allows easy introdution of new member API to help reduce profile merge time in the follow up patch. llvm-svn: 306432
* Resubmit r295469 [PGO] Suspend SIGKILL for PR_SET_PDEATHSIG in profile-writeRong Xu2017-03-171-0/+9
| | | | | | | | And also r295364 [PGO] remove unintended debug trace. NFC I removed the test case: it's hard to write synchronized test b/w processes in this framework. I will revisit the test-case later. llvm-svn: 298113
* Revert "[PGO] Suspend SIGKILL for PR_SET_PDEATHSIG in profile-write"Renato Golin2017-02-201-9/+0
| | | | | | | | Revert "[PGO] remove unintended debug trace. NFC" This reverts commit r295469, r295364, as they are unstable on ARM/AArch64. llvm-svn: 295664
* [PGO] Suspend SIGKILL for PR_SET_PDEATHSIG in profile-writeRong Xu2017-02-161-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: We found a nondeterministic behavior when doing online profile merging for multi-process applications. The application forks a sub-process and sub-process sets to get SIGKILL when the parent process exits, The first process gets the lock, and dumps the profile. The second one will mmap the file, do the merge and write out the file. Note that before the merged write, we truncate the profile. Depending on the timing, the child process might be terminated abnormally when the parent exits first. If this happens: (1) before the truncation, we will get the profile for the main process (2) after the truncation, and before write-out the profile, we will get 0 size profile. (3) after the merged write, we get merged profile. This patch temporarily suspend the SIGKILL for PR_SET_PDEATHSIG before profile-write and restore it after the write. This patch only applies to Linux system. Reviewers: davidxl Reviewed By: davidxl Subscribers: xur, llvm-commits Differential Revision: https://reviews.llvm.org/D29954 llvm-svn: 295364
* [PGO] Delay profile dir creation until writeXinliang David Li2017-02-141-7/+13
| | | | | | Differential Revision: http://reviews.llvm.org/D29960 llvm-svn: 295108
* [profile] use GetComputerNameExW instead of gethostname on WindowsBob Haarman2016-11-291-6/+6
| | | | | | | | | | | | Summary: In profile data paths, we replace "%h" with the hostname of the machine the program is running on. On Windows, we used gethostname() to obtain the hostname. This requires linking with ws2_32. With this change, we instead get the hostname from GetComputerNameExW(), which does not require ws2_32. Reviewers: rnk, vsk, amccarth Subscribers: zturner, ruiu, hans Differential Revision: https://reviews.llvm.org/D27178 llvm-svn: 288146
* [profile] Mark lprofCurFilename as COMPILER_RT_WEAKVedant Kumar2016-10-181-1/+2
| | | | | | | | | | | | | | | | | | This makes __llvm_profile_set_filename() work across dylib boundaries on Darwin. This functionality was originally meant to work on all platforms, but was moved to a Linux-only directory with r272404. The root cause of the test failure on Darwin was that lprofCurFilename was not marked weak. Each dylib maintained its own copy of the variable due to the two-level namespace. Tested with check-profile (on Darwin). I don't expect this to regress other platforms. Differential Revision: https://reviews.llvm.org/D25707 llvm-svn: 284440
* Revert "[profile] Hide lprofCurFilename"Vedant Kumar2016-09-231-2/+1
| | | | | | | | | | | | | | | This reverts commit r282294. It breaks a Linux bot: http://lab.llvm.org:8011/builders/clang-cmake-aarch64-42vma/builds/12180 It looks like the test checks that __llvm_profile_set_filename() alters the raw profile filename in both the dylib and the main program. Now that lprofCurFilename is hidden, this can't work, and we get two profiles (one for the call to "main" and one for "func"). Back this change out so that we don't affect external users. llvm-svn: 282304
* [profile] Hide lprofCurFilenameVedant Kumar2016-09-231-1/+2
| | | | | | Differential Revision: https://reviews.llvm.org/D24885 llvm-svn: 282294
* [Profile] suppress verbose rt message by defaultXinliang David Li2016-09-221-5/+7
| | | | llvm-svn: 282193
* Correctly escape %.Nico Weber2016-09-081-1/+1
| | | | | | Found be an MSVC warning; I filed PR30320 for adding a similar warning to clang. llvm-svn: 280900
* test commit.Ying Yi2016-08-101-1/+1
| | | | llvm-svn: 278210
* [Profile] Implement new API __llvm_profile_dumpXinliang David Li2016-08-091-0/+18
| | | | | | | | | The API is intended to be used by user to do fine grained (per-region) control of profile dumping. Differential Revision: http://reviews.llvm.org/D23106 llvm-svn: 278092
* [Profile] track ownership of filename pattern stringXinliang David Li2016-08-021-7/+24
| | | | | | | Make sure runtime copy and owns the string when passed in from external users of runtime API. llvm-svn: 277507
* [Profile] deprecate __llvm_profile_override_default_filename (part2)Xinliang David Li2016-07-211-20/+17
| | | | | | | | This eliminates unncessary calls and init functions. Differential Revision: http://reviews.llvm.org/D22614 llvm-svn: 276355
* [Profile] bug fix: profile dir not recursively createdXinliang David Li2016-07-211-2/+6
| | | | llvm-svn: 276234
* Minor cleanup -- clear name structure before parsingXinliang David Li2016-07-201-6/+5
| | | | llvm-svn: 276089
* [Profile] implement interface to get profile path prefixXinliang David Li2016-07-201-1/+39
| | | | | | Differential Revision: http://reviews.llvm.org/D22546 llvm-svn: 276083
OpenPOWER on IntegriCloud