Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS app launch time measurement

How can I count the time it takes from the moment the user presses the launch button on the home screen until the moment the app is active (for example, until the viewDidAppear method of the first view controller)?

Id does not need to be programmatically but must be reliable.

Analogously in Android, logcat can be used for this effect.

like image 881
da Rocha Pires Avatar asked Mar 10 '16 23:03

da Rocha Pires


2 Answers

There is a possibility to get process start time with C api

#import <sys/sysctl.h>

static CFTimeInterval processStartTime() {
    size_t len = 4;
    int mib[len];
    struct kinfo_proc kp;

    sysctlnametomib("kern.proc.pid", mib, &len);
    mib[3] = getpid();
    len = sizeof(kp);
    sysctl(mib, 4, &kp, &len, NULL, 0);

    struct timeval startTime = kp.kp_proc.p_un.__p_starttime;
    return startTime.tv_sec + startTime.tv_usec / 1e6;
}

You can also do this in swift, but that would be wordier. Example can be found in CwlUtils.

After that you can calculate startup time with the different ways.

For example I do:

let currentTime = CFAbsoluteTimeGetCurrent() + kCFAbsoluteTimeIntervalSince1970
let startupTime = currentTime - processStartTime()

Full post about that I found here

like image 101
Gleb Tarasov Avatar answered Oct 05 '22 23:10

Gleb Tarasov


You can go to edit scheme on Xcode and add a environment variable (DYLD_PRINT_STATISTICS = 1) as shown in the image enter image description here

When you run the app the details will be printed on debugger output as below:

Total pre-main time: 481.88 milliseconds (100.0%)
         dylib loading time:  71.70 milliseconds (14.8%)
        rebase/binding time:  53.66 milliseconds (11.1%)
            ObjC setup time:  40.04 milliseconds (8.3%)
           initializer time: 316.33 milliseconds (65.6%)
           slowest intializers :
             libSystem.B.dylib :  16.71 milliseconds (3.4%)

Please watch the video for more details.

like image 27
sukesh Avatar answered Oct 05 '22 23:10

sukesh