Skip to content

Commit bae376b

Browse files
committed
add -o support to bstracing
1 parent 2353f7d commit bae376b

File tree

1 file changed

+35
-18
lines changed

1 file changed

+35
-18
lines changed

Diff for: lib/bstracing

+35-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env node
22
"use strict";
3-
// @ts-check
3+
//@ts-check
44

55
const fs = require("fs");
66
const readline = require("readline");
@@ -14,7 +14,7 @@ const path = require("path");
1414
*/
1515
function processEntry(file, lineCb, finish) {
1616
let input = fs.createReadStream(file);
17-
input.on("error", function(error) {
17+
input.on("error", function (error) {
1818
console.error(error.message);
1919
console.error(
2020
"make sure you are running after bsb building and in the top directory"
@@ -23,14 +23,14 @@ function processEntry(file, lineCb, finish) {
2323
});
2424
const rl = readline.createInterface({
2525
input: input,
26-
crlfDelay: Infinity
26+
crlfDelay: Infinity,
2727
});
2828

2929
rl.on("line", lineCb);
3030
rl.on("close", finish);
3131
}
3232

33-
class Target {
33+
class Interval {
3434
/**
3535
*
3636
* @param {number} start
@@ -70,9 +70,9 @@ class Threads {
7070
}
7171
/**
7272
*
73-
* @param {Map<string,Target>} map
73+
* @param {Map<string,Interval>} map
7474
* @param {string} key
75-
* @param {Target} def
75+
* @param {Interval} def
7676
*
7777
* */
7878
function setDefault(map, key, def) {
@@ -118,7 +118,7 @@ const colors = [
118118
"cq_build_abandoned",
119119
"cq_build_attempt_runnig",
120120
"cq_build_attempt_passed",
121-
"cq_build_attempt_failed"
121+
"cq_build_attempt_failed",
122122
];
123123

124124
let allocated = new Map();
@@ -136,7 +136,7 @@ function getColorName(obj, cat) {
136136
}
137137
/**
138138
*
139-
* @param {Target} target
139+
* @param {Interval} target
140140
*/
141141
function category(target, obj) {
142142
let targets = target.targets;
@@ -156,19 +156,23 @@ function category(target, obj) {
156156
} else {
157157
getColorName(obj, "cmj");
158158
}
159-
obj.name = target.targets.map(x => path.parse(x).base).join(",");
159+
obj.name = target.targets.map((x) => path.parse(x).base).join(",");
160160
return obj;
161161
}
162162
/**
163163
* @param {string} file
164164
* @param {boolean} showAll
165+
* @param {string} outputFile
165166
*/
166-
function readTargets(file, showAll) {
167+
function readIntervals(file, showAll, outputFile) {
167168
let lastEndSeen = 0;
169+
/**
170+
* @type {Map<string,Interval>}
171+
*/
168172
let targets = new Map();
169173
processEntry(
170174
file,
171-
line => {
175+
(line) => {
172176
let lineTrim = line.trim();
173177
if (lineTrim.startsWith("#")) {
174178
return;
@@ -180,7 +184,9 @@ function readTargets(file, showAll) {
180184
}
181185

182186
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+
);
184190
},
185191
() => {
186192
let sorted = [...targets.values()].sort((a, b) => {
@@ -196,14 +202,12 @@ function readTargets(file, showAll) {
196202
dur: (target.end - target.start) * 1000,
197203
ts: target.start * 1000,
198204
tid: threads.alloc(target),
199-
args: {}
205+
args: {},
200206
})
201207
);
202208
}
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");
207211
}
208212
);
209213
}
@@ -230,6 +234,11 @@ function tryLocation(ps) {
230234
);
231235
process.exit(2);
232236
}
237+
238+
let showAll = false;
239+
let curDate = new Date();
240+
let outputFile = `tracing_${curDate.getHours()}_${curDate.getMinutes()}_${curDate.getSeconds()}.json`;
241+
233242
{
234243
let index = process.argv.indexOf(`-C`);
235244
if (index >= 0) {
@@ -238,6 +247,14 @@ function tryLocation(ps) {
238247
} else {
239248
tryLocation([".", path.join("lib", "bs")]);
240249
}
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+
}
241257
}
258+
242259
console.log("loading build log", file, "is used");
243-
readTargets(file, false);
260+
readIntervals(file, showAll, outputFile);

0 commit comments

Comments
 (0)