Mircea Trofin b034905c82
[ctxprof] Capture sampling info for context roots (#131201)
When we collect a contextual profile, we sample the threads entering its root and only collect on one at a time (see `ContextRoot::Taken`). If we want to compare profiles between contextual profiles, and/or flat profiles, we have a problem: we don't know how to compare the counter values relative to each other. To that end, we add `ContextRoot::TotalEntries`, which is incremented every time a root is entered and serves as multiplier for the counter values collected under that root.

We expose this in the profile and leave the normalization to the user of the profile, for a few reasons:

* it's only needed if reasoning about all profiles in aggregate.
* the goal, in compiler_rt, is to flush out the profile as quickly as possible, and performing multiplications adds an overhead that may not even be necessary if the consumer of the profile doesn't care about combining profiles
* the information itself may be interesting as an indication of relative sampling of various contexts.
2025-03-14 21:10:22 -07:00

48 lines
1.3 KiB
LLVM

; REQUIRES: x86_64-linux
;
; Check that, if none of the roots in the profile are defined in the module, the
; profile is treated as empty (i.e. "none provided")
;
; RUN: rm -rf %t
; RUN: split-file %s %t
; RUN: llvm-ctxprof-util fromYAML --input=%t/profile.yaml --output=%t/profile.ctxprofdata
; RUN: opt -passes='require<ctx-prof-analysis>,print<ctx-prof-analysis>' -ctx-profile-printer-level=everything \
; RUN: %t/example.ll -S 2>&1 | FileCheck %s
; CHECK: No contextual profile was provided
;
; This is the reference profile, laid out in the format the json formatter will
; output it from opt. Note that the root GUIDs - 12341 and 34234 - are different from
; the GUID present in the module, which is otherwise present in the profile, but not
; as a root.
;--- profile.yaml
Contexts:
- Guid: 12341
TotalRootEntryCount: 24
Counters: [9]
- Guid: 1000
TotalRootEntryCount: 25
Counters: [5]
- Guid: 34234
TotalRootEntryCount: 2
Counters: [1]
Callsites: -
- Guid: 1000
Counters: [6, 7]
;--- example.ll
declare void @bar()
define void @an_entrypoint(i32 %a) !guid !0 {
%t = icmp eq i32 %a, 0
br i1 %t, label %yes, label %no
yes:
call void @bar()
ret void
no:
ret void
}
attributes #0 = { noinline }
!0 = !{ i64 1000 }