This repository has been archived by the owner on Dec 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 974
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auditors: Test Plan:
- Loading branch information
Showing
7 changed files
with
195 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
logs | ||
*.log | ||
npm-debug.log.* | ||
cpu-profiles | ||
*.cpuprofile | ||
|
||
# Runtime data | ||
pids | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
'use strict' | ||
|
||
const CDP = require('chrome-remote-interface') | ||
const fs = require('fs') | ||
|
||
const LOG_FOLDER = './cpu-profiles' | ||
|
||
/** | ||
* Connect to a remote instance using Chrome Debugging Protocol and enable | ||
* the Profiler. Afterwards you need to profiler.start | ||
* See https://github.com/cyrus-and/chrome-remote-interface#cdpoptions-callback | ||
*/ | ||
const initProfiler = function * (context) { | ||
const cdp = yield CDP({port: 9222}) | ||
context.profiler = cdp.Profiler | ||
yield context.profiler.enable() | ||
yield context.profiler.setSamplingInterval({interval: 100}) | ||
} | ||
|
||
/** | ||
* initProfiler and start it. | ||
* @param context {object} webdriver client | ||
*/ | ||
const startProfiler = function * (context) { | ||
yield initProfiler(context) | ||
yield context.profiler.start() | ||
} | ||
|
||
/** | ||
* @param context {object} webdriver client | ||
* @param tag {string=} Optional file prefix | ||
* @returns filename to which CPU profile was written | ||
*/ | ||
const stopProfiler = function * (context, tag = '') { | ||
const cdpProfilerResult = yield context.profiler.stop() | ||
if (!fs.existsSync(LOG_FOLDER)) { | ||
console.log(`Creating directory ${LOG_FOLDER}`) | ||
fs.mkdirSync(LOG_FOLDER) | ||
} | ||
const filename = `${LOG_FOLDER}/${process.env.NODE_ENV}-${tag}-${new Date().toISOString()}.cpuprofile` | ||
const string = JSON.stringify(cdpProfilerResult.profile, null, 2) | ||
fs.writeFile(filename, string) | ||
console.log(`Wrote CPU profile data to: ${filename}`) | ||
return filename | ||
} | ||
|
||
module.exports = { | ||
initProfiler, | ||
startProfiler, | ||
stopProfiler | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const Immutable = require('immutable') | ||
|
||
// TODO: Decouple test tab generation from topsites | ||
const {topSites} = require('../../app/common/data/topSites') | ||
|
||
// XXX: Up to ~2000 bookmarks | ||
const addBookmarksN = function (total) { | ||
return function * (client) { | ||
const data = [] | ||
let n = 0 | ||
const pushBookmark = (etld, suffix = '') => { | ||
if (n >= total) { | ||
return false | ||
} | ||
data.push({ | ||
location: `https://www.${etld}/${suffix}`, | ||
title: `${etld}, ${suffix}`, | ||
parentFolderId: 0 | ||
}) | ||
n += 1 | ||
} | ||
for (let etld of topSites) { | ||
const success = | ||
pushBookmark(etld) && | ||
pushBookmark(etld, 'tomato') && | ||
pushBookmark(etld, 'potato') && | ||
pushBookmark(etld, 'onion') | ||
if (!success) { break } | ||
} | ||
const immutableData = Immutable.fromJS(data) | ||
yield client.addBookmarks(immutableData) | ||
} | ||
} | ||
const addBookmarks2000 = addBookmarksN(2000) | ||
|
||
const addTabsN = function (total) { | ||
return function * (client) { | ||
const data = [] | ||
for (let i = 0; i < total; i++) { | ||
const etld = topSites[i] | ||
data.push({ | ||
active: false, | ||
discarded: true, | ||
url: `https://www.${etld}` | ||
}) | ||
} | ||
for (let datum of data) { | ||
yield client.newTab(datum, false, true) // isRestore | ||
} | ||
} | ||
} | ||
const addTabs100 = addTabsN(100) | ||
|
||
module.exports = { | ||
addBookmarks2000, | ||
addTabs100 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* global describe, it, beforeEach, afterEach */ | ||
|
||
const Brave = require('../lib/brave') | ||
const profilerUtil = require('../lib/profilerUtil') | ||
const {urlInput} = require('../lib/selectors') | ||
const userProfiles = require('../lib/userProfiles') | ||
|
||
describe('Performance startup', function () { | ||
Brave.beforeAllServerSetup(this) | ||
|
||
function * setup () { | ||
yield Brave.startApp() | ||
Brave.addCommands() | ||
yield Brave.app.client | ||
.waitForUrl(Brave.newTabUrl) | ||
.waitForBrowserWindow() | ||
} | ||
|
||
function * restart (timeout = 1000) { | ||
// XXX Wait for Brave to fully shutdown and free up inspect port 9222 | ||
yield Brave.stopApp(false, timeout) | ||
yield Brave.startApp() | ||
Brave.addCommands() | ||
} | ||
|
||
beforeEach(function * () { | ||
this.url = Brave.server.url('page1.html') | ||
yield setup() | ||
}) | ||
|
||
afterEach(function * () { | ||
yield Brave.stopApp() | ||
}) | ||
|
||
function * runStory () { | ||
yield Brave.app.client | ||
.waitForUrl(Brave.newTabUrl, 10000, 250) | ||
.waitForBrowserWindow() | ||
.windowByUrl(Brave.browserWindowUrl) | ||
.ipcSend('shortcut-focus-url') | ||
.waitForVisible(urlInput) | ||
.waitForElementFocus(urlInput) | ||
for (let i = 0; i < this.url.length; i++) { | ||
yield Brave.app.client | ||
.keys(this.url[i]) | ||
.pause(30) | ||
} | ||
yield Brave.app.client | ||
.keys(Brave.keys.ENTER) | ||
.waitForUrl(this.url) | ||
} | ||
|
||
it('fresh', function * () { | ||
yield restart() | ||
yield profilerUtil.startProfiler(this) | ||
yield runStory.call(this) | ||
yield profilerUtil.stopProfiler(this, 'fresh') | ||
}) | ||
|
||
it('2000 bookmarks', function * () { | ||
yield userProfiles.addBookmarks2000(Brave.app.client) | ||
yield restart() | ||
yield profilerUtil.startProfiler(this) | ||
yield runStory.call(this) | ||
yield profilerUtil.stopProfiler(this, '2000-bookmarks') | ||
}) | ||
|
||
it('100 tabs', function * () { | ||
yield userProfiles.addTabs100(Brave.app.client) | ||
yield restart(5000) | ||
yield profilerUtil.startProfiler(this) | ||
yield runStory.call(this) | ||
yield profilerUtil.stopProfiler(this, '100-tabs') | ||
}) | ||
}) |