Skip to content
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

Expose GCInfo size and EH clause count as metrics #109035

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/coreclr/gcinfo/gcinfoencoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ GcInfoEncoder::GcInfoEncoder(
m_pCallSiteSizes = NULL;
m_NumCallSites = 0;
#endif
m_BlockSize = 0;

m_GSCookieStackSlot = NO_GS_COOKIE;
m_GSCookieValidRangeStart = 0;
Expand Down Expand Up @@ -2576,9 +2577,14 @@ BYTE* GcInfoEncoder::Emit()

void * GcInfoEncoder::eeAllocGCInfo (size_t blockSize)
{
m_BlockSize = blockSize;
return m_pCorJitInfo->allocGCInfo(blockSize);
}

size_t GcInfoEncoder::GetEncodedGCInfoSize() const
{
return m_BlockSize;
}

BitStreamWriter::BitStreamWriter( IAllocator* pAllocator )
{
Expand Down
8 changes: 8 additions & 0 deletions src/coreclr/inc/gcinfoencoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,12 @@ class GcInfoEncoder
//
BYTE* Emit();

//
// Return the size in bytes of the constructed GC info. This is the size passed
// to the VM via `allocGCInfo`. It is only valid after `Emit` is called.
//
size_t GetEncodedGCInfoSize() const;

private:

friend struct CompareLifetimeTransitionsByOffsetThenSlot;
Expand Down Expand Up @@ -534,6 +540,8 @@ class GcInfoEncoder
UINT32 m_NumCallSites;
#endif // PARTIALLY_INTERRUPTIBLE_GC_SUPPORTED

size_t m_BlockSize; // The byte size passed to the `allocGCInfo` call

void GrowSlotTable();

void WriteSlotStateVector(BitStreamWriter &writer, const BitArray& vector);
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/codegenarmarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4138,7 +4138,7 @@ void CodeGen::genCreateAndStoreGCInfo(unsigned codeSize,
// GC Encoder automatically puts the GC info in the right spot using ICorJitInfo::allocGCInfo(size_t)
// let's save the values anyway for debugging purposes
compiler->compInfoBlkAddr = gcInfoEncoder->Emit();
compiler->compInfoBlkSize = 0; // not exposed by the GCEncoder interface
compiler->compInfoBlkSize = gcInfoEncoder->GetEncodedGCInfoSize();
}

// clang-format off
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/jit/codegencommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2288,6 +2288,7 @@ void CodeGen::genEmitUnwindDebugGCandEH()

// Create and store the GC info for this method.
genCreateAndStoreGCInfo(codeSize, prologSize, epilogSize DEBUGARG(codePtr));
compiler->Metrics.GCInfoBytes = compiler->compInfoBlkSize;

/* Tell the emitter that we're done with this function */

Expand Down Expand Up @@ -2420,6 +2421,7 @@ void CodeGen::genReportEH()

// Tell the VM how many EH clauses to expect.
compiler->eeSetEHcount(EHCount);
compiler->Metrics.EHClauseCount = (int)EHCount;

struct EHClauseInfo
{
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/codegenloongarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6488,7 +6488,7 @@ void CodeGen::genCreateAndStoreGCInfo(unsigned codeSize,
// GC Encoder automatically puts the GC info in the right spot using ICorJitInfo::allocGCInfo(size_t)
// let's save the values anyway for debugging purposes
compiler->compInfoBlkAddr = gcInfoEncoder->Emit();
compiler->compInfoBlkSize = 0; // not exposed by the GCEncoder interface
compiler->compInfoBlkSize = gcInfoEncoder->GetEncodedGCInfoSize();
}

//------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/codegenriscv64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6488,7 +6488,7 @@ void CodeGen::genCreateAndStoreGCInfo(unsigned codeSize,
// GC Encoder automatically puts the GC info in the right spot using ICorJitInfo::allocGCInfo(size_t)
// let's save the values anyway for debugging purposes
compiler->compInfoBlkAddr = gcInfoEncoder->Emit();
compiler->compInfoBlkSize = 0; // not exposed by the GCEncoder interface
compiler->compInfoBlkSize = gcInfoEncoder->GetEncodedGCInfoSize();
}

//------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/codegenxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8880,7 +8880,7 @@ void CodeGen::genCreateAndStoreGCInfoX64(unsigned codeSize, unsigned prologSize
// GC Encoder automatically puts the GC info in the right spot using ICorJitInfo::allocGCInfo(size_t)
// let's save the values anyway for debugging purposes
compiler->compInfoBlkAddr = gcInfoEncoder->Emit();
compiler->compInfoBlkSize = 0; // not exposed by the GCEncoder interface
compiler->compInfoBlkSize = gcInfoEncoder->GetEncodedGCInfoSize();
}
#endif // !JIT32_GCENCODER

Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/jit/jitmetadatalist.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
// Name, type flags
JITMETADATAINFO(MethodFullName, const char*, 0)
JITMETADATAINFO(TieringName, const char*, 0)
JITMETADATAMETRIC(GCInfoBytes, int64_t, JIT_METADATA_LOWER_IS_BETTER)
JITMETADATAMETRIC(EHClauseCount, int, 0)
JITMETADATAMETRIC(PhysicallyPromotedFields, int, 0)
JITMETADATAMETRIC(LoopsFoundDuringOpts, int, 0)
JITMETADATAMETRIC(LoopsCloned, int, 0)
Expand Down
8 changes: 7 additions & 1 deletion src/coreclr/tools/superpmi/superpmi/jitinstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,13 @@ ReplayResults JitInstance::CompileMethod(MethodContext* MethodToCompile, int mcI

pParam->pThis->mc->cr->recMessageLog(jitResult == CORJIT_OK ? "Successful Compile" : "Successful Compile (BADCODE)");

pParam->results.NumCodeBytes = NCodeSizeBlock;
pParam->results.NumCodeBytes = NCodeSizeBlock;

// Extract the GCInfo size.
size_t size;
void* retval_unused;
pParam->pThis->mc->cr->repAllocGCInfo(&size, &retval_unused);
pParam->results.NumGCInfoBytes = size;
}
else
{
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/tools/superpmi/superpmi/jitinstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ struct ReplayResults
ReplayResult Result = ReplayResult::Success;
bool IsMinOpts = false;
uint32_t NumCodeBytes = 0;
size_t NumGCInfoBytes = 0;
uint64_t NumExecutedInstructions = 0;
CompileResult* CompileResults = nullptr;
};
Expand Down
11 changes: 6 additions & 5 deletions src/coreclr/tools/superpmi/superpmi/superpmi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ static const char* ResultToString(ReplayResult result)

static void PrintDiffsCsvHeader(FileWriter& fw)
{
fw.Print("Context,Context size,Method full name,Tier name,Base result,Diff result,MinOpts,Has diff,Base size,Diff size,Base instructions,Diff instructions");
fw.Print("Context,Context size,Method full name,Tier name,Base result,Diff result,MinOpts,Has diff,Base size,Diff size,Base GCInfo size,Diff GCInfo size,Base instructions,Diff instructions");

#define JITMETADATAINFO(name, type, flags)
#define JITMETADATAMETRIC(name, type, flags) fw.Print(",Base " #name ",Diff " #name);
Expand All @@ -159,12 +159,13 @@ static void PrintDiffsCsvRow(
fw.Printf("%d,%u,", context, contextSize);
fw.PrintQuotedCsvField(baseRes.CompileResults->MethodFullName == nullptr ? "" : baseRes.CompileResults->MethodFullName);
fw.Printf(
",%s,%s,%s,%s,%s,%u,%u,%lld,%lld",
",%s,%s,%s,%s,%s,%u,%u,%u,%u,%lld,%lld",
baseRes.CompileResults->TieringName == nullptr ? "" : baseRes.CompileResults->TieringName,
ResultToString(baseRes.Result), ResultToString(diffRes.Result),
baseRes.IsMinOpts ? "True" : "False",
hasDiff ? "True" : "False",
baseRes.NumCodeBytes, diffRes.NumCodeBytes,
(uint32_t)baseRes.NumGCInfoBytes, (uint32_t)diffRes.NumGCInfoBytes,
baseRes.NumExecutedInstructions, diffRes.NumExecutedInstructions);

#define JITMETADATAINFO(name, type, flags)
Expand All @@ -181,7 +182,7 @@ static void PrintDiffsCsvRow(

static void PrintReplayCsvHeader(FileWriter& fw)
{
fw.Printf("Context,Context size,Method full name,Tier name,Result,MinOpts,Size,Instructions");
fw.Printf("Context,Context size,Method full name,Tier name,Result,MinOpts,Size,GCInfo size,Instructions");

#define JITMETADATAINFO(name, type, flags)
#define JITMETADATAMETRIC(name, type, flags) fw.Print("," #name);
Expand All @@ -198,11 +199,11 @@ static void PrintReplayCsvRow(
{
fw.Printf("%d,%u,", context, contextSize);
fw.PrintQuotedCsvField(res.CompileResults->MethodFullName == nullptr ? "" : res.CompileResults->MethodFullName);
fw.Printf(",%s,%s,%s,%u,%lld",
fw.Printf(",%s,%s,%s,%u,%u,%lld",
res.CompileResults->TieringName == nullptr ? "" : res.CompileResults->TieringName,
ResultToString(res.Result),
res.IsMinOpts ? "True" : "False",
res.NumCodeBytes, res.NumExecutedInstructions);
res.NumCodeBytes, (uint32_t)res.NumGCInfoBytes, res.NumExecutedInstructions);

#define JITMETADATAINFO(name, type, flags)
#define JITMETADATAMETRIC(name, type, flags) \
Expand Down
Loading