| 1 |
// timestamp tapset -- gettimeofday variants |
| 2 |
// Copyright (C) 2012 Red Hat, Inc. |
| 3 |
// |
| 4 |
// This file is part of systemtap, and is free software. You can |
| 5 |
// redistribute it and/or modify it under the terms of the GNU General |
| 6 |
// Public License (GPL); either version 2, or (at your option) any |
| 7 |
// later version. |
| 8 |
|
| 9 |
// NB: functionally equivalent to linux/timestamp_gtod.stp |
| 10 |
|
| 11 |
%{ |
| 12 |
#include <sys/time.h> |
| 13 |
%} |
| 14 |
|
| 15 |
function gettimeofday_ns:long () { |
| 16 |
return gettimeofday_us() * 1000; // XXX available resolution isn't this high! |
| 17 |
} |
| 18 |
|
| 19 |
function gettimeofday_us:long () %{ /* pure */ /* unprivileged */ |
| 20 |
struct timeval tv; |
| 21 |
if (gettimeofday(&tv, NULL) == 0) |
| 22 |
STAP_RETVALUE = (uint64_t)tv.tv_sec * 1000000 + tv.tv_usec; |
| 23 |
%} |
| 24 |
|
| 25 |
function gettimeofday_ms:long () { |
| 26 |
return gettimeofday_us() / 1000; |
| 27 |
} |
| 28 |
|
| 29 |
function gettimeofday_s:long () { |
| 30 |
return gettimeofday_us() / 1000000; |
| 31 |
} |