@ark/attest 0.43.0 ā 0.43.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 +161 -72
- package/package.json +4 -4
package/out/cli/trace.js
CHANGED
|
@@ -117,12 +117,11 @@ const processCallExpression = (callExpr, entry, pos, end, ctx) => {
|
|
|
117
117
|
// Use the function name for both ID and display name
|
|
118
118
|
// This will ensure all calls to the same function are grouped together
|
|
119
119
|
const typeId = `function-${functionName}`;
|
|
120
|
-
const typeName = functionName;
|
|
121
120
|
const callSite = `${entry.args.path}:${pos}-${end}`;
|
|
122
121
|
ctx.callRanges.push({
|
|
123
122
|
id: `${entry.ts}-${pos}-${end}`,
|
|
124
123
|
typeId,
|
|
125
|
-
|
|
124
|
+
functionName,
|
|
126
125
|
callSite,
|
|
127
126
|
startTime: entry.ts,
|
|
128
127
|
endTime: entry.ts + (entry.dur || 0),
|
|
@@ -143,7 +142,7 @@ const processNonCallNode = (sourceFile, entry, pos, end, ctx) => {
|
|
|
143
142
|
ctx.callRanges.push({
|
|
144
143
|
id: `${entry.ts}-${pos}-${end}`,
|
|
145
144
|
typeId,
|
|
146
|
-
typeName,
|
|
145
|
+
functionName: typeName,
|
|
147
146
|
callSite,
|
|
148
147
|
startTime: entry.ts,
|
|
149
148
|
endTime: entry.ts + (entry.dur || 0),
|
|
@@ -198,8 +197,7 @@ const collectFunctionStats = (call, ctx) => {
|
|
|
198
197
|
if (!ctx.functionStats[call.typeId]) {
|
|
199
198
|
ctx.functionStats[call.typeId] = {
|
|
200
199
|
typeId: call.typeId,
|
|
201
|
-
|
|
202
|
-
callSites: new Set(),
|
|
200
|
+
functionName: call.functionName,
|
|
203
201
|
totalTime: 0,
|
|
204
202
|
selfTime: 0,
|
|
205
203
|
count: 0,
|
|
@@ -211,7 +209,6 @@ const collectFunctionStats = (call, ctx) => {
|
|
|
211
209
|
// Track detailed call site information
|
|
212
210
|
addCallSiteToStats(call, stats);
|
|
213
211
|
// Update aggregate metrics
|
|
214
|
-
stats.callSites.add(call.callSite);
|
|
215
212
|
stats.totalTime += call.duration;
|
|
216
213
|
stats.selfTime += call.selfTime;
|
|
217
214
|
stats.count++;
|
|
@@ -236,58 +233,149 @@ const sortAndRankFunctions = (ctx) => {
|
|
|
236
233
|
// Sort functions by self-time
|
|
237
234
|
ctx.allFunctions = Object.values(ctx.functionStats).sort((a, b) => b.selfTime - a.selfTime);
|
|
238
235
|
};
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
236
|
+
const analyzeTypeInstantiations = (traceDir) => {
|
|
237
|
+
// Initialize the analysis context
|
|
238
|
+
const ctx = initializeAnalysisContext(traceDir);
|
|
239
|
+
// Filter entries with duration information
|
|
240
|
+
filterDurationEntries(ctx);
|
|
241
|
+
// Process each duration entry to extract call ranges
|
|
242
|
+
ctx.durationEntries.forEach(entry => processDurationEntry(entry, ctx));
|
|
243
|
+
// Build call tree from ranges
|
|
244
|
+
buildCallTree(ctx);
|
|
245
|
+
// Calculate self-time for each call
|
|
246
|
+
ctx.rootCalls.forEach(calculateSelfTimes);
|
|
247
|
+
// Collect statistics by view type
|
|
248
|
+
const ungroupedStats = collectUngroupedStats(ctx);
|
|
249
|
+
ctx.rootCalls.forEach(call => collectFunctionStats(call, ctx));
|
|
250
|
+
// Sort and rank functions
|
|
251
|
+
sortAndRankFunctions(ctx);
|
|
252
|
+
// Display summaries to console
|
|
253
|
+
console.log("\nš Performance Analysis - Top Individual Calls:\n");
|
|
254
|
+
displayIndividualSummary(ungroupedStats);
|
|
255
|
+
console.log("\nš Performance Analysis - Functions by Self Time:\n");
|
|
256
|
+
displayGroupedSummary(ctx.allFunctions);
|
|
257
|
+
// Write CSV reports
|
|
258
|
+
const rangesCsvPath = join(traceDir, "ranges.csv");
|
|
259
|
+
const namesCsvPath = join(traceDir, "names.csv");
|
|
260
|
+
// Export individual ranges to CSV
|
|
261
|
+
writeToCsv(rangesCsvPath, ["Function Name", "Self (ms)", "Duration (ms)", "Location"], ungroupedStats.map(stat => [
|
|
262
|
+
stat.functionName,
|
|
263
|
+
(stat.selfTime / 1000).toFixed(3),
|
|
264
|
+
(stat.duration / 1000).toFixed(3),
|
|
265
|
+
formatLocation(stat.callSite)
|
|
266
|
+
]));
|
|
267
|
+
// Export grouped functions to CSV
|
|
268
|
+
writeToCsv(namesCsvPath, [
|
|
269
|
+
"Function Name",
|
|
270
|
+
"Total Self (ms)",
|
|
271
|
+
"Avg Self (ms)",
|
|
272
|
+
"Call Count",
|
|
273
|
+
"Top Location",
|
|
274
|
+
"Top Self (ms)"
|
|
275
|
+
], ctx.allFunctions.map(stats => {
|
|
276
|
+
const topUsage = stats.detailedCallSites[0] || {
|
|
277
|
+
path: "unknown",
|
|
278
|
+
pos: 0,
|
|
279
|
+
end: 0,
|
|
280
|
+
selfTime: 0
|
|
281
|
+
};
|
|
282
|
+
return [
|
|
283
|
+
stats.functionName,
|
|
284
|
+
(stats.selfTime / 1000).toFixed(3),
|
|
285
|
+
(stats.selfTime / stats.count / 1000).toFixed(3),
|
|
286
|
+
stats.count.toString(),
|
|
287
|
+
formatLocation(`${topUsage.path}:${topUsage.pos}-${topUsage.end}`),
|
|
288
|
+
(topUsage.selfTime / 1000).toFixed(3)
|
|
289
|
+
];
|
|
290
|
+
}));
|
|
291
|
+
console.log(`\nā
Analysis complete! Results exported to:\n` +
|
|
292
|
+
` - ${rangesCsvPath} (individual calls)\n` +
|
|
293
|
+
` - ${namesCsvPath} (grouped by function name)`);
|
|
245
294
|
};
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
const
|
|
251
|
-
//
|
|
252
|
-
const
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
295
|
+
/**
|
|
296
|
+
* Collect statistics for individual (ungrouped) calls
|
|
297
|
+
*/
|
|
298
|
+
const collectUngroupedStats = (ctx) => {
|
|
299
|
+
const ungroupedStats = [];
|
|
300
|
+
// Flatten the call tree into individual entries
|
|
301
|
+
const flattenCallTree = (call) => {
|
|
302
|
+
ungroupedStats.push({
|
|
303
|
+
typeId: call.typeId,
|
|
304
|
+
functionName: call.functionName,
|
|
305
|
+
callSite: call.callSite,
|
|
306
|
+
duration: call.duration,
|
|
307
|
+
selfTime: call.selfTime
|
|
308
|
+
});
|
|
309
|
+
call.children.forEach(flattenCallTree);
|
|
257
310
|
};
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
311
|
+
ctx.rootCalls.forEach(flattenCallTree);
|
|
312
|
+
// Sort by self time in descending order
|
|
313
|
+
return ungroupedStats.sort((a, b) => b.selfTime - a.selfTime);
|
|
261
314
|
};
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
315
|
+
/**
|
|
316
|
+
* Display a summary of individual calls
|
|
317
|
+
*/
|
|
318
|
+
const displayIndividualSummary = (stats) => {
|
|
319
|
+
displayTableHeader(["Rank", "Function Name", "Self (ms)", "Location"]);
|
|
320
|
+
const top20 = stats.slice(0, 20);
|
|
321
|
+
top20.forEach((stat, index) => {
|
|
322
|
+
const typeNameFormatted = formatTypeName(stat.functionName, 20);
|
|
323
|
+
const selfTimeMs = (stat.selfTime / 1000).toFixed(2).padStart(15);
|
|
324
|
+
const location = formatLocation(stat.callSite);
|
|
325
|
+
console.log(`${(index + 1).toString().padStart(4)} | ${typeNameFormatted} | ${selfTimeMs} | ${location}`);
|
|
268
326
|
});
|
|
269
|
-
// Write to file
|
|
270
|
-
writeFile(outputPath, outputContent);
|
|
271
|
-
console.log(`\nā
Analysis complete! A more detailed breakdown is available at ${outputPath}`);
|
|
272
327
|
};
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
const
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
328
|
+
/**
|
|
329
|
+
* Display a summary table header with aligned columns
|
|
330
|
+
*/
|
|
331
|
+
const displayTableHeader = (columns) => {
|
|
332
|
+
// Create header row with standard column widths
|
|
333
|
+
const headerRow = [
|
|
334
|
+
columns[0].padEnd(4),
|
|
335
|
+
columns[1].padEnd(20),
|
|
336
|
+
columns[2].padEnd(15),
|
|
337
|
+
...columns.slice(3)
|
|
338
|
+
].join(" | ");
|
|
339
|
+
// Create separator line matching the header column widths
|
|
340
|
+
const separatorRow = [
|
|
341
|
+
"----",
|
|
342
|
+
"--------------------",
|
|
343
|
+
"---------------",
|
|
344
|
+
...columns.slice(3).map(col => "-".repeat(col.length))
|
|
345
|
+
].join("-|-");
|
|
346
|
+
console.log(headerRow);
|
|
347
|
+
console.log(separatorRow);
|
|
348
|
+
};
|
|
349
|
+
/**
|
|
350
|
+
* Display a combined summary of grouped functions showing both total and average times
|
|
351
|
+
*/
|
|
352
|
+
const displayGroupedSummary = (functions) => {
|
|
353
|
+
displayTableHeader([
|
|
354
|
+
"Rank",
|
|
355
|
+
"Function Name",
|
|
356
|
+
"Total Self (ms)",
|
|
357
|
+
"Avg Self (ms)",
|
|
358
|
+
"Calls",
|
|
359
|
+
"Top Usage"
|
|
360
|
+
]);
|
|
361
|
+
functions.slice(0, 20).forEach((stats, index) => {
|
|
362
|
+
const typeNameFormatted = formatTypeName(stats.functionName, 20);
|
|
363
|
+
const totalTimeMs = (stats.selfTime / 1000).toFixed(2).padStart(15);
|
|
364
|
+
const avgTimeMs = (stats.selfTime / stats.count / 1000)
|
|
365
|
+
.toFixed(2)
|
|
366
|
+
.padStart(13);
|
|
367
|
+
const calls = stats.count.toString().padStart(5);
|
|
368
|
+
// Get details about top usage site
|
|
369
|
+
const topUsage = stats.detailedCallSites[0] || {
|
|
370
|
+
path: "unknown",
|
|
371
|
+
pos: 0,
|
|
372
|
+
end: 0,
|
|
373
|
+
selfTime: 0
|
|
374
|
+
};
|
|
375
|
+
const topUsageTime = (topUsage.selfTime / 1000).toFixed(2) + "ms";
|
|
376
|
+
const topUsageLocation = formatLocation(`${topUsage.path}:${topUsage.pos}-${topUsage.end}`);
|
|
377
|
+
console.log(`${(index + 1).toString().padStart(4)} | ${typeNameFormatted} | ${totalTimeMs} | ${avgTimeMs} | ${calls} | ${topUsageLocation} (${topUsageTime})`);
|
|
378
|
+
});
|
|
291
379
|
};
|
|
292
380
|
/**
|
|
293
381
|
* Format a type name for display, ensuring the most identifiable parts are preserved
|
|
@@ -370,23 +458,24 @@ const findNodeByPreference = (nodes) => {
|
|
|
370
458
|
// Default: first node
|
|
371
459
|
return nodes[0];
|
|
372
460
|
};
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
461
|
+
/**
|
|
462
|
+
* Write data to a CSV file
|
|
463
|
+
*/
|
|
464
|
+
const writeToCsv = (filePath, headers, rows) => {
|
|
465
|
+
const content = [
|
|
466
|
+
headers.join(","),
|
|
467
|
+
...rows.map(row => row.map(escapeForCsv).join(","))
|
|
468
|
+
].join("\n");
|
|
469
|
+
writeFile(filePath, content);
|
|
470
|
+
};
|
|
471
|
+
/**
|
|
472
|
+
* Escape string for CSV format
|
|
473
|
+
*/
|
|
474
|
+
const escapeForCsv = (value) => {
|
|
475
|
+
if (value.includes(",") || value.includes('"') || value.includes("\n")) {
|
|
476
|
+
// If the value contains commas, double quotes, or newlines, wrap it in quotes
|
|
477
|
+
// and escape any double quotes by doubling them
|
|
478
|
+
return `"${value.replace(/"/g, '""')}"`;
|
|
479
|
+
}
|
|
480
|
+
return value;
|
|
392
481
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ark/attest",
|
|
3
|
-
"version": "0.43.
|
|
3
|
+
"version": "0.43.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.0",
|
|
38
38
|
"prettier": "3.4.2",
|
|
39
|
-
"@ark/
|
|
40
|
-
"
|
|
41
|
-
"
|
|
39
|
+
"@ark/fs": "0.43.2",
|
|
40
|
+
"@ark/util": "0.43.2",
|
|
41
|
+
"arktype": "2.1.2"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"typescript": "5.8.2"
|