HTTPArchive / custom-metrics

Custom metrics to use with WebPageTest agents
Apache License 2.0
19 stars 21 forks source link

Observe Worker initialization #35

Closed kevinfarrugia closed 2 years ago

kevinfarrugia commented 2 years ago

Required for JavaScript 2022

Added support to count the number of times the Worker constructor is called.

Test: https://webpagetest.httparchive.org/result/220529_6B_M/1/details/#waterfall_view_step1

Uses custom metric:

[observers]
return Object.fromEntries(Object.entries(httparchive_observers).filter(([_, value]) => value));

Results include:

observers { Worker: 1 }
rviscomi commented 2 years ago

I think all that's needed is a minimal change to add Worker to the OBSERVERS list. There was a bug in the implementation that I recently fixed in #32 where top-level properties under window weren't being observed properly. That might by why you thought you needed a separate implementation for constructors.

Here's a test where I just added the constructor name to the const, and it worked.

image
kevinfarrugia commented 2 years ago

Thank you @rviscomi . I have updated the PR and it seems to work correctly.

https://webpagetest.httparchive.org/result/220528_ZX_10/1/details/#waterfall_view_step1

rviscomi commented 2 years ago

Did you push your changes? I'm still seeing the separate CONSTRUCTORS array.

kevinfarrugia commented 2 years ago

😴. Updated.

kevinfarrugia commented 2 years ago

Updated test using observers.js.

https://webpagetest.httparchive.org/result/220529_6B_M/1/details/#waterfall_view_step1