This reverts commit 3f20602735.
This commit is contained in:
parent
3ceac4bf53
commit
2518bfa8d3
|
|
@ -61,9 +61,7 @@ type RecordingState = {
|
||||||
filesCount: number,
|
filesCount: number,
|
||||||
networkSha1s: Set<string>,
|
networkSha1s: Set<string>,
|
||||||
traceSha1s: Set<string>,
|
traceSha1s: Set<string>,
|
||||||
recording: boolean,
|
recording: boolean;
|
||||||
pendingTraceEvents: trace.TraceEvent[],
|
|
||||||
flushPendingTraceEventsTimer: NodeJS.Timer | undefined,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const kScreencastOptions = { width: 800, height: 600, quality: 90 };
|
const kScreencastOptions = { width: 800, height: 600, quality: 90 };
|
||||||
|
|
@ -134,7 +132,7 @@ export class Tracing extends SdkObject implements InstrumentationListener, Snaps
|
||||||
// and conflict.
|
// and conflict.
|
||||||
const traceName = options.name || createGuid();
|
const traceName = options.name || createGuid();
|
||||||
// Init the state synchronously.
|
// 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;
|
const state = this._state;
|
||||||
|
|
||||||
state.tracesDir = await this._createTracesDirIfNeeded();
|
state.tracesDir = await this._createTracesDirIfNeeded();
|
||||||
|
|
@ -160,7 +158,6 @@ export class Tracing extends SdkObject implements InstrumentationListener, Snaps
|
||||||
state.filesCount++;
|
state.filesCount++;
|
||||||
state.traceFile = path.join(state.tracesDir, `${state.traceName}${suffix}.trace`);
|
state.traceFile = path.join(state.tracesDir, `${state.traceName}${suffix}.trace`);
|
||||||
state.recording = true;
|
state.recording = true;
|
||||||
state.flushPendingTraceEventsTimer = setInterval(() => this._flushTraceEvents(state), 100);
|
|
||||||
|
|
||||||
if (options.name && options.name !== this._state.traceName)
|
if (options.name && options.name !== this._state.traceName)
|
||||||
this._changeTraceName(this._state, options.name);
|
this._changeTraceName(this._state, options.name);
|
||||||
|
|
@ -231,8 +228,6 @@ export class Tracing extends SdkObject implements InstrumentationListener, Snaps
|
||||||
async dispose() {
|
async dispose() {
|
||||||
this._snapshotter?.dispose();
|
this._snapshotter?.dispose();
|
||||||
this._harTracer.stop();
|
this._harTracer.stop();
|
||||||
if (this._state?.flushPendingTraceEventsTimer)
|
|
||||||
clearInterval(this._state.flushPendingTraceEventsTimer);
|
|
||||||
await this._writeChain;
|
await this._writeChain;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -256,9 +251,6 @@ export class Tracing extends SdkObject implements InstrumentationListener, Snaps
|
||||||
if (state.options.snapshots)
|
if (state.options.snapshots)
|
||||||
await this._snapshotter?.stop();
|
await this._snapshotter?.stop();
|
||||||
|
|
||||||
clearInterval(state.flushPendingTraceEventsTimer);
|
|
||||||
this._flushTraceEvents(state);
|
|
||||||
|
|
||||||
// Chain the export operation against write operations,
|
// Chain the export operation against write operations,
|
||||||
// so that neither trace files nor sha1s change during the export.
|
// so that neither trace files nor sha1s change during the export.
|
||||||
return await this._appendTraceOperation(async () => {
|
return await this._appendTraceOperation(async () => {
|
||||||
|
|
@ -413,16 +405,9 @@ export class Tracing extends SdkObject implements InstrumentationListener, Snaps
|
||||||
}
|
}
|
||||||
|
|
||||||
private _appendTraceEvent(event: trace.TraceEvent) {
|
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 () => {
|
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');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue