LLVM 18.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
31namespace sampleprof {
32
33class FunctionSamples;
34
35} // end namespace sampleprof
36
38private:
39 /// We keep track of the number of times a count (block count or samples)
40 /// appears in the profile. The map is kept sorted in the descending order of
41 /// counts.
42 std::map<uint64_t, uint32_t, std::greater<uint64_t>> CountFrequencies;
43 std::vector<uint32_t> DetailedSummaryCutoffs;
44
45protected:
52
53 ProfileSummaryBuilder(std::vector<uint32_t> Cutoffs)
54 : DetailedSummaryCutoffs(std::move(Cutoffs)) {}
56
57 inline void addCount(uint64_t Count);
59
60public:
61 /// A vector of useful cutoff values for detailed summary.
63
64 /// Find the summary entry for a desired percentile of counts.
65 static const ProfileSummaryEntry &
69};
70
72 uint64_t MaxInternalBlockCount = 0;
73
74 inline void addEntryCount(uint64_t Count);
75 inline void addInternalCount(uint64_t Count);
76
77public:
78 InstrProfSummaryBuilder(std::vector<uint32_t> Cutoffs)
79 : ProfileSummaryBuilder(std::move(Cutoffs)) {}
80
81 void addRecord(const InstrProfRecord &);
82 std::unique_ptr<ProfileSummary> getSummary();
83};
84
86public:
87 SampleProfileSummaryBuilder(std::vector<uint32_t> Cutoffs)
88 : ProfileSummaryBuilder(std::move(Cutoffs)) {}
89
91 bool isCallsiteSample = false);
92 std::unique_ptr<ProfileSummary>
94 std::unique_ptr<ProfileSummary> getSummary();
95};
96
97/// This is called when a count is seen in the profile.
99 TotalCount += Count;
100 if (Count > MaxCount)
101 MaxCount = Count;
102 NumCounts++;
103 CountFrequencies[Count]++;
104}
105
106} // end namespace llvm
107
108#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:78
void addCount(uint64_t Count)
This is called when a count is seen in the profile.
Definition: ProfileCommon.h:98
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:62
ProfileSummaryBuilder(std::vector< uint32_t > Cutoffs)
Definition: ProfileCommon.h:53
SummaryEntryVector DetailedSummary
Definition: ProfileCommon.h:46
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:87
Representation of the samples collected for a function.
Definition: SampleProf.h:751
This class provides operator overloads to the map container using MD5 as the key type,...
Definition: SampleProf.h:1382
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
std::vector< ProfileSummaryEntry > SummaryEntryVector
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:1854
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:691