Skip to content

Commit

Permalink
Implement METHOD STATS verbose output
Browse files Browse the repository at this point in the history
- introduce new verbose tag: "#METHOD STATS"
- print "key=value" pairs for each method where "key" is an arbitrary string
- values can be agrregated across all methods by a parsing script
- in particular, introduce a method that prints various foorptint
  stats for a method
  • Loading branch information
gita-omr committed Apr 11, 2024
1 parent 6391cf4 commit 9942092
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 1 deletion.
112 changes: 112 additions & 0 deletions compiler/codegen/OMRCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3388,3 +3388,115 @@ OMR::CodeGenerator::redoTrampolineReservationIfNecessary(TR::Instruction *callIn
self()->fe()->reserveTrampolineIfNecessary(self()->comp(), calleeSymRef, true);
}
}

uint32_t
OMR::CodeGenerator::getCodeSnippetsSize()
{
uint32_t codeSnippetsSize = 0;

TR::list<TR::Snippet*> snippetList = self()->getSnippetList();

for (auto snippets = snippetList.begin(); snippets != snippetList.end(); ++snippets)
codeSnippetsSize += (*snippets)->getLength(0);

return codeSnippetsSize;
}

void
OMR::CodeGenerator::getMethodStats(uint32_t &codeSize, uint32_t &warmBlocks, uint32_t &coldBlocks, uint32_t &prologue,
uint32_t &snippets, uint32_t &outOfLine, uint32_t &unaccounted,
uint32_t &blocksInColdCache, uint32_t &overestimateInColdCache)
{
codeSize = 0;
warmBlocks = 0;
coldBlocks = 0;
prologue = 0;
snippets = 0;
outOfLine = 0;
unaccounted = 0;
blocksInColdCache = 0;
overestimateInColdCache = 0; // TODO: implement

uint32_t allBlocks = 0;
uint32_t sizeBeforeFirstBlock = 0;
bool firstBlock = true;
bool insideColdCache = false;
static int const MAX_FREQ = 6;
uint32_t cold_frequence_size[MAX_FREQ] = {0};

codeSize = self()->getCodeEnd() - self()->getCodeStart();

#if 0
// enable when splitting warm and cold blocks is enabled
if (self()->getLastWarmInstruction())
codeSize = codeSize + self()->getWarmCodeEnd() - self()->getColdCodeStart();
#endif

const char *names[MAX_FREQ] = {
"UNKNOWN_COLD_BLOCK_COUNT",
"VERSIONED_COLD_BLOCK_COUNT",
"UNRESOLVED_COLD_BLOCK_COUNT",
"CATCH_COLD_BLOCK_COUNT",
"INTERP_CALLEE_COLD_BLOCK_COUNT",
"REVERSE_ARRAYCOPY_COLD_BLOCK_COUNT"
};

for (TR::TreeTop *tt = self()->comp()->getMethodSymbol()->getFirstTreeTop(); tt ; tt = tt->getNextTreeTop())
{
TR::Node *node = tt->getNode();

TR::Block *block;
uint8_t *startCursor, *endCursor;

if (node->getOpCodeValue() == TR::BBStart)
{
block = node->getBlock();
startCursor = block->getFirstInstruction()->getBinaryEncoding();
endCursor = block->getLastInstruction()->getBinaryEncoding();

uint32_t blockSize = endCursor - startCursor;
allBlocks += blockSize;

if (block->isCold())
{
coldBlocks += blockSize;
int32_t freq = block->getFrequency();

if (freq >= 0 && freq < MAX_FREQ)
cold_frequence_size[freq] += blockSize;
}

if (insideColdCache)
blocksInColdCache += blockSize;

if (firstBlock)
{
sizeBeforeFirstBlock = startCursor - self()->getCodeStart();
firstBlock = false;
}
#if 0
/// enable when splitting warm and cold blocks is enabled
if (block->isLastWarmBlock())
insideColdCache = true;
#endif
}
}

warmBlocks = allBlocks - coldBlocks;
snippets = self()->getCodeSnippetsSize() + self()->getDataSnippetsSize();
outOfLine = self()->getOutOfLineCodeSize();
unaccounted = codeSize - allBlocks - sizeBeforeFirstBlock - outOfLine - snippets;
prologue = sizeBeforeFirstBlock;

if (self()->comp()->getOption(TR_TraceCG))
{
uint32_t known_cold_blocks = 0;
for (int i = 0; i < MAX_FREQ; i++)
{
traceMsg(self()->comp(), "FOOTPRINT: COLD BLOCK TYPE: %s = %d\n", names[i], cold_frequence_size[i]);

known_cold_blocks += cold_frequence_size[i];
}
traceMsg(self()->comp(), "FOOTPRINT: COLD BLOCK TYPE: OTHER = %d\n", coldBlocks - known_cold_blocks);
}
}
25 changes: 25 additions & 0 deletions compiler/codegen/OMRCodeGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,31 @@ class OMR_EXTENSIBLE CodeGenerator

