Skip to content

Commit

Permalink
TimestampDiff: Enable nanosecond precision
Browse files Browse the repository at this point in the history
  • Loading branch information
tbarbette committed Jul 18, 2023
1 parent 26a2b65 commit 37de87a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
7 changes: 4 additions & 3 deletions elements/analysis/timestampdiff.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ int TimestampDiff::configure(Vector<String> &conf, ErrorHandler *errh)
.read("OFFSET",_offset)
.read("N", _limit)
.read("MAXDELAY", _max_delay_ms)
.read("NANO", _nano)
.read_or_set("SAMPLE", _sample, 1)
.read_or_set("VERBOSE", _verbose, false)
.read_or_set("TC_OFFSET", _tc_offset, -1)
Expand Down Expand Up @@ -256,12 +257,12 @@ inline int TimestampDiff::smaction(Packet *p)
}

TimestampT diff = now - old;
uint32_t usec = diff.usecval();
if ((usec > _max_delay_ms * 1000)) {
uint32_t usec = _nano? diff.nsecval() : diff.usecval();
if ((usec > _max_delay_ms * (_nano?1000000:1000))) {
if (_verbose) {
click_chatter(
"Packet %" PRIu64 " experienced delay %u ms > %u ms",
i, (usec)/1000, _max_delay_ms
i, (usec)/ (_nano?1000000:1000), _max_delay_ms
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion elements/analysis/timestampdiff.hh
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private:
bool _verbose;
int _tc_offset;
unsigned char _tc_mask;

bool _nano;
inline int smaction(Packet *p);

RecordTimestamp *get_recordtimestamp_instance();
Expand Down
7 changes: 7 additions & 0 deletions include/click/tsctimestamp.hh
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ class TSCTimestamp {
return val / (cycles_hz_warp() / 1000000);
}

/**
* @brief returns the total number of nsecs represented by this timestamp
*/
inline double nsecval() {
return (double)val / ((double)cycles_hz_warp() / 1000000000.0d);
}

inline int64_t tsc_val() {
return val;
}
Expand Down

0 comments on commit 37de87a

Please sign in to comment.