Skip to content

Commit

Permalink
RecordTimestamp: Add a sample parameter too
Browse files Browse the repository at this point in the history
This allows to record only one packet out of N. And therefore need 1/N
of the space.

TimestampDiff should use the same parameter.
  • Loading branch information
tbarbette committed Jul 27, 2023
1 parent b977c90 commit 907084c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
11 changes: 9 additions & 2 deletions elements/analysis/recordtimestamp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ int RecordTimestamp::configure(Vector<String> &conf, ErrorHandler *errh) {
.read("COUNTER", e)
.read("N", n)
.read("OFFSET", _offset)
.read("DYNAMIC", _dynamic)
.read("NET_ORDER", _net_order)
.read_or_set("DYNAMIC", _dynamic, false)
.read_or_set("NET_ORDER", _net_order, false)
.read_or_set("SAMPLE", _sample, false)
.complete() < 0)
return -1;

Expand All @@ -64,6 +65,12 @@ RecordTimestamp::rmaction(Packet *p) {
uint64_t i;
if (_offset >= 0) {
i = get_numberpacket(p, _offset, _net_order);
if (_sample > 1) {
if (i % _sample == 0)
i = i / _sample;
else
return;
}
assert(i < ULLONG_MAX);
while (i >= (unsigned)_timestamps.size()) {
if (!_dynamic && i >= (unsigned)_timestamps.capacity()) {
Expand Down
3 changes: 3 additions & 0 deletions elements/analysis/recordtimestamp.hh
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ private:
int _offset;
bool _dynamic;
bool _net_order;
uint32_t _sample;
Vector<TimestampT> _timestamps;
NumberPacket *_np;
};
Expand All @@ -105,6 +106,8 @@ private:
const TimestampT read_timestamp = TimestampUnread;

inline TimestampT RecordTimestamp::get(uint64_t i) {
if (_sample > 1)
i = i / _sample;
if (i >= (unsigned)_timestamps.size()) {
click_chatter("%p{element}: Index %lu is out of range !", this, i);
return TimestampT::uninitialized_t();
Expand Down
11 changes: 6 additions & 5 deletions elements/analysis/timestampdiff.cc
Original file line number Diff line number Diff line change
Expand Up @@ -244,17 +244,18 @@ inline int TimestampDiff::smaction(Packet *p)
{
TimestampT now = TimestampT::now_steady();
uint64_t i = NumberPacket::read_number_of_packet(p, _offset, _net_order);
if (_sample != 1) {
if ((uint32_t)i % _sample != 0) {
return 0;
}
}
TimestampT old = get_recordtimestamp_instance()->get(i);

if (old == TimestampT::uninitialized_t()) {
return 1;
}

if (_sample != 1) {
if ((uint32_t)i % _sample != 0) {
return 0;
}
}


TimestampT diff = now - old;
uint32_t usec = _nano? diff.nsecval() : diff.usecval();
Expand Down

0 comments on commit 907084c

Please sign in to comment.