Last active
November 24, 2018 02:53
-
-
Save michaeleisel/edd9b2bb54d91d0e48c07346926b7911 to your computer and use it in GitHub Desktop.
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
#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; | |
} | |
static CFTimeInterval sPreMainStartTimeRelative; | |
int main(int argc, char * argv[], char **envp) { | |
CFTimeInterval absoluteTimeToRelativeTime = CACurrentMediaTime() - [NSDate date].timeIntervalSince1970; | |
sPreMainStartTimeRelative = processStartTime() + absoluteTimeToRelativeTime; | |
// ... | |
} | |
// Call this function to get your final measurement | |
CFTimeInterval timeFromStartToNow() { | |
return CACurrentMediaTime() - sPreMainStartTimeRelative; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment