Minor renaming changes to event handler stats bif, plus a test

This commit is contained in:
Tim Wojtulewicz 2022-11-11 16:32:55 -07:00
parent accac2d3bb
commit bfd5b06943
4 changed files with 14 additions and 9 deletions

View file

@ -797,9 +797,9 @@ type ReporterStats: record {
## .. zeek:see:: get_event_handler_call_counts
type EventNameCounter: record {
## Name of the zeek event.
name: string &log;
## Times it was queued, as captured by event hook.
times_queued: count &log;
name: string &log;
## Times it was called, as counted by the event handlers.
times_called: count &log;
} &log;
type EventNameStats: vector of EventNameCounter;

View file

@ -485,17 +485,15 @@ function get_reporter_stats%(%): ReporterStats
return r;
%}
## Returns a list of event handlers that were called and the number of times
## each was called.
## Returns statistics about calls to event handlers.
##
## Returns: A record with event call statistics.
##
function get_event_handler_call_counts%(%): EventNameStats
function get_event_handler_stats%(%): EventNameStats
%{
auto rval = zeek::make_intrusive<zeek::VectorVal>(zeek::id::find_type<VectorType>("EventNameStats"));
const auto& recordType = zeek::id::find_type<RecordType>("EventNameCounter");
int i = 0;
const auto& events = event_registry->UsedHandlers();
for ( const auto& name : events )
{
@ -507,8 +505,7 @@ function get_event_handler_call_counts%(%): EventNameStats
auto eventStatRecord = zeek::make_intrusive<zeek::RecordVal>(recordType);
eventStatRecord->Assign(0, zeek::make_intrusive<zeek::StringVal>(name));
eventStatRecord->Assign(1, zeek::val_mgr->Count(handler->CallCount()));
rval->Assign(i, std::move(eventStatRecord));
i++;
rval->Append(std::move(eventStatRecord));
}
}

View file

@ -0,0 +1 @@
[[name=Broker::log_flush, times_called=2], [name=ChecksumOffloading::check, times_called=2], [name=NetControl::init, times_called=1], [name=analyzer_confirmation_info, times_called=1], [name=connection_established, times_called=1], [name=connection_state_remove, times_called=1], [name=file_new, times_called=1], [name=file_over_new_connection, times_called=1], [name=file_sniff, times_called=1], [name=file_state_remove, times_called=1], [name=filter_change_tracking, times_called=3], [name=get_file_handle, times_called=4], [name=http_begin_entity, times_called=2], [name=http_end_entity, times_called=2], [name=http_header, times_called=13], [name=http_message_done, times_called=2], [name=http_reply, times_called=1], [name=http_request, times_called=1], [name=net_done, times_called=1], [name=new_connection, times_called=1], [name=run_sync_hook, times_called=2], [name=zeek_done, times_called=1], [name=zeek_init, times_called=1]]

View file

@ -0,0 +1,7 @@
# @TEST-EXEC: zeek -r $TRACES/http/get.trace %INPUT >out
# @TEST-EXEC: btest-diff out
event zeek_done()
{
print(get_event_handler_stats());
}