From a6017aa728c12c48faf758e6df3b3a1e2b704dad Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Sat, 11 Oct 2008 19:25:16 +0200 Subject: [PATCH] Add mean calculation in debug tools Another simple performance counter... Signed-off-by: Marco Costalba --- src/misc.cpp | 9 +++++++++ src/misc.h | 9 ++++++++- src/search.cpp | 6 ++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/misc.cpp b/src/misc.cpp index 07d58d63..8c2fc28a 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -51,6 +51,9 @@ int gettimeofday(struct timeval * tp, struct timezone * tzp); long dbg_cnt0 = 0; long dbg_cnt1 = 0; +bool dbg_show_mean = false; +bool dbg_show_hit_rate = false; + //// //// Functions @@ -63,6 +66,12 @@ void dbg_print_hit_rate() { << std::endl; } +void dbg_print_mean() { + + std::cout << "Total " << dbg_cnt0 << " Mean " + << (float)dbg_cnt1 / (dbg_cnt0 ? dbg_cnt0 : 1) << std::endl; +} + /// engine_name() returns the full name of the current Glaurung version. /// This will be either "Glaurung YYMMDD" (where YYMMDD is the date when the /// program was compiled) or "Glaurung ", depending on whether diff --git a/src/misc.h b/src/misc.h index a1c76e87..d3b555cb 100644 --- a/src/misc.h +++ b/src/misc.h @@ -61,7 +61,6 @@ extern int Bioskey(); //// extern long dbg_cnt0; extern long dbg_cnt1; -extern void dbg_print_hit_rate(); inline void dbg_hit_on(bool b) { dbg_cnt0++; if (b) dbg_cnt1++; } inline void dbg_hit_on_c(bool c, bool b) { if (c) dbg_hit_on(b); } @@ -69,4 +68,12 @@ inline void dbg_hit_on_c(bool c, bool b) { if (c) dbg_hit_on(b); } inline void dbg_before() { dbg_cnt0++; } inline void dbg_after() { dbg_cnt1++; } +inline void dbg_mean_of(int v) { dbg_cnt0++; dbg_cnt1 += v; } + +extern void dbg_print_hit_rate(); +extern void dbg_print_mean(); + +extern bool dbg_show_mean; +extern bool dbg_show_hit_rate; + #endif // !defined(MISC_H_INCLUDED) diff --git a/src/search.cpp b/src/search.cpp index 4b966f61..8279d157 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -2172,6 +2172,12 @@ namespace { { lastInfoTime = t; lock_grab(&IOLock); + if (dbg_show_mean) + dbg_print_mean(); + + if (dbg_show_hit_rate) + dbg_print_hit_rate(); + std::cout << "info nodes " << nodes_searched() << " nps " << nps() << " time " << t << " hashfull " << TT.full() << std::endl; lock_release(&IOLock); -- 2.39.2