Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

Revert "feat(tracing): throttle trace event writes (#21694)" (#21718)

Dmitry Gozman2518bfa8d35a
diff --git a/packages/playwright-core/src/server/trace/recorder/tracing.ts b/packages/playwright-core/src/server/trace/recorder/tracing.ts
index 285e366c93..37fe87836f 100644
--- a/packages/playwright-core/src/server/trace/recorder/tracing.ts
+++ b/packages/playwright-core/src/server/trace/recorder/tracing.ts
@@ -61,9 +61,7 @@ type RecordingState = {
filesCount: number,
networkSha1s: Set<string>,
traceSha1s: Set<string>,
- recording: boolean,
- pendingTraceEvents: trace.TraceEvent[],
- flushPendingTraceEventsTimer: NodeJS.Timer | undefined,
+ recording: boolean;
};
const kScreencastOptions = { width: 800, height: 600, quality: 90 };
@@ -134,7 +132,7 @@ export class Tracing extends SdkObject implements InstrumentationListener, Snaps
// and conflict.
const traceName = options.name || createGuid();
// Init the state synchronously.
- this._state = { options, traceName, traceFile: '', networkFile: '', tracesDir: '', resourcesDir: '', filesCount: 0, traceSha1s: new Set(), networkSha1s: new Set(), recording: false, pendingTraceEvents: [], flushPendingTraceEventsTimer: undefined };
+ this._state = { options, traceName, traceFile: '', networkFile: '', tracesDir: '', resourcesDir: '', filesCount: 0, traceSha1s: new Set(), networkSha1s: new Set(), recording: false };
const state = this._state;
state.tracesDir = await this._createTracesDirIfNeeded();
@@ -160,7 +158,6 @@ export class Tracing extends SdkObject implements InstrumentationListener, Snaps
state.filesCount++;
state.traceFile = path.join(state.tracesDir, `${state.traceName}${suffix}.trace`);
state.recording = true;
- state.flushPendingTraceEventsTimer = setInterval(() => this._flushTraceEvents(state), 100);
if (options.name && options.name !== this._state.traceName)
this._changeTraceName(this._state, options.name);
@@ -231,8 +228,6 @@ export class Tracing extends SdkObject implements InstrumentationListener, Snaps
async dispose() {
this._snapshotter?.dispose();
this._harTracer.stop();
- if (this._state?.flushPendingTraceEventsTimer)
- clearInterval(this._state.flushPendingTraceEventsTimer);
await this._writeChain;
}
@@ -256,9 +251,6 @@ export class Tracing extends SdkObject implements InstrumentationListener, Snaps
if (state.options.snapshots)
await this._snapshotter?.stop();
- clearInterval(state.flushPendingTraceEventsTimer);
- this._flushTraceEvents(state);
-
// Chain the export operation against write operations,
// so that neither trace files nor sha1s change during the export.
return await this._appendTraceOperation(async () => {
@@ -413,16 +405,9 @@ export class Tracing extends SdkObject implements InstrumentationListener, Snaps
}
private _appendTraceEvent(event: trace.TraceEvent) {
- this._state!.pendingTraceEvents.push(event);
- }
-
- private _flushTraceEvents(state: RecordingState) {
- if (!state.pendingTraceEvents.length)
- return;
- const lines = state.pendingTraceEvents.map(event => JSON.stringify(visitTraceEvent(event, state.traceSha1s)) + '\n');
- state.pendingTraceEvents = [];
this._appendTraceOperation(async () => {
- await fs.promises.appendFile(state.traceFile, lines.join(''));
+ const visited = visitTraceEvent(event, this._state!.traceSha1s);
+ await fs.promises.appendFile(this._state!.traceFile, JSON.stringify(visited) + '\n');
});
}