// The well known EventTrace event numbers
enum EventType {
+ // Range 0..99: Generic events
CustomEvent = 0; // A custom event
- RecRecv = 1; // A request was received by the recursor process
+ ReqRecv = 1; // A request was received
PCacheCheck = 2; // A packet cache check was initiated or completed; value: bool cacheHit
- SyncRes = 3; // Syncres main function has started or completed; value: int rcode
- AnswerSent = 4; // The answer was sent to the client
- LuaGetTag = 100; // Events below mark start or end of Lua hook calls; value: return value of hook
- LuaGetTagFFI = 101;
- LuaIPFilter = 102;
- LuaPreRPZ = 103;
- LuaPreResolve = 104;
- LuaPreOutQuery = 105;
- LuaPostResolve = 106;
- LuaNoData = 107;
- LuaNXDomain = 108;
+ AnswerSent = 3; // An answer was sent to the client
+
+ // Range 100: Recursor events
+ SyncRes = 100; // Recursor Syncres main function has started or completed; value: int rcode
+ LuaGetTag = 101; // Events below mark start or end of Lua hook calls; value: return value of hook
+ LuaGetTagFFI = 102;
+ LuaIPFilter = 103;
+ LuaPreRPZ = 104;
+ LuaPreResolve = 105;
+ LuaPreOutQuery = 106;
+ LuaPostResolve = 107;
+ LuaNoData = 108;
+ LuaNXDomain = 109;
}
message Event {
.. code-block:: protobuf
enum EventType {
- CustomEvent = 0;
- RecRecv = 1;
- PCacheCheck = 2;
- SyncRes = 3;
- AnswerSent = 4;
- LuaGetTag = 100;
- LuaGetTagFFI = 101;
- LuaIPFilter = 102;
- LuaPreRPZ = 103;
- LuaPreResolve = 104;
- LuaPreOutQuery = 105;
- LuaPostResolve = 106;
- LuaNoData = 107;
- LuaNXDomain = 108;
- }
+ // Range 0..99: Generic events
+ CustomEvent = 0; // A custom event
+ ReqRecv = 1; // A request was received
+ PCacheCheck = 2; // A packet cache check was initiated or completed; value: bool cacheHit
+ AnswerSent = 3; // An answer was sent to the client
+
+ // Range 100: Recursor events
+ SyncRes = 100; // Recursor Syncres main function has started or completed; value: int rcode
+ LuaGetTag = 101; // Events below mark start or end of Lua hook calls; value: return value of hook
+ LuaGetTagFFI = 102;
+ LuaIPFilter = 103;
+ LuaPreRPZ = 104;
+ LuaPreResolve = 105;
+ LuaPreOutQuery = 106;
+ LuaPostResolve = 107;
+ LuaNoData = 108;
+ LuaNXDomain = 109;
+ }
.. code-block:: protobuf
.. code-block:: C
- - RecRecv(70);
+ - ReqRecv(70);
- PCacheCheck(411964);
- PCacheCheck(416783,0,done);
- SyncRes(441811);
.. code-block:: C
- - RecRecv(60);
+ - ReqRecv(60);
- PCacheCheck(22913);
- PCacheCheck(113255,1,done);
- AnswerSent(117493)
.. code-block:: C
- RecRecv(150);
+ ReqRecv(150);
PCacheCheck(26912);
PCacheCheck(51308,0,done);
LuaIPFilter(56868);
#include "misc.hh"
#include "noinitvector.hh"
-#include <protozero/pbf_writer.hpp>
#include <optional>
#include <time.h>
#include <unordered_map>
public:
enum EventType : uint8_t
{
+ // Keep in-syc with dnsmessagge.proto!
// Don't forget to add a new entry to the table in the .cc file!
+ // Generic events
CustomEvent = 0,
- RecRecv = 1,
+ ReqRecv = 1,
PCacheCheck = 2,
- SyncRes = 3,
- AnswerSent = 4,
- LuaGetTag = 100,
- LuaGetTagFFI = 101,
- LuaIPFilter = 102,
- LuaPreRPZ = 103,
- LuaPreResolve = 104,
- LuaPreOutQuery = 105,
- LuaPostResolve = 106,
- LuaNoData = 107,
- LuaNXDomain = 108,
+ AnswerSent = 3,
+
+ // Recursor specific events
+ SyncRes = 100,
+ LuaGetTag = 101,
+ LuaGetTagFFI = 102,
+ LuaIPFilter = 103,
+ LuaPreRPZ = 104,
+ LuaPreResolve = 105,
+ LuaPreOutQuery = 106,
+ LuaPostResolve = 107,
+ LuaNoData = 108,
+ LuaNXDomain = 109,
};
static const std::unordered_map<EventType, std::string> s_eventNames;
}
RecEventTrace(const RecEventTrace& old) :
- d_events(std::move(old.d_events)),
+ d_events(old.d_events),
d_base(old.d_base),
d_status(old.d_status)
{
+ // An RecEventTrace object can be copied, but the original will be marked invalid.
+ // This is do detect (very likely) unintended modifications to the original after
+ // the ownership changed.
old.d_status = Invalid;
}
d_base(old.d_base),
d_status(old.d_status)
{
+ // An RecEventTrace object can be moved, but the original will be marked invalid.
+ // This is do detect (very likely) unintended modifications to the original after
+ // the ownership changed.
old.d_status = Invalid;
}
struct Entry
{
- Entry(Value_t& v, EventType e, bool start, int64_t ts) :
- d_value(v), d_ts(ts), d_event(e), d_start(start)
+ Entry(Value_t&& v, EventType e, bool start, int64_t ts) :
+ d_value(std::move(v)), d_ts(ts), d_event(e), d_start(start)
{
}
- Entry(Value_t& v, const std::string& custom, bool start, int64_t ts) :
- d_value(v), d_custom(custom), d_ts(ts), d_event(CustomEvent), d_start(start)
+ Entry(Value_t&& v, const std::string& custom, bool start, int64_t ts) :
+ d_value(std::move(v)), d_custom(custom), d_ts(ts), d_event(CustomEvent), d_start(start)
{
}
Value_t d_value;
}
template <class E>
- void add(E e, Value_t v, bool start)
+ void add(E e, Value_t&& v, bool start, int64_t stamp = 0)
{
assert(d_status != Invalid);
if (d_status == Disabled) {
return;
}
- struct timespec ts;
- clock_gettime(CLOCK_MONOTONIC, &ts);
- int64_t stamp = ts.tv_nsec + ts.tv_sec * 1000000000;
+ if (stamp == 0) {
+ struct timespec ts;
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+ stamp = ts.tv_nsec + ts.tv_sec * 1000000000;
+ }
+ if (stamp < d_base) {
+ // If we get a ts before d_base, we adjust d_base and the existing events
+ // This is possble if we add a kernel provided packet timestamp in the future
+ // (Though it seems those timestamps do not use CLOCK_MONOTONIC...)
+ const int64_t adj = d_base - stamp;
+ for (auto& i : d_events) {
+ i.d_ts += adj;
+ }
+ // and move to the new base
+ d_base = stamp;
+ }
stamp -= d_base;
- d_events.emplace_back(v, e, start, stamp);
+ d_events.emplace_back(std::move(v), e, start, stamp);
}
template <class E>
d_events.clear();
reset();
}
+
void reset()
{
struct timespec ts;
private:
std::vector<Entry> d_events;
int64_t d_base;
- enum Status
+ enum Status : uint8_t
{
Disabled,
Invalid,