Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const [
controlSettings,
experimentSettings,
] = this.generateControlExperimentServerConfig();
// this should be directly above the instantiation of the InitialRenderBenchmarks
if (this.parsedConfig.debug) {
Object.entries(this.parsedConfig).forEach(([key, value]) => {
if (value) {
this.log(`${key}: ${JSON.stringify(value)}`);
}
});
}
const benchmarks = {
control: new InitialRenderBenchmark(controlSettings),
experiment: new InitialRenderBenchmark(experimentSettings),
};
const runner = new Runner([benchmarks.control, benchmarks.experiment]);
await runner
.run(this.compareFlags.fidelity, this.log)
.then(async (results: any) => {
if (!results[0].samples[0]) {
this.error(
`Could not sample from provided urls\nCONTROL: ${this.parsedConfig.controlURL}\nEXPERIMENT: ${this.parsedConfig.experimentURL}.`
);
}
const resultJSONPath = `${this.parsedConfig.tbResultsFolder}/compare.json`;
fs.writeFileSync(resultJSONPath, JSON.stringify(results, null, 2));
// tslint:disable-next-line: max-line-length
controlSettings,
experimentSettings,
] = this.generateControlExperimentServerConfig();
// this should be directly above the instantiation of the InitialRenderBenchmarks
if (this.parsedConfig.debug) {
Object.entries(this.parsedConfig).forEach(([key, value]) => {
if (value) {
this.log(`${key}: ${JSON.stringify(value)}`);
}
});
}
const benchmarks = {
control: new InitialRenderBenchmark(controlSettings),
experiment: new InitialRenderBenchmark(experimentSettings),
};
const runner = new Runner([benchmarks.control, benchmarks.experiment]);
await runner
.run(this.compareFlags.fidelity, this.log)
.then(async (results: any) => {
if (!results[0].samples[0]) {
this.error(
`Could not sample from provided urls\nCONTROL: ${this.parsedConfig.controlURL}\nEXPERIMENT: ${this.parsedConfig.experimentURL}.`
);
}
const resultJSONPath = `${this.parsedConfig.tbResultsFolder}/compare.json`;
fs.writeFileSync(resultJSONPath, JSON.stringify(results, null, 2));
// tslint:disable-next-line: max-line-length
const message = `${chalkScheme.blackBgGreen(
// this should be directly above the instantiation of the InitialRenderBenchmarks
if (this.parsedConfig.debug) {
Object.entries(this.parsedConfig).forEach(([key, value]) => {
if (value) {
this.log(`${key}: ${JSON.stringify(value)}`);
}
});
}
const benchmarks = {
control: new InitialRenderBenchmark(controlSettings),
experiment: new InitialRenderBenchmark(experimentSettings),
};
const runner = new Runner([benchmarks.control, benchmarks.experiment]);
await runner
.run(this.compareFlags.fidelity, this.log)
.then(async (results: any) => {
if (!results[0].samples[0]) {
this.error(
`Could not sample from provided urls\nCONTROL: ${this.parsedConfig.controlURL}\nEXPERIMENT: ${this.parsedConfig.experimentURL}.`
);
}
const resultJSONPath = `${this.parsedConfig.tbResultsFolder}/compare.json`;
fs.writeFileSync(resultJSONPath, JSON.stringify(results, null, 2));
// tslint:disable-next-line: max-line-length
const message = `${chalkScheme.blackBgGreen(
` ${chalkScheme.white('SUCCESS!')} `
)} ${this.parsedConfig.fidelity} test samples were taken.`;
this.log(`\n${message}`);
// run the liveTrace
const { traceEvents } = await liveTrace(
url,
tbResultsFolder,
cookiesJSON,
conditions
);
const analyzeOptions: IAnalyze = {
traceEvents,
traceHARJSON,
methods,
};
// analyze the liveTrace
await analyze(analyzeOptions);
if (insights) {
// js-eval-time
let trace: any;
let totalJSDuration: number = 0;
let totalCSSDuration: number = 0;
const methods = new Set();
try {
trace = setTraceEvents(traceEvents);
} catch (error) {
this.error(`${error}`);
}
trace
const { url, dest, cookiespath, filename, marker } = flags;
const { network, cpuThrottleRate, browserArgs } = this.parsedConfig;
const conditions: IConditions = {
network: network ? network : 'none',
cpu: cpuThrottleRate ? parseInt(cpuThrottleRate as string, 10) : 1,
};
// grab the auth cookies
const cookies = await readJson(resolve(cookiespath));
// record the actual HAR and return the archive file
const harArchive = await recordHARClient(
url,
cookies,
marker,
conditions,
getBrowserArgs(browserArgs)
);
const harPath = join(dest, `${filename}.har`);
writeFileSync(harPath, JSON.stringify(harArchive));
this.log(`HAR recorded and available here: ${harPath}`);
}
}
locations,
network,
harpath,
} = flags;
const methods = [''];
const cookiesJSON = await readJson(path.resolve(cookiespath));
const traceHAR = path.resolve(harpath);
const traceHARJSON = await readJson(traceHAR);
const conditions: IConditions = {
cpu: cpuThrottleRate,
network,
};
// run the liveTrace
const { traceEvents } = await liveTrace(
url,
tbResultsFolder,
cookiesJSON,
conditions
);
const analyzeOptions: IAnalyze = {
traceEvents,
traceHARJSON,
methods,
};
// analyze the liveTrace
await analyze(analyzeOptions);
if (insights) {
.filter((event: any) => event.args.data.styleSheetUrl)
.forEach((event: any) => {
const url = event.args.data.styleSheetUrl;
const durationInMs = event.dur / 1000;
totalCSSDuration += durationInMs;
this.log(`CSS: ${url}: ${durationInMs.toFixed(2)}`);
});
// log css-parse-time
this.log(
`CSS: Evaluation Total Duration: ${totalCSSDuration.toFixed(2)}ms \n\n`
);
// list-functions
try {
const profile = loadTrace(trace).cpuProfile(-1, -1);
if (locations) {
profile.nodeMap.forEach((node: any) => {
const {
functionName,
url,
lineNumber,
columnNumber,
} = node.callFrame;
methods.add(
`${url}:${lineNumber}:${columnNumber}.${normalizeFnName(
functionName
)}`
);
});
} else {
public async run() {
const { flags } = this.parse(RecordHAR);
const { url, dest, cookiespath, filename, marker } = flags;
const { network, cpuThrottleRate, browserArgs } = this.parsedConfig;
const conditions: IConditions = {
network: network ? network : 'none',
cpu: cpuThrottleRate ? parseInt(cpuThrottleRate as string, 10) : 1,
};
// grab the auth cookies
const cookies = await readJson(resolve(cookiespath));
// record the actual HAR and return the archive file
const harArchive = await recordHARClient(
url,
cookies,
marker,
conditions,
getBrowserArgs(browserArgs)
);
const harPath = join(dest, `${filename}.har`);
writeFileSync(harPath, JSON.stringify(harArchive));
this.log(`HAR recorded and available here: ${harPath}`);
}
}
url: 'http://localhost:4200/?tracerbench=true',
markers,
browser,
saveTraces: () => path.resolve(TRACER_BENCH_RESULTS_PATH, 'control-trace.json'),
});
const experiment = new InitialRenderBenchmark({
name: 'experiment',
url: 'http://localhost:4201/?tracerbench=true',
markers,
browser,
saveTraces: () => path.resolve(TRACER_BENCH_RESULTS_PATH, 'experiment-trace.json'),
});
console.log('Computing results...');
const runner = new Runner([control, experiment]);
runner
.run(samplesCount)
.then(results => {
return fs.writeFileSync(
path.resolve(TRACER_BENCH_RESULTS_PATH, 'trace-results.json'),
JSON.stringify(results, null, 2)
);
})
.catch(err => {
console.error(err);
process.exit(1);
});
};
const TRACER_BENCH_RESULTS_PATH = path.resolve(
__dirname,
`../../../packages/unpublished-relationship-performance-test-app/tracerbench-results`
);
const control = new InitialRenderBenchmark({
name: 'control',
url: 'http://localhost:4200/?tracerbench=true',
markers,
browser,
saveTraces: () => path.resolve(TRACER_BENCH_RESULTS_PATH, 'control-trace.json'),
});
const experiment = new InitialRenderBenchmark({
name: 'experiment',
url: 'http://localhost:4201/?tracerbench=true',
markers,
browser,
saveTraces: () => path.resolve(TRACER_BENCH_RESULTS_PATH, 'experiment-trace.json'),
});
console.log('Computing results...');
const runner = new Runner([control, experiment]);
runner
.run(samplesCount)
.then(results => {
return fs.writeFileSync(
path.resolve(TRACER_BENCH_RESULTS_PATH, 'trace-results.json'),
JSON.stringify(results, null, 2)
);