Skip to content
Extraits de code Groupes Projets
Valider 907084cf rédigé par Tom Barbette's avatar Tom Barbette
Parcourir les fichiers

RecordTimestamp: Add a sample parameter too

This allows to record only one packet out of N. And therefore need 1/N
of the space.

TimestampDiff should use the same parameter.
parent b977c901
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -39,8 +39,9 @@ int RecordTimestamp::configure(Vector<String> &conf, ErrorHandler *errh) { ...@@ -39,8 +39,9 @@ int RecordTimestamp::configure(Vector<String> &conf, ErrorHandler *errh) {
.read("COUNTER", e) .read("COUNTER", e)
.read("N", n) .read("N", n)
.read("OFFSET", _offset) .read("OFFSET", _offset)
.read("DYNAMIC", _dynamic) .read_or_set("DYNAMIC", _dynamic, false)
.read("NET_ORDER", _net_order) .read_or_set("NET_ORDER", _net_order, false)
.read_or_set("SAMPLE", _sample, false)
.complete() < 0) .complete() < 0)
return -1; return -1;
...@@ -64,6 +65,12 @@ RecordTimestamp::rmaction(Packet *p) { ...@@ -64,6 +65,12 @@ RecordTimestamp::rmaction(Packet *p) {
uint64_t i; uint64_t i;
if (_offset >= 0) { if (_offset >= 0) {
i = get_numberpacket(p, _offset, _net_order); i = get_numberpacket(p, _offset, _net_order);
if (_sample > 1) {
if (i % _sample == 0)
i = i / _sample;
else
return;
}
assert(i < ULLONG_MAX); assert(i < ULLONG_MAX);
while (i >= (unsigned)_timestamps.size()) { while (i >= (unsigned)_timestamps.size()) {
if (!_dynamic && i >= (unsigned)_timestamps.capacity()) { if (!_dynamic && i >= (unsigned)_timestamps.capacity()) {
......
...@@ -97,6 +97,7 @@ private: ...@@ -97,6 +97,7 @@ private:
int _offset; int _offset;
bool _dynamic; bool _dynamic;
bool _net_order; bool _net_order;
uint32_t _sample;
Vector<TimestampT> _timestamps; Vector<TimestampT> _timestamps;
NumberPacket *_np; NumberPacket *_np;
}; };
...@@ -105,6 +106,8 @@ private: ...@@ -105,6 +106,8 @@ private:
const TimestampT read_timestamp = TimestampUnread; const TimestampT read_timestamp = TimestampUnread;
inline TimestampT RecordTimestamp::get(uint64_t i) { inline TimestampT RecordTimestamp::get(uint64_t i) {
if (_sample > 1)
i = i / _sample;
if (i >= (unsigned)_timestamps.size()) { if (i >= (unsigned)_timestamps.size()) {
click_chatter("%p{element}: Index %lu is out of range !", this, i); click_chatter("%p{element}: Index %lu is out of range !", this, i);
return TimestampT::uninitialized_t(); return TimestampT::uninitialized_t();
......
...@@ -244,17 +244,18 @@ inline int TimestampDiff::smaction(Packet *p) ...@@ -244,17 +244,18 @@ inline int TimestampDiff::smaction(Packet *p)
{ {
TimestampT now = TimestampT::now_steady(); TimestampT now = TimestampT::now_steady();
uint64_t i = NumberPacket::read_number_of_packet(p, _offset, _net_order); 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); TimestampT old = get_recordtimestamp_instance()->get(i);
if (old == TimestampT::uninitialized_t()) { if (old == TimestampT::uninitialized_t()) {
return 1; return 1;
} }
if (_sample != 1) {
if ((uint32_t)i % _sample != 0) {
return 0;
}
}
TimestampT diff = now - old; TimestampT diff = now - old;
uint32_t usec = _nano? diff.nsecval() : diff.usecval(); uint32_t usec = _nano? diff.nsecval() : diff.usecval();
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter