chore(tracing): do not produce cached resources maps (#8110)
This commit is contained in:
parent
9d6c7cdf20
commit
a9e1916672
|
|
@ -14,16 +14,16 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { ContextResources, FrameSnapshot, NodeSnapshot, RenderedFrameSnapshot } from './snapshotTypes';
|
||||
import { FrameSnapshot, NodeSnapshot, RenderedFrameSnapshot, ResourceSnapshot } from './snapshotTypes';
|
||||
|
||||
export class SnapshotRenderer {
|
||||
private _snapshots: FrameSnapshot[];
|
||||
private _index: number;
|
||||
private _contextResources: ContextResources;
|
||||
readonly snapshotName: string | undefined;
|
||||
private _resources: ResourceSnapshot[];
|
||||
|
||||
constructor(contextResources: ContextResources, snapshots: FrameSnapshot[], index: number) {
|
||||
this._contextResources = contextResources;
|
||||
constructor(resources: ResourceSnapshot[], snapshots: FrameSnapshot[], index: number) {
|
||||
this._resources = resources;
|
||||
this._snapshots = snapshots;
|
||||
this._index = index;
|
||||
this.snapshotName = snapshots[index].snapshotName;
|
||||
|
|
@ -82,10 +82,19 @@ export class SnapshotRenderer {
|
|||
`;
|
||||
|
||||
const resources: { [key: string]: { resourceId: string, sha1?: string } } = {};
|
||||
for (const [url, contextResources] of this._contextResources) {
|
||||
const contextResource = contextResources.find(r => r.frameId === snapshot.frameId) || contextResources[0];
|
||||
if (contextResource)
|
||||
resources[url] = { resourceId: contextResource.resourceId };
|
||||
// First capture all resources for all frames, to account for memory cache.
|
||||
for (const resource of this._resources) {
|
||||
if (resource.timestamp >= snapshot.timestamp)
|
||||
break;
|
||||
resources[resource.url] = { resourceId: resource.resourceId };
|
||||
}
|
||||
// Then overwrite with the ones from our frame.
|
||||
for (const resource of this._resources) {
|
||||
if (resource.timestamp >= snapshot.timestamp)
|
||||
break;
|
||||
if (resource.frameId !== snapshot.frameId)
|
||||
continue;
|
||||
resources[resource.url] = { resourceId: resource.resourceId };
|
||||
}
|
||||
for (const o of snapshot.resourceOverrides) {
|
||||
const resource = resources[o.url];
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
*/
|
||||
|
||||
import { EventEmitter } from 'events';
|
||||
import { ContextResources, FrameSnapshot, ResourceSnapshot } from './snapshotTypes';
|
||||
import { FrameSnapshot, ResourceSnapshot } from './snapshotTypes';
|
||||
import { SnapshotRenderer } from './snapshotRenderer';
|
||||
|
||||
export interface SnapshotStorage {
|
||||
|
|
@ -32,26 +32,16 @@ export abstract class BaseSnapshotStorage extends EventEmitter implements Snapsh
|
|||
raw: FrameSnapshot[],
|
||||
renderer: SnapshotRenderer[]
|
||||
}>();
|
||||
protected _contextResources: ContextResources = new Map();
|
||||
private _contextResourcesCopyOnWrite: ContextResources | null = null;
|
||||
|
||||
clear() {
|
||||
this._resources = [];
|
||||
this._resourceMap.clear();
|
||||
this._frameSnapshots.clear();
|
||||
this._contextResources.clear();
|
||||
}
|
||||
|
||||
addResource(resource: ResourceSnapshot): void {
|
||||
this._contextResourcesCopyOnWrite = null;
|
||||
this._resourceMap.set(resource.resourceId, resource);
|
||||
this._resources.push(resource);
|
||||
let resources = this._contextResources.get(resource.url);
|
||||
if (!resources) {
|
||||
resources = [];
|
||||
this._contextResources.set(resource.url, resources);
|
||||
}
|
||||
resources.push({ frameId: resource.frameId, resourceId: resource.resourceId });
|
||||
}
|
||||
|
||||
addFrameSnapshot(snapshot: FrameSnapshot): void {
|
||||
|
|
@ -66,9 +56,7 @@ export abstract class BaseSnapshotStorage extends EventEmitter implements Snapsh
|
|||
this._frameSnapshots.set(snapshot.pageId, frameSnapshots);
|
||||
}
|
||||
frameSnapshots.raw.push(snapshot);
|
||||
if (!this._contextResourcesCopyOnWrite)
|
||||
this._contextResourcesCopyOnWrite = new Map(this._contextResources);
|
||||
const renderer = new SnapshotRenderer(this._contextResourcesCopyOnWrite, frameSnapshots.raw, frameSnapshots.raw.length - 1);
|
||||
const renderer = new SnapshotRenderer(this._resources, frameSnapshots.raw, frameSnapshots.raw.length - 1);
|
||||
frameSnapshots.renderer.push(renderer);
|
||||
this.emit('snapshot', renderer);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,8 +63,6 @@ export type FrameSnapshot = {
|
|||
isMainFrame: boolean,
|
||||
};
|
||||
|
||||
export type ContextResources = Map<string, { resourceId: string, frameId: string }[]>;
|
||||
|
||||
export type RenderedFrameSnapshot = {
|
||||
html: string;
|
||||
resources: { [key: string]: { resourceId: string, sha1?: string } };
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import * as trace from '../common/traceEvents';
|
||||
import { ContextResources, ResourceSnapshot } from '../../snapshot/snapshotTypes';
|
||||
import { ResourceSnapshot } from '../../snapshot/snapshotTypes';
|
||||
import { BaseSnapshotStorage } from '../../snapshot/snapshotStorage';
|
||||
import { BrowserContextOptions } from '../../types';
|
||||
import { shouldCaptureSnapshot, VERSION } from '../recorder/tracing';
|
||||
|
|
@ -26,7 +26,6 @@ export * as trace from '../common/traceEvents';
|
|||
export class TraceModel {
|
||||
contextEntry: ContextEntry;
|
||||
pageEntries = new Map<string, PageEntry>();
|
||||
contextResources = new Map<string, ContextResources>();
|
||||
private _snapshotStorage: PersistentSnapshotStorage;
|
||||
private _version: number | undefined;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue