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

misc(scripts): add trace/devtoolslog minification scripts #5237

Merged
merged 8 commits into from
May 22, 2018

Conversation

patrickhulce
Copy link
Collaborator

@patrickhulce patrickhulce commented May 17, 2018

phase 1 of lantern accuracy checks per commit

does a pretty awesome job of minifying traces from light/medium sites for inclusion, OK job of minifying the devtoolslog

example.com: 526KB -> 28KB, 7KB -> 4KB
paulirish.com: 2.3MB -> 151KB, 147KB -> 47KB

does okish on heavy sites like CNN

cnn.com: 30MB ->3.8MB, 2.9MB -> 1.3MB

package.json Outdated
@@ -63,7 +63,8 @@
"update:sample-json": "node ./lighthouse-cli -A=./lighthouse-core/test/results/artifacts --throttling-method=devtools --output=json --output-path=./lighthouse-core/test/results/sample_v2.json http://localhost/dobetterweb/dbw_tester.html && node lighthouse-core/scripts/cleanup-LHR-for-diff.js ./lighthouse-core/test/results/sample_v2.json --only-remove-timing",
"diff:sample-json": "bash lighthouse-core/scripts/assert-golden-lhr-unchanged.sh",
"update:crdp-typings": "node lighthouse-core/scripts/extract-crdp-mapping.js",
"mixed-content": "./lighthouse-cli/index.js --chrome-flags='--headless' --config-path=./lighthouse-core/config/mixed-content.js"
"mixed-content": "./lighthouse-cli/index.js --chrome-flags='--headless' --config-path=./lighthouse-core/config/mixed-content.js",
"minify-latest-run": "./lighthouse-core/scripts/lantern/minify-trace.js ./latest-run/defaultPass.trace.json ./latest-run/defaultPass.trace.json && ./lighthouse-core/scripts/lantern/minify-devtoolslog.js ./latest-run/defaultPass.devtoolslog.json ./latest-run/defaultPass.devtoolslog.json"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

latest-run/defaultPass.trace.json is in there twice. same with the dtlog.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's going to do it in place, maybe make the default output just be the input? Would make it a lot easier to read here, at least (otoh you might be sad that it automatically wrote over your saved trace, but I don't foresee many folks running this script independently)

Copy link
Collaborator Author

@patrickhulce patrickhulce May 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer not to make the default mode be inplace, I can put the latest-run files into different files? defaultPass.trace.min.json?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's fine (either way, really). It was mostly a comment on npm scripts being generally unreadable and this with the doubled-up everything is especially hard to read :)

* @param {LH.TraceEvent[]} events
*/
function filterTraceEvents(events) {
const startedInPageEvt = events.find(evt => evt.name === 'TracingStartedInPage');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lucky you: #5271 :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

speaking of which, is there some way to share all this logic with trace-of-tab so things like this (and what's considered "important") are always kept in sync?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I'd want #5271 to move the logic into tracing-process for mainthread identification and then I can just reuse it :D

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, so...future TODO/file an issue/wait until something breaks? :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO it is!

});

// Filter down the screenshots to key moments + 2fps animations
const screenshotTimestamps = filtered.filter(evt => evt.name === 'Screenshot').map(evt => evt.ts);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you break each of these techniques into its own fn. i might want to use just the screenshots one in the future.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 done

'x-robots-tag',
]);

/** @param {any} headers */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LH.Crdp.Network.Headers (which is just Record<string, string>)? Or I guess could be Partial<LH.Crdp.Network.Headers> since setting to undefined below?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

obj.url = obj.url.replace(/^(data:.*?base64,).*/, '$1FILLER');
}

/** @param {LH.Crdp.Network.ResponseReceivedEvent['response']} [response] */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LH.Crdp.Network.Response?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

/** @type {any} */
const timing = response.timing || {};
for (const [k, v] of Object.entries(timing)) {
if (v === -1) timing[k] = undefined;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how much does this end up mattering since the values will be just -1, not some unconstrained payload?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just eliminates most of the useless keys here, are you saying you'd rather keep them?

* @param {LH.TraceEvent[]} events
*/
function filterTraceEvents(events) {
const startedInPageEvt = events.find(evt => evt.name === 'TracingStartedInPage');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

speaking of which, is there some way to share all this logic with trace-of-tab so things like this (and what's considered "important") are always kept in sync?

package.json Outdated
@@ -63,7 +63,8 @@
"update:sample-json": "node ./lighthouse-cli -A=./lighthouse-core/test/results/artifacts --throttling-method=devtools --output=json --output-path=./lighthouse-core/test/results/sample_v2.json http://localhost/dobetterweb/dbw_tester.html && node lighthouse-core/scripts/cleanup-LHR-for-diff.js ./lighthouse-core/test/results/sample_v2.json --only-remove-timing",
"diff:sample-json": "bash lighthouse-core/scripts/assert-golden-lhr-unchanged.sh",
"update:crdp-typings": "node lighthouse-core/scripts/extract-crdp-mapping.js",
"mixed-content": "./lighthouse-cli/index.js --chrome-flags='--headless' --config-path=./lighthouse-core/config/mixed-content.js"
"mixed-content": "./lighthouse-cli/index.js --chrome-flags='--headless' --config-path=./lighthouse-core/config/mixed-content.js",
"minify-latest-run": "./lighthouse-core/scripts/lantern/minify-trace.js ./latest-run/defaultPass.trace.json ./latest-run/defaultPass.trace.json && ./lighthouse-core/scripts/lantern/minify-devtoolslog.js ./latest-run/defaultPass.devtoolslog.json ./latest-run/defaultPass.devtoolslog.json"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's going to do it in place, maybe make the default output just be the input? Would make it a lot easier to read here, at least (otoh you might be sad that it automatically wrote over your saved trace, but I don't foresee many folks running this script independently)


/* eslint-disable no-console */

const fs = require('fs');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fileoverview for both of these scripts would be 👍 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@patrickhulce
Copy link
Collaborator Author

PTAL :)

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@patrickhulce patrickhulce merged commit 40cf8da into master May 22, 2018
@patrickhulce patrickhulce deleted the mini_traces branch May 22, 2018 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants