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

Add --har option to save HAR of network activity #301

Merged
merged 4 commits into from Sep 8, 2016
Merged

Add --har option to save HAR of network activity #301

merged 4 commits into from Sep 8, 2016

Conversation

paulirish
Copy link
Member

I was curious about the network performance of kpm. That ended up here, a new command line flag which can save a HAR file.

Screenshots:
image

image

As part of this effort, I contributed a small patch to request which adds responseStartTime timing. As of today, this is not in a shipped version of request, so I've adjusted the dependency. (It's currently pointing a few commits past the recent 2.74.1)

Already, the data from the HAR is pretty fascinating, though I bet it'd be more useful in y'allz hands.

@cpojer
Copy link
Contributor

cpojer commented Sep 8, 2016

woah this is cool. Nice work Paul!

@sebmck
Copy link
Contributor

sebmck commented Sep 8, 2016

I'm concerned that this will lead to memory leaks since every single request is cached by the request-capture-har module.

@cpojer
Copy link
Contributor

cpojer commented Sep 8, 2016

Can we inline-require it?

if (this.flags.har) {
steps.push(async (curr: number, total: number) => {
this.reporter.step(curr, total, 'Saving a HAR', emoji.get('recycle'));
await requestHarCapture.saveHar(`kpm-install_${new Date().toISOString()}.har`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we include the name of the saved file in the previous message?

Copy link
Member Author

@paulirish paulirish Sep 8, 2016

Choose a reason for hiding this comment

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

done.

image

@sebmck
Copy link
Contributor

sebmck commented Sep 8, 2016

@cpojer I'm not sure what you mean? Module loading doesn't really have anything to do with it.

@paulirish Actually, could you add requestCaptureHar.clearHAR() to RequestManager#clearCache? Should help if kpm is used in long running processes.

@cpojer
Copy link
Contributor

cpojer commented Sep 8, 2016

I'm thinking we could only require the capture module when the har flag is passed?

@sebmck
Copy link
Contributor

sebmck commented Sep 8, 2016

That could work. I'd really prefer if the request HAR module could localise it's state rather than being global. Multiple installs in the same process can't have separate HAR files for example.

@sebmck
Copy link
Contributor

sebmck commented Sep 8, 2016

Opened paulirish/request-capture-har#2 to isolate the capture state. Let me know what you think @paulirish.

@sebmck
Copy link
Contributor

sebmck commented Sep 8, 2016

Awesome! Looks like there's a few type errors, requestCaptureHar: RequestCaptureHar; needs to be added to request-manager.js and captureHar: boolean to the ConfigOptions type in config.js. Happy to merge once CI passes.

@paulirish
Copy link
Member Author

Thanks to @kittens's PR, request-capture-har now keeps its state local. I've now updated this PR:

  • Gave requestManager it's own instance of requestCaptureHar. (Is it the right object to own it?)
  • Made sure we only through rCH if neccessary
  • added requestCaptureHar.clearHAR() to RequestManager#clearCache
  • piped the --har option value through to the requestManager

Other than that, I'm seeing some flow type errors. Might take me a moment to sort that out; never worked with Flow before.

@@ -33,6 +33,7 @@ type ConfigOptions = {
modulesFolder?: string,
offline?: boolean,
preferOffline?: boolean,
captureHar: boolean,
Copy link
Contributor

Choose a reason for hiding this comment

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

My bad, looks like this needs a ? like the other properties.

Copy link
Member Author

Choose a reason for hiding this comment

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

yup! just tackled. thanks for the help

@paulirish
Copy link
Member Author

Flow now passing. Not bad at all. :)

@sebmck
Copy link
Contributor

sebmck commented Sep 8, 2016

This is great! Thank you @paulirish!

@sebmck sebmck merged commit 770e41f into yarnpkg:master Sep 8, 2016
@paulirish paulirish deleted the har branch September 8, 2016 04:25
@bestander
Copy link
Member

Looks like trunk got broken when this PR was merged https://circleci.com/gh/facebook/fbkpm/491

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.

None yet

5 participants