chore: align monotonicTime across processes (#35130)
This commit is contained in:
parent
43ee924087
commit
ec4c66133e
|
@ -14,6 +14,18 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function monotonicTime(): number {
|
let _timeOrigin = performance.timeOrigin;
|
||||||
return Math.floor(performance.now() * 1000) / 1000;
|
let _timeShift = 0;
|
||||||
|
|
||||||
|
export function setTimeOrigin(origin: number) {
|
||||||
|
_timeOrigin = origin;
|
||||||
|
_timeShift = performance.timeOrigin - origin;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function timeOrigin(): number {
|
||||||
|
return _timeOrigin;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function monotonicTime(): number {
|
||||||
|
return Math.floor((performance.now() + _timeShift) * 1000) / 1000;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,7 @@ export type SerializedConfig = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ProcessInitParams = {
|
export type ProcessInitParams = {
|
||||||
|
timeOrigin: number;
|
||||||
processName: string;
|
processName: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { startProfiling, stopProfiling } from 'playwright-core/lib/utils';
|
import { setTimeOrigin, startProfiling, stopProfiling } from 'playwright-core/lib/utils';
|
||||||
|
|
||||||
import { serializeError } from '../util';
|
import { serializeError } from '../util';
|
||||||
import { registerESMLoader } from './esmLoaderHost';
|
import { registerESMLoader } from './esmLoaderHost';
|
||||||
|
@ -69,6 +69,7 @@ process.on('message', async (message: any) => {
|
||||||
if (message.method === '__init__') {
|
if (message.method === '__init__') {
|
||||||
const { processParams, runnerParams, runnerScript } = message.params as { processParams: ProcessInitParams, runnerParams: any, runnerScript: string };
|
const { processParams, runnerParams, runnerScript } = message.params as { processParams: ProcessInitParams, runnerParams: any, runnerScript: string };
|
||||||
void startProfiling();
|
void startProfiling();
|
||||||
|
setTimeOrigin(processParams.timeOrigin);
|
||||||
const { create } = require(runnerScript);
|
const { create } = require(runnerScript);
|
||||||
processRunner = create(runnerParams) as ProcessRunner;
|
processRunner = create(runnerParams) as ProcessRunner;
|
||||||
processName = processParams.processName;
|
processName = processParams.processName;
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
import child_process from 'child_process';
|
import child_process from 'child_process';
|
||||||
import { EventEmitter } from 'events';
|
import { EventEmitter } from 'events';
|
||||||
|
|
||||||
import { assert } from 'playwright-core/lib/utils';
|
import { assert, timeOrigin } from 'playwright-core/lib/utils';
|
||||||
import { debug } from 'playwright-core/lib/utilsBundle';
|
import { debug } from 'playwright-core/lib/utilsBundle';
|
||||||
|
|
||||||
import { esmLoaderRegistered } from '../common/esmLoaderHost';
|
import { esmLoaderRegistered } from '../common/esmLoaderHost';
|
||||||
|
@ -115,7 +115,8 @@ export class ProcessHost extends EventEmitter {
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
const processParams: ProcessInitParams = {
|
const processParams: ProcessInitParams = {
|
||||||
processName: this._processName
|
processName: this._processName,
|
||||||
|
timeOrigin: timeOrigin(),
|
||||||
};
|
};
|
||||||
|
|
||||||
this.send({
|
this.send({
|
||||||
|
|
Loading…
Reference in New Issue