Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plots: better support power use cases #2464

Merged
merged 17 commits into from
Jun 14, 2017
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
4 changes: 2 additions & 2 deletions docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ launchChromeAndRunLighthouse('https://example.com', flags).then(results => {

### Performance-only Lighthouse run

Many modules consuming Lighthouse are only interested in the performance numbers.
Many modules consuming Lighthouse are only interested in the performance numbers.
Lighthouse ships with a [performance-only config](https://github.com/GoogleChrome/lighthouse/blob/master/lighthouse-core/config/perf.json) that you can use:

```js
Expand All @@ -39,7 +39,7 @@ const perfConfig: any = require('lighthouse/lighthouse-core/config/perf.json');
launchChromeAndRunLighthouse(url, flags, perfConfig).then( // ...
```

You can also craft your own config (e.g. [plots.json](https://github.com/GoogleChrome/lighthouse/blob/master/lighthouse-core/config/plots.json)) for completely custom runs. Also see the [basic custom audit recipe](https://github.com/GoogleChrome/lighthouse/tree/master/docs/recipes/custom-audit).
You can also craft your own config (e.g. [plots-config.js](https://github.com/GoogleChrome/lighthouse/blob/master/lighthouse-core/config/plots-config.js)) for completely custom runs. Also see the [basic custom audit recipe](https://github.com/GoogleChrome/lighthouse/tree/master/docs/recipes/custom-audit).


### Turn on logging
Expand Down
19 changes: 15 additions & 4 deletions plots/open.js → lighthouse-core/config/plots-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,19 @@
*/
'use strict';

const path = require('path');
module.exports = {
passes: [{
recordTrace: true,
pauseBeforeTraceEndMs: 5000,
useThrottling: true,
gatherers: []
}],

const opn = require('opn');

opn(path.resolve(__dirname, 'index.html'));
audits: [
'first-meaningful-paint',
'speed-index-metric',
'estimated-input-latency',
'first-interactive',
'consistently-interactive'
]
};
16 changes: 0 additions & 16 deletions lighthouse-core/config/plots.json

This file was deleted.

13 changes: 7 additions & 6 deletions plots/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ You need to build lighthouse first.
# Run lighthouse to collect metrics data
$ node measure.js

# Analyze the data to generate a summary file (i.e. out/generatedResults.js)
# This will launch the charts web page in the browser
$ node analyze.js
# OR if you want to specify an out directory
$ node measure.js --out out-123

# If you need to view the charts later
$ node open.js
# Analyze the data to generate a summary file (i.e. out-hello/generated-results.js)
# This will launch the charts web page in the browser
# node analyze.js {out_directory}
$ node analyze.js ./out-hello
```

### Advanced usage
Expand All @@ -44,6 +45,7 @@ Options to specify sites:

Options:
--help Show help [boolean]
--out Custom out path
-n Number of runs per site [default: 3]
--reuse-chrome Reuse the same Chrome instance across all site runs
--keep-first-run If you use --reuse-chrome, by default the first run results are discarded
Expand All @@ -52,5 +54,4 @@ Examples:
node measure.js -n 3 --sites-path ./sample-sites.json
node measure.js --site https://google.com/
node measure.js --subset

```
31 changes: 22 additions & 9 deletions plots/analyze.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,50 @@

const fs = require('fs');
const path = require('path');
const util = require('util');

const opn = require('opn');
const args = require('yargs')
.example('node $0 ./out-dir')
.help('help')
.demand(1)
.argv;

const constants = require('./constants');
const utils = require('./utils');
const Metrics = require('../lighthouse-core/lib/traces/pwmetrics-events');

const GENERATED_RESULTS_PATH = path.resolve(constants.OUT_PATH, 'generatedResults.js');
const outFolder = args._[0];
const outPath = path.resolve(__dirname, outFolder);

/**
* Analyzes output generated from the measure step and
* generates a summary file for consumption by chart.js.
*/
function main() {
const allResults = [];
fs.readdirSync(constants.OUT_PATH).forEach(siteDir => {
const sitePath = path.resolve(constants.OUT_PATH, siteDir);
fs.readdirSync(outPath).forEach(siteDir => {
const sitePath = path.resolve(outPath, siteDir);
if (!utils.isDir(sitePath)) {
return;
}
allResults.push({site: siteDir, results: analyzeSite(sitePath)});
});
const generatedResults = groupByMetrics(allResults);
fs.writeFileSync(
GENERATED_RESULTS_PATH,
path.resolve(outPath, constants.GENERATED_RESULTS_FILENAME),
`var generatedResults = ${JSON.stringify(generatedResults)}`
);
const chartsPath = path.resolve(__dirname, constants.CHARTS_FOLDER);
utils.copy(path.resolve(chartsPath, constants.CHARTS_HTML_FILENAME), outPath);
utils.copy(path.resolve(chartsPath, constants.CHARTS_JS_FILENAME), outPath);
utils.copy(path.resolve(chartsPath, constants.CHARTS_LOADER_FILENAME), outPath);

if (process.env.CI) {
return;
}
console.log('Opening the charts web page...'); // eslint-disable-line no-console
opn(path.resolve(__dirname, 'index.html'));
opn(path.resolve(outPath, constants.CHARTS_HTML_FILENAME));
}

main();
Expand All @@ -51,17 +63,18 @@ main();
function analyzeSite(sitePath) {
console.log('Analyzing', sitePath); // eslint-disable-line no-console
const runResults = [];
fs.readdirSync(sitePath).forEach(runDir => {
fs.readdirSync(sitePath).sort((a, b) => a.localeCompare(b)).forEach(runDir => {
const resultsPath = path.resolve(sitePath, runDir, constants.LIGHTHOUSE_RESULTS_FILENAME);
if (!utils.isFile(resultsPath)) {
return;
}
const metrics = readResult(resultsPath);
console.log(`Metric for ${runDir}: ${JSON.stringify(metrics)}`); // eslint-disable-line no-console
runResults[runDir] = {
const prettymetrics = util.inspect(metrics, {colors: true, breakLength: Infinity});
console.log(`Metrics for ${runDir}:`, prettymetrics); // eslint-disable-line no-console
runResults.push({
runId: runDir,
metrics
};
});
});
return runResults;
}
Expand Down
29 changes: 0 additions & 29 deletions plots/bars-per-site.html

This file was deleted.

75 changes: 0 additions & 75 deletions plots/bars-per-site.js

This file was deleted.

49 changes: 49 additions & 0 deletions plots/charts/charts-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* @license Copyright 2017 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
'use strict';

/* eslint-env browser */
/* global generateBoxPlotChartPerMetric, generateLinePlotChartPerMetric, generateBoxPlotPerSite, generateGroupedBarChart */

const CHART_TYPES = {
'by-metric': {
name: 'Group by metric',
initFunctions: [generateBoxPlotChartPerMetric, generateLinePlotChartPerMetric],
},
'by-site': {
name: 'Group by site',
initFunctions: [generateBoxPlotPerSite],
},
'by-site-bars': {
name: 'Group by site (bars)',
initFunctions: [generateGroupedBarChart],
},
};

const DEFAULT_SLUG = 'by-metric';

function createNavLink(name, slug, currentSlug) {
const nav = document.querySelector('#nav');
const link = document.createElement('a');
if (slug !== currentSlug) {
link.href = `./index.html?${slug}`;
}
link.appendChild(document.createTextNode(name));
nav.appendChild(link);
}

(function main() {
const queryParams = new URLSearchParams(window.location.search);
const chartSlug = [...queryParams.keys()].pop() || DEFAULT_SLUG;

for (const key of Object.keys(CHART_TYPES)) {
createNavLink(CHART_TYPES[key].name, key, chartSlug);
}

for (const fn of CHART_TYPES[chartSlug].initFunctions) {
fn();
}
})();
Loading