MCPcopy Create free account
hub / github.com/SIPp/sipp / getmicroseconds

Function getmicroseconds

src/time.cpp:54–83  ·  view source on GitHub ↗

Returns the number of microseconds that have passed since SIPp started. Also updates the current clock_tick.

Source from the content-addressed store, hash-verified

52// Returns the number of microseconds that have passed since SIPp
53// started. Also updates the current clock_tick.
54unsigned long long getmicroseconds()
55{
56 struct timespec time;
57 unsigned long long microseconds;
58 static unsigned long long start_time = 0;
59
60#if defined(__MACH__) && defined(__APPLE__)
61 // OS X does not have clock_gettime, use clock_get_time
62 clock_serv_t cclock;
63 mach_timespec_t mts;
64 host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock);
65 clock_get_time(cclock, &mts);
66 mach_port_deallocate(mach_task_self(), cclock);
67 time.tv_sec = mts.tv_sec;
68 time.tv_nsec = mts.tv_nsec;
69#else
70#if defined(CLOCK_MONOTONIC_COARSE)
71 clock_gettime(CLOCK_MONOTONIC_COARSE, &time);
72#else
73 clock_gettime(CLOCK_MONOTONIC, &time);
74#endif
75#endif
76 microseconds = (MICROSECONDS_PER_SECOND * time.tv_sec) + (time.tv_nsec / NANOSECONDS_PER_MICROSECOND);
77 if (start_time == 0) {
78 start_time = microseconds - 1;
79 }
80 microseconds = microseconds - start_time;
81
82 return microseconds;
83}
84
85void update_clock_tick() {
86 clock_tick = getmilliseconds();

Callers 3

initMethod · 0.85
do_bookkeepingMethod · 0.85
getmillisecondsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected