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

feat: save devtools log #1665

Merged
merged 2 commits into from
Feb 8, 2017
Merged

feat: save devtools log #1665

merged 2 commits into from
Feb 8, 2017

Conversation

patrickhulce
Copy link
Collaborator

fixes #1662

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.

what does WPT use the log for? It can just consume arbitrary chatter between a client and the browser, or is it only interested in a subset of the log?

Also somewhat concerned about size here...if it's just events this is interested in we e.g. won't get the trace in there, but not sure how well the log size will be bounded

@@ -108,6 +129,11 @@ class Connection {
return object.result;
}));
}

if (this._recordMessages) {
Copy link
Member

Choose a reason for hiding this comment

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

is this only for events, not command responses?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, figured that would be distracting and not make very much sense without the request payload

Copy link
Member

Choose a reason for hiding this comment

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

yup, we dont need command reqs/responses.

const traceFilename = `${pathWithBasename}-${index}.trace.json`;
fs.writeFileSync(traceFilename, JSON.stringify(traceData, null, 2));
Copy link
Member

Choose a reason for hiding this comment

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

you mentioned the WPT trace parser doesn't do pretty JSON.
Should we start saving it in the right format? (or another PR i suppose)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm planning on handling the pretty printed file in WPT since I don't think its an excuse to be human-hostile here

this._messageLog = [];
}

beginRecording() {
Copy link
Member

Choose a reason for hiding this comment

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

i think we should have a whitelist filter to only record given domains. that way we could only do Page/Network which is all that WPT needs (and same for Lighthouse in its artifact-driven run).

honestly the API doesn't really need to be configurable.. maybe just set the filter as a property on this class?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

will do

/**
* @return {!Array<Object>}
*/
get messageLog() {
Copy link
Member

Choose a reason for hiding this comment

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

maybe bump this stuff into it's own class and instantiate it in the connection constructor?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

will do

it('devtools log file saved to disk with data', () => {
const filename = 'the_file-0.devtools.json';
const fileContents = fs.readFileSync(filename, 'utf8');
assert.ok(fileContents.includes('"message": "first"'));
Copy link
Member

Choose a reason for hiding this comment

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

are there any constraints around the format for this file? (aka not pretty print?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

no constraints on this one

log.log('trace file saved to disk', traceFilename);

const devtoolsLogFilename = `${pathWithBasename}-${index}.devtools.json`;
Copy link
Member

Choose a reason for hiding this comment

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

can we use "*devtoolslog.json" rather?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

will do

@patrickhulce
Copy link
Collaborator Author

WPT uses the message log to generate most of what you see in a report, network waterfalls, request breakdowns, timing information, etc. For that it needs the page and network events, and from the samples I've done the trace is far larger (~5-30x) than the devtools log.

@brendankenny
Copy link
Member

WPT uses the message log to generate most of what you see in a report, network waterfalls, request breakdowns, timing information, etc.

Got it. I do like @paulirish's idea of filtering messages saved.

For that it needs the page and network events, and from the samples I've done the trace is far larger (~5-30x) than the devtools log.

Right, but we don't stream in the trace until after we're done tracing :) If it's just events and just for the two domains it should probably be fine

@patrickhulce
Copy link
Collaborator Author

Filtering to just Page and Network cuts down about 33% of the file size.

@paulirish paulirish merged commit 4e66001 into master Feb 8, 2017
@paulirish paulirish deleted the save_devtools_messages branch February 8, 2017 03:10
@brendankenny
Copy link
Member

I didn't get to this fast enough, but some drive by thoughts when future changes touch the code:

  • it may be better for the log to live totally in driver. Could easily happen in the 'notification' event handler currently added in the driver constructor. That would keep it from being partially in connection and partially in driver reaching into connection, and it would mean connection wouldn't have to know about a class that knows about contents of the messages its handling.

  • Should MessageLog be DevtoolsLog to match the asset being saved?

  • Really need some comments :) No one reading is going to know what MessageLog is doing and why it's only saving those particular events

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.

WPT compat: save DevTools message log with trace
3 participants