Path: blob/main/contrib/llvm-project/llvm/lib/ProfileData/MemProfSummaryBuilder.cpp
213766 views
//=-- MemProfSummaryBuilder.cpp - MemProf summary building ---------------=//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file contains MemProf summary builder.9//10//===----------------------------------------------------------------------===//1112#include "llvm/ProfileData/MemProfSummaryBuilder.h"13#include "llvm/ProfileData/MemProfCommon.h"1415using namespace llvm;16using namespace llvm::memprof;1718std::unique_ptr<MemProfSummary> MemProfSummaryBuilder::getSummary() {19return std::make_unique<MemProfSummary>(NumContexts, NumColdContexts,20NumHotContexts, MaxColdTotalSize,21MaxWarmTotalSize, MaxHotTotalSize);22}2324void MemProfSummaryBuilder::addRecord(uint64_t CSId,25const PortableMemInfoBlock &Info) {26auto I = Contexts.insert(CSId);27if (!I.second)28return;29NumContexts++;30auto AllocType = getAllocType(Info.getTotalLifetimeAccessDensity(),31Info.getAllocCount(), Info.getTotalLifetime());32auto TotalSize = Info.getTotalSize();33switch (AllocType) {34case AllocationType::Cold:35NumColdContexts++;36if (TotalSize > MaxColdTotalSize)37MaxColdTotalSize = TotalSize;38break;39case AllocationType::NotCold:40if (TotalSize > MaxWarmTotalSize)41MaxWarmTotalSize = TotalSize;42break;43case AllocationType::Hot:44NumHotContexts++;45if (TotalSize > MaxHotTotalSize)46MaxHotTotalSize = TotalSize;47break;48default:49assert(false);50}51}5253void MemProfSummaryBuilder::addRecord(const IndexedMemProfRecord &Record) {54for (auto &Alloc : Record.AllocSites)55addRecord(Alloc.CSId, Alloc.Info);56}5758void MemProfSummaryBuilder::addRecord(const MemProfRecord &Record) {59for (auto &Alloc : Record.AllocSites)60addRecord(computeFullStackId(Alloc.CallStack), Alloc.Info);61}626364