From b47620e501944acddde0277fd2e9c7ab4de6cfec Mon Sep 17 00:00:00 2001 From: Bernhard Amann Date: Fri, 30 Mar 2012 09:18:44 -0700 Subject: [PATCH] add a couple more configuration options --- .../frameworks/input/readers/benchmark.bro | 6 +++++ src/input.bif | 2 ++ src/input/readers/Benchmark.cc | 23 +++++++++++++++---- src/input/readers/Benchmark.h | 3 +++ 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/scripts/base/frameworks/input/readers/benchmark.bro b/scripts/base/frameworks/input/readers/benchmark.bro index 0f3553b117..b5adc70861 100644 --- a/scripts/base/frameworks/input/readers/benchmark.bro +++ b/scripts/base/frameworks/input/readers/benchmark.bro @@ -14,4 +14,10 @@ export { ## addition factor for each heartbeat const addfactor = 0 &redef; + + ## stop spreading at x lines per heartbeat + const stopspreadat = 0 &redef; + + ## 1 -> enable timed spreading + const timedspread = 0 &redef; } diff --git a/src/input.bif b/src/input.bif index 798759ab66..63cbb2796d 100644 --- a/src/input.bif +++ b/src/input.bif @@ -51,3 +51,5 @@ const factor: double; const spread: count; const autospread: double; const addfactor: count; +const stopspreadat: count; +const timedspread: count; diff --git a/src/input/readers/Benchmark.cc b/src/input/readers/Benchmark.cc index a914f1a2e8..391fdd7435 100644 --- a/src/input/readers/Benchmark.cc +++ b/src/input/readers/Benchmark.cc @@ -26,6 +26,8 @@ Benchmark::Benchmark(ReaderFrontend *frontend) : ReaderBackend(frontend) spread = int(BifConst::InputBenchmark::spread); add = int(BifConst::InputBenchmark::addfactor); autospread_time = 0; + stopspreadat = int(BifConst::InputBenchmark::stopspreadat); + timedspread = int(BifConst::InputBenchmark::timedspread); } @@ -54,6 +56,7 @@ bool Benchmark::DoInit(string path, int arg_mode, int arg_num_fields, const Fiel return false; } + heartbeatstarttime = CurrTime(); DoUpdate(); return true; @@ -97,12 +100,23 @@ bool Benchmark::DoUpdate() { SendEntry(field); } - if ( spread != 0 ) - usleep(spread); + if ( stopspreadat == 0 || num_lines < stopspreadat ) { + if ( spread != 0 ) + usleep(spread); - if ( autospread_time != 0 ) { - usleep( autospread_time ); + if ( autospread_time != 0 ) + usleep( autospread_time ); } + + if ( timedspread == 1 ) { + double diff; + do { + diff = CurrTime() - heartbeatstarttime; + //printf("%d %f\n", i, diff); + } while ( diff < i/(num_lines + (num_lines * 0.15) ) ); + //} while ( diff < 0.8); + } + } if ( mode != STREAM ) { @@ -215,6 +229,7 @@ bool Benchmark::DoHeartbeat(double network_time, double current_time) ReaderBackend::DoHeartbeat(network_time, current_time); num_lines = (int) ( (double) num_lines*multiplication_factor); num_lines += add; + heartbeatstarttime = CurrTime(); switch ( mode ) { case MANUAL: diff --git a/src/input/readers/Benchmark.h b/src/input/readers/Benchmark.h index 182adcd1af..e5dca66889 100644 --- a/src/input/readers/Benchmark.h +++ b/src/input/readers/Benchmark.h @@ -43,6 +43,9 @@ private: double autospread; int autospread_time; int add; + int stopspreadat; + double heartbeatstarttime; + int timedspread; string RandomString(const int len);