Skip to content

Commit

Permalink
refactor(cli, core): tracing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
lynchbomb committed Oct 29, 2019
1 parent 6561ce5 commit 7ded3c3
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 27 deletions.
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## (2019-10-28)

* feat(cli, core): save addt requests ([09db45a](https://github.com/tracerbench/tracerbench/commit/09db45a))
* refactor(cli, core): tracing logic ([6561ce5](https://github.com/tracerbench/tracerbench/commit/6561ce5))
* Update README.md ([1deff5d](https://github.com/tracerbench/tracerbench/commit/1deff5d))
* v2.2.3 ([b3f4b59](https://github.com/tracerbench/tracerbench/commit/b3f4b59))
* v2.2.4 ([6b9a9d4](https://github.com/tracerbench/tracerbench/commit/6b9a9d4))
* v2.3.0 ([828bce9](https://github.com/tracerbench/tracerbench/commit/828bce9))
* feat(cli): exporting cmds (#79) ([b738c3a](https://github.com/tracerbench/tracerbench/commit/b738c3a)), closes [#79](https://github.com/tracerbench/tracerbench/issues/79)
* feat(cli): exporting cmds (#79) ([60e8409](https://github.com/tracerbench/tracerbench/commit/60e8409)), closes [#79](https://github.com/tracerbench/tracerbench/issues/79)
* feat(cli): tracerbench base cmd ([4d1747d](https://github.com/tracerbench/tracerbench/commit/4d1747d))
* feat(core): exporting archive interfaces ([a3c1d18](https://github.com/tracerbench/tracerbench/commit/a3c1d18))
* fix(all): recording all requests ([79ba9bc](https://github.com/tracerbench/tracerbench/commit/79ba9bc))
* fix(cli): fixes gh issue 77 ([37e3a09](https://github.com/tracerbench/tracerbench/commit/37e3a09))
* fix(cli): merging ([c4ee0f2](https://github.com/tracerbench/tracerbench/commit/c4ee0f2))
* chore(all): dep upgrades to latest (#78) ([e9c81d6](https://github.com/tracerbench/tracerbench/commit/e9c81d6)), closes [#78](https://github.com/tracerbench/tracerbench/issues/78)
* chore(all): inc lerna-changelog ([01e9912](https://github.com/tracerbench/tracerbench/commit/01e9912))
* chore(cli): cleanup scripts ([d4ca02a](https://github.com/tracerbench/tracerbench/commit/d4ca02a))
* chore(cli): cleanup tests ([725d124](https://github.com/tracerbench/tracerbench/commit/725d124))
* chore(cli): cleanup tests ([9eb4ed0](https://github.com/tracerbench/tracerbench/commit/9eb4ed0))
* chore(cli): test cleanup ([cd1c6d2](https://github.com/tracerbench/tracerbench/commit/cd1c6d2))
* chore(cli): test cleanup ([2ef2e40](https://github.com/tracerbench/tracerbench/commit/2ef2e40))
* chore(core): bump fix for catalina chrome bug ([dda3aa6](https://github.com/tracerbench/tracerbench/commit/dda3aa6))
* docs(all): including changelog script ([4d5e654](https://github.com/tracerbench/tracerbench/commit/4d5e654))
* docs(cli): update README & manifest ([5be0f68](https://github.com/tracerbench/tracerbench/commit/5be0f68))



7 changes: 6 additions & 1 deletion packages/cli/src/command-config/tb-base.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { Command } from '@oclif/command';
import { IConfig } from '@oclif/config';

export { flags } from '@oclif/command';

import { ITBConfig, defaultFlagArgs } from '../command-config';
export default abstract class TBBaseCommand extends Command {
public parsedConfig: ITBConfig = defaultFlagArgs;
// flags explicitly specified within the cli when
// running the command. these will override all
public explicitFlags: string[];
constructor(argv: string[], config: IConfig) {
super(argv, config);
this.explicitFlags = argv;
}
}
27 changes: 23 additions & 4 deletions packages/cli/src/commands/record-har.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@ import { resolve, join } from 'path';
import { setGracefulCleanup } from 'tmp';
import { recordHARClient, getBrowserArgs } from '@tracerbench/core';

import { TBBaseCommand } from '../command-config';
import { dest, url, cookiespath, filename, marker } from '../helpers/flags';
import { TBBaseCommand, getConfig } from '../command-config';
import {
dest,
url,
cookiespath,
filename,
marker,
config,
} from '../helpers/flags';

setGracefulCleanup();

Expand All @@ -16,21 +23,33 @@ export default class RecordHAR extends TBBaseCommand {
cookiespath: cookiespath({ required: true }),
filename: filename({ required: true, default: 'tracerbench' }),
marker: marker({ required: true }),
config: config(),
};
public async init() {
const { flags } = this.parse(RecordHAR);
this.parsedConfig = getConfig(flags.config, flags, this.explicitFlags);
}

public async run() {
const { flags } = this.parse(RecordHAR);
const { url, dest, cookiespath, filename, marker } = flags;
let browserArgs;

try {
browserArgs = this.parsedConfig.browserArgs;
} catch (e) {
//
}

// grab the auth cookies
const cookies = await readJson(resolve(cookiespath));

// record the actual HAR and return the archive file
const harArchive = await recordHARClient(
url,
getBrowserArgs(),
cookies,
marker
marker,
getBrowserArgs(browserArgs)
);

const harPath = join(dest, `${filename}.har`);
Expand Down
12 changes: 1 addition & 11 deletions packages/cli/src/commands/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ import * as fs from 'fs-extra';
import { join, resolve } from 'path';

import { IConfig } from '@oclif/config';
import {
ITBConfig,
defaultFlagArgs,
getConfig,
TBBaseCommand,
} from '../command-config';
import { getConfig, TBBaseCommand } from '../command-config';
import createConsumeableHTML, {
ITracerBenchTraceResult,
} from '../helpers/create-consumable-html';
Expand All @@ -29,16 +24,11 @@ export default class Report extends TBBaseCommand {
config: config(),
};
public reportFlags: IReportFlags;
public parsedConfig: ITBConfig = defaultFlagArgs;
// flags explicitly specified within the cli when
// running the command. these will override all
public explicitFlags: string[];

constructor(argv: string[], config: IConfig) {
super(argv, config);
const { flags } = this.parse(Report);

this.explicitFlags = argv;
this.reportFlags = flags;
}
// instantiated before this.run()
Expand Down
7 changes: 5 additions & 2 deletions packages/tracerbench/src/trace/archive_trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import Protocol from 'devtools-protocol';
import { createBrowser, getTab, setCookies } from './trace-utils';
import { getBrowserArgs } from './utils';

import {
Archive as IArchive,
Log as ILog,
Expand All @@ -28,9 +30,9 @@ export {

export async function recordHARClient(
url: string,
browserArgs: string[],
cookies: Protocol.Network.CookieParam[],
marker: string
marker: string,
altBrowserArgs?: string[]
): Promise<IArchive> {
const networkRequests: Protocol.Network.ResponseReceivedEvent[] = [];
const archive: IArchive = {
Expand All @@ -43,6 +45,7 @@ export async function recordHARClient(
entries: [],
},
};
const browserArgs = getBrowserArgs(altBrowserArgs);
const browser = await createBrowser(browserArgs);

try {
Expand Down
19 changes: 13 additions & 6 deletions packages/tracerbench/src/trace/live_trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ import { IConditions } from './conditions';
import { createBrowser, getTab, emulate, setCookies } from './trace-utils';
import { getBrowserArgs } from './utils';
import { ITraceEvent } from '../trace';

const DEVTOOLS_CATEGORIES = [
'-*',
'devtools.timeline',
'viz',
'benchmark',
'blink',
'cc',
'gpu',
'v8',
'v8.execute',
'disabled-by-default-devtools.timeline',
Expand All @@ -19,9 +23,12 @@ const DEVTOOLS_CATEGORIES = [
'blink.console',
'blink.user_timing',
'latencyInfo',
'disabled-by-default-devtools.timeline.stack',
'disabled-by-default-v8.cpu_profiler',
'disabled-by-default-v8.cpu_profiler.hires',
'disabled-by-default-v8.cpu_profiler',
'disabled-by-default.cpu_profiler',
'disabled-by-default.cpu_profiler.debug',
'renderer',
'cpu_profiler',
];

interface ITraceEvents {
Expand Down Expand Up @@ -74,8 +81,8 @@ export async function liveTrace(
transferMode: 'ReturnAsStream',
streamCompression: 'none',
traceConfig: {
recordMode: 'recordAsMuchAsPossible',
includedCategories: DEVTOOLS_CATEGORIES,
recordMode: 'recordUntilFull',
},
});

Expand All @@ -91,8 +98,8 @@ export async function liveTrace(
const timeout = new Promise(reject => {
timeoutId = setTimeout(() => {
clearTimeout(timeoutId);
reject('Promise timed out after waiting for 10 seconds');
}, 10000);
reject('Promise timed out after waiting for 15 seconds');
}, 15000);
});

await Promise.race([evalPromise, timeout]).then(() => {
Expand Down
7 changes: 4 additions & 3 deletions packages/tracerbench/src/trace/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export async function wait(dur: number) {
});
}

export function getBrowserArgs(): string[] {
export function getBrowserArgs(explictArgs?: string[]): string[] {
interface IViewOptions {
windowSize: {
width: number;
Expand All @@ -217,7 +217,7 @@ export function getBrowserArgs(): string[] {
userAgent: undefined,
};

return [
const defaultFlags = [
`--crash-dumps-dir=${tmpDir.name}`,
'--disable-background-networking',
'--disable-background-timer-throttling',
Expand All @@ -238,7 +238,6 @@ export function getBrowserArgs(): string[] {
'--disable-translate',
'--disable-v8-idle-tasks',
`--device-scale-factor=${options.deviceScaleFactor}`,
'--ignore-certificate-errors-spki-list=uU0W87bsSHNaY+g/o8S9PmyxIgf92JepLWrPg5bYb+s=',
'--metrics-recording-only',
'--no-pings',
'--no-first-run',
Expand All @@ -254,4 +253,6 @@ export function getBrowserArgs(): string[] {
`--window-size=${options.windowSize.width},${options.windowSize.height}`,
'--headless',
];

return explictArgs ? explictArgs.concat(defaultFlags) : defaultFlags;
}

0 comments on commit 7ded3c3

Please sign in to comment.