mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
chore(trace): dedupe filenames, not stack frames (#21160)
This commit is contained in:
parent
0e93f1d511
commit
b61036d22a
@ -14,28 +14,26 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { ClientSideCallMetadata, StackFrame } from '@protocol/channels';
|
import type { ClientSideCallMetadata } from '@protocol/channels';
|
||||||
import type { SerializedClientSideCallMetadata } from '@trace/traceUtils';
|
import type { SerializedClientSideCallMetadata, SerializedStack, SerializedStackFrame } from '@trace/traceUtils';
|
||||||
|
|
||||||
export function serializeClientSideCallMetadata(metadatas: ClientSideCallMetadata[]): SerializedClientSideCallMetadata {
|
export function serializeClientSideCallMetadata(metadatas: ClientSideCallMetadata[]): SerializedClientSideCallMetadata {
|
||||||
const stackFrames = new Map<string, number>();
|
const fileNames = new Map<string, number>();
|
||||||
const frames: StackFrame[] = [];
|
const stacks: SerializedStack[] = [];
|
||||||
const stacks: [number, number[]][] = [];
|
|
||||||
for (const m of metadatas) {
|
for (const m of metadatas) {
|
||||||
if (!m.stack || !m.stack.length)
|
if (!m.stack || !m.stack.length)
|
||||||
continue;
|
continue;
|
||||||
const stack: number[] = [];
|
const stack: SerializedStackFrame[] = [];
|
||||||
for (const frame of m.stack) {
|
for (const frame of m.stack) {
|
||||||
const key = `${frame.file}:${frame.line || 0}:${frame.column || 0}`;
|
let ordinal = fileNames.get(frame.file);
|
||||||
let ordinal = stackFrames.get(key);
|
|
||||||
if (typeof ordinal !== 'number') {
|
if (typeof ordinal !== 'number') {
|
||||||
ordinal = stackFrames.size;
|
ordinal = fileNames.size;
|
||||||
stackFrames.set(key, ordinal);
|
fileNames.set(frame.file, ordinal);
|
||||||
frames.push(frame);
|
|
||||||
}
|
}
|
||||||
stack.push(ordinal);
|
const stackFrame: SerializedStackFrame = [ordinal, frame.line || 0, frame.column || 0, frame.function || ''];
|
||||||
|
stack.push(stackFrame);
|
||||||
}
|
}
|
||||||
stacks.push([m.id, stack]);
|
stacks.push([m.id, stack]);
|
||||||
}
|
}
|
||||||
return { frames, stacks };
|
return { files: [...fileNames.keys()], stacks };
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,17 +16,20 @@
|
|||||||
|
|
||||||
import type { StackFrame } from '@protocol/channels';
|
import type { StackFrame } from '@protocol/channels';
|
||||||
|
|
||||||
|
export type SerializedStackFrame = [number, number, number, string];
|
||||||
|
export type SerializedStack = [number, SerializedStackFrame[]];
|
||||||
|
|
||||||
export type SerializedClientSideCallMetadata = {
|
export type SerializedClientSideCallMetadata = {
|
||||||
frames: StackFrame[];
|
files: string[];
|
||||||
stacks: [number, number[]][];
|
stacks: SerializedStack[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export function parseClientSideCallMetadata(data: SerializedClientSideCallMetadata): Map<string, StackFrame[]> {
|
export function parseClientSideCallMetadata(data: SerializedClientSideCallMetadata): Map<string, StackFrame[]> {
|
||||||
const result = new Map<string, StackFrame[]>();
|
const result = new Map<string, StackFrame[]>();
|
||||||
const { frames, stacks } = data;
|
const { files, stacks } = data;
|
||||||
for (const s of stacks) {
|
for (const s of stacks) {
|
||||||
const [id, ff] = s;
|
const [id, ff] = s;
|
||||||
result.set(`call@${id}`, ff.map((f: number) => frames[f]));
|
result.set(`call@${id}`, ff.map(f => ({ file: files[f[0]], line: f[1], column: f[2], function: f[3] })));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user