1
1
#!/usr/bin/env node
2
2
"use strict" ;
3
- // @ts -check
3
+ //@ts -check
4
4
5
5
const fs = require ( "fs" ) ;
6
6
const readline = require ( "readline" ) ;
@@ -14,7 +14,7 @@ const path = require("path");
14
14
*/
15
15
function processEntry ( file , lineCb , finish ) {
16
16
let input = fs . createReadStream ( file ) ;
17
- input . on ( "error" , function ( error ) {
17
+ input . on ( "error" , function ( error ) {
18
18
console . error ( error . message ) ;
19
19
console . error (
20
20
"make sure you are running after bsb building and in the top directory"
@@ -23,14 +23,14 @@ function processEntry(file, lineCb, finish) {
23
23
} ) ;
24
24
const rl = readline . createInterface ( {
25
25
input : input ,
26
- crlfDelay : Infinity
26
+ crlfDelay : Infinity ,
27
27
} ) ;
28
28
29
29
rl . on ( "line" , lineCb ) ;
30
30
rl . on ( "close" , finish ) ;
31
31
}
32
32
33
- class Target {
33
+ class Interval {
34
34
/**
35
35
*
36
36
* @param {number } start
@@ -70,9 +70,9 @@ class Threads {
70
70
}
71
71
/**
72
72
*
73
- * @param {Map<string,Target > } map
73
+ * @param {Map<string,Interval > } map
74
74
* @param {string } key
75
- * @param {Target } def
75
+ * @param {Interval } def
76
76
*
77
77
* */
78
78
function setDefault ( map , key , def ) {
@@ -118,7 +118,7 @@ const colors = [
118
118
"cq_build_abandoned" ,
119
119
"cq_build_attempt_runnig" ,
120
120
"cq_build_attempt_passed" ,
121
- "cq_build_attempt_failed"
121
+ "cq_build_attempt_failed" ,
122
122
] ;
123
123
124
124
let allocated = new Map ( ) ;
@@ -136,7 +136,7 @@ function getColorName(obj, cat) {
136
136
}
137
137
/**
138
138
*
139
- * @param {Target } target
139
+ * @param {Interval } target
140
140
*/
141
141
function category ( target , obj ) {
142
142
let targets = target . targets ;
@@ -156,19 +156,23 @@ function category(target, obj) {
156
156
} else {
157
157
getColorName ( obj , "cmj" ) ;
158
158
}
159
- obj . name = target . targets . map ( x => path . parse ( x ) . base ) . join ( "," ) ;
159
+ obj . name = target . targets . map ( ( x ) => path . parse ( x ) . base ) . join ( "," ) ;
160
160
return obj ;
161
161
}
162
162
/**
163
163
* @param {string } file
164
164
* @param {boolean } showAll
165
+ * @param {string } outputFile
165
166
*/
166
- function readTargets ( file , showAll ) {
167
+ function readIntervals ( file , showAll , outputFile ) {
167
168
let lastEndSeen = 0 ;
169
+ /**
170
+ * @type {Map<string,Interval> }
171
+ */
168
172
let targets = new Map ( ) ;
169
173
processEntry (
170
174
file ,
171
- line => {
175
+ ( line ) => {
172
176
let lineTrim = line . trim ( ) ;
173
177
if ( lineTrim . startsWith ( "#" ) ) {
174
178
return ;
@@ -180,7 +184,9 @@ function readTargets(file, showAll) {
180
184
}
181
185
182
186
lastEndSeen = + end ;
183
- setDefault ( targets , cmdHash , new Target ( + start , + end ) ) . targets . push ( name ) ;
187
+ setDefault ( targets , cmdHash , new Interval ( + start , + end ) ) . targets . push (
188
+ name
189
+ ) ;
184
190
} ,
185
191
( ) => {
186
192
let sorted = [ ...targets . values ( ) ] . sort ( ( a , b ) => {
@@ -196,14 +202,12 @@ function readTargets(file, showAll) {
196
202
dur : ( target . end - target . start ) * 1000 ,
197
203
ts : target . start * 1000 ,
198
204
tid : threads . alloc ( target ) ,
199
- args : { }
205
+ args : { } ,
200
206
} )
201
207
) ;
202
208
}
203
- let curDate = new Date ( ) ;
204
- let file = `tracing_${ curDate . getHours ( ) } _${ curDate . getMinutes ( ) } _${ curDate . getSeconds ( ) } .json` ;
205
- console . log ( ` ${ file } is produced, loade it via chrome://tracing/` ) ;
206
- fs . writeFileSync ( file , JSON . stringify ( jsonArray ) , "utf8" ) ;
209
+ console . log ( ` ${ outputFile } is produced, loade it via chrome://tracing/` ) ;
210
+ fs . writeFileSync ( outputFile , JSON . stringify ( jsonArray ) , "utf8" ) ;
207
211
}
208
212
) ;
209
213
}
@@ -230,6 +234,11 @@ function tryLocation(ps) {
230
234
) ;
231
235
process . exit ( 2 ) ;
232
236
}
237
+
238
+ let showAll = false ;
239
+ let curDate = new Date ( ) ;
240
+ let outputFile = `tracing_${ curDate . getHours ( ) } _${ curDate . getMinutes ( ) } _${ curDate . getSeconds ( ) } .json` ;
241
+
233
242
{
234
243
let index = process . argv . indexOf ( `-C` ) ;
235
244
if ( index >= 0 ) {
@@ -238,6 +247,14 @@ function tryLocation(ps) {
238
247
} else {
239
248
tryLocation ( [ "." , path . join ( "lib" , "bs" ) ] ) ;
240
249
}
250
+ if ( process . argv . includes ( "-all" ) ) {
251
+ showAll = true ;
252
+ }
253
+ index = process . argv . indexOf ( `-o` )
254
+ if ( index >= 0 ) {
255
+ outputFile = process . argv [ index + 1 ]
256
+ }
241
257
}
258
+
242
259
console . log ( "loading build log" , file , "is used" ) ;
243
- readTargets ( file , false ) ;
260
+ readIntervals ( file , showAll , outputFile ) ;
0 commit comments