mirror of
https://github.com/Mozilla-Actions/sccache-action.git
synced 2026-04-08 17:42:13 +08:00
Output sccache stats as a notice and a summary table
This commit is contained in:
committed by
Thomas Forbes
parent
f2edb47f42
commit
d947000745
2
dist/show_stats/index.js
vendored
2
dist/show_stats/index.js
vendored
File diff suppressed because one or more lines are too long
@@ -14,24 +14,140 @@
|
||||
|
||||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
import {SummaryTableRow} from '@actions/core/lib/summary';
|
||||
|
||||
async function get_output(command: string, args: string[]): Promise<string> {
|
||||
core.debug(`get_output: ${command} ${args.join(' ')}`);
|
||||
|
||||
const output = await exec.getExecOutput(command, args);
|
||||
// --stats-format=json does not emit a newline, which messes up group
|
||||
// processing. Here we add a newline if it's missing.
|
||||
if (!output.stdout.endsWith('\n')) {
|
||||
process.stdout.write('\n');
|
||||
}
|
||||
return output.stdout.toString();
|
||||
}
|
||||
|
||||
async function show_stats() {
|
||||
core.debug('start sccache show starts');
|
||||
|
||||
const defaultListener = {
|
||||
stdout: (data: Buffer) => {
|
||||
stdout.push(data.toString());
|
||||
}
|
||||
};
|
||||
|
||||
const stdout: string[] = [];
|
||||
|
||||
await exec.getExecOutput(`${process.env.SCCACHE_PATH}`, ['--show-stats'], {
|
||||
listeners: defaultListener
|
||||
const human_stats = await core.group('Get human-readable stats', async () => {
|
||||
return get_output(`${process.env.SCCACHE_PATH}`, ['--show-stats']);
|
||||
});
|
||||
const json_stats = await core.group('Get JSON stats', async () => {
|
||||
return get_output(`${process.env.SCCACHE_PATH}`, [
|
||||
'--show-stats',
|
||||
'--stats-format=json'
|
||||
]);
|
||||
});
|
||||
|
||||
const formatted_stats = format_json_stats(json_stats);
|
||||
|
||||
core.notice(formatted_stats.notice, {
|
||||
title: 'sccache stats'
|
||||
});
|
||||
core.info('\nFull human-readable stats:');
|
||||
core.info(human_stats);
|
||||
|
||||
core.summary.addHeading('sccache stats', 2);
|
||||
core.summary.addTable(formatted_stats.table);
|
||||
core.summary.addDetails(
|
||||
'Full human-readable stats',
|
||||
'\n\n```\n' + human_stats + '\n```\n\n'
|
||||
);
|
||||
|
||||
await core.summary.write();
|
||||
}
|
||||
|
||||
show_stats().catch(err => {
|
||||
core.error(err);
|
||||
core.setFailed(err.message);
|
||||
});
|
||||
|
||||
interface Duration {
|
||||
secs: number;
|
||||
nanos: number;
|
||||
}
|
||||
|
||||
interface Counter {
|
||||
counts: {
|
||||
[key: string]: number;
|
||||
};
|
||||
adv_counts: {
|
||||
[key: string]: number;
|
||||
};
|
||||
}
|
||||
|
||||
interface Stats {
|
||||
stats: {
|
||||
compile_requests: number;
|
||||
requests_executed: number;
|
||||
|
||||
cache_errors: Counter;
|
||||
cache_hits: Counter;
|
||||
cache_misses: Counter;
|
||||
|
||||
cache_write_errors: number;
|
||||
cache_writes: number;
|
||||
|
||||
cache_write_duration: Duration;
|
||||
cache_read_hit_duration: Duration;
|
||||
compiler_write_duration: Duration;
|
||||
};
|
||||
}
|
||||
|
||||
function sum_stats(stats: Counter): number {
|
||||
return Object.values(stats.counts).reduce((acc, val) => acc + val, 0);
|
||||
}
|
||||
|
||||
function format_duration(duration: Duration): string {
|
||||
const ms = duration.nanos / 1e6;
|
||||
return `${duration.secs}s ${ms}ms`;
|
||||
}
|
||||
|
||||
function format_json_stats(raw_stats: string): {
|
||||
table: SummaryTableRow[];
|
||||
notice: string;
|
||||
} {
|
||||
const stats: Stats = JSON.parse(raw_stats);
|
||||
const cache_error_count = sum_stats(stats.stats.cache_errors).toString();
|
||||
const cache_hit_count = sum_stats(stats.stats.cache_hits).toString();
|
||||
const cache_miss_count = sum_stats(stats.stats.cache_misses).toString();
|
||||
|
||||
const write_duration = format_duration(stats.stats.cache_write_duration);
|
||||
const read_duration = format_duration(stats.stats.cache_read_hit_duration);
|
||||
const compiler_duration = format_duration(
|
||||
stats.stats.compiler_write_duration
|
||||
);
|
||||
|
||||
const notice = `${cache_hit_count} hits, ${cache_miss_count} misses, ${cache_error_count} errors`;
|
||||
|
||||
const table = [
|
||||
[{data: 'Cache hits', header: true}, {data: cache_hit_count.toString()}],
|
||||
[{data: 'Cache misses', header: true}, {data: cache_miss_count.toString()}],
|
||||
[
|
||||
{data: 'Cache errors', header: true},
|
||||
{data: cache_error_count.toString()}
|
||||
],
|
||||
[
|
||||
{data: 'Compile requests', header: true},
|
||||
{data: stats.stats.compile_requests.toString()}
|
||||
],
|
||||
[
|
||||
{data: 'Requests executed', header: true},
|
||||
{data: stats.stats.requests_executed.toString()}
|
||||
],
|
||||
[
|
||||
{data: 'Cache writes', header: true},
|
||||
{data: stats.stats.cache_writes.toString()}
|
||||
],
|
||||
[
|
||||
{data: 'Cache write errors', header: true},
|
||||
{data: stats.stats.cache_write_errors.toString()}
|
||||
],
|
||||
[{data: 'Cache write duration', header: true}, {data: write_duration}],
|
||||
[{data: 'Cache read hit duration', header: true}, {data: read_duration}],
|
||||
[{data: 'Compiler write duration', header: true}, {data: compiler_duration}]
|
||||
];
|
||||
|
||||
return {table, notice};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user