Skip to content
This repository was archived by the owner on Jan 26, 2024. It is now read-only.

Commit a5f411b

Browse files
committed
[llvm-profgen] Allow unsymbolized profile as perf input
This change allows the unsymbolized profile as input. The unsymbolized profile is created by `llvm-profgen` with `--skip-symbolization` and it's after the sample aggregation but before symbolization , so it has much small file size. It can be used for sample merging and trimming, also is useful for debugging or adding test cases. A switch `--unsymbolized-profile=file-patch` is added for this. Format of unsymbolized profile: ``` [context stack1] # If it's a CS profile number of entries in RangeCounter from_1-to_1:count_1 from_2-to_2:count_2 ...... from_n-to_n:count_n number of entries in BranchCounter src_1->dst_1:count_1 src_2->dst_2:count_2 ...... src_n->dst_n:count_n [context stack2] ...... ``` Reviewed By: hoy, wenlei Differential Revision: https://reviews.llvm.org/D111750
1 parent 9bbfe0f commit a5f411b

File tree

7 files changed

+321
-165
lines changed

7 files changed

+321
-165
lines changed

llvm/include/llvm/ProfileData/SampleProf.h

+20-16
Original file line numberDiff line numberDiff line change
@@ -495,28 +495,32 @@ class SampleContext {
495495
State = UnknownContext;
496496
Name = ContextStr;
497497
} else {
498-
// Remove encapsulating '[' and ']' if any
499-
ContextStr = ContextStr.substr(1, ContextStr.size() - 2);
500498
CSNameTable.emplace_back();
501499
SampleContextFrameVector &Context = CSNameTable.back();
502-
/// Create a context vector from a given context string and save it in
503-
/// `Context`.
504-
StringRef ContextRemain = ContextStr;
505-
StringRef ChildContext;
506-
StringRef CalleeName;
507-
while (!ContextRemain.empty()) {
508-
auto ContextSplit = ContextRemain.split(" @ ");
509-
ChildContext = ContextSplit.first;
510-
ContextRemain = ContextSplit.second;
511-
LineLocation CallSiteLoc(0, 0);
512-
decodeContextString(ChildContext, CalleeName, CallSiteLoc);
513-
Context.emplace_back(CalleeName, CallSiteLoc);
514-
}
515-
500+
createCtxVectorFromStr(ContextStr, Context);
516501
setContext(Context, CState);
517502
}
518503
}
519504

505+
/// Create a context vector from a given context string and save it in
506+
/// `Context`.
507+
static void createCtxVectorFromStr(StringRef ContextStr,
508+
SampleContextFrameVector &Context) {
509+
// Remove encapsulating '[' and ']' if any
510+
ContextStr = ContextStr.substr(1, ContextStr.size() - 2);
511+
StringRef ContextRemain = ContextStr;
512+
StringRef ChildContext;
513+
StringRef CalleeName;
514+
while (!ContextRemain.empty()) {
515+
auto ContextSplit = ContextRemain.split(" @ ");
516+
ChildContext = ContextSplit.first;
517+
ContextRemain = ContextSplit.second;
518+
LineLocation CallSiteLoc(0, 0);
519+
decodeContextString(ChildContext, CalleeName, CallSiteLoc);
520+
Context.emplace_back(CalleeName, CallSiteLoc);
521+
}
522+
}
523+
520524
// Promote context by removing top frames with the length of
521525
// `ContextFramesToRemove`. Note that with array representation of context,
522526
// the promotion is effectively a slice operation with first

llvm/test/tools/llvm-profgen/inline-noprobe.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
; RUN: FileCheck %s --input-file %t --check-prefix=CHECK-RAW-PROFILE
33
; RUN: llvm-profgen --format=text --use-dwarf-correlation --perfscript=%S/Inputs/inline-noprobe.perfscript --binary=%S/Inputs/inline-noprobe.perfbin --output=%t --skip-symbolization
44
; RUN: FileCheck %s --input-file %t --check-prefix=CHECK-RAW-PROFILE
5-
; RUN: llvm-profgen --format=text --perfscript=%S/Inputs/inline-noprobe.perfscript --binary=%S/Inputs/inline-noprobe.perfbin --output=%t
6-
; RUN: FileCheck %s --input-file %t --check-prefix=CHECK
5+
; RUN: llvm-profgen --format=text --unsymbolized-profile=%t --binary=%S/Inputs/inline-noprobe.perfbin --output=%t1
6+
; RUN: FileCheck %s --input-file %t1 --check-prefix=CHECK
77
; RUN: llvm-profgen --format=text --use-dwarf-correlation --perfscript=%S/Inputs/inline-noprobe.perfscript --binary=%S/Inputs/inline-noprobe.perfbin --output=%t
88
; RUN: FileCheck %s --input-file %t --check-prefix=CHECK
99

llvm/test/tools/llvm-profgen/inline-noprobe2.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
; RUN: FileCheck %s --input-file %t --check-prefix=CHECK-ARTIFICIAL-BRANCH
33
; RUN: llvm-profgen --format=text --perfscript=%S/Inputs/inline-noprobe2.perfscript --binary=%S/Inputs/inline-noprobe2.perfbin --output=%t --skip-symbolization --use-offset=0
44
; RUN: FileCheck %s --input-file %t --check-prefix=CHECK-RAW-PROFILE
5-
; RUN: llvm-profgen --format=text --perfscript=%S/Inputs/inline-noprobe2.perfscript --binary=%S/Inputs/inline-noprobe2.perfbin --output=%t
6-
; RUN: FileCheck %s --input-file %t --check-prefix=CHECK
5+
; RUN: llvm-profgen --format=text --unsymbolized-profile=%t --binary=%S/Inputs/inline-noprobe2.perfbin --output=%t1 --use-offset=0
6+
; RUN: FileCheck %s --input-file %t1 --check-prefix=CHECK
77

88
; RUN: llvm-profgen --format=extbinary --perfscript=%S/Inputs/inline-noprobe2.perfscript --binary=%S/Inputs/inline-noprobe2.perfbin --output=%t
99
; RUN: llvm-profdata show -show-prof-sym-list -sample %t | FileCheck %s --check-prefix=CHECK-SYM-LIST

llvm/test/tools/llvm-profgen/noinline-cs-noprobe.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
; REQUIRES: x86_64-linux
33
; RUN: llvm-profgen --format=text --perfscript=%S/Inputs/noinline-cs-noprobe.perfscript --binary=%S/Inputs/noinline-cs-noprobe.perfbin --output=%t --skip-symbolization --profile-summary-cold-count=0
44
; RUN: FileCheck %s --input-file %t --check-prefix=CHECK-UNWINDER
5-
; RUN: llvm-profgen --format=text --perfscript=%S/Inputs/noinline-cs-noprobe.perfscript --binary=%S/Inputs/noinline-cs-noprobe.perfbin --output=%t --profile-summary-cold-count=0
6-
; RUN: FileCheck %s --input-file %t
5+
; RUN: llvm-profgen --format=text --unsymbolized-profile=%t --binary=%S/Inputs/noinline-cs-noprobe.perfbin --output=%t1 --profile-summary-cold-count=0
6+
; RUN: FileCheck %s --input-file %t1
77
; RUN: llvm-profgen --format=text --perfscript=%S/Inputs/noinline-cs-noprobe.perfscript --binary=%S/Inputs/noinline-cs-noprobe.perfbin --output=%t --profile-summary-cold-count=0 --ignore-stack-samples
88
; RUN: FileCheck %s --input-file %t --check-prefix=CHECK-STRIP-CTX
99
; RUN: llvm-profgen --format=text --perfscript=%S/Inputs/noinline-cs-noprobe.aggperfscript --binary=%S/Inputs/noinline-cs-noprobe.perfbin --output=%t --skip-symbolization --profile-summary-cold-count=0

0 commit comments

Comments
 (0)