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