Skip to content

optimize report scripts and fix app.js #34

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

Merged
merged 2 commits into from
Mar 11, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
patchId:
description: 'Benchmark batch ID'
required: true
default: ''
default: -1
jobs:
benchmark:
strategy:
Expand Down
3 changes: 2 additions & 1 deletion packages/server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ app.get('/', (req, res) => {
app.post('/sync/benchmark/getDelayedMessage', (req, res) => {
const { delay } = req.body;
setTimeout(() => {
res.send(`Delay return time: ${delay} ms! ${index}`);
res.send(`Delay return time: ${delay} ms!`);
console.log(`Delay return time: ${delay} ms!`);
}, delay);
});

Expand Down
54 changes: 28 additions & 26 deletions scripts/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,43 @@ const os = require('os');
const techStack = 'unitTest';
const url = process.env.REPORT_URL;
const input = process.env.REPORT_INPUT || '0 0 0 0';
let patchId = '';

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

async function main() {
if (process.env.CI) {
patchId = process.env.REPORT_PATCH_ID
} else {
const response = await axios.post(
url + '/sync/benchmark/getPatchId',
{}
);
patchId = response.data;
}
const res = dealdata(jsonData, patchId.toString());
postData(res);
const patchId_ = (process.env.CI) ? process.env.REPORT_PATCH_ID : (await axios.post(url + '/sync/benchmark/getPatchId', {})).data;
const res = dealdata(jsonData, patchId_);
postResults(res);
}

function dealdata(jsonData, patchId) {
return jsonData.results.map((el) => ({
projectName: getProjectInfo(el.command)[0],
benchmark: getProjectInfo(el.command)[1] + '_' + input.split(/[\s|_]/).join('_'),
function dealdata(data, patchId_) {
return data.results.map(({command, mean}) => ({
projectName: getProjectInfo(command)[0],
benchmark: `${getProjectInfo(command)[1]}_${getBenchmark(input)}`,
techStack,
rawValue: parseFloat(el.mean.toFixed(2)),
content: el,
patchId,
platform: os.platform()
rawValue: parseFloat(mean.toFixed(2)),
content: {command, mean},
patchId: patchId_,
platform: os.platform(),
}));
}


function getBenchmarkType(input) {
const type = input.split(/[\s_]/).pop();
return type === '0' ? 'CPU' : 'IO';
}
function getBenchmark(input) {
const type = getBenchmarkType(input);
const inputParts = input.split(/[\s_]/);
return `${type}_${inputParts.join('_')}`;
}


function getProjectInfo(command) {
const projectInfo = command.split(':').pop();
if ((projectInfo.split('-').length === 1)) {
if (projectInfo.split('-').length === 1) {
projectMethod = 'default';
} else {
projectMethod = projectInfo.split('-').pop();
Expand All @@ -48,12 +51,11 @@ function getProjectInfo(command) {
return [projectName, projectMethod];
}

async function postData(res) {
for (const data of res) {
async function postResults(results) {
for (const result of results) {
try {
const response = await axios.post(url + '/sync/benchmark', data);
console.log(data);
console.log(response.data);
const {data} = await axios.post(url + '/sync/benchmark', result);
console.log(result);
} catch (error) {
console.error(error);
}
Expand Down