Skip to content

Commit 95543b0

Browse files
committed
optimize report scripts
1 parent 538af61 commit 95543b0

File tree

2 files changed

+29
-27
lines changed

2 files changed

+29
-27
lines changed

.github/workflows/benchmark.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
patchId:
77
description: 'Benchmark batch ID'
88
required: true
9-
default: ''
9+
default: -1
1010
jobs:
1111
benchmark:
1212
strategy:

scripts/report.js

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,43 @@ const os = require('os');
55
const techStack = 'unitTest';
66
const url = process.env.REPORT_URL;
77
const input = process.env.REPORT_INPUT || '0 0 0 0';
8-
let patchId = '';
98

109
// Read the JSON file
1110
const jsonData = JSON.parse(fs.readFileSync('result.json', 'utf8'));
1211

1312
async function main() {
14-
if (process.env.CI) {
15-
patchId = process.env.REPORT_PATCH_ID
16-
} else {
17-
const response = await axios.post(
18-
url + '/sync/benchmark/getPatchId',
19-
{}
20-
);
21-
patchId = response.data;
22-
}
23-
const res = dealdata(jsonData, patchId.toString());
24-
postData(res);
13+
const patchId_ = (process.env.CI) ? process.env.REPORT_PATCH_ID : (await axios.post(url + '/sync/benchmark/getPatchId', {})).data;
14+
const res = dealdata(jsonData, patchId_);
15+
postResults(res);
2516
}
2617

27-
function dealdata(jsonData, patchId) {
28-
return jsonData.results.map((el) => ({
29-
projectName: getProjectInfo(el.command)[0],
30-
benchmark: getProjectInfo(el.command)[1] + '_' + input.split(/[\s|_]/).join('_'),
18+
function dealdata(data, patchId_) {
19+
return data.results.map(({command, mean}) => ({
20+
projectName: getProjectInfo(command)[0],
21+
benchmark: `${getProjectInfo(command)[1]}_${getBenchmark(input)}`,
3122
techStack,
32-
rawValue: parseFloat(el.mean.toFixed(2)),
33-
content: el,
34-
patchId,
35-
platform: os.platform()
23+
rawValue: parseFloat(mean.toFixed(2)),
24+
content: {command, mean},
25+
patchId: patchId_,
26+
platform: os.platform(),
3627
}));
3728
}
3829

30+
31+
function getBenchmarkType(input) {
32+
const type = input.split(/[\s_]/).pop();
33+
return type === '0' ? 'CPU' : 'IO';
34+
}
35+
function getBenchmark(input) {
36+
const type = getBenchmarkType(input);
37+
const inputParts = input.split(/[\s_]/);
38+
return `${type}_${inputParts.join('_')}`;
39+
}
40+
41+
3942
function getProjectInfo(command) {
4043
const projectInfo = command.split(':').pop();
41-
if ((projectInfo.split('-').length === 1)) {
44+
if (projectInfo.split('-').length === 1) {
4245
projectMethod = 'default';
4346
} else {
4447
projectMethod = projectInfo.split('-').pop();
@@ -48,12 +51,11 @@ function getProjectInfo(command) {
4851
return [projectName, projectMethod];
4952
}
5053

51-
async function postData(res) {
52-
for (const data of res) {
54+
async function postResults(results) {
55+
for (const result of results) {
5356
try {
54-
const response = await axios.post(url + '/sync/benchmark', data);
55-
console.log(data);
56-
console.log(response.data);
57+
const {data} = await axios.post(url + '/sync/benchmark', result);
58+
console.log(result);
5759
} catch (error) {
5860
console.error(error);
5961
}

0 commit comments

Comments
 (0)