Jeroen Demeyer on Sat, 11 Sep 2004 11:39:45 +0200


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

patch: Timing using system() or extern()


The attached patch makes the PARI timer also count the time spent in a system() or extern() call. This allows for instance to time a call to mwrank.

Technically: times() is used instead of getrusage(). times() easily allows one to get the time for child processes.
Index: config/get_libc
===================================================================
RCS file: /home/cvs/pari/config/get_libc,v
retrieving revision 1.5
diff -u -r1.5 get_libc
--- config/get_libc	5 May 2004 12:36:37 -0000	1.5
+++ config/get_libc	11 Sep 2004 09:14:15 -0000
@@ -13,7 +13,7 @@
   alpha) list='times ftime';; # gp-dyn has problems with getrusage 
   *) case "$osname" in
     *cygwin*) list='times ftime';; # getrusage based timer always returns 0
-    *) list='getrusage times ftime';;
+    *) list='times getrusage ftime';;
     esac;;
 esac; . ./look
 list='sigsetmask sigrelse'; . ./look
Index: config/has_times.c
===================================================================
RCS file: /home/cvs/pari/config/has_times.c,v
retrieving revision 1.2
diff -u -r1.2 has_times.c
--- config/has_times.c	7 Jan 2003 20:33:19 -0000	1.2
+++ config/has_times.c	11 Sep 2004 09:14:15 -0000
@@ -1,2 +1,3 @@
 #include <stdio.h>
-main(){ extern int times(); printf("%d",times());}
+#include <sys/times.h>
+main(){ struct tms t; printf("%d",times(&t));}
Index: config/paricfg.h.SH
===================================================================
RCS file: /home/cvs/pari/config/paricfg.h.SH,v
retrieving revision 1.23
diff -u -r1.23 paricfg.h.SH
--- config/paricfg.h.SH	19 Jul 2004 14:49:42 -0000	1.23
+++ config/paricfg.h.SH	11 Sep 2004 09:14:15 -0000
@@ -150,10 +150,10 @@
 no) echo '#define ULONG_NOT_DEFINED' >> $file;;
 esac
 
-case "$has_getrusage" in
-yes) echo '#define USE_GETRUSAGE 1' >> $file;;
-  *) case "$has_times" in
-     yes) echo '#define USE_TIMES 1' >> $file;;
+case "$has_times" in
+yes) echo '#define USE_TIMES 1' >> $file;;
+  *) case "$has_getrusage" in
+     yes) echo '#define USE_GETRUSAGE 1' >> $file;;
        *) case "$has_ftime" in
           yes) echo '#define USE_FTIME 1' >> $file;;
           esac;;
Index: src/headers/pari.h
===================================================================
RCS file: /home/cvs/pari/src/headers/pari.h,v
retrieving revision 1.4
diff -u -r1.4 pari.h
--- src/headers/pari.h	22 Jul 2004 15:28:32 -0000	1.4
+++ src/headers/pari.h	11 Sep 2004 09:14:17 -0000
@@ -35,6 +35,10 @@
 #  include <stdio.h>
 #endif
 
+#ifdef USE_TIMES
+#  include <sys/times.h>
+#endif
+
 #include <stdarg.h>
 #include <setjmp.h>
 #include <string.h>
Index: src/language/init.c
===================================================================
RCS file: /home/cvs/pari/src/language/init.c,v
retrieving revision 1.238
diff -u -r1.238 init.c
--- src/language/init.c	8 Sep 2004 10:51:54 -0000	1.238
+++ src/language/init.c	11 Sep 2004 09:14:21 -0000
@@ -1906,7 +1906,7 @@
 TIMER(pari_timer *T)
 {
   struct tms t; times(&t);
-  return _get_time(T, t.tms_utime, CLK_TCK);
+  return _get_time(T, t.tms_utime + t.tms_cutime, CLK_TCK);
 }
 #elif USE_GETRUSAGE