Skip to content

Commit

Permalink
[InstrProf] Report error when merging temporal profiles
Browse files Browse the repository at this point in the history
Temporal profiles do not support profile merging at runtime. The reason
is that each function can only store one timestamp and the
`llmv-profdata` tool is responsible for sampling traces during the merge
command. Report an error in `__llvm_profile_merge_from_buffer()` if
merging a temporal profile.

The added test also checks that lightweight profiles throw an error,
although this may be fixed in https://reviews.llvm.org/D157632

Reviewed By: MaskRay, zequanwu

Differential Revision: https://reviews.llvm.org/D157664
  • Loading branch information
ellishg committed Aug 11, 2023
1 parent bee23de commit 8287db2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions compiler-rt/lib/profile/InstrProfilingMerge.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ int __llvm_profile_merge_from_buffer(const char *ProfileData,
"Instead, merge raw profiles using the llvm-profdata tool.");
return 1;
}
if (__llvm_profile_get_version() & VARIANT_MASK_TEMPORAL_PROF) {
PROF_ERR("%s\n",
"Temporal profiles do not support profile merging at runtime. "
"Instead, merge raw profiles using the llvm-profdata tool.");
return 1;
}

__llvm_profile_data *SrcDataStart, *SrcDataEnd, *SrcData, *DstData;
__llvm_profile_header *Header = (__llvm_profile_header *)ProfileData;
Expand Down
15 changes: 15 additions & 0 deletions compiler-rt/test/profile/instrprof-merge-error.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// RUN: rm -rf %t; mkdir %t

// RUN: %clang_pgogen -o %t/dbg -g -mllvm --debug-info-correlate -mllvm --disable-vp=true %s
// RUN: env LLVM_PROFILE_FILE=%t/dbg_%m.profdata %run %t/dbg 2>&1 | count 0
// RUN: env LLVM_PROFILE_FILE=%t/dbg_%m.profdata %run %t/dbg 2>&1 | FileCheck %s --check-prefix=DBG

// DBG: Debug info correlation does not support profile merging at runtime.

// RUN: %clang_pgogen -o %t/timeprof -mllvm -pgo-temporal-instrumentation %s
// RUN: env LLVM_PROFILE_FILE=%t/timeprof_%m.profdata %run %t/timeprof 2>&1 | count 0
// RUN: env LLVM_PROFILE_FILE=%t/timeprof_%m.profdata %run %t/timeprof 2>&1 | FileCheck %s --check-prefix=TIMEPROF

// TIMEPROF: Temporal profiles do not support profile merging at runtime.

int main() { return 0; }

0 comments on commit 8287db2

Please sign in to comment.