LLVM 20.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"
21#include "llvm/Support/Error.h"
22#include <algorithm>
23#include <cstdint>
24#include <functional>
25#include <map>
26#include <memory>
27#include <vector>
28
29namespace llvm {
30
31extern cl::opt<bool> UseContextLessSummary;
32extern cl::opt<int> ProfileSummaryCutoffHot;
33extern cl::opt<int> ProfileSummaryCutoffCold;
34extern cl::opt<unsigned> ProfileSummaryHugeWorkingSetSizeThreshold;
35extern cl::opt<unsigned> ProfileSummaryLargeWorkingSetSizeThreshold;
36extern cl::opt<uint64_t> ProfileSummaryHotCount;
37extern cl::opt<uint64_t> ProfileSummaryColdCount;
38
39namespace sampleprof {
40
41class FunctionSamples;
42
43} // end namespace sampleprof
44
46private:
47 /// We keep track of the number of times a count (block count or samples)
48 /// appears in the profile. The map is kept sorted in the descending order of
49 /// counts.
50 std::map<uint64_t, uint32_t, std::greater<uint64_t>> CountFrequencies;
51 std::vector<uint32_t> DetailedSummaryCutoffs;
52
53protected:
60
61 ProfileSummaryBuilder(std::vector<uint32_t> Cutoffs)
62 : DetailedSummaryCutoffs(std::move(Cutoffs)) {}
64
65 inline void addCount(uint64_t Count);
67
68public:
69 /// A vector of useful cutoff values for detailed summary.
71
72 /// Find the summary entry for a desired percentile of counts.
73 static const ProfileSummaryEntry &
77};
78
80 uint64_t MaxInternalBlockCount = 0;
81
82 inline void addEntryCount(uint64_t Count);
83 inline void addInternalCount(uint64_t Count);
84
85public:
86 InstrProfSummaryBuilder(std::vector<uint32_t> Cutoffs)
87 : ProfileSummaryBuilder(std::move(Cutoffs)) {}
88
89 void addRecord(const InstrProfRecord &);
90 std::unique_ptr<ProfileSummary> getSummary();
91};
92
94public:
95 SampleProfileSummaryBuilder(std::vector<uint32_t> Cutoffs)
96 : ProfileSummaryBuilder(std::move(Cutoffs)) {}
97
99 bool isCallsiteSample = false);
100 std::unique_ptr<ProfileSummary>
102 std::unique_ptr<ProfileSummary> getSummary();
103};
104
105/// This is called when a count is seen in the profile.
107 TotalCount += Count;
108 if (Count > MaxCount)
109 MaxCount = Count;
110 NumCounts++;
111 CountFrequencies[Count]++;
112}
113
114} // end namespace llvm
115
116#endif // LLVM_PROFILEDATA_PROFILECOMMON_H
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
std::unique_ptr< ProfileSummary > getSummary()
void addRecord(const InstrProfRecord &)
InstrProfSummaryBuilder(std::vector< uint32_t > Cutoffs)
Definition: ProfileCommon.h:86
void addCount(uint64_t Count)
This is called when a count is seen in the profile.
static const ProfileSummaryEntry & getEntryForPercentile(const SummaryEntryVector &DS, uint64_t Percentile)
Find the summary entry for a desired percentile of counts.
static const ArrayRef< uint32_t > DefaultCutoffs
A vector of useful cutoff values for detailed summary.
Definition: ProfileCommon.h:70
ProfileSummaryBuilder(std::vector< uint32_t > Cutoffs)
Definition: ProfileCommon.h:61
SummaryEntryVector DetailedSummary
Definition: ProfileCommon.h:54
static uint64_t getHotCountThreshold(const SummaryEntryVector &DS)
static uint64_t getColdCountThreshold(const SummaryEntryVector &DS)
std::unique_ptr< ProfileSummary > getSummary()
std::unique_ptr< ProfileSummary > computeSummaryForProfiles(const sampleprof::SampleProfileMap &Profiles)
void addRecord(const sampleprof::FunctionSamples &FS, bool isCallsiteSample=false)
SampleProfileSummaryBuilder(std::vector< uint32_t > Cutoffs)
Definition: ProfileCommon.h:95
Representation of the samples collected for a function.
Definition: SampleProf.h:745
This class provides operator overloads to the map container using MD5 as the key type,...
Definition: SampleProf.h:1313
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
cl::opt< uint64_t > ProfileSummaryHotCount
cl::opt< bool > UseContextLessSummary
cl::opt< uint64_t > ProfileSummaryColdCount
cl::opt< int > ProfileSummaryCutoffCold
std::vector< ProfileSummaryEntry > SummaryEntryVector
cl::opt< unsigned > ProfileSummaryLargeWorkingSetSizeThreshold
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:1856
cl::opt< unsigned > ProfileSummaryHugeWorkingSetSizeThreshold
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
Profiling information for a single function.
Definition: InstrProf.h:827