TR::list<TR::Snippet*> *getSnippetsToBePatchedOnClassRedefinition() { return &_snippetsToBePatchedOnClassRedefinition; }

/**
* \brief Calculates total size of all code snippets
*
* \return total size of all code snippets
*/
uint32_t getCodeSnippetsSize();

/**
* \brief Calculates total size of all data snippets
*
* \return total size of all data snippets
*/
uint32_t getDataSnippetsSize() { return 0; }

/**
* \brief Calculates total size of all out of line code
*
* \return total size of all out of line code
*/
uint32_t getOutOfLineCodeSize() { return 0; }

void getMethodStats(uint32_t &codeSize, uint32_t &warmBlocks, uint32_t &coldBlocks, uint32_t &prologue,
uint32_t &snippets, uint32_t &outOfLine, uint32_t &unaccounted,
uint32_t &blocksInColdCache, uint32_t &overestimateInColdCache);

// --------------------------------------------------------------------------
// Register pressure
//
Expand Down
3 changes: 2 additions & 1 deletion compiler/control/OMROptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4960,7 +4960,8 @@ const char *OMR::Options::_verboseOptionNames[TR_NumVerboseOptions] =
"vectorAPI",
"iprofilerPersistence",
"CheckpointRestore",
"CheckpointRestoreDetails"
"CheckpointRestoreDetails",
"Footprint"
};


Expand Down
1 change: 1 addition & 0 deletions compiler/control/OMROptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,7 @@ enum TR_VerboseFlags
TR_VerboseIProfilerPersistence,
TR_VerboseCheckpointRestore,
TR_VerboseCheckpointRestoreDetails,
TR_VerboseFootprint,
//If adding new options add an entry to _verboseOptionNames as well
TR_NumVerboseOptions // Must be the last one;
};
Expand Down
1 change: 1 addition & 0 deletions compiler/env/VerboseLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const char * TR_VerboseLog::_vlogTable[] =
"#FSD: ",
"#VECTOR API: ",
"#CHECKPOINT RESTORE: ",
"#METHOD STATS: "
};

void TR_VerboseLog::writeLine(TR_VlogTag tag, const char *format, ...)
Expand Down
1 change: 1 addition & 0 deletions compiler/env/VerboseLog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ enum TR_VlogTag
TR_Vlog_FSD,
TR_Vlog_VECTOR_API,
TR_Vlog_CHECKPOINT_RESTORE,
TR_Vlog_METHOD_STATS,
TR_Vlog_numTags
};

Expand Down
32 changes: 32 additions & 0 deletions compiler/x/codegen/OMRCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2363,6 +2363,19 @@ void OMR::X86::CodeGenerator::emitDataSnippets()
}
}

uint32_t OMR::X86::CodeGenerator::getDataSnippetsSize()
{
uint32_t length = 0;

for (auto iterator = _dataSnippetList.begin(); iterator != _dataSnippetList.end(); ++iterator)
{
length +=(*iterator)->getLength(0);
}

return length;
}


TR::X86ConstantDataSnippet *OMR::X86::CodeGenerator::findOrCreate2ByteConstant(TR::Node * n, int16_t c)
{
return self()->findOrCreateConstantDataSnippet(n, &c, 2);
Expand Down Expand Up @@ -3311,3 +3324,22 @@ OMR::X86::CodeGenerator::considerTypeForGRA(TR::SymbolReference *symRef)
return true;
}
}

uint32_t
OMR::X86::CodeGenerator::getOutOfLineCodeSize()
{
uint32_t totalSize = 0;

auto oiIterator = self()->getOutlinedInstructionsList().begin();
while (oiIterator != self()->getOutlinedInstructionsList().end())
{
uint32_t startOffset = (*oiIterator)->getFirstInstruction()->getBinaryEncoding() - self()->getCodeStart();
uint32_t endOffset = (*oiIterator)->getAppendInstruction()->getBinaryEncoding() - self()->getCodeStart();

totalSize += endOffset - startOffset;

++oiIterator;
}

return totalSize;
}
3 changes: 3 additions & 0 deletions compiler/x/codegen/OMRCodeGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ class OMR_EXTENSIBLE CodeGenerator : public OMR::CodeGenerator
int32_t setEstimatedLocationsForDataSnippetLabels(int32_t estimatedSnippetStart);
void emitDataSnippets();
bool hasDataSnippets() { return _dataSnippetList.empty() ? false : true; }
uint32_t getDataSnippetsSize();

TR::list<TR::Register*> &getSpilledIntRegisters() {return _spilledIntRegisters;}

Expand Down Expand Up @@ -637,6 +638,8 @@ class OMR_EXTENSIBLE CodeGenerator : public OMR::CodeGenerator
bool considerTypeForGRA(TR::DataType dt);
bool considerTypeForGRA(TR::SymbolReference *symRef);

uint32_t getOutOfLineCodeSize();

/*
* \brief create a data snippet.
*
Expand Down

0 comments on commit 9942092

Please sign in to comment.