gnugo-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnugo-devel] trevor_1_10.6: CPU time


From: Trevor Morris
Subject: [gnugo-devel] trevor_1_10.6: CPU time
Date: Sun, 14 Oct 2001 15:47:43 -0400

Here's a command I'd like to add.  It returns the actual CPU time
used by the application.  There is some difficulty in having the
controller return this information on the fly, especially on Win32
systems, so having this simple GTP command will help quite a bit.

I've tested on both cygwin & VC builds, but I've also added a new
header, so it may break on other systems.  May also require an
automake modification.

Also, I'll remind the automake maintainer:
  - Cygwin default installs curses.h under ncurses, and by adding
    a symlink to it, the cygwin colors (for -T) work fine.  Can
    automake be enhanced to detect this case, and the include of
    curses.h in display.h modified?

-Trevor

http://www.public32.com/games/go/trevor_1_10.6

(For reference - use the web-diff to patch...)

Index: play_gtp.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/interface/play_gtp.c,v
retrieving revision 1.21
diff -u -b -r1.21 play_gtp.c
--- play_gtp.c  2001/10/06 20:00:51     1.21
+++ play_gtp.c  2001/10/14 19:34:19
@@ -28,6 +28,9 @@
 #include <assert.h>
 #include <ctype.h>
 #include <string.h>
+#ifndef HAVE_VISUAL_C
+#include <sys/times.h>
+#endif
 
 #include "gnugo.h"
 #include "interface.h"
@@ -70,6 +73,7 @@
 DECLARE(gtp_combination_attack);
 DECLARE(gtp_connect);
 DECLARE(gtp_countlib);
+DECLARE(gtp_cputime);
 DECLARE(gtp_debug_influence);
 DECLARE(gtp_debug_move_influence);
 DECLARE(gtp_decrease_depths);
@@ -141,6 +145,7 @@
   {"combination_attack",      gtp_combination_attack},
   {"connect",                gtp_connect},
   {"countlib",                       gtp_countlib},
+  {"cputime",                            gtp_cputime},
   {"debug_influence",         gtp_debug_influence},
   {"debug_move_influence",    gtp_debug_move_influence},
   {"decrease_depths",                gtp_decrease_depths},
@@ -1697,6 +1702,39 @@
  * debug *
  *********/
 
+
+/* Function:  Returns elapsed CPU time.
+ * Arguments: none
+ * Fails:     never
+ * Returns:   Total elapsed (user + system) CPU time in milliseconds
+ */
+static int
+gtp_cputime(char *s, int id)
+{
+#ifdef WIN32
+    FILETIME creationTime, exitTime, kernelTime, userTime;
+    ULARGE_INTEGER uKernelTime,uUserTime,uElapsedTime;
+    unsigned long ulElapsedTime;
+    UNUSED(s);
+    GetProcessTimes(GetCurrentProcess(), &creationTime, &exitTime,
&kernelTime, &userTime);
+    uKernelTime.LowPart = kernelTime.dwLowDateTime;
+    uKernelTime.HighPart = kernelTime.dwHighDateTime;
+    uUserTime.LowPart = userTime.dwLowDateTime;
+    uUserTime.HighPart = userTime.dwHighDateTime;
+    uElapsedTime.QuadPart = uKernelTime.QuadPart + uUserTime.QuadPart;
+    ulElapsedTime = (unsigned long)(uElapsedTime.QuadPart / 10000); /*
convert to milliseconds: */
+    /*_ASSERTE(0 && "Debug Times");*/
+    return gtp_success(id, "%ld", ulElapsedTime);
+#else
+    struct tms t;
+    UNUSED(s);
+    times(&t);
+       return gtp_success(id, "%ld", t.tms_utime + t.tms_stime + t.tms_cutime +
t.tms_cstime);
+#endif
+}
+
+
+
 /* Function:  Write the position to stderr.
  * Arguments: none
  * Fails:     never





reply via email to

[Prev in Thread] Current Thread [Next in Thread]