@@ -5,40 +5,43 @@ const os = require('os');
5
5
const techStack = 'unitTest' ;
6
6
const url = process . env . REPORT_URL ;
7
7
const input = process . env . REPORT_INPUT || '0 0 0 0' ;
8
- let patchId = '' ;
9
8
10
9
// Read the JSON file
11
10
const jsonData = JSON . parse ( fs . readFileSync ( 'result.json' , 'utf8' ) ) ;
12
11
13
12
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 ) ;
25
16
}
26
17
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 ) } ` ,
31
22
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 ( ) ,
36
27
} ) ) ;
37
28
}
38
29
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
+
39
42
function getProjectInfo ( command ) {
40
43
const projectInfo = command . split ( ':' ) . pop ( ) ;
41
- if ( ( projectInfo . split ( '-' ) . length === 1 ) ) {
44
+ if ( projectInfo . split ( '-' ) . length === 1 ) {
42
45
projectMethod = 'default' ;
43
46
} else {
44
47
projectMethod = projectInfo . split ( '-' ) . pop ( ) ;
@@ -48,12 +51,11 @@ function getProjectInfo(command) {
48
51
return [ projectName , projectMethod ] ;
49
52
}
50
53
51
- async function postData ( res ) {
52
- for ( const data of res ) {
54
+ async function postResults ( results ) {
55
+ for ( const result of results ) {
53
56
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 ) ;
57
59
} catch ( error ) {
58
60
console . error ( error ) ;
59
61
}
0 commit comments