LLVM 22.0.0git
ProfileCommon.h
Go to the documentation of this file.
1//===- ProfileCommon.h - Common profiling APIs. -----------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains data structures and functions common to both instrumented
10// and sample profiling.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_PROFILEDATA_PROFILECOMMON_H
15#define LLVM_PROFILEDATA_PROFILECOMMON_H
16
17#include "llvm/ADT/ArrayRef.h"
22#include "llvm/Support/Error.h"
23#include <algorithm>
24#include <cstdint>
25#include <functional>
26#include <map>
27#include <memory>
28#include <vector>
29
30namespace llvm {
31
37LLVM_ABI extern cl::opt<uint64_t> ProfileSummaryHotCount;
38LLVM_ABI extern cl::opt<uint64_t> ProfileSummaryColdCount;
39
40namespace sampleprof {
41
42class FunctionSamples;
43
44} // end namespace sampleprof
45
47private:
48 /// We keep track of the number of times a count (block count or samples)
49 /// appears in the profile. The map is kept sorted in the descending order of
50 /// counts.
51 std::map<uint64_t, uint32_t, std::greater<uint64_t>> CountFrequencies;
52 std::vector<uint32_t> DetailedSummaryCutoffs;
53
54protected:
61
62 ProfileSummaryBuilder(std::vector<uint32_t> Cutoffs)
63 : DetailedSummaryCutoffs(std::move(Cutoffs)) {}
65
66 inline void addCount(uint64_t Count);
68
69public:
70 /// A vector of useful cutoff values for detailed summary.
72
73 /// Find the summary entry for a desired percentile of counts.
74 LLVM_ABI static const ProfileSummaryEntry &
78};
79
81 uint64_t MaxInternalBlockCount = 0;
82
83public:
84 InstrProfSummaryBuilder(std::vector<uint32_t> Cutoffs)
85 : ProfileSummaryBuilder(std::move(Cutoffs)) {}
86
89
91 LLVM_ABI std::unique_ptr<ProfileSummary> getSummary();
92};
93
95public:
96 SampleProfileSummaryBuilder(std::vector<uint32_t> Cutoffs)
97 : ProfileSummaryBuilder(std::move(Cutoffs)) {}
98
100 bool isCallsiteSample = false);
101 LLVM_ABI std::unique_ptr<ProfileSummary>
103 LLVM_ABI std::unique_ptr<ProfileSummary> getSummary();
104};
105
106/// This is called when a count is seen in the profile.
108 TotalCount += Count;
109 if (Count > MaxCount)
110 MaxCount = Count;
111 NumCounts++;
112 CountFrequencies[Count]++;
113}
114
115} // end namespace llvm
116
117#endif // LLVM_PROFILEDATA_PROFILECOMMON_H
#define LLVM_ABI
Definition: Compiler.h:213
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
LLVM_ABI void addInternalCount(uint64_t Count)
LLVM_ABI std::unique_ptr< ProfileSummary > getSummary()
LLVM_ABI void addRecord(const InstrProfRecord &)
LLVM_ABI void addEntryCount(uint64_t Count)
InstrProfSummaryBuilder(std::vector< uint32_t > Cutoffs)
Definition: ProfileCommon.h:84
void addCount(uint64_t Count)
This is called when a count is seen in the profile.
static LLVM_ABI const ProfileSummaryEntry & getEntryForPercentile(const SummaryEntryVector &DS, uint64_t Percentile)
Find the summary entry for a desired percentile of counts.
static LLVM_ABI const ArrayRef< uint32_t > DefaultCutoffs
A vector of useful cutoff values for detailed summary.
Definition: ProfileCommon.h:71
ProfileSummaryBuilder(std::vector< uint32_t > Cutoffs)
Definition: ProfileCommon.h:62
SummaryEntryVector DetailedSummary
Definition: ProfileCommon.h:55
static LLVM_ABI uint64_t getHotCountThreshold(const SummaryEntryVector &DS)
static LLVM_ABI uint64_t getColdCountThreshold(const SummaryEntryVector &DS)
LLVM_ABI std::unique_ptr< ProfileSummary > getSummary()
LLVM_ABI std::unique_ptr< ProfileSummary > computeSummaryForProfiles(const sampleprof::SampleProfileMap &Profiles)
LLVM_ABI void addRecord(const sampleprof::FunctionSamples &FS, bool isCallsiteSample=false)
SampleProfileSummaryBuilder(std::vector< uint32_t > Cutoffs)
Definition: ProfileCommon.h:96
Representation of the samples collected for a function.
Definition: SampleProf.h:757
This class provides operator overloads to the map container using MD5 as the key type,...
Definition: SampleProf.h:1325
template class LLVM_TEMPLATE_ABI opt< bool >
Definition: CommandLine.cpp:79
template class LLVM_TEMPLATE_ABI opt< unsigned >
Definition: CommandLine.cpp:82
template class LLVM_TEMPLATE_ABI opt< int >
Definition: CommandLine.cpp:81
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
LLVM_ABI cl::opt< uint64_t > ProfileSummaryHotCount
LLVM_ABI cl::opt< bool > UseContextLessSummary
LLVM_ABI cl::opt< uint64_t > ProfileSummaryColdCount
LLVM_ABI cl::opt< int > ProfileSummaryCutoffCold
std::vector< ProfileSummaryEntry > SummaryEntryVector
LLVM_ABI cl::opt< unsigned > ProfileSummaryLargeWorkingSetSizeThreshold
LLVM_ABI cl::opt< int > ProfileSummaryCutoffHot
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1886
LLVM_ABI cl::opt< unsigned > ProfileSummaryHugeWorkingSetSizeThreshold
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:856
Profiling information for a single function.
Definition: InstrProf.h:895