mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 19:23:23 +01:00
f4e40e0ed8
Summary: Currently ProfileSummaryBuilder doesn't count into callsite samples when computing total samples. Considering that ProfileSummaryInfo is used to checked the hotness of not only body samples but also callsite samples (from SampleProfileLoader), I think the callsite sample counts should be considered when computing total samples. Reviewers: eraman, danielcdh, wmi Subscribers: hiraditya, jdoerfert, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D59835 llvm-svn: 357627
103 lines
3.0 KiB
C++
103 lines
3.0 KiB
C++
//===- ProfileCommon.h - Common profiling APIs. -----------------*- C++ -*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file contains data structures and functions common to both instrumented
|
|
// and sample profiling.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_PROFILEDATA_PROFILECOMMON_H
|
|
#define LLVM_PROFILEDATA_PROFILECOMMON_H
|
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
|
#include "llvm/IR/ProfileSummary.h"
|
|
#include "llvm/ProfileData/InstrProf.h"
|
|
#include "llvm/Support/Error.h"
|
|
#include <algorithm>
|
|
#include <cstdint>
|
|
#include <functional>
|
|
#include <map>
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
namespace llvm {
|
|
|
|
namespace sampleprof {
|
|
|
|
class FunctionSamples;
|
|
|
|
} // end namespace sampleprof
|
|
|
|
inline const char *getHotSectionPrefix() { return ".hot"; }
|
|
inline const char *getUnlikelySectionPrefix() { return ".unlikely"; }
|
|
|
|
class ProfileSummaryBuilder {
|
|
private:
|
|
/// We keep track of the number of times a count (block count or samples)
|
|
/// appears in the profile. The map is kept sorted in the descending order of
|
|
/// counts.
|
|
std::map<uint64_t, uint32_t, std::greater<uint64_t>> CountFrequencies;
|
|
std::vector<uint32_t> DetailedSummaryCutoffs;
|
|
|
|
protected:
|
|
SummaryEntryVector DetailedSummary;
|
|
uint64_t TotalCount = 0;
|
|
uint64_t MaxCount = 0;
|
|
uint64_t MaxFunctionCount = 0;
|
|
uint32_t NumCounts = 0;
|
|
uint32_t NumFunctions = 0;
|
|
|
|
ProfileSummaryBuilder(std::vector<uint32_t> Cutoffs)
|
|
: DetailedSummaryCutoffs(std::move(Cutoffs)) {}
|
|
~ProfileSummaryBuilder() = default;
|
|
|
|
inline void addCount(uint64_t Count);
|
|
void computeDetailedSummary();
|
|
|
|
public:
|
|
/// A vector of useful cutoff values for detailed summary.
|
|
static const ArrayRef<uint32_t> DefaultCutoffs;
|
|
};
|
|
|
|
class InstrProfSummaryBuilder final : public ProfileSummaryBuilder {
|
|
uint64_t MaxInternalBlockCount = 0;
|
|
|
|
inline void addEntryCount(uint64_t Count);
|
|
inline void addInternalCount(uint64_t Count);
|
|
|
|
public:
|
|
InstrProfSummaryBuilder(std::vector<uint32_t> Cutoffs)
|
|
: ProfileSummaryBuilder(std::move(Cutoffs)) {}
|
|
|
|
void addRecord(const InstrProfRecord &);
|
|
std::unique_ptr<ProfileSummary> getSummary();
|
|
};
|
|
|
|
class SampleProfileSummaryBuilder final : public ProfileSummaryBuilder {
|
|
public:
|
|
SampleProfileSummaryBuilder(std::vector<uint32_t> Cutoffs)
|
|
: ProfileSummaryBuilder(std::move(Cutoffs)) {}
|
|
|
|
void addRecord(const sampleprof::FunctionSamples &FS,
|
|
bool isCallsiteSample = false);
|
|
std::unique_ptr<ProfileSummary> getSummary();
|
|
};
|
|
|
|
/// This is called when a count is seen in the profile.
|
|
void ProfileSummaryBuilder::addCount(uint64_t Count) {
|
|
TotalCount += Count;
|
|
if (Count > MaxCount)
|
|
MaxCount = Count;
|
|
NumCounts++;
|
|
CountFrequencies[Count]++;
|
|
}
|
|
|
|
} // end namespace llvm
|
|
|
|
#endif // LLVM_PROFILEDATA_PROFILECOMMON_H
|