Skip to content

Add javascript timing metrics to timing panel onLoad if available #319

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

Merged
merged 5 commits into from
Jun 21, 2013

Conversation

mindsocket
Copy link
Contributor

Some browsers support navigation timing via javascript. Since these metrics fit the category of timing, this commit adds a section to the timing panel containing key metrics from the browser, triggered soon after the onLoad event.

The change is plain javascript, so no library dependencies.

Background:
https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/NavigationTiming/Overview.html

Screenshot:
http://dl.dropbox.com/u/15940111/browser_timing.png

Tested on Chrome 22 and Firefox 14

@SiDChik
Copy link

SiDChik commented Oct 22, 2012

Nice feature, very usefull. Waiting for release:)

@mindsocket
Copy link
Contributor Author

Is there anything I can do to help get this merged?

@ebertti
Copy link

ebertti commented Feb 8, 2013

👍

@jezdez
Copy link
Contributor

jezdez commented Mar 2, 2013

I like the idea two, but can you do two things:

  • add a fallback for browsers that don't support it (which are those btw?)
  • afaik there are more than those 8 events that can be tracked, should DDT support more?

@mindsocket
Copy link
Contributor Author

  • The javascript already includes that check (if (perf) {...} wraps most of the code in the commit)
  • I deliberately chose a subset of the timing events for 2 reasons...
    • Some are effectively duplicates (eg one event starts at the exact same time as another ends)
    • Some are not relevant to application debugging or performance in development (eg redirect time, domain lookup time)

@jezdez
Copy link
Contributor

jezdez commented Mar 3, 2013

Thanks @mindsocket, that sounds sensible. Regarding the fallback, I saw the condition check for perf but missed the .djDebugBrowserTiming block being hidden by default and only made visible if supported. Apologies.

With regard to the second point, I'm not sure if we can make an educated guess about all applications and which performance measuring is useful (e.g. domain lookup time isn't totally useless when debugging a frontend issue). Do you think we could make that configurable (without adding another setting)? Is there another way to specify all of them?

@mindsocket
Copy link
Contributor Author

My admittedly opinionated approach was to choose metrics based on those
that are commonly relevant to debugging Django back- and front-end,
particularly at development time, rather than clutter up the timing data
for application developers with network- and DNS-related metrics (often a
production concern). It's still possible for developers to use the browser
console for the complete set. I'm not strongly of this opinion though, it
just seems a pragmatic one to me.

So, in terms of an alternative solution, one could simply add all of the
PerformanceTiming values listed at:
https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/NavigationTiming/Overview.html

This appears to be possible without an explicit list by iterating over the
timing object in the Javascript block. Using Chrome console I put together
this proof-of-concept:
for (var metric in window.performance.timing) {
console.log(metric, window.performance.timing[metric]);
}

One way to make it "configurable" might be to have a basic list shown by
default, with an expandable section for the rest.

Let me know what you think, happy to let you run with it, or I can resubmit
w/ changes.

On 3 March 2013 22:33, Jannis Leidel notifications@github.com wrote:

Thanks @mindsocket https://github.com/mindsocket, that sounds sensible.
Regarding the fallback, I saw the condition check for perf but missed the
.djDebugBrowserTiming block being hidden by default and only made visible
if supported. Apologies.

With regard to the second point, I'm not sure if we can make an educated
guess about all applications and which performance measuring is useful
(e.g. domain lookup time isn't totally useless when debugging a frontend
issue). Do you think we could make that configurable (without adding
another setting)? Is there another way to specify all of them?


Reply to this email directly or view it on GitHubhttps://github.com//pull/319#issuecomment-14345584
.

@jezdez
Copy link
Contributor

jezdez commented Mar 3, 2013

