Created
October 31, 2019 17:41
-
-
Save biocross/3486ff5d5b090da13c20ab255877293f to your computer and use it in GitHub Desktop.
Measuring Pre-main time in Production (iOS)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // End Time (should be in main.m): | |
| let start = processStartTime() | |
| let end = [[NSDate date] timeIntervalSince1970] | |
| // Swift | |
| if let startTime = start as? NSNumber, let endTime = end as? NSNumber { | |
| let pre_main_time_in_ms = (endTime.doubleValue - startTime.doubleValue) * 1000 | |
| print(pre_main_time_in_ms) // Send to analytics | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (NSTimeInterval)processStartTime { | |
| pid_t pid = [NSProcessInfo processInfo].processIdentifier; | |
| int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, pid }; | |
| struct kinfo_proc proc; | |
| size_t size = sizeof(proc); | |
| sysctl(mib, 4, &proc, &size, NULL, 0); | |
| return proc.kp_proc.p_starttime.tv_sec + proc.kp_proc.p_starttime.tv_usec / 1000000.0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment