mirror of
https://github.com/zeek/zeek.git
synced 2025-10-06 08:38:20 +00:00
make curr_CPU_time() broadly available rather than just isolated to ZAM
This commit is contained in:
parent
aa5a5b2136
commit
41aee03c17
3 changed files with 14 additions and 11 deletions
|
@ -124,13 +124,6 @@ VEC_COERCE(UD, TYPE_COUNT, bro_uint_t, AsDouble(), double_to_count_would_overflo
|
|||
"double to unsigned")
|
||||
VEC_COERCE(UI, TYPE_COUNT, bro_int_t, AsInt(), int_to_count_would_overflow, "signed to unsigned")
|
||||
|
||||
double curr_CPU_time()
|
||||
{
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts);
|
||||
return double(ts.tv_sec) + double(ts.tv_nsec) / 1e9;
|
||||
}
|
||||
|
||||
ZBody::ZBody(const char* _func_name, const ZAMCompiler* zc) : Stmt(STMT_ZAM)
|
||||
{
|
||||
func_name = _func_name;
|
||||
|
@ -240,14 +233,14 @@ void ZBody::InitProfile()
|
|||
ValPtr ZBody::Exec(Frame* f, StmtFlowType& flow)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
double t = analysis_options.profile_ZAM ? curr_CPU_time() : 0.0;
|
||||
double t = analysis_options.profile_ZAM ? util::curr_CPU_time() : 0.0;
|
||||
#endif
|
||||
|
||||
auto val = DoExec(f, 0, flow);
|
||||
|
||||
#ifdef DEBUG
|
||||
if ( analysis_options.profile_ZAM )
|
||||
*CPU_time += curr_CPU_time() - t;
|
||||
*CPU_time += util::curr_CPU_time() - t;
|
||||
#endif
|
||||
|
||||
return val;
|
||||
|
@ -305,7 +298,7 @@ ValPtr ZBody::DoExec(Frame* f, int start_pc, StmtFlowType& flow)
|
|||
++(*inst_count)[pc];
|
||||
|
||||
profile_pc = pc;
|
||||
profile_CPU = curr_CPU_time();
|
||||
profile_CPU = util::curr_CPU_time();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -327,7 +320,7 @@ ValPtr ZBody::DoExec(Frame* f, int start_pc, StmtFlowType& flow)
|
|||
#ifdef DEBUG
|
||||
if ( do_profile )
|
||||
{
|
||||
double dt = curr_CPU_time() - profile_CPU;
|
||||
double dt = util::curr_CPU_time() - profile_CPU;
|
||||
inst_CPU->at(profile_pc) += dt;
|
||||
ZOP_CPU[z.op] += dt;
|
||||
}
|
||||
|
|
|
@ -2058,6 +2058,13 @@ int time_compare(struct timeval* tv_a, struct timeval* tv_b)
|
|||
return tv_a->tv_sec - tv_b->tv_sec;
|
||||
}
|
||||
|
||||
double curr_CPU_time()
|
||||
{
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts);
|
||||
return double(ts.tv_sec) + double(ts.tv_nsec) / 1e9;
|
||||
}
|
||||
|
||||
struct UIDEntry
|
||||
{
|
||||
UIDEntry() : key(0, 0), needs_init(true) { }
|
||||
|
|
|
@ -424,6 +424,9 @@ extern struct timeval double_to_timeval(double t);
|
|||
// Return > 0 if tv_a > tv_b, 0 if equal, < 0 if tv_a < tv_b.
|
||||
extern int time_compare(struct timeval* tv_a, struct timeval* tv_b);
|
||||
|
||||
// Returns the CPU time consumed to date.
|
||||
extern double curr_CPU_time();
|
||||
|
||||
// Returns an integer that's very likely to be unique, even across Zeek
|
||||
// instances. The integer can be drawn from different pools, which is helpful
|
||||
// when the random number generator is seeded to be deterministic. In that
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue