Saturday, 15 March 2014

osx - Get mach_absolute_time/UpTime() in nanoseconds in Python -


Since the start of the nanosecond from the Python program running on Mac OS X 10.6, I need to pass the time.

I use the following carbon call to get it in C code:

  AbsoluteTime uptimeAbs = AbsoluteToNanoseconds (uptime); Uint64_t elapsedTime = ((uint64_t) uptimeAbs.hi << 32) + uptimeAbs.lo;  

Is it possible to use these functions in a carbon or POBJC module in Python? I tried:

import * uptime ()

but name "error: name 'uptime' is not defined".

How can I use this value from Python on OS X?

In one of the codes in the answer, I found - [NSProcessInfo systemUptime], Available in 10.6 available . It gives me time in decimal seconds, which I can multiply:

  from Foundation Import * NSProcessInfo.processInfo (). SystemUptime () * 1e 9  

The result is the accuracy of nanoseconds, and should work well for my needs.

Update: The following method also works, and is also compatible with 10.5:

  from Quartz Quartzcore Import * CacRRTM MediaTime () * 1A9  

No comments:

Post a Comment