Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/contrib/llvm-project/llvm/lib/ProfileData/MemProfSummaryBuilder.cpp
213766 views
1
//=-- MemProfSummaryBuilder.cpp - MemProf summary building ---------------=//
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 MemProf summary builder.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "llvm/ProfileData/MemProfSummaryBuilder.h"
14
#include "llvm/ProfileData/MemProfCommon.h"
15
16
using namespace llvm;
17
using namespace llvm::memprof;
18
19
std::unique_ptr<MemProfSummary> MemProfSummaryBuilder::getSummary() {
20
return std::make_unique<MemProfSummary>(NumContexts, NumColdContexts,
21
NumHotContexts, MaxColdTotalSize,
22
MaxWarmTotalSize, MaxHotTotalSize);
23
}
24
25
void MemProfSummaryBuilder::addRecord(uint64_t CSId,
26
const PortableMemInfoBlock &Info) {
27
auto I = Contexts.insert(CSId);
28
if (!I.second)
29
return;
30
NumContexts++;
31
auto AllocType = getAllocType(Info.getTotalLifetimeAccessDensity(),
32
Info.getAllocCount(), Info.getTotalLifetime());
33
auto TotalSize = Info.getTotalSize();
34
switch (AllocType) {
35
case AllocationType::Cold:
36
NumColdContexts++;
37
if (TotalSize > MaxColdTotalSize)
38
MaxColdTotalSize = TotalSize;
39
break;
40
case AllocationType::NotCold:
41
if (TotalSize > MaxWarmTotalSize)
42
MaxWarmTotalSize = TotalSize;
43
break;
44
case AllocationType::Hot:
45
NumHotContexts++;
46
if (TotalSize > MaxHotTotalSize)
47
MaxHotTotalSize = TotalSize;
48
break;
49
default:
50
assert(false);
51
}
52
}
53
54
void MemProfSummaryBuilder::addRecord(const IndexedMemProfRecord &Record) {
55
for (auto &Alloc : Record.AllocSites)
56
addRecord(Alloc.CSId, Alloc.Info);
57
}
58
59
void MemProfSummaryBuilder::addRecord(const MemProfRecord &Record) {
60
for (auto &Alloc : Record.AllocSites)
61
addRecord(computeFullStackId(Alloc.CallStack), Alloc.Info);
62
}
63
64