Include page generation times in js code


I am working with Drupal, and optimizing my server for fast page generation times, because Google officially said, that it will show sites, that loading faster, above than other sites.
Also page rendering and end-user loading is important.
I want to include this info to my piwik stats.
I tried to find and found something about that.
and found some old ticket, and a removed commit here:
I am using Drupal’s Piwik module, and my js code much differs from that.
How to mix these codes to have all times in my piwik database?
More important are page generation (I can include it from php if needed) and rendering/total page loading
My code is:

But the code with times is:

So it uses window.onLoad, but my code not… And is this code full? or it is missing something? I read about API that measures these times…
How to combine it?