1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00
llvm-mirror/test/tools/llvm-profdata/suppl-instr-with-sample.test
Wei Mi 51d4708437 Supplement instr profile with sample profile.
PGO profile is usually more precise than sample profile. However, PGO profile
needs to be collected from loadtest and loadtest may not be representative
enough to the production workload. Sample profile collected from production
can be used as a supplement -- for functions cold in loadtest but warm/hot
in production, we can scale up the related function in PGO profile if the
function is warm or hot in sample profile.

The implementation contains changes in compiler side and llvm-profdata side.
Given an instr profile and a sample profile, for a function cold in PGO
profile but warm/hot in sample profile, llvm-profdata will either mark
all the counters in the profile to be -1 or scale up the max count in the
function to be above hot threshold, depending on the zero counter ratio in
the profile. The assumption is if there are too many counters being zero
in the function profile, the profile is more likely to cause harm than good,
then llvm-profdata will mark all the counters to be -1 indicating the
function is hot but the profile is unaccountable. In compiler side, if a
function profile with all -1 counters is seen, the function entry count will
be set to be above hot threshold but its internal profile will be dropped.

In the long run, it may be useful to let compiler support using PGO profile
and sample profile at the same time, but that requires more careful design
and more substantial changes to make two profiles work seamlessly. The patch
here serves as a simple intermediate solution.

Differential Revision: https://reviews.llvm.org/D81981
2020-07-27 20:17:40 -07:00

103 lines
4.3 KiB
Plaintext

Some basic tests for supplementing instrumentation profile with sample profile.
Test all of goo's counters will be set to -1.
RUN: llvm-profdata merge \
RUN: -supplement-instr-with-sample=%p/Inputs/mix_sample.proftext \
RUN: -suppl-min-size-threshold=0 %p/Inputs/mix_instr.proftext -o %t
RUN: llvm-profdata show %t -all-functions -counts | FileCheck %s --check-prefix=MIX1
MIX1: foo:
MIX1-NEXT: Hash: 0x0000000000000007
MIX1-NEXT: Counters: 5
MIX1-NEXT: Block counts: [12, 13, 0, 0, 0]
MIX1: goo:
MIX1-NEXT: Hash: 0x0000000000000005
MIX1-NEXT: Counters: 3
MIX1-NEXT: Block counts: [18446744073709551615, 18446744073709551615, 18446744073709551615]
MIX1: moo:
MIX1-NEXT: Hash: 0x0000000000000009
MIX1-NEXT: Counters: 4
MIX1-NEXT: Block counts: [3000, 1000, 2000, 500]
Test when the zero counter ratio of foo is higher than zero-counter-threshold.
RUN: llvm-profdata merge \
RUN: -supplement-instr-with-sample=%p/Inputs/mix_sample.proftext \
RUN: -suppl-min-size-threshold=0 -zero-counter-threshold=0.5 \
RUN: -instr-prof-cold-threshold=30 %p/Inputs/mix_instr.proftext -o %t
RUN: llvm-profdata show %t -all-functions -counts | FileCheck %s --check-prefix=MIX2
MIX2: foo:
MIX2-NEXT: Hash: 0x0000000000000007
MIX2-NEXT: Counters: 5
MIX2-NEXT: Block counts: [18446744073709551615, 18446744073709551615, 18446744073709551615, 18446744073709551615, 18446744073709551615]
MIX2: goo:
MIX2-NEXT: Hash: 0x0000000000000005
MIX2-NEXT: Counters: 3
MIX2-NEXT: Block counts: [18446744073709551615, 18446744073709551615, 18446744073709551615]
MIX2: moo:
MIX2-NEXT: Hash: 0x0000000000000009
MIX2-NEXT: Counters: 4
MIX2-NEXT: Block counts: [3000, 1000, 2000, 500]
Test when the zero counter ratio of foo is lower than zero-counter-threshold.
RUN: llvm-profdata merge \
RUN: -supplement-instr-with-sample=%p/Inputs/mix_sample.proftext \
RUN: -suppl-min-size-threshold=0 -zero-counter-threshold=0.7 \
RUN: -instr-prof-cold-threshold=30 %p/Inputs/mix_instr.proftext -o %t
RUN: llvm-profdata show %t -all-functions -counts | FileCheck %s --check-prefix=MIX3
MIX3: foo:
MIX3-NEXT: Hash: 0x0000000000000007
MIX3-NEXT: Counters: 5
MIX3-NEXT: Block counts: [1384, 1500, 0, 0, 0]
MIX3: goo:
MIX3-NEXT: Hash: 0x0000000000000005
MIX3-NEXT: Counters: 3
MIX3-NEXT: Block counts: [18446744073709551615, 18446744073709551615, 18446744073709551615]
MIX3: moo:
MIX3-NEXT: Hash: 0x0000000000000009
MIX3-NEXT: Counters: 4
MIX3-NEXT: Block counts: [3000, 1000, 2000, 500]
Test foo's profile won't be adjusted because its size is smaller
than suppl-min-size-threshold.
RUN: llvm-profdata merge \
RUN: -supplement-instr-with-sample=%p/Inputs/mix_sample.proftext \
RUN: -suppl-min-size-threshold=2 -zero-counter-threshold=0.7 \
RUN: -instr-prof-cold-threshold=30 %p/Inputs/mix_instr.proftext -o %t
RUN: llvm-profdata show %t -all-functions -counts | FileCheck %s --check-prefix=MIX4
MIX4: foo:
MIX4-NEXT: Hash: 0x0000000000000007
MIX4-NEXT: Counters: 5
MIX4-NEXT: Block counts: [12, 13, 0, 0, 0]
MIX4: goo:
MIX4-NEXT: Hash: 0x0000000000000005
MIX4-NEXT: Counters: 3
MIX4-NEXT: Block counts: [18446744073709551615, 18446744073709551615, 18446744073709551615]
MIX4: moo:
MIX4-NEXT: Hash: 0x0000000000000009
MIX4-NEXT: Counters: 4
MIX4-NEXT: Block counts: [3000, 1000, 2000, 500]
Test profile summary won't be affected by -1 counter.
RUN: llvm-profdata merge \
RUN: -supplement-instr-with-sample=%p/Inputs/mix_sample.proftext \
RUN: -suppl-min-size-threshold=0 %p/Inputs/mix_instr.proftext -o %t
RUN: llvm-profdata show %t -detailed-summary | FileCheck %s --check-prefix=MIX5
MIX5: Instrumentation level: IR
MIX5-NEXT: Total functions: 3
MIX5-NEXT: Maximum function count: 3000
MIX5-NEXT: Maximum internal block count: 2000
MIX5-NEXT: Total number of blocks: 9
MIX5-NEXT: Total count: 6525
MIX5-NEXT: Detailed summary:
MIX5-NEXT: 3 blocks with count >= 1000 account for 80 percentage of the total counts.
MIX5-NEXT: 3 blocks with count >= 1000 account for 90 percentage of the total counts.
MIX5-NEXT: 4 blocks with count >= 500 account for 95 percentage of the total counts.
MIX5-NEXT: 4 blocks with count >= 500 account for 99 percentage of the total counts.
MIX5-NEXT: 6 blocks with count >= 12 account for 99.9 percentage of the total counts.
MIX5-NEXT: 6 blocks with count >= 12 account for 99.99 percentage of the total counts.
MIX5-NEXT: 6 blocks with count >= 12 account for 99.999 percentage of the total counts.