Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[profile] Create only prof header when no counters
When we use selective instrumentation and instrument a file that is not in the selected files list provided via -fprofile-list, we generate an empty raw profile. This leads to empty_raw_profile error when we try to read that profile. This patch fixes the issue by generating a raw profile that contains only a profile header when there are no counters and profile data. A small reproducer for the above issue: echo "src:other.cc" > code.list clang++ -O2 -fprofile-instr-generate -fcoverage-mapping -fprofile-list=code.list code.cc -o code ./code llvm-profdata show default.profraw Differential Revision: https://reviews.llvm.org/D132094
- Loading branch information
1 parent
7973346
commit 9998863
Showing
4 changed files
with
68 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Test a profile with only a header is generated when a src file is not in the | ||
// selected files list provided via -fprofile-list. | ||
|
||
// RUN: mkdir -p %t.d | ||
// RUN: echo "src:other.c" > %t-file.list | ||
// RUN: %clang_profgen -fprofile-list=%t-file.list -o %t %s | ||
// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t | ||
// RUN: llvm-profdata show %t.profraw | FileCheck %s --check-prefix=RAW-PROFILE-HEADER-ONLY | ||
|
||
// RUN: llvm-profdata merge -o %t.profdata %t.profraw | ||
// RUN: llvm-profdata show %t.profdata | FileCheck %s --check-prefix=INDEXED-PROFILE-HEADER-ONLY | ||
|
||
int main() { return 0; } | ||
|
||
// RAW-PROFILE-HEADER-ONLY: Instrumentation level: Front-end | ||
// RAW-PROFILE-HEADER-ONLY-NEXT: Total functions: 0 | ||
// RAW-PROFILE-HEADER-ONLY-NEXT: Maximum function count: 0 | ||
// RAW-PROFILE-HEADER-ONLY-NEXT: Maximum internal block count: 0 | ||
|
||
// INDEXED-PROFILE-HEADER-ONLY: Instrumentation level: Front-end | ||
// INDEXED-PROFILE-HEADER-ONLY-NEXT: Total functions: 0 | ||
// INDEXED-PROFILE-HEADER-ONLY-NEXT: Maximum function count: 0 | ||
// INDEXED-PROFILE-HEADER-ONLY-NEXT: Maximum internal block count: 0 |
42 changes: 42 additions & 0 deletions
42
compiler-rt/test/profile/Posix/instrprof-shared-empty-profile.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
""" | ||
This test produces two shared libraries: | ||
|
||
1. libt-instr.so is instrumented | ||
2. libt-no-instr.so is built with profile rt linked in (via -u<hook>), but the object file is built | ||
with instrumentation turned off. | ||
|
||
The test verifies concatenating profiles with only headers and no profile data and counters. | ||
""" | ||
|
||
RUN: mkdir -p %t.d | ||
RUN: %clang_profgen -o %t.d/libt-instr.so -fPIC -shared %S/../Inputs/instrprof-shared-lib.c | ||
RUN: %clang -c -o %t.d/instrprof-shared-lib-no-instr.o -fPIC %S/../Inputs/instrprof-shared-lib.c | ||
RUN: %clang_profgen -o %t.d/libt-no-instr.so -fPIC -shared %t.d/instrprof-shared-lib-no-instr.o | ||
|
||
# Header + Header | ||
RUN: echo "src:other.c" > %t-file.list | ||
RUN: %clang_profgen -fprofile-list=%t-file.list -o %t-no-instr-no-instr -L%t.d -rpath %t.d -lt-no-instr %S/../Inputs/instrprof-shared-main.c | ||
RUN: env LLVM_PROFILE_FILE=%t-no-instr-no-instr.profraw %run %t-no-instr-no-instr | ||
RUN: llvm-profdata show %t-no-instr-no-instr.profraw | FileCheck %s --check-prefix=HEADER-HEADER | ||
// HEADER-HEADER: Instrumentation level: Front-end | ||
// HEADER-HEADER-NEXT: Total functions: 0 | ||
// HEADER-HEADER-NEXT: Maximum function count: 0 | ||
// HEADER-HEADER-NEXT: Maximum internal block count: 0 | ||
|
||
# Header + Profile | ||
RUN: %clang_profgen -fprofile-list=%t-file.list -o %t-no-instr-instr -L%t.d -rpath %t.d -lt-instr %S/../Inputs/instrprof-shared-main.c | ||
RUN: env LLVM_PROFILE_FILE=%t-no-instr-instr.profraw %run %t-no-instr-instr | ||
RUN: llvm-profdata show %t-no-instr-instr.profraw | FileCheck %s --check-prefix=HEADER-PROFILE | ||
// HEADER-PROFILE: Instrumentation level: Front-end | ||
// HEADER-PROFILE-NEXT: Total functions: 1 | ||
// HEADER-PROFILE-NEXT: Maximum function count: 1000000 | ||
// HEADER-PROFILE-NEXT: Maximum internal block count: 360000 | ||
|
||
# Profile + Header | ||
RUN: %clang_profgen -o %t-instr-no-instr -L%t.d -rpath %t.d -lt-no-instr %S/../Inputs/instrprof-shared-main.c | ||
RUN: env LLVM_PROFILE_FILE=%t-instr-no-instr.profraw %run %t-instr-no-instr | ||
RUN: llvm-profdata show %t-instr-no-instr.profraw | FileCheck %s --check-prefix=PROFILE-HEADER | ||
// PROFILE-HEADER: Instrumentation level: Front-end | ||
// PROFILE-HEADER-NEXT: Total functions: 1 | ||
// PROFILE-HEADER-NEXT: Maximum function count: 1 | ||
// PROFILE-HEADER-NEXT: Maximum internal block count: 1000000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters