[SOLVED] How to measure/track execution time across pages?


#1

Hey,

I’m aware of

 console.time('something);
 console.timeEnd('something');

to track execution time, but how could I measure the time spent across pages?

Tried to put this kind of code in services but didn’t work out. For example, I want to know from app.component constructor to my first page constructor how much time is spent.

Thx in advance for your advices


#2

https://ionicframework.com/docs/api/util/Events/ could probably help.


#3

Perfect.

In app.component:

constructor() {
    var bootTime = Date.now();
    
    platform.ready().then(() => {
          events.subscribe('app:boot', (time) => {
            console.log('App boot start: ', bootTime);
            console.log('App boot ready: ', readyTime);
            console.log('App boot done: ', time);
            console.log('Diff boot', time - bootTime);
            console.log('Diff ready', time - readyTime);
        });
    });
}

in my first page:

 ionViewDidLoad() {
     events.publish('app:boot', Date.now());
 }

P.S.: I updated the solution because I thought it’s interesting to have the difference between the boot time and the app ready time


#4

Thanks for sharing the solution!