]> git.sesse.net Git - stockfish/commitdiff
Simplify debug functions
authorMarco Costalba <mcostalba@gmail.com>
Fri, 30 Dec 2011 15:14:24 +0000 (16:14 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Fri, 30 Dec 2011 15:23:11 +0000 (16:23 +0100)
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/misc.cpp
src/misc.h
src/search.cpp
src/thread.cpp

index 9cd953922ce8d59a685ef2c50d56a68a5088187b..2fb5e816f0320f8a504afe8d8e961d10b2d6b5b2 100644 (file)
 #  include <xmmintrin.h>
 #endif
 
+#include <algorithm>
 #include <cassert>
 #include <cstdio>
 #include <iomanip>
 #include <iostream>
 #include <sstream>
-#include <algorithm>
 
 #include "bitcount.h"
 #include "misc.h"
@@ -52,7 +52,6 @@
 
 using namespace std;
 
-
 /// Version number. If Version is left empty, then Tag plus current
 /// date (in the format YYMMDD) is used as a version number.
 
@@ -93,44 +92,25 @@ const string engine_info(bool to_uci) {
 }
 
 
-/// Debug stuff. Helper functions used mainly for debugging purposes
-
-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)
-      cerr << "Total " << dbg_hit_cnt0 << " Hit " << dbg_hit_cnt1
-           << " hit rate (%) " << 100 * dbg_hit_cnt1 / dbg_hit_cnt0 << endl;
-}
+/// Debug functions used mainly to collect run-time statistics
 
-void dbg_print_mean() {
+static uint64_t hits[2], means[2];
 
-  if (dbg_mean_cnt0)
-      cerr << "Total " << dbg_mean_cnt0 << " Mean "
-           << (float)dbg_mean_cnt1 / dbg_mean_cnt0 << endl;
-}
-
-void dbg_mean_of(int v) {
+void dbg_hit_on(bool b) { hits[0]++; if (b) hits[1]++; }
+void dbg_hit_on_c(bool c, bool b) { if (c) dbg_hit_on(b); }
+void dbg_mean_of(int v) { means[0]++; means[1] += v; }
 
-  dbg_mean_cnt0++;
-  dbg_mean_cnt1 += v;
-}
+void dbg_print() {
 
-void dbg_hit_on(bool b) {
+  if (hits[0])
+      cerr << "Total " << hits[0] << " Hits " << hits[1]
+           << " hit rate (%) " << 100 * hits[1] / hits[0] << endl;
 
-  dbg_hit_cnt0++;
-  if (b)
-      dbg_hit_cnt1++;
+  if (means[0])
+      cerr << "Total " << means[0] << " Mean "
+           << (float)means[1] / means[0] << endl;
 }
 
-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--; }
-
 
 /// system_time() returns the current system time, measured in milliseconds
 
index 55e2f55ebe0d15b841407bb3440e44c35dc24a87..d6fb062fb6f96f404bc7957b3be2567de91ab316 100644 (file)
@@ -34,11 +34,8 @@ extern void prefetch(char* addr);
 
 extern void dbg_hit_on(bool b);
 extern void dbg_hit_on_c(bool c, bool b);
-extern void dbg_before();
-extern void dbg_after();
 extern void dbg_mean_of(int v);
-extern void dbg_print_hit_rate();
-extern void dbg_print_mean();
+extern void dbg_print();
 
 class Position;
 extern Move move_from_uci(const Position& pos, const std::string& str);
index 9222cbbd9fbb66a182211648b23012a44bad0eb0..ebdcff0fa14f754b8c56f9bd66db05adf8c8e71c 100644 (file)
@@ -1974,9 +1974,7 @@ void do_timer_event() {
   if (system_time() - lastInfoTime >= 1000 || !lastInfoTime)
   {
       lastInfoTime = system_time();
-
-      dbg_print_mean();
-      dbg_print_hit_rate();
+      dbg_print();
   }
 
   if (Limits.ponder)
index 4c582e08d54645933dd2b8bd627938259faa2f5f..bc26d4df3462ffe354085bc6c2fe00688b2739a6 100644 (file)
@@ -176,10 +176,10 @@ void ThreadsManager::init() {
       threads[i].threadID = i;
 
 #if defined(_MSC_VER)
-      threads[i].handle = CreateThread(NULL, 0, start_routine, (LPVOID)&threads[i], 0, NULL);
+      threads[i].handle = CreateThread(NULL, 0, start_routine, &threads[i], 0, NULL);
       bool ok = (threads[i].handle != NULL);
 #else
-      bool ok = !pthread_create(&threads[i].handle, NULL, start_routine, (void*)&threads[i]);
+      bool ok = !pthread_create(&threads[i].handle, NULL, start_routine, &threads[i]);
 #endif
 
       if (!ok)