@ark/attest 0.48.1 → 0.48.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/cli/trace.js +184 -84
- package/package.json +3 -3
package/out/cli/trace.js
CHANGED
|
@@ -30,10 +30,92 @@ const formatMillis = (ms, fractionDigits = 2) => (ms / 1000).toFixed(fractionDig
|
|
|
30
30
|
* Formats microseconds to a padded string of milliseconds.
|
|
31
31
|
*/
|
|
32
32
|
const formatPaddedMillis = (ms, pad, fractionDigits = 2) => formatMillis(ms, fractionDigits).padStart(pad);
|
|
33
|
+
// Helper to format duration in seconds to a human-readable string
|
|
34
|
+
const formatSeconds = (totalSeconds) => {
|
|
35
|
+
if (totalSeconds < 0)
|
|
36
|
+
totalSeconds = 0;
|
|
37
|
+
const hours = Math.floor(totalSeconds / 3600);
|
|
38
|
+
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
|
39
|
+
const seconds = Math.floor(totalSeconds % 60);
|
|
40
|
+
if (hours > 0)
|
|
41
|
+
return `about ${hours} hour(s)`;
|
|
42
|
+
if (minutes > 0)
|
|
43
|
+
return `about ${minutes} minute(s)`;
|
|
44
|
+
return `${seconds}s`;
|
|
45
|
+
};
|
|
46
|
+
class ProgressDisplay {
|
|
47
|
+
totalItems;
|
|
48
|
+
processedItems = 0;
|
|
49
|
+
startTime = 0;
|
|
50
|
+
timerId;
|
|
51
|
+
barWidth = 30; // Width of the progress bar itself
|
|
52
|
+
constructor(totalItems) {
|
|
53
|
+
this.totalItems = totalItems;
|
|
54
|
+
if (this.totalItems <= 0)
|
|
55
|
+
this.totalItems = 0;
|
|
56
|
+
}
|
|
57
|
+
start() {
|
|
58
|
+
if (this.totalItems === 0)
|
|
59
|
+
return;
|
|
60
|
+
this.startTime = Date.now();
|
|
61
|
+
this.processedItems = 0;
|
|
62
|
+
this.render(); // Initial render
|
|
63
|
+
// Update every second for elapsed time and ETA
|
|
64
|
+
this.timerId = setInterval(() => this.render(), 1000);
|
|
65
|
+
}
|
|
66
|
+
update(processedCount) {
|
|
67
|
+
if (this.totalItems === 0)
|
|
68
|
+
return;
|
|
69
|
+
this.processedItems = Math.min(processedCount, this.totalItems);
|
|
70
|
+
this.render(); // Re-render on each item processed for immediate feedback
|
|
71
|
+
if (this.processedItems >= this.totalItems)
|
|
72
|
+
this.stop(); // Automatically stop if all items are processed
|
|
73
|
+
}
|
|
74
|
+
render() {
|
|
75
|
+
if (this.totalItems === 0 && this.processedItems === 0 && !this.startTime)
|
|
76
|
+
return; // Avoid rendering if not started for 0 items
|
|
77
|
+
const percent = this.totalItems > 0 ?
|
|
78
|
+
Math.min(100, (this.processedItems / this.totalItems) * 100)
|
|
79
|
+
: 100;
|
|
80
|
+
const filledLength = Math.floor((this.barWidth * percent) / 100);
|
|
81
|
+
const emptyLength = this.barWidth - filledLength;
|
|
82
|
+
const bar = `[${"=".repeat(filledLength)}${" ".repeat(emptyLength)}]`;
|
|
83
|
+
const elapsedMs = Date.now() - this.startTime;
|
|
84
|
+
const elapsedSec = elapsedMs / 1000;
|
|
85
|
+
const formattedElapsed = formatSeconds(elapsedSec);
|
|
86
|
+
let etaStr = "";
|
|
87
|
+
if (this.processedItems > 0 && this.processedItems < this.totalItems) {
|
|
88
|
+
const avgTimePerItemMs = elapsedMs / this.processedItems;
|
|
89
|
+
const remainingItems = this.totalItems - this.processedItems;
|
|
90
|
+
const etaMs = remainingItems * avgTimePerItemMs;
|
|
91
|
+
etaStr = ` (ETA: ${formatSeconds(etaMs / 1000)})`;
|
|
92
|
+
}
|
|
93
|
+
else if (this.processedItems >= this.totalItems && this.totalItems > 0)
|
|
94
|
+
etaStr = " (Done)";
|
|
95
|
+
const summary = `${this.processedItems}/${this.totalItems} entries (${percent.toFixed(0)}%)`;
|
|
96
|
+
const timeInfo = `${formattedElapsed} elapsed${etaStr}`;
|
|
97
|
+
process.stdout.clearLine(0); // Clear the current line
|
|
98
|
+
process.stdout.cursorTo(0); // Move cursor to the beginning of the line
|
|
99
|
+
process.stdout.write(`Processing: ${bar} ${summary} | ${timeInfo}`);
|
|
100
|
+
}
|
|
101
|
+
stop() {
|
|
102
|
+
if (this.timerId) {
|
|
103
|
+
clearInterval(this.timerId);
|
|
104
|
+
this.timerId = undefined;
|
|
105
|
+
}
|
|
106
|
+
if (this.totalItems > 0) {
|
|
107
|
+
this.processedItems = this.totalItems; // Ensure final state is 100%
|
|
108
|
+
this.render(); // Final render
|
|
109
|
+
process.stdout.write("\n"); // Move to the next line
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
33
113
|
export const trace = async (args) => {
|
|
34
114
|
const packageDir = resolve(args[0] ?? process.cwd());
|
|
35
115
|
const config = getConfig();
|
|
36
116
|
if (!config.tsconfig) {
|
|
117
|
+
// This message should go to console.error and also be captured if needed,
|
|
118
|
+
// but since it exits, direct console.error is fine.
|
|
37
119
|
console.error(`attest trace must be run from a directory with a tsconfig.json file`);
|
|
38
120
|
process.exit(1);
|
|
39
121
|
}
|
|
@@ -42,24 +124,27 @@ export const trace = async (args) => {
|
|
|
42
124
|
outputCapture.clear();
|
|
43
125
|
const initialMessages = [];
|
|
44
126
|
initialMessages.push(`⏳ Gathering type trace data for ${packageDir}...`);
|
|
45
|
-
outputCapture.write(initialMessages[0]);
|
|
127
|
+
outputCapture.write(initialMessages[0]); // This goes to console and buffer
|
|
46
128
|
const tracingOutput = generateTraceData(traceDir, config.tsconfig, packageDir);
|
|
47
129
|
const traceFile = join(traceDir, "trace.json");
|
|
48
130
|
if (!existsSync(traceFile)) {
|
|
49
131
|
outputCapture.write(`❌ No trace data found (expected a file at ${traceFile}). TSC output:\n${tracingOutput}`);
|
|
50
|
-
// Write what we have to summary and exit
|
|
51
132
|
const summaryPath = join(traceDir, "summary.txt");
|
|
52
133
|
writeFile(summaryPath, outputCapture.getBuffer());
|
|
53
134
|
return;
|
|
54
135
|
}
|
|
136
|
+
// This message will be followed by the progress bar on the next line
|
|
55
137
|
outputCapture.write(`⏳ Analyzing type trace data for ${packageDir}...`);
|
|
56
|
-
analyzeTypeInstantiations(traceDir);
|
|
138
|
+
analyzeTypeInstantiations(traceDir); // This function now handles its own progress display
|
|
139
|
+
// Collect all messages for the summary file
|
|
140
|
+
// The progress bar output is not part of outputCapture.getLines()
|
|
57
141
|
const analysisMessages = outputCapture
|
|
58
142
|
.getLines()
|
|
59
|
-
.slice(initialMessages.length);
|
|
143
|
+
.slice(initialMessages.length + 1); // +1 for the "Analyzing..." message
|
|
60
144
|
const summaryContent = [
|
|
61
145
|
...initialMessages,
|
|
62
146
|
tracingOutput,
|
|
147
|
+
outputCapture.getLines()[initialMessages.length], // The "Analyzing..." message
|
|
63
148
|
...analysisMessages
|
|
64
149
|
].join("\n");
|
|
65
150
|
const summaryPath = join(traceDir, "summary.txt");
|
|
@@ -68,13 +153,10 @@ export const trace = async (args) => {
|
|
|
68
153
|
const generateTraceData = (traceDir, tsconfigPath, packageDir) => {
|
|
69
154
|
try {
|
|
70
155
|
const output = getShellOutput(`${baseDiagnosticTscCmd} --project ${tsconfigPath} --generateTrace ${traceDir}`, { cwd: packageDir });
|
|
71
|
-
process.stdout.write(output);
|
|
156
|
+
process.stdout.write(output); // Display tsc output directly
|
|
72
157
|
return output;
|
|
73
158
|
}
|
|
74
159
|
catch (error) {
|
|
75
|
-
// even if tsc returns a non-zero exit code,
|
|
76
|
-
// we can still proceed as long as the trace.json
|
|
77
|
-
// file was generated. The existence of trace.json is checked later.
|
|
78
160
|
const e = error;
|
|
79
161
|
const output = e.stdout ?? "";
|
|
80
162
|
const errorOutput = e.stderr ?? "";
|
|
@@ -87,11 +169,9 @@ const initializeAnalysisContext = (traceDir) => {
|
|
|
87
169
|
const tsServer = TsServer.instance;
|
|
88
170
|
const tracePath = join(traceDir, "trace.json");
|
|
89
171
|
if (!existsSync(tracePath)) {
|
|
90
|
-
// This case should be caught by the `trace` function earlier,
|
|
91
|
-
// but as a safeguard:
|
|
92
172
|
throw new Error(`Critical: Expected a trace file at ${tracePath}, but it was not found during context initialization.`);
|
|
93
173
|
}
|
|
94
|
-
const traceEntries = readJson(tracePath);
|
|
174
|
+
const traceEntries = readJson(tracePath);
|
|
95
175
|
return {
|
|
96
176
|
traceDir,
|
|
97
177
|
tsServer,
|
|
@@ -106,21 +186,21 @@ const initializeAnalysisContext = (traceDir) => {
|
|
|
106
186
|
const filterDurationEntries = (ctx) => {
|
|
107
187
|
ctx.durationEntries = ctx.traceEntries.filter(entry => {
|
|
108
188
|
const { args, dur, ph } = entry;
|
|
109
|
-
return (ph === "X" &&
|
|
110
|
-
typeof dur === "number" &&
|
|
189
|
+
return (ph === "X" &&
|
|
190
|
+
typeof dur === "number" &&
|
|
111
191
|
args &&
|
|
112
192
|
typeof args.path === "string" &&
|
|
113
193
|
typeof args.pos === "number" &&
|
|
114
194
|
typeof args.end === "number");
|
|
115
195
|
});
|
|
196
|
+
// This message goes to outputCapture for the summary file
|
|
116
197
|
outputCapture.write(`Found ${ctx.durationEntries.length} complete event traces with duration, path, and position.`);
|
|
117
198
|
};
|
|
118
199
|
const processDurationEntry = (entry, ctx) => {
|
|
119
|
-
// These properties are guaranteed by filterDurationEntries
|
|
120
200
|
const entryPath = entry.args.path;
|
|
121
201
|
const entryPos = entry.args.pos;
|
|
122
202
|
const entryEnd = entry.args.end;
|
|
123
|
-
const entryDur = entry.dur;
|
|
203
|
+
const entryDur = entry.dur;
|
|
124
204
|
const sourceFile = ctx.tsServer.getSourceFileOrThrow(entryPath);
|
|
125
205
|
let callRangeData;
|
|
126
206
|
const callExpr = findCallExpressionInRange(sourceFile, entryPos, entryEnd);
|
|
@@ -137,7 +217,6 @@ const processDurationEntry = (entry, ctx) => {
|
|
|
137
217
|
const nodeType = getStringifiableType(relevantNode);
|
|
138
218
|
const nodeKind = ts.SyntaxKind[relevantNode.kind];
|
|
139
219
|
const typeName = `${nodeKind}: ${nodeType.toString().substring(0, 25)}`;
|
|
140
|
-
// Ensure typeId is unique and meaningful
|
|
141
220
|
const typeNodeIdPart = nodeType.id ?? nodeType.toString().substring(0, 20);
|
|
142
221
|
callRangeData = {
|
|
143
222
|
typeId: `node-${relevantNode.kind}-${typeNodeIdPart}`,
|
|
@@ -155,13 +234,11 @@ const processDurationEntry = (entry, ctx) => {
|
|
|
155
234
|
endTime: entry.ts + entryDur,
|
|
156
235
|
duration: entryDur,
|
|
157
236
|
children: [],
|
|
158
|
-
selfTime: entryDur
|
|
237
|
+
selfTime: entryDur
|
|
159
238
|
});
|
|
160
239
|
}
|
|
161
240
|
else {
|
|
162
|
-
|
|
163
|
-
// this indicates an issue with the trace data or our processing logic.
|
|
164
|
-
throw new Error(`Failed to identify a processable AST node for duration entry (name: ${entry.name}, path: ${entryPath}, pos: ${entryPos}-${entryEnd}). This entry will be skipped.`);
|
|
241
|
+
throw new Error(`Failed to identify a processable AST node for duration entry (name: ${entry.name}, path: ${entryPath}, pos: ${entryPos}-${entryEnd}).`);
|
|
165
242
|
}
|
|
166
243
|
};
|
|
167
244
|
const findCallExpressionInRange = (file, start, end) => {
|
|
@@ -181,9 +258,11 @@ const extractFunctionName = (callExpr) => {
|
|
|
181
258
|
return callExpr.expression.name.getText();
|
|
182
259
|
if (ts.isIdentifier(callExpr.expression))
|
|
183
260
|
return callExpr.expression.getText();
|
|
184
|
-
return "anonymousFunction";
|
|
261
|
+
return "anonymousFunction";
|
|
185
262
|
};
|
|
186
263
|
const buildCallTree = (ctx) => {
|
|
264
|
+
// This message goes to outputCapture for the summary file
|
|
265
|
+
outputCapture.write(`Building call tree from ${ctx.callRanges.length} ranges...`);
|
|
187
266
|
ctx.callRanges.sort((a, b) => a.startTime - b.startTime);
|
|
188
267
|
const activeCallStack = [];
|
|
189
268
|
for (const call of ctx.callRanges) {
|
|
@@ -198,18 +277,15 @@ const buildCallTree = (ctx) => {
|
|
|
198
277
|
}
|
|
199
278
|
activeCallStack.push(call);
|
|
200
279
|
}
|
|
280
|
+
outputCapture.write(`Call tree built with ${ctx.rootCalls.length} root calls.`);
|
|
201
281
|
};
|
|
202
282
|
const calculateSelfTimes = (call) => {
|
|
203
283
|
let childrenTime = 0;
|
|
204
284
|
for (const child of call.children)
|
|
205
285
|
childrenTime += calculateSelfTimes(child);
|
|
206
286
|
call.selfTime = call.duration - childrenTime;
|
|
207
|
-
if (call.selfTime < 0)
|
|
208
|
-
// This can happen due to precision issues or overlapping trace entries.
|
|
209
|
-
// Log a warning, but clamp to 0 to avoid negative self-times.
|
|
210
|
-
// console.warn(`Warning: Negative self-time calculated for ${call.functionName} at ${call.callSite}. Clamping to 0.`);
|
|
287
|
+
if (call.selfTime < 0)
|
|
211
288
|
call.selfTime = 0;
|
|
212
|
-
}
|
|
213
289
|
return call.duration;
|
|
214
290
|
};
|
|
215
291
|
const collectFunctionStats = (call, ctx) => {
|
|
@@ -220,7 +296,7 @@ const collectFunctionStats = (call, ctx) => {
|
|
|
220
296
|
totalTime: 0,
|
|
221
297
|
selfTime: 0,
|
|
222
298
|
count: 0,
|
|
223
|
-
firstLocation: call.callSite,
|
|
299
|
+
firstLocation: call.callSite,
|
|
224
300
|
detailedCallSites: []
|
|
225
301
|
};
|
|
226
302
|
}
|
|
@@ -247,67 +323,97 @@ const collectFunctionStats = (call, ctx) => {
|
|
|
247
323
|
collectFunctionStats(child, ctx);
|
|
248
324
|
};
|
|
249
325
|
const sortAndRankFunctions = (ctx) => {
|
|
326
|
+
outputCapture.write("Sorting and ranking functions...");
|
|
250
327
|
for (const stats of Object.values(ctx.functionStats))
|
|
251
328
|
stats.detailedCallSites.sort((a, b) => b.selfTime - a.selfTime);
|
|
252
329
|
ctx.allFunctions = Object.values(ctx.functionStats).sort((a, b) => b.selfTime - a.selfTime);
|
|
253
330
|
};
|
|
254
331
|
const analyzeTypeInstantiations = (traceDir) => {
|
|
255
332
|
const ctx = initializeAnalysisContext(traceDir);
|
|
256
|
-
filterDurationEntries(ctx);
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
333
|
+
filterDurationEntries(ctx); // Uses outputCapture
|
|
334
|
+
const totalEntries = ctx.durationEntries.length;
|
|
335
|
+
if (totalEntries === 0) {
|
|
336
|
+
outputCapture.write("No duration entries with path/pos to process.");
|
|
337
|
+
outputCapture.write(`\n✅ Analysis complete! No data to export. Summary written to:\n` +
|
|
338
|
+
` - ${join(traceDir, "summary.txt")}`);
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
const progressDisplay = new ProgressDisplay(totalEntries);
|
|
342
|
+
progressDisplay.start();
|
|
343
|
+
for (const [index, entry] of ctx.durationEntries.entries()) {
|
|
344
|
+
try {
|
|
345
|
+
processDurationEntry(entry, ctx);
|
|
346
|
+
}
|
|
347
|
+
catch (e) {
|
|
348
|
+
progressDisplay.stop(); // Stop progress before printing error via outputCapture
|
|
349
|
+
outputCapture.write(`\n❌ Error processing entry ${index + 1}/${totalEntries} (Path: ${entry.args.path ?? "N/A"}, Pos: ${entry.args.pos ?? "N/A"}): ${e.message}`);
|
|
350
|
+
outputCapture.write("Aborting analysis due to error.");
|
|
351
|
+
// Early exit, summary will be written by the main trace function
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
progressDisplay.update(index + 1);
|
|
261
355
|
}
|
|
262
|
-
|
|
356
|
+
progressDisplay.stop(); // Ensure it's stopped if loop finished
|
|
357
|
+
// Subsequent messages use outputCapture and will appear after the progress bar
|
|
358
|
+
buildCallTree(ctx); // Uses outputCapture
|
|
359
|
+
outputCapture.write("Calculating self-times for call tree nodes...");
|
|
263
360
|
for (const root of ctx.rootCalls)
|
|
264
361
|
calculateSelfTimes(root);
|
|
265
|
-
|
|
362
|
+
outputCapture.write("Collecting statistics...");
|
|
363
|
+
const ungroupedStats = collectUngroupedStats(ctx); // Uses outputCapture
|
|
266
364
|
for (const root of ctx.rootCalls)
|
|
267
365
|
collectFunctionStats(root, ctx);
|
|
268
|
-
sortAndRankFunctions(ctx);
|
|
366
|
+
sortAndRankFunctions(ctx); // Uses outputCapture
|
|
269
367
|
outputCapture.write("\n📊 Performance Analysis - Top Individual Calls:\n");
|
|
270
|
-
displayIndividualSummary(ungroupedStats);
|
|
368
|
+
displayIndividualSummary(ungroupedStats); // Uses outputCapture
|
|
271
369
|
outputCapture.write("\n📊 Performance Analysis - Functions by Self Time:\n");
|
|
272
|
-
displayGroupedSummary(ctx.allFunctions);
|
|
370
|
+
displayGroupedSummary(ctx.allFunctions); // Uses outputCapture
|
|
273
371
|
const rangesCsvPath = join(traceDir, "ranges.csv");
|
|
274
372
|
const namesCsvPath = join(traceDir, "names.csv");
|
|
275
|
-
const summaryFilePath = join(traceDir, "summary.txt"); //
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
373
|
+
const summaryFilePath = join(traceDir, "summary.txt"); // Path already defined in trace()
|
|
374
|
+
if (ctx.callRanges.length > 0) {
|
|
375
|
+
outputCapture.write("Exporting CSV reports...");
|
|
376
|
+
writeToCsv(rangesCsvPath, ["Function Name", "Self (ms)", "Duration (ms)", "Location"], ungroupedStats.map(stat => [
|
|
377
|
+
stat.functionName,
|
|
378
|
+
formatMillis(stat.selfTime, 3),
|
|
379
|
+
formatMillis(stat.duration, 3),
|
|
380
|
+
formatLocation(stat.callSite)
|
|
381
|
+
]));
|
|
382
|
+
writeToCsv(namesCsvPath, [
|
|
383
|
+
"Function Name",
|
|
384
|
+
"Total Self (ms)",
|
|
385
|
+
"Avg Self (ms)",
|
|
386
|
+
"Call Count",
|
|
387
|
+
"Top Location",
|
|
388
|
+
"Top Self (ms)"
|
|
389
|
+
], ctx.allFunctions.map(stats => {
|
|
390
|
+
const topUsage = stats.detailedCallSites[0] ?? {
|
|
391
|
+
path: "unknown",
|
|
392
|
+
pos: 0,
|
|
393
|
+
end: 0,
|
|
394
|
+
selfTime: 0
|
|
395
|
+
};
|
|
396
|
+
return [
|
|
397
|
+
stats.functionName,
|
|
398
|
+
formatMillis(stats.selfTime, 3),
|
|
399
|
+
formatMillis(stats.selfTime / Math.max(1, stats.count), 3),
|
|
400
|
+
stats.count.toString(),
|
|
401
|
+
formatLocation(`${topUsage.path}:${topUsage.pos}-${topUsage.end}`),
|
|
402
|
+
formatMillis(topUsage.selfTime, 3)
|
|
403
|
+
];
|
|
404
|
+
}));
|
|
405
|
+
outputCapture.write(`\n✅ Analysis complete! Results exported to:\n` +
|
|
406
|
+
` - ${rangesCsvPath} (individual calls)\n` +
|
|
407
|
+
` - ${namesCsvPath} (grouped by function name)\n` +
|
|
408
|
+
` - ${summaryFilePath} (complete analysis report)`);
|
|
409
|
+
}
|
|
410
|
+
else {
|
|
411
|
+
outputCapture.write(`\n✅ Analysis complete! No call ranges processed to export to CSV. Summary written to:\n` +
|
|
412
|
+
` - ${summaryFilePath}`);
|
|
413
|
+
}
|
|
309
414
|
};
|
|
310
415
|
const collectUngroupedStats = (ctx) => {
|
|
416
|
+
outputCapture.write("Collecting and sorting ungrouped call statistics...");
|
|
311
417
|
const ungroupedStats = [];
|
|
312
418
|
const flattenCallTree = (call) => {
|
|
313
419
|
ungroupedStats.push({
|
|
@@ -365,8 +471,7 @@ const displayGroupedSummary = (functions) => {
|
|
|
365
471
|
const stats = functions[i];
|
|
366
472
|
const typeNameFormatted = formatTypeName(stats.functionName, 20);
|
|
367
473
|
const totalTimeMs = formatPaddedMillis(stats.selfTime, 15, 2);
|
|
368
|
-
const avgTimeMs = formatPaddedMillis(stats.selfTime / Math.max(1, stats.count),
|
|
369
|
-
13, 2);
|
|
474
|
+
const avgTimeMs = formatPaddedMillis(stats.selfTime / Math.max(1, stats.count), 13, 2);
|
|
370
475
|
const calls = stats.count.toString().padStart(5);
|
|
371
476
|
const topUsage = stats.detailedCallSites[0] ?? {
|
|
372
477
|
path: "unknown",
|
|
@@ -383,7 +488,7 @@ const formatTypeName = (typeName, maxLength) => {
|
|
|
383
488
|
typeName = typeName.replace(/\(\)$/, "");
|
|
384
489
|
if (typeName.length <= maxLength)
|
|
385
490
|
return typeName.padEnd(maxLength);
|
|
386
|
-
const charsToKeep = maxLength - 3;
|
|
491
|
+
const charsToKeep = maxLength - 3;
|
|
387
492
|
const firstPart = Math.ceil(charsToKeep * 0.7);
|
|
388
493
|
const lastPart = charsToKeep - firstPart;
|
|
389
494
|
return (typeName.substring(0, firstPart) +
|
|
@@ -395,19 +500,14 @@ const formatLocation = (location) => {
|
|
|
395
500
|
return location || "unknown";
|
|
396
501
|
const parts = location.split(":");
|
|
397
502
|
if (parts.length < 2)
|
|
398
|
-
return basename(location);
|
|
399
|
-
const filePath = parts.slice(0, -1).join(":");
|
|
503
|
+
return basename(location);
|
|
504
|
+
const filePath = parts.slice(0, -1).join(":");
|
|
400
505
|
const positionRange = parts[parts.length - 1];
|
|
401
|
-
// This function now expects TsServer.instance.getSourceFileOrThrow to handle file existence
|
|
402
|
-
// and getLineAndCharacterOfPosition to handle valid positions.
|
|
403
|
-
// Errors from these will propagate up.
|
|
404
506
|
const relativePath = relative(process.cwd(), filePath);
|
|
405
507
|
const [posStr] = positionRange.split("-");
|
|
406
508
|
const pos = parseInt(posStr, 10);
|
|
407
|
-
if (isNaN(pos))
|
|
408
|
-
// If pos is not a number, fallback to simpler formatting
|
|
509
|
+
if (isNaN(pos))
|
|
409
510
|
return `${relativePath}:${positionRange}`;
|
|
410
|
-
}
|
|
411
511
|
const sourceFile = TsServer.instance.getSourceFileOrThrow(filePath);
|
|
412
512
|
const lineAndChar = sourceFile.getLineAndCharacterOfPosition(pos);
|
|
413
513
|
return `${relativePath}:${lineAndChar.line + 1}:${lineAndChar.character + 1}`;
|
|
@@ -418,7 +518,7 @@ const findMostSpecificNodeInRange = (file, start, end) => {
|
|
|
418
518
|
if (nodesInRange.length === 0)
|
|
419
519
|
return undefined;
|
|
420
520
|
const leafNodes = nodesInRange.filter(node => !nodesInRange.some(other => other !== node && other.pos >= node.pos && other.end <= node.end));
|
|
421
|
-
return findNodeByPreference(leafNodes.length > 0 ? leafNodes : nodesInRange);
|
|
521
|
+
return findNodeByPreference(leafNodes.length > 0 ? leafNodes : nodesInRange);
|
|
422
522
|
};
|
|
423
523
|
const findNodeByPreference = (nodes) => {
|
|
424
524
|
if (nodes.length === 0)
|
|
@@ -442,7 +542,7 @@ const findNodeByPreference = (nodes) => {
|
|
|
442
542
|
const expression = nodes.find(node => ts.isExpressionStatement(node) || ts.isExpression(node));
|
|
443
543
|
if (expression)
|
|
444
544
|
return expression;
|
|
445
|
-
return nodes.sort((a, b) => a.end - a.pos - (b.end - b.pos))[0];
|
|
545
|
+
return nodes.sort((a, b) => a.end - a.pos - (b.end - b.pos))[0];
|
|
446
546
|
};
|
|
447
547
|
const writeToCsv = (filePath, headers, rows) => {
|
|
448
548
|
const content = [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ark/attest",
|
|
3
|
-
"version": "0.48.
|
|
3
|
+
"version": "0.48.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "David Blass",
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
"@typescript/analyze-trace": "0.10.1",
|
|
37
37
|
"@typescript/vfs": "1.6.1",
|
|
38
38
|
"prettier": "3.5.3",
|
|
39
|
-
"
|
|
39
|
+
"arktype": "2.1.20",
|
|
40
40
|
"@ark/util": "0.46.0",
|
|
41
|
-
"
|
|
41
|
+
"@ark/fs": "0.46.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"typescript": "5.8.2"
|