mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 22:58:20 +00:00
Merge remote-tracking branch 'origin/topic/bernhard/topk'
* origin/topic/bernhard/topk: adapt to new folder structure fix opaqueval-related memleak synchronize pruned attribute potentially found wrong Ref. add sum function that can be used to get the number of total observed elements. in cluster settings, the resultvals can apparently been uninitialized in some special cases fix memory leaks fix warnings add topk cluster test make size of topk-list configureable when using sumstats implement merging for top-k. add serialization for topk make the get function const topk for sumstats well, a test that works.. implement topk.
This commit is contained in:
commit
81dcda3eb4
19 changed files with 1288 additions and 3 deletions
|
@ -5,5 +5,6 @@
|
|||
@load ./sample
|
||||
@load ./std-dev
|
||||
@load ./sum
|
||||
@load ./topk
|
||||
@load ./unique
|
||||
@load ./variance
|
||||
|
|
50
scripts/base/frameworks/sumstats/plugins/topk.bro
Normal file
50
scripts/base/frameworks/sumstats/plugins/topk.bro
Normal file
|
@ -0,0 +1,50 @@
|
|||
@load base/frameworks/sumstats
|
||||
|
||||
module SumStats;
|
||||
|
||||
export {
|
||||
redef record Reducer += {
|
||||
## number of elements to keep in the top-k list
|
||||
topk_size: count &default=500;
|
||||
};
|
||||
|
||||
redef enum Calculation += {
|
||||
TOPK
|
||||
};
|
||||
|
||||
redef record ResultVal += {
|
||||
topk: opaque of topk &optional;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
hook init_resultval_hook(r: Reducer, rv: ResultVal)
|
||||
{
|
||||
if ( TOPK in r$apply && ! rv?$topk )
|
||||
rv$topk = topk_init(r$topk_size);
|
||||
}
|
||||
|
||||
hook observe_hook(r: Reducer, val: double, obs: Observation, rv: ResultVal)
|
||||
{
|
||||
if ( TOPK in r$apply )
|
||||
topk_add(rv$topk, obs);
|
||||
}
|
||||
|
||||
hook compose_resultvals_hook(result: ResultVal, rv1: ResultVal, rv2: ResultVal)
|
||||
{
|
||||
if ( rv1?$topk )
|
||||
{
|
||||
result$topk = topk_init(topk_size(rv1$topk));
|
||||
|
||||
topk_merge(result$topk, rv1$topk);
|
||||
|
||||
if ( rv2?$topk )
|
||||
topk_merge(result$topk, rv2$topk);
|
||||
}
|
||||
|
||||
else if ( rv2?$topk )
|
||||
{
|
||||
result$topk = topk_init(topk_size(rv2$topk));
|
||||
topk_merge(result$topk, rv2$topk);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue