Skip to content

Commit 4ae6451

Browse files
TrueDoctorKeavon
andauthored
Improve profiling CI action's comment output text (GraphiteEditor#1939)
* Improve profiling ci output * Add padding to align output * Remove always post comment switch * Update .github/workflows/profiling.yaml Co-authored-by: Keavon Chambers <keavon@keavon.com> * Update .github/workflows/profiling.yaml Co-authored-by: Keavon Chambers <keavon@keavon.com> * Update .github/workflows/profiling.yaml * Add padding to baseline line * Apply suggestions from code review * Swap order in details table * Update .github/workflows/profiling.yaml --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
1 parent 6a2b0d7 commit 4ae6451

1 file changed

Lines changed: 44 additions & 11 deletions

File tree

.github/workflows/profiling.yaml

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,27 +66,60 @@ jobs:
6666
github-token: ${{secrets.GITHUB_TOKEN}}
6767
script: |
6868
const benchmarkOutput = JSON.parse(`${{ steps.benchmark.outputs.BENCHMARK_OUTPUT }}`);
69-
7069
let significantChanges = false;
7170
let commentBody = "#### Performance Benchmark Results\n\n";
72-
71+
72+
function formatNumber(num) {
73+
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
74+
}
75+
76+
function formatPercentage(pct) {
77+
const sign = pct >= 0 ? '+' : '';
78+
return `${sign}${pct.toFixed(2)}%`;
79+
}
80+
81+
function padRight(str, len) {
82+
return str.padEnd(len);
83+
}
84+
85+
function padLeft(str, len) {
86+
return str.padStart(len);
87+
}
88+
7389
for (const benchmark of benchmarkOutput) {
7490
if (benchmark.callgrind_summary && benchmark.callgrind_summary.summaries) {
75-
for (const summary of benchmark.callgrind_summary.summaries) {
91+
const summary = benchmark.callgrind_summary.summaries[0];
92+
const irDiff = summary.events.Ir;
93+
94+
if (irDiff.diff_pct !== null) {
95+
const changePercentage = formatPercentage(irDiff.diff_pct);
96+
const color = irDiff.diff_pct > 0 ? "red" : "lime";
97+
98+
commentBody += "---\n\n";
99+
commentBody += `${benchmark.module_path} ${benchmark.id}:${benchmark.details}\n`;
100+
commentBody += `Instructions: \`${formatNumber(irDiff.old)}\` (master) -> \`${formatNumber(irDiff.new)}\` (HEAD) : `;
101+
commentBody += `$$\\color{${color}}${changePercentage.replace("%", "\\\\%")}$$\n\n`;
102+
103+
commentBody += "<details>\n<summary>Detailed metrics</summary>\n\n```\n";
104+
commentBody += `Baselines: master| HEAD\n`;
105+
76106
for (const [eventKind, costsDiff] of Object.entries(summary.events)) {
77-
if (costsDiff.diff_pct !== null && Math.abs(costsDiff.diff_pct) > 5) {
78-
significantChanges = true;
79-
const changeDirection = costsDiff.diff_pct > 0 ? "Increase" : "Decrease";
80-
const color = costsDiff.diff_pct > 0 ? "red" : "lime";
81-
commentBody += `\`${benchmark.module_path}\` - ${eventKind}:\n`;
82-
commentBody += `${changeDirection} of $$\\color{${color}}${Math.abs(costsDiff.diff_pct).toFixed(2)}\\\\%$$\n`;
83-
commentBody += `Old: ${costsDiff.old}, New: ${costsDiff.new}\n\n`;
107+
if (costsDiff.diff_pct !== null) {
108+
const changePercentage = formatPercentage(costsDiff.diff_pct);
109+
const line = `${padRight(eventKind, 20)} ${padLeft(formatNumber(costsDiff.old), 11)}|${padLeft(formatNumber(costsDiff.new), 11)} ${padLeft(changePercentage, 15)}`;
110+
commentBody += `${line}\n`;
84111
}
85112
}
113+
114+
commentBody += "```\n</details>\n\n";
115+
116+
if (Math.abs(irDiff.diff_pct) > 5) {
117+
significantChanges = true;
118+
}
86119
}
87120
}
88121
}
89-
122+
90123
if (significantChanges) {
91124
github.rest.issues.createComment({
92125
issue_number: context.issue.number,

0 commit comments

Comments
 (0)