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.
​https://github.com/uamuzibora/nafasi/wiki/Page-load-times
​http://www.html5rocks.com/en/tutorials/webperformance/basics/
and found some old ticket, and a removed commit here:
​https://github.com/uamuzibora/nafasi/commit/b8e3dc14db22ad4b7d77b4861fb11918d87abc63
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?