The Click Timestamp class represents both moments in time and intervals in time. In most Click code, Timestamp replaces the Unix "struct timeval" and "struct timespec" structures; for example, Timer expiry times use the Timestamp class. Timestamps may be added, subtracted, and compared using the usual operators.
Timestamp measures time in seconds using a fixed-point representation, like "struct timeval" and "struct timespec". Seconds and "subseconds", or fractions of a second, are stored in separate integers. Timestamps have either microsecond or nanosecond precision, depending on how Click is configured. Thus, one subsecond might equal either one microsecond or one nanosecond. The subsec_per_sec enumeration constant equals the number of subseconds in a second; the timestamp's subsec() value should always lie between 0 and subsec_per_sec - 1. (The --enable-nanotimestamp configuration option enables nanosecond-precision timestamps at user level; kernel modules always use microsecond-precision timestamps.)
A Timestamp with sec() < 0 is negative. Note that subsec() is always nonnegative. A Timestamp's value always equals (sec() + subsec() / (double) subsec_per_sec); thus, the Timestamp value of -0.1 is represented as sec() == -1, usec() == +900000.
Public Types | |
| enum | { max_seconds = (seconds_type) 2147483647U, min_seconds = (seconds_type) -2147483648U, nsec_per_sec = 1000000000, nsec_per_msec = 1000000, nsec_per_usec = 1000, usec_per_sec = 1000000, usec_per_msec = 1000, msec_per_sec = 1000, subsec_per_sec = nsec_per_sec, subsec_per_msec = subsec_per_sec / msec_per_sec, subsec_per_usec = subsec_per_sec / usec_per_sec } |
| enum | { NSUBSEC = subsec_per_sec } |
| typedef int32_t | seconds_type |
| Type represents a number of seconds. | |
| typedef int32_t | value_type |
| Return type for msecval(), usecval(), and nsecval(). | |
| typedef seconds_type(Timestamp::*) | unspecified_bool_type () const |
Public Member Functions | |
| Timestamp () | |
| Construct a zero-valued Timestamp. | |
| Timestamp (long sec, uint32_t subsec=0) | |
| Construct a Timestamp of sec seconds plus subsec subseconds. | |
| Timestamp (int sec, uint32_t subsec=0) | |
| Timestamp (unsigned long sec, uint32_t subsec=0) | |
| Timestamp (unsigned sec, uint32_t subsec=0) | |
| Timestamp (double) | |
| Create a timestamp measuring d seconds. | |
| Timestamp (const struct timeval &tv) | |
| Create a Timestamp measuring tv. | |
| Timestamp (const struct timespec &ts) | |
| Create a Timestamp measuring ts. | |
| Timestamp (const uninitialized_t &unused) | |
| Construct an uninitialized timestamp. | |
| operator unspecified_bool_type () const | |
| Return true iff this timestamp is not zero-valued. | |
| seconds_type | sec () const |
| uint32_t | subsec () const |
| uint32_t | msec () const |
| Return this timestamp's subseconds component, converted to milliseconds. | |
| uint32_t | usec () const |
| Return this timestamp's subseconds component, converted to microseconds. | |
| uint32_t | nsec () const |
| Return this timestamp's subseconds component, converted to nanoseconds. | |
| void | set_sec (seconds_type sec) |
| Set this timestamp's seconds component. | |
| void | set_subsec (uint32_t subsec) |
| Set this timestamp's subseconds component. | |
| seconds_type | msec1 () const |
| Return this timestamp's interval length, converted to milliseconds. | |
| seconds_type | usec1 () const |
| Return this timestamp's interval length, converted to microseconds. | |
| seconds_type | nsec1 () const |
| Return this timestamp's interval length, converted to nanoseconds. | |
| timeval | timeval () const |
| Return a struct timeval with the same value as this timestamp. | |
| timespec | timespec () const |
| Return a struct timespec with the same value as this timestamp. | |
| double | doubleval () const |
| Return this timestamp's value, converted to a real number. | |
| value_type | msecval () const |
| Return this timestamp's interval length in milliseconds. | |
| value_type | usecval () const |
| Return this timestamp's interval length in microseconds. | |
| value_type | nsecval () const |
| Return this timestamp's interval length in nanoseconds. | |
| click_jiffies_t | jiffies () const |
| Return the number of jiffies represented by this timestamp. | |
| void | assign (seconds_type sec, uint32_t subsec=0) |
| void | assign_usec (seconds_type sec, uint32_t usec) |
| void | assign_nsec (seconds_type sec, uint32_t nsec) |
| void | set (seconds_type sec, uint32_t subsec=0) |
| void | set_usec (seconds_type sec, uint32_t usec) |
| void | set_nsec (seconds_type sec, uint32_t nsec) |
| void | set_now () |
| Set this timestamp to the current time. | |
| String | unparse () const |
| Unparse this timestamp into a String. | |
| String | unparse_interval () const |
| Unparse this timestamp into a String as an interval. | |
Static Public Member Functions | |
| static Timestamp | make_jiffies (click_jiffies_t jiffies) |
| Return a timestamp representing jiffies. | |
| static Timestamp | make_sec (seconds_type sec) |
| Return a timestamp representing sec seconds. | |
| static Timestamp | make_msec (seconds_type sec, uint32_t msec) |
| Return a timestamp representing sec seconds plus msec milliseconds. | |
| static Timestamp | make_msec (value_type msec) |
| Return a timestamp representing msec milliseconds. | |
| static Timestamp | make_usec (seconds_type sec, uint32_t usec) |
| Return a timestamp representing sec seconds plus usec microseconds. | |
| static Timestamp | make_usec (value_type usec) |
| Return a timestamp representing usec microseconds. | |
| static Timestamp | make_nsec (seconds_type sec, uint32_t nsec) |
| Return a timestamp representing sec seconds plus nsec nanoseconds. | |
| static Timestamp | make_nsec (value_type nsec) |
| Return a timestamp representing nsec nanoseconds. | |
| static Timestamp | now () |
| Return a timestamp representing the current time. | |
| static Timestamp | epsilon () |
| Return the smallest nonzero timestamp, Timestamp(0, 1). | |
| static uint32_t | msec_to_subsec (uint32_t msec) |
| Convert milliseconds to subseconds. | |
| static uint32_t | usec_to_subsec (uint32_t usec) |
| Convert microseconds to subseconds. | |
| static uint32_t | nsec_to_subsec (uint32_t nsec) |
| Convert nanoseconds to subseconds. | |
| static uint32_t | subsec_to_msec (uint32_t subsec) |
| Convert subseconds to milliseconds. | |
| static uint32_t | subsec_to_usec (uint32_t subsec) |
| Convert subseconds to microseconds. | |
| static uint32_t | subsec_to_nsec (uint32_t subsec) |
| Convert subseconds to nanoseconds. | |
Friends | |
| bool | operator== (const Timestamp &a, const Timestamp &b) |
| Compare two timestamps for equality. | |
| bool | operator< (const Timestamp &a, const Timestamp &b) |
| Compare two timestamps. | |
| Timestamp | operator- (const Timestamp &b) |
| Negate a and return the result. | |
| Timestamp & | operator+= (Timestamp &a, const Timestamp &b) |
| Add b to a. | |
| Timestamp & | operator-= (Timestamp &a, const Timestamp &b) |
| Subtract b from a. | |
Related Functions | |
| (Note that these are not member functions.) | |
| bool | operator!= (const Timestamp &a, const Timestamp &b) |
| Compare two timestamps for inequality. | |
| bool | operator<= (const Timestamp &a, const Timestamp &b) |
| Compare two timestamps. | |
| bool | operator>= (const Timestamp &a, const Timestamp &b) |
| Compare two timestamps. | |
| bool | operator> (const Timestamp &a, const Timestamp &b) |
| Compare two timestamps. | |
| StringAccum & | operator<< (StringAccum &sa, const Timestamp &ts) |
| Append the unparsed representation of ts to sa. | |
Classes | |
| struct | uninitialized_t |
| typedef int32_t Timestamp::seconds_type |
Type represents a number of seconds.
| typedef int32_t Timestamp::value_type |
| anonymous enum |
| Timestamp::Timestamp | ( | ) | [inline] |
Construct a zero-valued Timestamp.
| Timestamp::Timestamp | ( | long | sec, | |
| uint32_t | subsec = 0 | |||
| ) | [inline] |
Construct a Timestamp of sec seconds plus subsec subseconds.
| sec | number of seconds | |
| subsec | number of subseconds (defaults to 0) |
| Timestamp::Timestamp | ( | double | ) | [inline] |
Create a timestamp measuring d seconds.
| Timestamp::Timestamp | ( | const struct timeval & | tv | ) | [inline] |
| Timestamp::Timestamp | ( | const struct timespec & | ts | ) | [inline] |
| Timestamp::Timestamp | ( | const uninitialized_t & | unused | ) | [inline] |
Construct an uninitialized timestamp.
| Timestamp::operator unspecified_bool_type | ( | ) | const [inline] |
Return true iff this timestamp is not zero-valued.
| uint32_t Timestamp::msec | ( | ) | const [inline] |
Return this timestamp's subseconds component, converted to milliseconds.
| uint32_t Timestamp::usec | ( | ) | const [inline] |
Return this timestamp's subseconds component, converted to microseconds.
| uint32_t Timestamp::nsec | ( | ) | const [inline] |
Return this timestamp's subseconds component, converted to nanoseconds.
| void Timestamp::set_sec | ( | seconds_type | sec | ) | [inline] |
Set this timestamp's seconds component.
The subseconds component is left unchanged.
| void Timestamp::set_subsec | ( | uint32_t | subsec | ) | [inline] |
Set this timestamp's subseconds component.
| subsec | number of subseconds |
| Timestamp::seconds_type Timestamp::msec1 | ( | ) | const [inline] |
Return this timestamp's interval length, converted to milliseconds.
Will overflow on intervals of more than 2147483.647 seconds.
| Timestamp::seconds_type Timestamp::usec1 | ( | ) | const [inline] |
Return this timestamp's interval length, converted to microseconds.
Will overflow on intervals of more than 2147.483647 seconds.
| Timestamp::seconds_type Timestamp::nsec1 | ( | ) | const [inline] |
Return this timestamp's interval length, converted to nanoseconds.
Will overflow on intervals of more than 2.147483647 seconds.
| struct timeval Timestamp::timeval | ( | ) | const [inline] |
| struct timespec Timestamp::timespec | ( | ) | const [inline] |
| double Timestamp::doubleval | ( | ) | const [inline] |
Return this timestamp's value, converted to a real number.
| value_type Timestamp::msecval | ( | ) | const [inline] |
Return this timestamp's interval length in milliseconds.
| value_type Timestamp::usecval | ( | ) | const [inline] |
Return this timestamp's interval length in microseconds.
| value_type Timestamp::nsecval | ( | ) | const [inline] |
Return this timestamp's interval length in nanoseconds.
| Timestamp Timestamp::make_jiffies | ( | click_jiffies_t | jiffies | ) | [inline, static] |
Return a timestamp representing jiffies.
| click_jiffies_t Timestamp::jiffies | ( | ) | const [inline] |
Return the number of jiffies represented by this timestamp.
| static Timestamp Timestamp::make_sec | ( | seconds_type | sec | ) | [inline, static] |
Return a timestamp representing sec seconds.
| static Timestamp Timestamp::make_msec | ( | seconds_type | sec, | |
| uint32_t | msec | |||
| ) | [inline, static] |
Return a timestamp representing sec seconds plus msec milliseconds.
| static Timestamp Timestamp::make_msec | ( | value_type | msec | ) | [inline, static] |
Return a timestamp representing msec milliseconds.
| static Timestamp Timestamp::make_usec | ( | seconds_type | sec, | |
| uint32_t | usec | |||
| ) | [inline, static] |
Return a timestamp representing sec seconds plus usec microseconds.
| static Timestamp Timestamp::make_usec | ( | value_type | usec | ) | [inline, static] |
Return a timestamp representing usec microseconds.
| static Timestamp Timestamp::make_nsec | ( | seconds_type | sec, | |
| uint32_t | nsec | |||
| ) | [inline, static] |
Return a timestamp representing sec seconds plus nsec nanoseconds.
| static Timestamp Timestamp::make_nsec | ( | value_type | nsec | ) | [inline, static] |
Return a timestamp representing nsec nanoseconds.
| Timestamp Timestamp::now | ( | ) | [inline, static] |
Return a timestamp representing the current time.
The current time is measured in seconds since January 1, 1970 GMT.
| static Timestamp Timestamp::epsilon | ( | ) | [inline, static] |
Return the smallest nonzero timestamp, Timestamp(0, 1).
| void Timestamp::assign | ( | seconds_type | sec, | |
| uint32_t | subsec = 0 | |||
| ) | [inline] |
Set this timestamp to a seconds-and-subseconds value.
| void Timestamp::assign_usec | ( | seconds_type | sec, | |
| uint32_t | usec | |||
| ) | [inline] |
Assign this timestamp to a seconds-and-microseconds value.
| void Timestamp::assign_nsec | ( | seconds_type | sec, | |
| uint32_t | nsec | |||
| ) | [inline] |
Assign this timestamp to a seconds-and-nanoseconds value.
| void Timestamp::set | ( | seconds_type | sec, | |
| uint32_t | subsec = 0 | |||
| ) | [inline] |
Assign this timestamp to a seconds-and-subseconds value.
| void Timestamp::set_usec | ( | seconds_type | sec, | |
| uint32_t | usec | |||
| ) | [inline] |
Assign this timestamp to a seconds-and-microseconds value.
| void Timestamp::set_nsec | ( | seconds_type | sec, | |
| uint32_t | nsec | |||
| ) | [inline] |
Assign this timestamp to a seconds-and-nanoseconds value.
| void Timestamp::set_now | ( | ) | [inline] |
Set this timestamp to the current time.
The current time is measured in seconds since January 1, 1970 GMT. Returns the most precise timestamp available.
| String Timestamp::unparse | ( | ) | const |
Unparse this timestamp into a String.
Returns a string formatted like "10.000000", with at least six subsecond digits. (Nanosecond-precision timestamps where the number of nanoseconds is not evenly divisible by 1000 have nine subsecond digits.)
| String Timestamp::unparse_interval | ( | ) | const |
Unparse this timestamp into a String as an interval.
Returns a string formatted like "1us" or "1.000002s".
| static uint32_t Timestamp::msec_to_subsec | ( | uint32_t | msec | ) | [inline, static] |
Convert milliseconds to subseconds.
Subseconds are either microseconds or nanoseconds, depending on configuration options and driver choice.
| static uint32_t Timestamp::usec_to_subsec | ( | uint32_t | usec | ) | [inline, static] |
Convert microseconds to subseconds.
| static uint32_t Timestamp::nsec_to_subsec | ( | uint32_t | nsec | ) | [inline, static] |
Convert nanoseconds to subseconds.
| static uint32_t Timestamp::subsec_to_msec | ( | uint32_t | subsec | ) | [inline, static] |
Convert subseconds to milliseconds.
| static uint32_t Timestamp::subsec_to_usec | ( | uint32_t | subsec | ) | [inline, static] |
Convert subseconds to microseconds.
| static uint32_t Timestamp::subsec_to_nsec | ( | uint32_t | subsec | ) | [inline, static] |
Convert subseconds to nanoseconds.
Compare two timestamps for equality.
Returns true iff the two operands have the same seconds and subseconds components.
Compare two timestamps.
Returns true iff a represents a shorter interval than b, or considered as absolute time, a happened before b.
Add b to a.
Returns the result (the new value of a).
Subtract b from a.
Returns the result (the new value of a).
Compare two timestamps for inequality.
Returns true iff !(a == b).
Compare two timestamps.
Returns true iff a measures an interval no larger than b, or considered as absolute time, a happened at or before b.
Compare two timestamps.
Returns true iff a measures an interval no shorter than b, or considered as absolute time, a happened at or after b.
Compare two timestamps.
Returns true iff a measures a longer interval than b, or considered as absolute time, a happened after b.
| StringAccum & operator<< | ( | StringAccum & | sa, | |
| const Timestamp & | ts | |||
| ) | [related] |
Append the unparsed representation of ts to sa.
Same as sa << ts.unparse().
1.5.1