summaryrefslogtreecommitdiff
path: root/lib/profile/InstrProfilingFile.c
diff options
context:
space:
mode:
authorRong Xu <xur@google.com>2018-04-02 16:57:00 +0000
committerRong Xu <xur@google.com>2018-04-02 16:57:00 +0000
commitec8f63a145ed4856c2e4df84aaab81fbca904b89 (patch)
tree00f78aadb80ec29c32ccbdec90a9b609190fed72 /lib/profile/InstrProfilingFile.c
parent13c69d3bcd85a38da14fd28322b0b2f8b675d943 (diff)
downloadcompiler-rt-ec8f63a145ed4856c2e4df84aaab81fbca904b89.tar.gz
[profile] Fix value profile runtime merging issues
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 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@328987 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/profile/InstrProfilingFile.c')
-rw-r--r--lib/profile/InstrProfilingFile.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/profile/InstrProfilingFile.c b/lib/profile/InstrProfilingFile.c
index d7c0abbc1..6e6b8fac5 100644
--- a/lib/profile/InstrProfilingFile.c
+++ b/lib/profile/InstrProfilingFile.c
@@ -183,8 +183,12 @@ static int doProfileMerging(FILE *ProfileFile, int *MergeDone) {
/* Now start merging */
__llvm_profile_merge_from_buffer(ProfileBuffer, ProfileFileSize);
- (void)munmap(ProfileBuffer, ProfileFileSize);
+ // Truncate the file in case merging of value profile did not happend to
+ // prevent from leaving garbage data at the end of the profile file.
+ ftruncate(fileno(ProfileFile), __llvm_profile_get_size_for_buffer());
+
+ (void)munmap(ProfileBuffer, ProfileFileSize);
*MergeDone = 1;
return 0;
@@ -234,6 +238,7 @@ static int writeFile(const char *OutputName) {
FILE *OutputFile;
int MergeDone = 0;
+ VPMergeHook = &lprofMergeValueProfData;
if (!doMerging())
OutputFile = fopen(OutputName, "ab");
else