mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Profiling support for DNS_Mgr and triggers.
With misc/profiling.bro, both now report a line in prof.log with some counters on usage.
This commit is contained in:
parent
bd9c937236
commit
df4a22a27d
6 changed files with 77 additions and 2 deletions
|
@ -370,6 +370,9 @@ DNS_Mgr::DNS_Mgr(DNS_MgrMode arg_mode)
|
||||||
cache_name = dir = 0;
|
cache_name = dir = 0;
|
||||||
|
|
||||||
asyncs_pending = 0;
|
asyncs_pending = 0;
|
||||||
|
num_requests = 0;
|
||||||
|
successful = 0;
|
||||||
|
failed = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
DNS_Mgr::~DNS_Mgr()
|
DNS_Mgr::~DNS_Mgr()
|
||||||
|
@ -952,6 +955,8 @@ void DNS_Mgr::IssueAsyncRequests()
|
||||||
AsyncRequest* req = asyncs_queued.front();
|
AsyncRequest* req = asyncs_queued.front();
|
||||||
asyncs_queued.pop_front();
|
asyncs_queued.pop_front();
|
||||||
|
|
||||||
|
++num_requests;
|
||||||
|
|
||||||
DNS_Mgr_Request* dr;
|
DNS_Mgr_Request* dr;
|
||||||
if ( req->IsAddrReq() )
|
if ( req->IsAddrReq() )
|
||||||
dr = new DNS_Mgr_Request(req->host);
|
dr = new DNS_Mgr_Request(req->host);
|
||||||
|
@ -961,6 +966,7 @@ void DNS_Mgr::IssueAsyncRequests()
|
||||||
if ( ! dr->MakeRequest(nb_dns) )
|
if ( ! dr->MakeRequest(nb_dns) )
|
||||||
{
|
{
|
||||||
reporter->Warning("can't issue DNS request");
|
reporter->Warning("can't issue DNS request");
|
||||||
|
++failed;
|
||||||
req->Timeout();
|
req->Timeout();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -995,10 +1001,16 @@ void DNS_Mgr::CheckAsyncAddrRequest(dns_mgr_addr_type addr, bool timeout)
|
||||||
{
|
{
|
||||||
const char* name = LookupAddrInCache(addr);
|
const char* name = LookupAddrInCache(addr);
|
||||||
if ( name )
|
if ( name )
|
||||||
|
{
|
||||||
|
++successful;
|
||||||
i->second->Resolved(name);
|
i->second->Resolved(name);
|
||||||
|
}
|
||||||
|
|
||||||
else if ( timeout )
|
else if ( timeout )
|
||||||
|
{
|
||||||
|
++failed;
|
||||||
i->second->Timeout();
|
i->second->Timeout();
|
||||||
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
return;
|
return;
|
||||||
|
@ -1024,12 +1036,16 @@ void DNS_Mgr::CheckAsyncHostRequest(const char* host, bool timeout)
|
||||||
|
|
||||||
if ( addrs )
|
if ( addrs )
|
||||||
{
|
{
|
||||||
|
++successful;
|
||||||
i->second->Resolved(addrs);
|
i->second->Resolved(addrs);
|
||||||
Unref(addrs);
|
Unref(addrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if ( timeout )
|
else if ( timeout )
|
||||||
|
{
|
||||||
|
++failed;
|
||||||
i->second->Timeout();
|
i->second->Timeout();
|
||||||
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
return;
|
return;
|
||||||
|
@ -1146,3 +1162,14 @@ int DNS_Mgr::AnswerAvailable(int timeout)
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DNS_Mgr::GetStats(Stats* stats)
|
||||||
|
{
|
||||||
|
stats->requests = num_requests;
|
||||||
|
stats->successful = successful;
|
||||||
|
stats->failed = failed;
|
||||||
|
stats->pending = asyncs_pending;
|
||||||
|
stats->cached_hosts = host_mappings.Length();
|
||||||
|
stats->cached_addresses = addr_mappings.Length();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// See the file "COPYING" in the main distribution directory for copyright.
|
// See the file "COPYING" in the main distribution directory for copyright.
|
||||||
|
|
||||||
#ifndef dnsmgr_h
|
#ifndef dnsmgr_h
|
||||||
#define dnsmgr_h
|
#define dnsmgr_h
|
||||||
|
@ -81,6 +81,17 @@ public:
|
||||||
void AsyncLookupAddr(dns_mgr_addr_type host, LookupCallback* callback);
|
void AsyncLookupAddr(dns_mgr_addr_type host, LookupCallback* callback);
|
||||||
void AsyncLookupName(string name, LookupCallback* callback);
|
void AsyncLookupName(string name, LookupCallback* callback);
|
||||||
|
|
||||||
|
struct Stats {
|
||||||
|
unsigned long requests; // These count only async requests.
|
||||||
|
unsigned long successful;
|
||||||
|
unsigned long failed;
|
||||||
|
unsigned long pending;
|
||||||
|
unsigned long cached_hosts;
|
||||||
|
unsigned long cached_addresses;
|
||||||
|
};
|
||||||
|
|
||||||
|
void GetStats(Stats* stats);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class LookupCallback;
|
friend class LookupCallback;
|
||||||
friend class DNS_Mgr_Request;
|
friend class DNS_Mgr_Request;
|
||||||
|
@ -206,6 +217,10 @@ protected:
|
||||||
TimeoutQueue asyncs_timeouts;
|
TimeoutQueue asyncs_timeouts;
|
||||||
|
|
||||||
int asyncs_pending;
|
int asyncs_pending;
|
||||||
|
|
||||||
|
unsigned long num_requests;
|
||||||
|
unsigned long successful;
|
||||||
|
unsigned long failed;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern DNS_Mgr* dns_mgr;
|
extern DNS_Mgr* dns_mgr;
|
||||||
|
|
15
src/Stats.cc
15
src/Stats.cc
|
@ -7,6 +7,8 @@
|
||||||
#include "Scope.h"
|
#include "Scope.h"
|
||||||
#include "cq.h"
|
#include "cq.h"
|
||||||
#include "ConnCompressor.h"
|
#include "ConnCompressor.h"
|
||||||
|
#include "DNS_Mgr.h"
|
||||||
|
#include "Trigger.h"
|
||||||
|
|
||||||
|
|
||||||
int killed_by_inactivity = 0;
|
int killed_by_inactivity = 0;
|
||||||
|
@ -193,6 +195,19 @@ void ProfileLogger::Log()
|
||||||
(timer_mgr->Size() * padded_sizeof(ConnectionTimer))) / 1024,
|
(timer_mgr->Size() * padded_sizeof(ConnectionTimer))) / 1024,
|
||||||
network_time - timer_mgr->LastTimestamp()));
|
network_time - timer_mgr->LastTimestamp()));
|
||||||
|
|
||||||
|
DNS_Mgr::Stats dstats;
|
||||||
|
dns_mgr->GetStats(&dstats);
|
||||||
|
|
||||||
|
file->Write(fmt("%.06f DNS_Mgr: requests=%lu succesful=%lu failed=%lu pending=%lu cached_hosts=%lu cached_addrs=%lu\n",
|
||||||
|
network_time,
|
||||||
|
dstats.requests, dstats.successful, dstats.failed, dstats.pending,
|
||||||
|
dstats.cached_hosts, dstats.cached_addresses));
|
||||||
|
|
||||||
|
Trigger::Stats tstats;
|
||||||
|
Trigger::GetStats(&tstats);
|
||||||
|
|
||||||
|
file->Write(fmt("%.06f Triggers: total=%lu pending=%lu\n", network_time, tstats.total, tstats.pending));
|
||||||
|
|
||||||
unsigned int* current_timers = TimerMgr::CurrentTimers();
|
unsigned int* current_timers = TimerMgr::CurrentTimers();
|
||||||
for ( int i = 0; i < NUM_TIMER_TYPES; ++i )
|
for ( int i = 0; i < NUM_TIMER_TYPES; ++i )
|
||||||
{
|
{
|
||||||
|
|
|
@ -110,6 +110,8 @@ Trigger::Trigger(Expr* arg_cond, Stmt* arg_body, Stmt* arg_timeout_stmts,
|
||||||
is_return = arg_is_return;
|
is_return = arg_is_return;
|
||||||
location = arg_location;
|
location = arg_location;
|
||||||
|
|
||||||
|
++total_triggers;
|
||||||
|
|
||||||
DBG_LOG(DBG_NOTIFIERS, "%s: instantiating", Name());
|
DBG_LOG(DBG_NOTIFIERS, "%s: instantiating", Name());
|
||||||
|
|
||||||
if ( is_return )
|
if ( is_return )
|
||||||
|
@ -165,6 +167,7 @@ void Trigger::Init()
|
||||||
}
|
}
|
||||||
|
|
||||||
Trigger::TriggerList* Trigger::pending = 0;
|
Trigger::TriggerList* Trigger::pending = 0;
|
||||||
|
unsigned long Trigger::total_triggers = 0;
|
||||||
|
|
||||||
bool Trigger::Eval()
|
bool Trigger::Eval()
|
||||||
{
|
{
|
||||||
|
@ -413,3 +416,9 @@ const char* Trigger::Name()
|
||||||
return fmt("%s:%d-%d", location->filename,
|
return fmt("%s:%d-%d", location->filename,
|
||||||
location->first_line, location->last_line);
|
location->first_line, location->last_line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Trigger::GetStats(Stats* stats)
|
||||||
|
{
|
||||||
|
stats->total = total_triggers;
|
||||||
|
stats->pending = pending ? pending->size() : 0;
|
||||||
|
}
|
||||||
|
|
|
@ -67,6 +67,13 @@ public:
|
||||||
// Evaluates all queued Triggers.
|
// Evaluates all queued Triggers.
|
||||||
static void EvaluatePending();
|
static void EvaluatePending();
|
||||||
|
|
||||||
|
struct Stats {
|
||||||
|
unsigned long total;
|
||||||
|
unsigned long pending;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void GetStats(Stats* stats);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class TriggerTraversalCallback;
|
friend class TriggerTraversalCallback;
|
||||||
friend class TriggerTimer;
|
friend class TriggerTimer;
|
||||||
|
@ -99,6 +106,8 @@ private:
|
||||||
|
|
||||||
typedef list<Trigger*> TriggerList;
|
typedef list<Trigger*> TriggerList;
|
||||||
static TriggerList* pending;
|
static TriggerList* pending;
|
||||||
|
|
||||||
|
static unsigned long total_triggers;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -560,7 +560,7 @@ function to_addr%(ip: string%): addr
|
||||||
|
|
||||||
function count_to_v4_addr%(ip: count%): addr
|
function count_to_v4_addr%(ip: count%): addr
|
||||||
%{
|
%{
|
||||||
if ( ip > 4294967295 )
|
if ( ip > 4294967295LU )
|
||||||
{
|
{
|
||||||
builtin_error("conversion of non-IPv4 count to addr", @ARG@[0]);
|
builtin_error("conversion of non-IPv4 count to addr", @ARG@[0]);
|
||||||
return new AddrVal(uint32(0));
|
return new AddrVal(uint32(0));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue