[llvm-profdata] Implement llvm-profdata overlap for sample profiles

Implemented the `llvm-profdata overlap` feature for sample profiles. It reports weighted //similarity// and unweighted //overlap// metrics at program and function level for two input profiles. Similarity metrics are symmetric with regards to the order of two input profiles. By default, the tool only reports program-level summary. Users can look into function-level details via additional options `--function`, `--similarity-cutoff`, and `--value-cutoff`.

The similarity metrics are designed as follows:
* Program-level summary
    * Whole program profile similarity is an aggregate over function-level similarity `FS`: `PS = sum(FS(A) * avg_weight(A))` for all function `A`.
    * Whole program sample overlap: `PSO = common_samples / total_samples`.
    * Function overlap: `FO = #common_function / #total_function`.
    * Hot-function overlap: `HFO = #common_hot_function / #total_hot_function`.
    * Hot-block overlap: `HBO = #common_hot_block / #total_hot_block`.
* Function-level details
    * Function-level similarity is an aggregate over line/block-level similarities `BS` of all sample lines/blocks in the function, weighted by the closeness of the function's weights in two profiles: `FS = sum(BS(i)) * (1 - weight_distance(A))`.
    * Function-level sample overlap: `FSO = common_samples / total_samples` for samples in the function.

Reviewed By: wenlei, hoyFB, wmi

Differential Revision: https://reviews.llvm.org/D83852
This commit is contained in:
weihe 2020-08-08 17:49:33 -07:00 committed by Wenlei He
parent a4d78d23c5
commit 540489de68
8 changed files with 1181 additions and 16 deletions

View File

@ -0,0 +1,18 @@
_Z3bari:20301:1437
1: 1437
_Z3fooi:7711:610
1: 610
main:184019:0
4: 534
4.2: 534
5: 1075
5.1: 1075
6: 2080
7: 534
9: 2064 _Z3bari:1471 _Z3fooi:631
10: inline1:1000
1: 1000
10: inline2:2000
1: 2000
_Z3bazi:20301:1000
1: 1000

View File

@ -0,0 +1,18 @@
_Z3bari:203010:14370
1: 14370
_Z3fooi:77110:6100
1: 6100
main:1840190:0
4: 5340
4.2: 5340
5: 10750
5.1: 10750
6: 20800
7: 5340
9: 20640 _Z3bari:14710 _Z3fooi:6310
10: inline1:10000
1: 10000
10: inline2:20000
1: 20000
_Z3bazi:203010:10000
1: 10000

View File

@ -0,0 +1,18 @@
_Z3bari:20301:1437
1: 1437
_Z3fooi:7711:610
1: 610
main:18401:0
4: 53
4.2: 53
5: 107
5.1: 107
6: 208
7: 53
9: 206 _Z3bari:1471 _Z3fooi:631
10: inline1:100
1: 100
10: inline2:200
1: 200
_Z3bazi:20301:1000
1: 1000

View File

@ -0,0 +1,18 @@
_Z3bari:20301:1437
1: 1437
_Z3fooi2:7711:610
1: 610
main2:184019:0
4: 534
4.2: 534
5: 1075
5.1: 1075
6: 2080
7: 534
9: 2064 _Z3bari:1471 _Z3fooi:631
10: inline1:1000
1: 1000
10: inline2:2000
1: 2000
_Z3bazi:20301:1000
1: 100

View File

@ -0,0 +1,18 @@
_Z3bari:20301:1437
2: 1437
_Z3fooi:7711:610
2: 610
main:184019:0
5: 534
5.2: 534
6: 1075
6.1: 1075
7: 208
8: 534
10: 206 _Z3bari:1471 _Z3fooi:631
11: inline1:1000
1: 1000
11: inline2:2000
1: 2000
_Z3bazi:20301:1000
2: 1000

View File

@ -0,0 +1,18 @@
_Z3bari:0:0
1: 0
_Z3fooi:0:0
1: 0
main:0:0
4: 0
4.2: 0
5: 0
5.1: 0
6: 0
7: 0
9: 0
10: inline1:0
1: 0
10: inline2:0
1: 0
_Z3bazi:0:0
1: 0

