Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions lib/core/engine/command/simpleperf.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { isAndroidConfigured } from '../../../android/index.js';

const log = getLogger('browsertime.command.simpleperf');

const defaultOptions =
const defaultRecordOptions =
'--call-graph fp --duration 240 -f 1000 --trace-offcpu -e cpu-clock';

/**
Expand Down Expand Up @@ -72,7 +72,11 @@ export class SimplePerfProfiler {
* @throws {Error} Throws an error if app_profiler.py fails to execute.
*/

async start(profilerOptions = defaultOptions, dirName = 'simpleperf') {
async start(
profilerOptions = [],
recordOptions = defaultRecordOptions,
dirName = 'simpleperf'
) {
if (!isAndroidConfigured(this.options)) {
throw new Error('Simpleperf profiling is only available on Android.');
}
Expand All @@ -83,6 +87,8 @@ export class SimplePerfProfiler {
let dirname = `${dirName}-${this.index}`;
let counter = 0;

this.profilerOptions = profilerOptions;

while (true) {
log.info(`Checking if ${dirname} exists...`);

Expand All @@ -102,13 +108,14 @@ export class SimplePerfProfiler {
this.options.browser === 'firefox'
? this.options.firefox?.android?.package
: this.options.chrome?.android?.package;
let ndkPath = this.options.androidNDK;
let cmd = `${ndkPath}/simpleperf/app_profiler.py`;
let simpleperfPath = this.options.androidSimpleperf;
let cmd = join(simpleperfPath, 'app_profiler.py');
let args = [
...profilerOptions,
'-p',
packageName,
'-r',
profilerOptions,
recordOptions,
'--log',
'debug',
'-o',
Expand Down Expand Up @@ -167,11 +174,24 @@ export class SimplePerfProfiler {
stderrStream.on('data', data => {
const dataStr = data.toString();
log.info(dataStr);
// Resolve immediately if -nb or --skip_collect_binaries is passed
// into the app_profiler options as a binary cache will not be produced.
if (
this.profilerOptions.includes('-nb') ||
this.profilerOptions.includes('--skip_collect_binaries')
) {
stderrStream.removeAllListeners('data');
return resolve();
}
if (/profiling is finished./.test(dataStr)) {
stderrStream.removeAllListeners('data');
// There is no way to specify the output of binary_cache, so manually move
// it into the data directory.
renameSync('binary_cache', join(this.dataDir, 'binary_cache'));
// There is no way to specify the output of binary_cache,
// so manually move it (if it exists) into the data directory.
if (existsSync('binary_cache')) {
renameSync('binary_cache', join(this.dataDir, 'binary_cache'));
} else {
log.info('binary_cache does not exist.');
}
return resolve();
}
});
Expand Down
6 changes: 3 additions & 3 deletions lib/support/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -837,10 +837,10 @@ export function parseCommandLine() {
'Before a test start, verify that the device has a Internet connection by pinging 8.8.8.8 (or a configurable domain with --androidPingAddress)',
group: 'android'
})
.option('android.ndk', {
alias: 'androidNDK',
.option('android.simpleperf', {
alias: 'androidSimpleperf',
type: 'string',
describe: 'Path to the Android NDK (required for simpleperf profiling).',
describe: 'Path to the Simpleperf profiler from the Android NDK.',
group: 'android'
})
.option('android.perfettoTrace', {
Expand Down
3 changes: 2 additions & 1 deletion types/core/engine/command/simpleperf.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export class SimplePerfProfiler {
* @returns {Promise<void>} A promise that resolves when simpleperf has started profiling.
* @throws {Error} Throws an error if app_profiler.py fails to execute.
*/
start(profilerOptions?: string, dirName?: string): Promise<void>;
start(profilerOptions?: any[], recordOptions?: string, dirName?: string): Promise<void>;
profilerOptions: any[];
dataDir: any;
simpleperfProcess: import("execa").ResultPromise<{}>;
/**
Expand Down
2 changes: 1 addition & 1 deletion types/core/engine/command/simpleperf.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.