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

Sort oper allocation counts table #60223

Merged
Merged
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
84 changes: 57 additions & 27 deletions src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1508,55 +1508,85 @@ void Compiler::compShutdown()
#if COUNT_AST_OPERS

// Add up all the counts so that we can show percentages of total
unsigned gtc = 0;
unsigned totalCount = 0;
for (unsigned op = 0; op < GT_COUNT; op++)
gtc += GenTree::s_gtNodeCounts[op];
{
totalCount += GenTree::s_gtNodeCounts[op];
}

if (gtc > 0)
if (totalCount > 0)
{
unsigned rem_total = gtc;
unsigned rem_large = 0;
unsigned rem_small = 0;
struct OperInfo
{
unsigned Count;
unsigned Size;
genTreeOps Oper;
};

OperInfo opers[GT_COUNT];
for (unsigned op = 0; op < GT_COUNT; op++)
{
opers[op] = {GenTree::s_gtNodeCounts[op], GenTree::s_gtTrueSizes[op], static_cast<genTreeOps>(op)};
}

jitstd::sort(opers, opers + ArrLen(opers), [](const OperInfo& l, const OperInfo& r) {
// We'll be sorting in descending order.
return l.Count >= r.Count;
});

unsigned remainingCount = totalCount;
unsigned remainingCountLarge = 0;
unsigned remainingCountSmall = 0;

unsigned tot_large = 0;
unsigned tot_small = 0;
unsigned countLarge = 0;
unsigned countSmall = 0;

fprintf(fout, "\nGenTree operator counts (approximate):\n\n");

for (unsigned op = 0; op < GT_COUNT; op++)
for (OperInfo oper : opers)
{
unsigned siz = GenTree::s_gtTrueSizes[op];
unsigned cnt = GenTree::s_gtNodeCounts[op];
double pct = 100.0 * cnt / gtc;
unsigned size = oper.Size;
unsigned count = oper.Count;
double percentage = 100.0 * count / totalCount;

if (siz > TREE_NODE_SZ_SMALL)
tot_large += cnt;
if (size > TREE_NODE_SZ_SMALL)
{
countLarge += count;
}
else
tot_small += cnt;
{
countSmall += count;
}

// Let's not show anything below a threshold
if (pct >= 0.5)
if (percentage >= 0.5)
{
fprintf(fout, " GT_%-17s %7u (%4.1lf%%) %3u bytes each\n", GenTree::OpName((genTreeOps)op), cnt,
pct, siz);
rem_total -= cnt;
fprintf(fout, " GT_%-17s %7u (%4.1lf%%) %3u bytes each\n", GenTree::OpName(oper.Oper), count,
percentage, size);
remainingCount -= count;
}
else
{
if (siz > TREE_NODE_SZ_SMALL)
rem_large += cnt;
if (size > TREE_NODE_SZ_SMALL)
{
remainingCountLarge += count;
}
else
rem_small += cnt;
{
remainingCountSmall += count;
}
}
}
if (rem_total > 0)

if (remainingCount > 0)
{
fprintf(fout, " All other GT_xxx ... %7u (%4.1lf%%) ... %4.1lf%% small + %4.1lf%% large\n", rem_total,
100.0 * rem_total / gtc, 100.0 * rem_small / gtc, 100.0 * rem_large / gtc);
fprintf(fout, " All other GT_xxx ... %7u (%4.1lf%%) ... %4.1lf%% small + %4.1lf%% large\n",
remainingCount, 100.0 * remainingCount / totalCount, 100.0 * remainingCountSmall / totalCount,
100.0 * remainingCountLarge / totalCount);
}
fprintf(fout, " -----------------------------------------------------\n");
fprintf(fout, " Total ....... %11u --ALL-- ... %4.1lf%% small + %4.1lf%% large\n", gtc,
100.0 * tot_small / gtc, 100.0 * tot_large / gtc);
fprintf(fout, " Total ....... %11u --ALL-- ... %4.1lf%% small + %4.1lf%% large\n", totalCount,
100.0 * countSmall / totalCount, 100.0 * countLarge / totalCount);
fprintf(fout, "\n");
}

Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ unsigned char GenTree::s_gtTrueSizes[GT_COUNT + 1]{
#endif // NODEBASH_STATS || MEASURE_NODE_SIZE || COUNT_AST_OPERS

#if COUNT_AST_OPERS
LONG GenTree::s_gtNodeCounts[GT_COUNT + 1] = {0};
unsigned GenTree::s_gtNodeCounts[GT_COUNT + 1] = {0};
#endif // COUNT_AST_OPERS

/* static */
Expand Down Expand Up @@ -509,8 +509,8 @@ void GenTree::DumpNodeSizes(FILE* fp)
{
// Dump the sizes of the various GenTree flavors

fprintf(fp, "Small tree node size = %3u bytes\n", TREE_NODE_SZ_SMALL);
fprintf(fp, "Large tree node size = %3u bytes\n", TREE_NODE_SZ_LARGE);
fprintf(fp, "Small tree node size = %zu bytes\n", TREE_NODE_SZ_SMALL);
fprintf(fp, "Large tree node size = %zu bytes\n", TREE_NODE_SZ_LARGE);
fprintf(fp, "\n");

// Verify that node sizes are set kosherly and dump sizes
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/gentree.h
Original file line number Diff line number Diff line change
Expand Up @@ -1877,7 +1877,7 @@ struct GenTree
static unsigned char s_gtTrueSizes[];
#endif
#if COUNT_AST_OPERS
static LONG s_gtNodeCounts[];
static unsigned s_gtNodeCounts[];
#endif

static void InitNodeSize();
Expand Down