View File

@ -0,0 +1,118 @@
; RUN: llvm-profdata overlap --sample %S/Inputs/sample-overlap-0.proftext %S/Inputs/sample-overlap-0.proftext | FileCheck %s --check-prefix=OVERLAP0 --match-full-lines --strict-whitespace
; OVERLAP0:Program level:
; OVERLAP0: Whole program profile similarity: 100.000%
; OVERLAP0: Whole program sample overlap: 100.000%
; OVERLAP0: percentage of samples unique in base profile: 0.000%
; OVERLAP0: percentage of samples unique in test profile: 0.000%
; OVERLAP0: total samples in base profile: 13943
; OVERLAP0: total samples in test profile: 13943
; OVERLAP0: Function overlap: 100.000%
; OVERLAP0: overlap functions: 4
; OVERLAP0: functions unique in base profile: 0
; OVERLAP0: functions unique in test profile: 0
; OVERLAP0: Hot-function overlap: 100.000%
; OVERLAP0: overlap hot functions: 4
; OVERLAP0: hot functions unique in base profile: 0
; OVERLAP0: hot functions unique in test profile: 0
; OVERLAP0: Hot-block overlap: 100.000%
; OVERLAP0: overlap hot blocks: 12
; OVERLAP0: hot blocks unique in base profile: 0
; OVERLAP0: hot blocks unique in test profile: 0
; RUN: llvm-profdata overlap --sample %S/Inputs/sample-overlap-0.proftext %S/Inputs/sample-overlap-1.proftext | FileCheck %s --check-prefix=OVERLAP1 --match-full-lines --strict-whitespace
; OVERLAP1:Program level:
; OVERLAP1: Whole program profile similarity: 100.000%
; OVERLAP1: Whole program sample overlap: 10.000%
; OVERLAP1: percentage of samples unique in base profile: 0.000%
; OVERLAP1: percentage of samples unique in test profile: 0.000%
; OVERLAP1: total samples in base profile: 13943
; OVERLAP1: total samples in test profile: 139430
; OVERLAP1: Function overlap: 100.000%
; OVERLAP1: overlap functions: 4
; OVERLAP1: functions unique in base profile: 0
; OVERLAP1: functions unique in test profile: 0
; OVERLAP1: Hot-function overlap: 100.000%
; OVERLAP1: overlap hot functions: 4
; OVERLAP1: hot functions unique in base profile: 0
; OVERLAP1: hot functions unique in test profile: 0
; OVERLAP1: Hot-block overlap: 100.000%
; OVERLAP1: overlap hot blocks: 12
; OVERLAP1: hot blocks unique in base profile: 0
; OVERLAP1: hot blocks unique in test profile: 0
; RUN: llvm-profdata overlap --sample --similarity-cutoff=800000 %S/Inputs/sample-overlap-0.proftext %S/Inputs/sample-overlap-2.proftext | FileCheck %s --check-prefix=OVERLAP2 --match-full-lines --strict-whitespace
; OVERLAP2:Program level:
; OVERLAP2: Whole program profile similarity: 63.720%
; OVERLAP2: Whole program sample overlap: 29.649%
; OVERLAP2: percentage of samples unique in base profile: 0.000%
; OVERLAP2: percentage of samples unique in test profile: 0.000%
; OVERLAP2: total samples in base profile: 13943
; OVERLAP2: total samples in test profile: 4134
; OVERLAP2: Function overlap: 100.000%
; OVERLAP2: overlap functions: 4
; OVERLAP2: functions unique in base profile: 0
; OVERLAP2: functions unique in test profile: 0
; OVERLAP2: Hot-function overlap: 100.000%
; OVERLAP2: overlap hot functions: 4
; OVERLAP2: hot functions unique in base profile: 0
; OVERLAP2: hot functions unique in test profile: 0
; OVERLAP2: Hot-block overlap: 100.000%
; OVERLAP2: overlap hot blocks: 12
; OVERLAP2: hot blocks unique in base profile: 0
; OVERLAP2: hot blocks unique in test profile: 0
; OVERLAP2:Function-level details:
; OVERLAP2:Base weight Test weight Similarity Overlap Base unique Test unique Base samples Test samples Function name
; OVERLAP2:78.15% 26.29% 48.09% 9.98% 0.00% 0.00% 10896 1087 main
; OVERLAP2:10.31% 34.76% 75.55% 100.00% 0.00% 0.00% 1437 1437 _Z3bari
; RUN: llvm-profdata overlap --sample --value-cutoff=1000 %S/Inputs/sample-overlap-0.proftext %S/Inputs/sample-overlap-3.proftext | FileCheck %s --check-prefix=OVERLAP3 --match-full-lines --strict-whitespace
; OVERLAP3:Program level:
; OVERLAP3: Whole program profile similarity: 14.301%
; OVERLAP3: Whole program sample overlap: 6.040%
; OVERLAP3: percentage of samples unique in base profile: 82.522%
; OVERLAP3: percentage of samples unique in test profile: 88.216%
; OVERLAP3: total samples in base profile: 13943
; OVERLAP3: total samples in test profile: 13043
; OVERLAP3: Function overlap: 33.333%
; OVERLAP3: overlap functions: 2
; OVERLAP3: functions unique in base profile: 2
; OVERLAP3: functions unique in test profile: 2
; OVERLAP3: Hot-function overlap: 16.667%
; OVERLAP3: overlap hot functions: 1
; OVERLAP3: hot functions unique in base profile: 3
; OVERLAP3: hot functions unique in test profile: 2
; OVERLAP3: Hot-block overlap: 4.545%
; OVERLAP3: overlap hot blocks: 1
; OVERLAP3: hot blocks unique in base profile: 11
; OVERLAP3: hot blocks unique in test profile: 10
; OVERLAP3:Function-level details:
; OVERLAP3:Base weight Test weight Similarity Overlap Base unique Test unique Base samples Test samples Function name
; OVERLAP3:10.31% 11.02% 99.29% 100.00% 0.00% 0.00% 1437 1437 _Z3bari
; OVERLAP3:0.00% 83.54% 0.00% 0.00% 0.00% 100.00% 0 10896 main2
; RUN: llvm-profdata overlap --sample --function=main %S/Inputs/sample-overlap-0.proftext %S/Inputs/sample-overlap-4.proftext | FileCheck %s --check-prefix=OVERLAP4 --match-full-lines --strict-whitespace
; OVERLAP4:Program level:
; OVERLAP4: Whole program profile similarity: 17.302%
; OVERLAP4: Whole program sample overlap: 8.134%
; OVERLAP4: percentage of samples unique in base profile: 73.542%
; OVERLAP4: percentage of samples unique in test profile: 82.209%
; OVERLAP4: total samples in base profile: 13943
; OVERLAP4: total samples in test profile: 10213
; OVERLAP4: Function overlap: 100.000%
; OVERLAP4: overlap functions: 4
; OVERLAP4: functions unique in base profile: 0
; OVERLAP4: functions unique in test profile: 0
; OVERLAP4: Hot-function overlap: 100.000%
; OVERLAP4: overlap hot functions: 4
; OVERLAP4: hot functions unique in base profile: 0
; OVERLAP4: hot functions unique in test profile: 0
; OVERLAP4: Hot-block overlap: 14.286%
; OVERLAP4: overlap hot blocks: 3
; OVERLAP4: hot blocks unique in base profile: 9
; OVERLAP4: hot blocks unique in test profile: 9
; OVERLAP4:Function-level details:
; OVERLAP4:Base weight Test weight Similarity Overlap Base unique Test unique Base samples Test samples Function name
; OVERLAP4:78.15% 70.17% 23.33% 11.18% 66.14% 74.64% 10896 7166 main
; RUN: llvm-profdata overlap --sample %S/Inputs/sample-overlap-0.proftext %S/Inputs/sample-overlap-5.proftext | FileCheck %s --check-prefix=OVERLAP5 --match-full-lines --strict-whitespace
; OVERLAP5:Sum of sample counts for profile {{.*}}/Inputs/sample-overlap-5.proftext is 0.

File diff suppressed because it is too large Load Diff