Skip to content

Instantly share code, notes, and snippets.

@michaeleisel
Last active November 24, 2018 02:53
Show Gist options
  • Save michaeleisel/edd9b2bb54d91d0e48c07346926b7911 to your computer and use it in GitHub Desktop.
Save michaeleisel/edd9b2bb54d91d0e48c07346926b7911 to your computer and use it in GitHub Desktop.
#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