diff --git a/elements/analysis/recordtimestamp.cc b/elements/analysis/recordtimestamp.cc index db9c7c44713262ee9d11d919b2154ea23edfe95e..02f3e8692a4b5b2f49ac0af96f1963a166fc80ca 100644 --- a/elements/analysis/recordtimestamp.cc +++ b/elements/analysis/recordtimestamp.cc @@ -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; @@ -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()) { diff --git a/elements/analysis/recordtimestamp.hh b/elements/analysis/recordtimestamp.hh index 8d9e38349d56833a89e00aa129b5ca0e51220efb..1f2b2d37fe233ad581637e844bef35eaac5896c3 100644 --- a/elements/analysis/recordtimestamp.hh +++ b/elements/analysis/recordtimestamp.hh @@ -97,6 +97,7 @@ private: int _offset; bool _dynamic; bool _net_order; + uint32_t _sample; Vector<TimestampT> _timestamps; NumberPacket *_np; }; @@ -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(); diff --git a/elements/analysis/timestampdiff.cc b/elements/analysis/timestampdiff.cc index dc1130552186f36694fb0acf25e933cbefb1e200..eadca02878ef8f10aabc7bd4624a14cfeafd4509 100644 --- a/elements/analysis/timestampdiff.cc +++ b/elements/analysis/timestampdiff.cc @@ -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();