devtools-tracing 1.2.2 → 1.3.0
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/.vscode/launch.json +20 -0
- package/README.md +57 -2
- package/dist/index.d.ts +4 -1
- package/dist/index.js +76804 -18793
- package/dist/lib/front_end/third_party/codemirror.next/bundle.d.ts +39 -0
- package/dist/src/sourcemap.d.ts +27 -0
- package/examples/sourcemap.ts +121 -0
- package/package.json +2 -1
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export { acceptCompletion, autocompletion, closeBrackets, closeBracketsKeymap, closeCompletion, completeAnyWord, Completion, CompletionContext, CompletionResult, CompletionSource, completionStatus, currentCompletions, ifNotIn, moveCompletionSelection, selectedCompletion, selectedCompletionIndex, startCompletion } from '@codemirror/autocomplete';
|
|
2
|
+
export { cursorMatchingBracket, cursorGroupLeft, cursorGroupRight, cursorSyntaxLeft, cursorSyntaxRight, history, historyKeymap, indentLess, indentMore, insertNewlineAndIndent, redo, redoSelection, selectMatchingBracket, selectGroupLeft, selectGroupRight, selectSyntaxLeft, selectSyntaxRight, standardKeymap, toggleComment, undo, undoSelection } from '@codemirror/commands';
|
|
3
|
+
export * as html from '@codemirror/lang-html';
|
|
4
|
+
export * as javascript from '@codemirror/lang-javascript';
|
|
5
|
+
export { bracketMatching, codeFolding, bidiIsolates, ensureSyntaxTree, foldGutter, foldKeymap, HighlightStyle, indentOnInput, indentUnit, Language, LanguageSupport, StreamLanguage, StreamParser, StringStream, syntaxHighlighting, syntaxTree, TagStyle, syntaxParserRunning, forceParsing } from '@codemirror/language';
|
|
6
|
+
export { highlightSelectionMatches, selectNextOccurrence } from '@codemirror/search';
|
|
7
|
+
export { Annotation, AnnotationType, ChangeDesc, ChangeSet, ChangeSpec, Compartment, EditorSelection, EditorState, EditorStateConfig, Extension, Facet, Line, MapMode, Prec, Range, RangeSet, RangeSetBuilder, SelectionRange, StateEffect, StateEffectType, StateField, Text, TextIterator, Transaction, TransactionSpec } from '@codemirror/state';
|
|
8
|
+
export { Command, Decoration, DecorationSet, drawSelection, EditorView, gutter, GutterMarker, gutters, highlightSpecialChars, KeyBinding, keymap, lineNumberMarkers, lineNumbers, MatchDecorator, Panel, placeholder, repositionTooltips, scrollPastEnd, showPanel, showTooltip, Tooltip, tooltips, TooltipView, ViewPlugin, ViewUpdate, WidgetType } from '@codemirror/view';
|
|
9
|
+
export { NodeProp, NodeSet, NodeType, Parser, SyntaxNode, Tree, TreeCursor } from '@lezer/common';
|
|
10
|
+
export { highlightTree, Tag, tags } from '@lezer/highlight';
|
|
11
|
+
export { LRParser } from '@lezer/lr';
|
|
12
|
+
export { StyleModule } from 'style-mod';
|
|
13
|
+
export { indentationMarkers } from '@replit/codemirror-indentation-markers';
|
|
14
|
+
export declare function angular(): Promise<any>;
|
|
15
|
+
export declare function clojure(): Promise<any>;
|
|
16
|
+
export declare function coffeescript(): Promise<any>;
|
|
17
|
+
export declare function cpp(): Promise<any>;
|
|
18
|
+
export declare const css: {
|
|
19
|
+
cssCompletionSource: any;
|
|
20
|
+
cssLanguage: any;
|
|
21
|
+
css(): any;
|
|
22
|
+
};
|
|
23
|
+
export declare function dart(): Promise<any>;
|
|
24
|
+
export declare function gss(): Promise<any>;
|
|
25
|
+
export declare function go(): Promise<any>;
|
|
26
|
+
export declare function java(): Promise<any>;
|
|
27
|
+
export declare function kotlin(): Promise<any>;
|
|
28
|
+
export declare function less(): Promise<any>;
|
|
29
|
+
export declare function markdown(): Promise<any>;
|
|
30
|
+
export declare function php(): Promise<any>;
|
|
31
|
+
export declare function python(): Promise<any>;
|
|
32
|
+
export declare function sass(): Promise<any>;
|
|
33
|
+
export declare function scala(): Promise<any>;
|
|
34
|
+
export declare function shell(): Promise<any>;
|
|
35
|
+
export declare function svelte(): Promise<any>;
|
|
36
|
+
export declare function cssStreamParser(): Promise<any>;
|
|
37
|
+
export declare function vue(): Promise<any>;
|
|
38
|
+
export declare function wast(): Promise<any>;
|
|
39
|
+
export declare function xml(): Promise<any>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as Trace from '../lib/front_end/models/trace/trace.js';
|
|
2
|
+
type Event = Trace.Types.Events.Event;
|
|
3
|
+
type Script = Trace.Handlers.ModelHandlers.Scripts.Script;
|
|
4
|
+
export interface SourceMapResolverOptions {
|
|
5
|
+
fetch?: (url: string) => Promise<Response>;
|
|
6
|
+
}
|
|
7
|
+
export declare function createSourceMapResolver(options?: SourceMapResolverOptions): NonNullable<Trace.Types.Configuration.ParseOptions['resolveSourceMap']>;
|
|
8
|
+
export interface SymbolicateResult {
|
|
9
|
+
/** Number of individual CallFrames that were rewritten. */
|
|
10
|
+
symbolicatedFrames: number;
|
|
11
|
+
/** Number of trace events that contained at least one rewritten frame. */
|
|
12
|
+
symbolicatedEvents: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Symbolicate trace events in-place by rewriting CallFrame locations using
|
|
16
|
+
* resolved source maps. Call this after `traceModel.parse()` has resolved
|
|
17
|
+
* source maps via `resolveSourceMap`.
|
|
18
|
+
*
|
|
19
|
+
* @param traceEvents - The raw trace events array (mutated in-place).
|
|
20
|
+
* @param scripts - The parsed scripts from `parsedTrace.data.Scripts.scripts`.
|
|
21
|
+
*/
|
|
22
|
+
export interface SymbolicateOptions {
|
|
23
|
+
/** Rewrite the resolved source URL after symbolication. Line and column are 0-based. */
|
|
24
|
+
rewriteSourceUrl?: (url: string, lineNumber: number, columnNumber: number) => string;
|
|
25
|
+
}
|
|
26
|
+
export declare function symbolicateTrace(traceEvents: readonly Event[], scripts: readonly Script[], options?: SymbolicateOptions): SymbolicateResult;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as zlib from 'node:zlib';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
initDevToolsTracing,
|
|
6
|
+
createSourceMapResolver,
|
|
7
|
+
symbolicateTrace,
|
|
8
|
+
Trace,
|
|
9
|
+
} from '../';
|
|
10
|
+
|
|
11
|
+
async function main() {
|
|
12
|
+
const tracePath = process.argv[2];
|
|
13
|
+
if (!tracePath) {
|
|
14
|
+
console.error('Usage: npm run example:sourcemap <path-to-trace-file>');
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
initDevToolsTracing();
|
|
18
|
+
|
|
19
|
+
const fileData = fs.readFileSync(tracePath);
|
|
20
|
+
const decompressedData = tracePath.endsWith('.gz')
|
|
21
|
+
? zlib.gunzipSync(fileData)
|
|
22
|
+
: fileData;
|
|
23
|
+
const traceData = JSON.parse(
|
|
24
|
+
decompressedData.toString(),
|
|
25
|
+
) as Trace.Types.File.TraceFile;
|
|
26
|
+
|
|
27
|
+
const traceModel = Trace.TraceModel.Model.createWithAllHandlers();
|
|
28
|
+
const resolveSourceMap = createSourceMapResolver({
|
|
29
|
+
fetch: verboseFetch,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
await traceModel.parse(traceData.traceEvents, {
|
|
33
|
+
isCPUProfile: false,
|
|
34
|
+
isFreshRecording: false,
|
|
35
|
+
metadata: traceData.metadata,
|
|
36
|
+
showAllEvents: false,
|
|
37
|
+
resolveSourceMap,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const parsedTrace = traceModel.parsedTrace(0)!;
|
|
41
|
+
const parsedTraceData = parsedTrace.data;
|
|
42
|
+
const scripts = parsedTraceData.Scripts.scripts;
|
|
43
|
+
|
|
44
|
+
const metadataSourceMaps = traceData.metadata?.sourceMaps?.length ?? 0;
|
|
45
|
+
console.log(`Found ${scripts.length} scripts in trace`);
|
|
46
|
+
console.log(`Source maps in trace metadata: ${metadataSourceMaps}\n`);
|
|
47
|
+
|
|
48
|
+
// Diagnostic: show script properties to explain resolution results.
|
|
49
|
+
let withUrl = 0;
|
|
50
|
+
let withFrame = 0;
|
|
51
|
+
let withSourceMapUrl = 0;
|
|
52
|
+
let withElided = 0;
|
|
53
|
+
for (const script of scripts) {
|
|
54
|
+
if (script.url) withUrl++;
|
|
55
|
+
if (script.frame) withFrame++;
|
|
56
|
+
if (script.sourceMapUrl) withSourceMapUrl++;
|
|
57
|
+
if (script.sourceMapUrlElided) withElided++;
|
|
58
|
+
}
|
|
59
|
+
console.log('Script breakdown:');
|
|
60
|
+
console.log(` with url: ${withUrl}`);
|
|
61
|
+
console.log(` with frame: ${withFrame}`);
|
|
62
|
+
console.log(` with sourceMapUrl: ${withSourceMapUrl}`);
|
|
63
|
+
console.log(` with sourceMapUrlElided: ${withElided}`);
|
|
64
|
+
console.log(` (resolution requires url + frame + sourceMapUrl/elided)\n`);
|
|
65
|
+
|
|
66
|
+
let resolvedCount = 0;
|
|
67
|
+
for (const script of scripts) {
|
|
68
|
+
if (!script.sourceMap) {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
resolvedCount++;
|
|
72
|
+
|
|
73
|
+
const sourceMap = script.sourceMap;
|
|
74
|
+
const sourceURLs = sourceMap.sourceURLs();
|
|
75
|
+
|
|
76
|
+
console.log(
|
|
77
|
+
` ${script.url || script.scriptId} -> ${sourceURLs.length} sources, ${sourceMap.mappings().length} mappings`,
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
console.log(
|
|
82
|
+
`Resolved source maps for ${resolvedCount} of ${scripts.length} scripts\n`,
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
// Symbolicate the raw trace events in-place using resolved source maps.
|
|
86
|
+
const result = symbolicateTrace(traceData.traceEvents, scripts);
|
|
87
|
+
console.log(
|
|
88
|
+
`Symbolicated ${result.symbolicatedFrames} frames across ${result.symbolicatedEvents} events`,
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
// Write the symbolicated trace to a new file.
|
|
92
|
+
const outPath = tracePath.replace(/(\.(json|json\.gz))$/i, '.symbolicated$1');
|
|
93
|
+
if (outPath === tracePath) {
|
|
94
|
+
console.error(
|
|
95
|
+
'Could not determine output path (expected .json or .json.gz extension)',
|
|
96
|
+
);
|
|
97
|
+
process.exit(1);
|
|
98
|
+
}
|
|
99
|
+
const outputJson = JSON.stringify(traceData);
|
|
100
|
+
if (outPath.endsWith('.gz')) {
|
|
101
|
+
fs.writeFileSync(outPath, zlib.gzipSync(outputJson));
|
|
102
|
+
} else {
|
|
103
|
+
fs.writeFileSync(outPath, outputJson);
|
|
104
|
+
}
|
|
105
|
+
console.log(`Wrote symbolicated trace to ${outPath}`);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async function verboseFetch(url: string): Promise<Response> {
|
|
109
|
+
console.log(`[sourcemap] fetching ${url}`);
|
|
110
|
+
const response = await fetch(url);
|
|
111
|
+
if (!response.ok) {
|
|
112
|
+
console.warn(
|
|
113
|
+
`[sourcemap] ${url} -> ${response.status} ${response.statusText}`,
|
|
114
|
+
);
|
|
115
|
+
} else {
|
|
116
|
+
console.log(`[sourcemap] ${url} -> ok`);
|
|
117
|
+
}
|
|
118
|
+
return response;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
main();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "devtools-tracing",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Utilities for working with trace files",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
"build": "tsc --emitDeclarationOnly || true; esbuild index.ts --bundle --platform=node --outfile=dist/index.js --format=cjs",
|
|
9
9
|
"generate": "tsx generate.ts",
|
|
10
10
|
"example:inp": "tsx examples/inp.ts",
|
|
11
|
+
"example:sourcemap": "tsx examples/sourcemap.ts",
|
|
11
12
|
"example:stats": "tsx examples/stats.ts",
|
|
12
13
|
"size": "du -sh dist/",
|
|
13
14
|
"prepublishOnly": "npm run generate && npm run build"
|