1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-05-01 09:13:08 +00:00

Cleanup debug counters

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2011-04-13 15:12:33 +02:00
parent 54f1c383d3
commit 7f367e6019
6 changed files with 125 additions and 164 deletions

View file

@ -64,7 +64,7 @@ int main(int argc, char* argv[]) {
if (argc < 2) if (argc < 2)
{ {
// Print copyright notice // Print copyright notice
cout << engine_name() << " by " << engine_author() << endl; cout << engine_name() << " by " << engine_authors() << endl;
if (CpuHasPOPCNT) if (CpuHasPOPCNT)
cout << "Good! CPU has hardware POPCNT." << endl; cout << "Good! CPU has hardware POPCNT." << endl;

View file

@ -17,11 +17,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
////
//// Includes
////
#if !defined(_MSC_VER) #if !defined(_MSC_VER)
# include <sys/time.h> # include <sys/time.h>
@ -55,83 +50,18 @@
using namespace std; using namespace std;
/// Version number. If this is left empty, the current date (in the format /// Version number. If EngineVersion is left empty, then AppTag plus
/// YYMMDD) is used as a version number. /// current date (in the format YYMMDD) is used as a version number.
static const string EngineVersion = "";
static const string AppName = "Stockfish"; static const string AppName = "Stockfish";
static const string EngineVersion = "";
static const string AppTag = ""; static const string AppTag = "";
////
//// Variables
////
static uint64_t dbg_cnt0 = 0;
static uint64_t dbg_cnt1 = 0;
bool dbg_show_mean = false;
bool dbg_show_hit_rate = false;
////
//// Functions
////
void dbg_hit_on(bool b) {
assert(!dbg_show_mean);
dbg_show_hit_rate = true;
dbg_cnt0++;
if (b)
dbg_cnt1++;
}
void dbg_hit_on_c(bool c, bool b) {
if (c)
dbg_hit_on(b);
}
void dbg_before() {
assert(!dbg_show_mean);
dbg_show_hit_rate = true;
dbg_cnt0++;
}
void dbg_after() {
assert(!dbg_show_mean);
dbg_show_hit_rate = true;
dbg_cnt1++;
}
void dbg_mean_of(int v) {
assert(!dbg_show_hit_rate);
dbg_show_mean = true;
dbg_cnt0++;
dbg_cnt1 += v;
}
void dbg_print_hit_rate() {
cout << "Total " << dbg_cnt0 << " Hit " << dbg_cnt1
<< " hit rate (%) " << (dbg_cnt1*100)/(dbg_cnt0 ? dbg_cnt0 : 1) << endl;
}
void dbg_print_mean() {
cout << "Total " << dbg_cnt0 << " Mean "
<< (float)dbg_cnt1 / (dbg_cnt0 ? dbg_cnt0 : 1) << endl;
}
/// engine_name() returns the full name of the current Stockfish version. /// engine_name() returns the full name of the current Stockfish version.
/// This will be either "Stockfish YYMMDD" (where YYMMDD is the date when /// This will be either "Stockfish YYMMDD" (where YYMMDD is the date when
/// the program was compiled) or "Stockfish <version number>", depending /// the program was compiled) or "Stockfish <version number>", depending
/// on whether the constant EngineVersion (defined in misc.h) is empty. /// on whether the constant EngineVersion is empty.
const string engine_name() { const string engine_name() {
@ -154,65 +84,101 @@ const string engine_name() {
return s.str(); return s.str();
} }
const string engine_author() { return "Tord Romstad, Marco Costalba and Joona Kiiski"; }
/// Our brave developers! Required by UCI
const string engine_authors() {
return "Tord Romstad, Marco Costalba and Joona Kiiski";
}
/// get_system_time() returns the current system time, measured in /// Debug stuff. Helper functions used mainly for debugging purposes
/// milliseconds.
static uint64_t dbg_hit_cnt0;
static uint64_t dbg_hit_cnt1;
static uint64_t dbg_mean_cnt0;
static uint64_t dbg_mean_cnt1;
void dbg_print_hit_rate() {
if (dbg_hit_cnt0)
cout << "Total " << dbg_hit_cnt0 << " Hit " << dbg_hit_cnt1
<< " hit rate (%) " << 100 * dbg_hit_cnt1 / (dbg_hit_cnt0 + 1) << endl;
}
void dbg_print_mean() {
if (dbg_mean_cnt0)
cout << "Total " << dbg_mean_cnt0 << " Mean "
<< (float)dbg_mean_cnt1 / (dbg_mean_cnt0 + 1) << endl;
}
void dbg_mean_of(int v) {
dbg_mean_cnt0++;
dbg_mean_cnt1 += v;
}
void dbg_hit_on(bool b) {
dbg_hit_cnt0++;
if (b)
dbg_hit_cnt1++;
}
void dbg_hit_on_c(bool c, bool b) { if (c) dbg_hit_on(b); }
void dbg_before() { dbg_hit_on(false); }
void dbg_after() { dbg_hit_on(true); dbg_hit_cnt0--; }
/// get_system_time() returns the current system time, measured in milliseconds
int get_system_time() { int get_system_time() {
#if defined(_MSC_VER) #if defined(_MSC_VER)
struct _timeb t; struct _timeb t;
_ftime(&t); _ftime(&t);
return int(t.time*1000 + t.millitm); return int(t.time * 1000 + t.millitm);
#else #else
struct timeval t; struct timeval t;
gettimeofday(&t, NULL); gettimeofday(&t, NULL);
return t.tv_sec*1000 + t.tv_usec/1000; return t.tv_sec * 1000 + t.tv_usec / 1000;
#endif #endif
} }
/// cpu_count() tries to detect the number of CPU cores. /// cpu_count() tries to detect the number of CPU cores
#if !defined(_MSC_VER)
# if defined(_SC_NPROCESSORS_ONLN)
int cpu_count() {
return Min(sysconf(_SC_NPROCESSORS_ONLN), MAX_THREADS);
}
# elif defined(__hpux)
int cpu_count() {
struct pst_dynamic psd;
if (pstat_getdynamic(&psd, sizeof(psd), (size_t)1, 0) == -1)
return 1;
return Min(psd.psd_proc_cnt, MAX_THREADS);
}
# else
int cpu_count() {
return 1;
}
# endif
#else
int cpu_count() { int cpu_count() {
#if defined(_MSC_VER)
SYSTEM_INFO s; SYSTEM_INFO s;
GetSystemInfo(&s); GetSystemInfo(&s);
return Min(s.dwNumberOfProcessors, MAX_THREADS); return Min(s.dwNumberOfProcessors, MAX_THREADS);
} #else
# if defined(_SC_NPROCESSORS_ONLN)
return Min(sysconf(_SC_NPROCESSORS_ONLN), MAX_THREADS);
# elif defined(__hpux)
struct pst_dynamic psd;
if (pstat_getdynamic(&psd, sizeof(psd), (size_t)1, 0) == -1)
return 1;
return Min(psd.psd_proc_cnt, MAX_THREADS);
# else
return 1;
# endif
#endif #endif
}
/// Check for console input. Original code from Beowulf, Olithink and Greko /// Check for console input. Original code from Beowulf, Olithink and Greko
#ifndef _WIN32 #ifndef _WIN32
int input_available() int input_available() {
{
fd_set readfds; fd_set readfds;
struct timeval timeout; struct timeval timeout;
@ -227,8 +193,8 @@ int input_available()
#else #else
int input_available() int input_available() {
{
static HANDLE inh = NULL; static HANDLE inh = NULL;
static bool usePipe = false; static bool usePipe = false;
INPUT_RECORD rec[256]; INPUT_RECORD rec[256];
@ -282,9 +248,11 @@ int input_available()
/// prefetch() preloads the given address in L1/L2 cache. This is a non /// prefetch() preloads the given address in L1/L2 cache. This is a non
/// blocking function and do not stalls the CPU waiting for data to be /// blocking function and do not stalls the CPU waiting for data to be
/// loaded from RAM, that can be very slow. /// loaded from memory, that can be quite slow.
#if defined(NO_PREFETCH) #if defined(NO_PREFETCH)
void prefetch(char*) {} void prefetch(char*) {}
#else #else
void prefetch(char* addr) { void prefetch(char* addr) {
@ -300,4 +268,3 @@ void prefetch(char* addr) {
} }
#endif #endif

View file

@ -24,16 +24,13 @@
#include "types.h" #include "types.h"
extern const std::string engine_name(); extern const std::string engine_name();
extern const std::string engine_author(); extern const std::string engine_authors();
extern int get_system_time(); extern int get_system_time();
extern int cpu_count(); extern int cpu_count();
extern int input_available(); extern int input_available();
extern void prefetch(char* addr); extern void prefetch(char* addr);
extern void prefetchTables(Key pKey, Key mKey, int threadID); extern void prefetchTables(Key pKey, Key mKey, int threadID);
// Debug functions
extern bool dbg_show_mean;
extern bool dbg_show_hit_rate;
extern void dbg_hit_on(bool b); extern void dbg_hit_on(bool b);
extern void dbg_hit_on_c(bool c, bool b); extern void dbg_hit_on_c(bool c, bool b);
extern void dbg_before(); extern void dbg_before();

View file

@ -33,7 +33,7 @@ enum MoveType {
MV_PSEUDO_LEGAL MV_PSEUDO_LEGAL
}; };
template<MoveType T> template<MoveType>
MoveStack* generate(const Position& pos, MoveStack* mlist); MoveStack* generate(const Position& pos, MoveStack* mlist);
#endif // !defined(MOVEGEN_H_INCLUDED) #endif // !defined(MOVEGEN_H_INCLUDED)

View file

@ -1933,10 +1933,7 @@ split_point_start: // At split points actual search starts from here
{ {
lastInfoTime = t; lastInfoTime = t;
if (dbg_show_mean)
dbg_print_mean(); dbg_print_mean();
if (dbg_show_hit_rate)
dbg_print_hit_rate(); dbg_print_hit_rate();
// Send info on searched nodes as soon as we return to root // Send info on searched nodes as soon as we return to root

View file

@ -77,7 +77,7 @@ bool execute_uci_command(const string& cmd) {
else if (token == "uci") else if (token == "uci")
cout << "id name " << engine_name() cout << "id name " << engine_name()
<< "\nid author " << engine_author() << "\nid author " << engine_authors()
<< "\n" << options_to_uci() << "\n" << options_to_uci()
<< "\nuciok" << endl; << "\nuciok" << endl;