You're right, network and DNS stats are less useful for most debugging sessions, but completely leaving them out would be a bad idea. When using the toolbar to get a picture of the performance of a Django site you usually try to get a picture of a bigger stack -- memory, database, cache, search index, etc. -- effectively the single reason why there are so different panels included. Getting access to information about browser performance is incredibly useful to eventually finding issues that other panels cannot describe successfully. I agree it may delude the frontend related performance stats, so maybe we should group the stats in "rendering" and "networking"?

@robhudson
Copy link
Contributor

Very cool idea.

I'm curious... Are the timing set up calls initiated early enough? I haven't played with this yet but was curious.

Also, a waterfall like display would be slick but I wouldn't hold this back as it is.

@mindsocket
Copy link
Contributor Author

@jezdez We could group them. I'll try to add the others in the coming days. IMHO the commit as is could go out without that in the interests of getting it in front of more eyes for feedback.

@robhudson The timing is captured automatically by the browser (it's a builtin in many modern browsers), the javascript above just grabs it when all is said and done (after page load).

A waterfall (a la SQL queries) is a great idea, if I get a chance I'll take a look

@mindsocket
Copy link
Contributor Author

timing_sample
I've rebased my commit and rearranged things somewhat.

@jezdez I've included more of the timing events. Also, based on @robhudson 's suggestion I took inspiration from the SQL panel and rendered a timeline of timing events. I'm not sure I like the output exactly as I have it now, but it's an improvement.

@jezdez
Copy link
Contributor

jezdez commented Mar 24, 2013

Awesome, this looks amazing @mindsocket! Any feedback @robhudson?

@mindsocket
Copy link
Contributor Author

Is there anything I can do to help get this merged?

@robhudson
Copy link
Contributor

Apologies... I missed the original call from @jezdez. This looks pretty good.

My only concern is that this is using inline scripts. I've been away from debug toolbar but thought we had some efforts to reduce the amount of inline scripting. (I just found issue #330 which would actually be nice) Would it be much more effort to put this in the javascript file with a hook into the panel display events?

timingOffset = perf.timing.navigationStart,
timingEnd = perf.timing.loadEventEnd;
var totalTime = timingEnd - timingOffset;
console.log(timingOffset, timingEnd, totalTime);
Copy link
Contributor

Choose a reason for hiding this comment

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

We might want this removed before merging.

@mindsocket
Copy link
Contributor Author

I'll move the inline javascript to an included file. As an included panel, is toolbar.js ok for that purpose? If not, where, and should the panel then render the inclusion?

I'll also remove the console logging and replace the load event binding with a jQuery.bind('load'...)

@mindsocket
Copy link
Contributor Author

I've rebased and updated per suggestions. JS is minified already based on lastest toolbar.js, so hopefully this is good to go.

@jezdez
Copy link
Contributor

jezdez commented May 1, 2013

LGTM!

@robhudson
Copy link
Contributor

Looks great to me too.

@robhudson
Copy link
Contributor

@mindsocket Is there anything you need to add here based on @andymckay's comment?

@mindsocket
Copy link
Contributor Author

@robhudson I believe the solution as committed is the only way to ensure loadEventEnd is picked up in all browsers. So, nothing to add AFAIK

@mindsocket
Copy link
Contributor Author

Committed and pushed a change to the setTimeout call (reduced delay to 0). Tested and working on Firefox and Chrome

@mindsocket
Copy link
Contributor Author

Ping @andymckay and @robhudson , I think we're close :)

@mindsocket
Copy link
Contributor Author

Is there anything I can do to help get this merged? I'm going to use it in a talk at PyConAU next month and having it in mainline means I can say it's a more readily available tool.

robhudson added a commit that referenced this pull request Jun 21, 2013
Add javascript timing metrics to timing panel onLoad if available
@robhudson robhudson merged commit 7e4ecfd into django-commons:master Jun 21, 2013
ryneeverett pushed a commit to ryneeverett/django-debug-toolbar that referenced this pull request Oct 2, 2016
Add javascript timing metrics to timing panel onLoad if available
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.

6 participants