Hi,
I'm trying to add some timing code to my application to debug a threading issue. For this I want to generate timestamps using the same method as the driver uses to generate ConnexionDeviceState.time. In the API documentation, it states the value comes from get_clock_uptime. This function does not exist. In the API header, it states it comes from clock_get_uptime, which is a kernel method, and presumably not accesible from userspace. I have seen a moderator in the forums suggest using mach_absolute_time. However, it was unclear if this value should be converted to nanoseconds when comparing with ConnextionDeviceState.time.
So, what is the correct method of doing this?
Thanks.
event timestamps
Moderator: Moderators
-
- Posts: 20
- Joined: Tue Mar 11, 2008 10:36 pm
The function "UpTime()" is the one you want. and yes, convert to nanoseconds for ease of comparison.
in the following code, i then convert to milliseconds cuz the clocks really aren't that accurate anyway, and i do not need such precision.
in the following code, i then convert to milliseconds cuz the clocks really aren't that accurate anyway, and i do not need such precision.
Code: Select all
#define kNanoSecondsPerSecond 1000000000
#define kMilliSecondsPerSecond 1000
#define kNanoSecondsPerMilli (kNanoSecondsPerSecond / kMilliSecondsPerSecond)
static bool IsMostRecentMessage(UInt64& messageT)
{
UInt64 dur_message_nanoT(UnsignedWideToUInt64(
AbsoluteDeltaToNanoseconds(UpTime(), UInt64ToUnsignedWide(messageT))));
UInt64 dur_message_milliT(dur_message_nanoT / kNanoSecondsPerMilli);
UInt64 dur_tick_milliT(kMilliSecondsPerSecond / 60);
bool recentB = dur_message_milliT <= dur_tick_milliT;
return recentB;
}
-
- Posts: 20
- Joined: Tue Mar 11, 2008 10:36 pm
-
- Posts: 20
- Joined: Tue Mar 11, 2008 10:36 pm
Re: event timestamps
yes, "messageT" in the above code is "ConnexionDeviceState.time"