-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[MemProf] Add basic summary section support #141805
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
//===- MemProfSummary.h - MemProf summary support ---------------*- 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 MemProf summary support and related interfaces. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_PROFILEDATA_MEMPROFSUMMARY_H | ||
#define LLVM_PROFILEDATA_MEMPROFSUMMARY_H | ||
|
||
#include "llvm/IR/ModuleSummaryIndex.h" | ||
#include "llvm/ProfileData/InstrProf.h" | ||
#include "llvm/ProfileData/MemProf.h" | ||
|
||
namespace llvm { | ||
namespace memprof { | ||
|
||
/// Return the allocation type for a given set of memory profile values. | ||
AllocationType getAllocType(uint64_t TotalLifetimeAccessDensity, | ||
uint64_t AllocCount, uint64_t TotalLifetime); | ||
|
||
/// Helper to generate a single hash id for a given callstack, used for emitting | ||
/// matching statistics and useful for uniquing such statistics across modules. | ||
/// Also used to dedup contexts when computing the summary. | ||
uint64_t computeFullStackId(ArrayRef<Frame> CallStack); | ||
|
||
class MemProfSummary { | ||
private: | ||
/// The number of summary fields below, which is used to enable some forwards | ||
/// and backwards compatibility for the summary when serialized in the indexed | ||
/// MemProf format. As long as no existing summary fields are removed or | ||
/// reordered, and new summary fields are added after existing summary fields, | ||
/// the MemProf indexed profile version does not need to be bumped to | ||
/// accommodate new summary fields. | ||
static constexpr unsigned NumSummaryFields = 6; | ||
|
||
const uint64_t NumContexts, NumColdContexts, NumHotContexts; | ||
const uint64_t MaxColdTotalSize, MaxWarmTotalSize, MaxHotTotalSize; | ||
|
||
public: | ||
MemProfSummary(uint64_t NumContexts, uint64_t NumColdContexts, | ||
uint64_t NumHotContexts, uint64_t MaxColdTotalSize, | ||
uint64_t MaxWarmTotalSize, uint64_t MaxHotTotalSize) | ||
: NumContexts(NumContexts), NumColdContexts(NumColdContexts), | ||
NumHotContexts(NumHotContexts), MaxColdTotalSize(MaxColdTotalSize), | ||
MaxWarmTotalSize(MaxWarmTotalSize), MaxHotTotalSize(MaxHotTotalSize) {} | ||
|
||
static constexpr unsigned getNumSummaryFields() { return NumSummaryFields; } | ||
uint64_t getNumContexts() const { return NumContexts; } | ||
uint64_t getNumColdContexts() const { return NumColdContexts; } | ||
uint64_t getNumHotContexts() const { return NumHotContexts; } | ||
uint64_t getMaxColdTotalSize() const { return MaxColdTotalSize; } | ||
uint64_t getMaxWarmTotalSize() const { return MaxWarmTotalSize; } | ||
uint64_t getMaxHotTotalSize() const { return MaxHotTotalSize; } | ||
void printSummaryYaml(raw_ostream &OS) const; | ||
/// Write to indexed MemProf profile. | ||
void write(ProfOStream &OS) const; | ||
/// Read from indexed MemProf profile. | ||
static std::unique_ptr<MemProfSummary> deserialize(const unsigned char *&); | ||
}; | ||
|
||
} // namespace memprof | ||
} // namespace llvm | ||
|
||
#endif // LLVM_PROFILEDATA_MEMPROFSUMMARY_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//===- MemProfSummaryBuilder.h - MemProf summary building -------*- 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 MemProf summary builder. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_PROFILEDATA_MEMPROFSUMMARYBUILDER_H | ||
#define LLVM_PROFILEDATA_MEMPROFSUMMARYBUILDER_H | ||
|
||
#include "llvm/ProfileData/MemProf.h" | ||
#include "llvm/ProfileData/MemProfSummary.h" | ||
|
||
namespace llvm { | ||
namespace memprof { | ||
|
||
class MemProfSummaryBuilder { | ||
private: | ||
// The set of full context IDs that we've recorded so far. This is needed to | ||
// dedup the MIBs, which are duplicated between functions containing inline | ||
// instances of the same allocations. | ||
DenseSet<uint64_t> Contexts; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May I suggest some comment here? Something like:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
void addRecord(uint64_t, const PortableMemInfoBlock &); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this one private and not the others? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is called by the other 2. I'll add a comment to clarify |
||
|
||
protected: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are these protected? I don't see a usage where this is needed. Did I miss something? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is just leftover from something else, I will remove. |
||
uint64_t MaxColdTotalSize = 0; | ||
uint64_t MaxWarmTotalSize = 0; | ||
uint64_t MaxHotTotalSize = 0; | ||
uint64_t NumContexts = 0; | ||
uint64_t NumColdContexts = 0; | ||
uint64_t NumHotContexts = 0; | ||
|
||
public: | ||
MemProfSummaryBuilder() = default; | ||
~MemProfSummaryBuilder() = default; | ||
|
||
void addRecord(const IndexedMemProfRecord &); | ||
void addRecord(const MemProfRecord &); | ||
std::unique_ptr<MemProfSummary> getSummary(); | ||
}; | ||
|
||
} // namespace memprof | ||
} // namespace llvm | ||
|
||
#endif // LLVM_PROFILEDATA_MEMPROFSUMMARYBUILDER_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no need to keep the memprof summary around after we call
writeMemProf
, since it's a unique_ptr already can we just move it here instead of passing a pointer?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ack