Skip to content

Commit

Permalink
[SampleFDO] Add a cutoff flag to control how many symbols will be inc…
Browse files Browse the repository at this point in the history
…luded

into profile symbol list.

When test is unrepresentative to production behavior, sample profile
collected from production can cause unexpected performance behavior
in test. To triage such issue, it is useful to have a cutoff flag
to control how many symbols will be included into profile symbol list
in order to do binary search.

Differential Revision: https://reviews.llvm.org/D97623
  • Loading branch information
wmi-11 committed Feb 28, 2021
1 parent b3c2821 commit 7fb4001
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
12 changes: 10 additions & 2 deletions llvm/lib/ProfileData/SampleProf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/PseudoProbe.h"
#include "llvm/ProfileData/SampleProfReader.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Error.h"
Expand All @@ -29,6 +30,11 @@
using namespace llvm;
using namespace sampleprof;

static cl::opt<uint64_t> ProfileSymbolListCutOff(
"profile-symbol-list-cutoff", cl::Hidden, cl::init(-1), cl::ZeroOrMore,
cl::desc("Cutoff value about how many symbols in profile symbol list "
"will be used. This is very useful for performance debugging"));

namespace llvm {
namespace sampleprof {
SampleProfileFormat FunctionSamples::Format;
Expand Down Expand Up @@ -274,12 +280,14 @@ std::error_code ProfileSymbolList::read(const uint8_t *Data,
uint64_t ListSize) {
const char *ListStart = reinterpret_cast<const char *>(Data);
uint64_t Size = 0;
while (Size < ListSize) {
uint64_t StrNum = 0;
while (Size < ListSize && StrNum < ProfileSymbolListCutOff) {
StringRef Str(ListStart + Size);
add(Str);
Size += Str.size() + 1;
StrNum++;
}
if (Size != ListSize)
if (Size != ListSize && StrNum != ProfileSymbolListCutOff)
return sampleprof_error::malformed;
return sampleprof_error::success;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
_Z3goov
_Z3sumii
_Z3toov
__libc_csu_fini
__libc_csu_init
_dl_relocate_static_pie
Expand Down
14 changes: 14 additions & 0 deletions llvm/test/Transforms/SampleProfile/profile-sample-accurate.ll
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
; RUN: llvm-profdata merge -sample -extbinary -prof-sym-list=%S/Inputs/profile-symbol-list.text %S/Inputs/profsampleacc.extbinary.afdo -o %t.symlist.afdo
; RUN: opt < %s -sample-profile -sample-profile-file=%t.symlist.afdo -profile-summary-cutoff-hot=600000 -profile-accurate-for-symsinlist -enable-new-pm=0 -S | FileCheck %s --check-prefix=PROFSYMLIST
; RUN: opt < %s -passes=sample-profile -sample-profile-file=%t.symlist.afdo -profile-summary-cutoff-hot=600000 -profile-accurate-for-symsinlist -S | FileCheck %s --check-prefix=PROFSYMLIST
; RUN: opt < %s -passes=sample-profile -sample-profile-file=%t.symlist.afdo -profile-accurate-for-symsinlist -profile-symbol-list-cutoff=2 -S | FileCheck %s --check-prefix=PSLCUTOFF2
; RUN: opt < %s -passes=sample-profile -sample-profile-file=%t.symlist.afdo -profile-accurate-for-symsinlist -profile-symbol-list-cutoff=3 -S | FileCheck %s --check-prefix=PSLCUTOFF3
;
; If -profile-accurate-for-symsinlist and -profile-sample-accurate both present,
; -profile-sample-accurate will override -profile-accurate-for-symsinlist.
Expand Down Expand Up @@ -60,6 +62,16 @@ entry:
ret i32 %add, !dbg !11
}

; Check -profile-symbol-list-cutoff=3 will include _Z3toov into profile
; symbol list and -profile-symbol-list-cutoff=2 will not.
; PSLCUTOFF2: define i32 @_Z3toov{{.*}}!prof ![[TOO_ID:[0-9]+]]
; PSLCUTOFF3: define i32 @_Z3toov{{.*}}!prof ![[TOO_ID:[0-9]+]]
define i32 @_Z3toov(i32 %x, i32 %y) #0 {
entry:
%add = add nsw i32 %x, %y
ret i32 %add
}

; Function Attrs: uwtable
define i32 @main() #0 !dbg !7 {
entry:
Expand Down Expand Up @@ -132,6 +144,8 @@ attributes #0 = { "use-sample-profile" }
; CALL_SUM_IS_HOT: ![[ZERO_ID]] = !{!"function_entry_count", i64 0}
; CALL_SUM_IS_WARM: ![[NONZERO_ID]] = !{!"function_entry_count", i64 5179}
; PROFSYMLIST: ![[UNKNOWN_ID]] = !{!"function_entry_count", i64 -1}
; PSLCUTOFF2: ![[TOO_ID]] = !{!"function_entry_count", i64 -1}
; PSLCUTOFF3: ![[TOO_ID]] = !{!"function_entry_count", i64 0}
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.5 ", isOptimized: false, emissionKind: NoDebug, file: !1, enums: !2, retainedTypes: !2, globals: !2, imports: !2)
!1 = !DIFile(filename: "calls.cc", directory: ".")
!2 = !{}
Expand Down

0 comments on commit 7fb4001

Please sign in to comment.