This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

time usage for subprocesses



This is an interesting little hack which makes the gcc driver report user
and system time consumed by the compilation subprocesses.  It prints out
decimal seconds like this:

# cpp 1.21 0.04
# cc1 3.60 0.10
# as 0.12 0.02

-first user, then system.  The format is intended to be readily crunched by
a script.  You can get statistics like these:

# libc compile, -O2
cpp   	  851.09   178.59	  14:11.09    2:58.59
cc1   	 2400.45   123.45	  40:00.44    2:03.45
as    	  266.54    49.52	   4:26.54      49.52
total  	 3518.08   351.56	  58:38.08    5:51.56

# same with -O2 -pipe
cpp   	  854.05   171.45	  14:14.05    2:51.45
cc1   	 2405.74   104.15	  40:05.73    1:44.15
as    	  273.37    42.62	   4:33.37      42.62
total  	 3533.16   318.22	  58:53.16    5:18.22


The changes to gcc itself are not that exciting, but I had to modify
libiberty; I'm not sure about the portability issues there.  The feature
only works on Unix systems, and I assume wait4 is available if getrusage is,
which may not be safe.

zw

Index: libiberty/pexecute.c
===================================================================
RCS file: /cvs/egcs/egcs/libiberty/pexecute.c,v
retrieving revision 1.13
diff -u -r1.13 pexecute.c
--- pexecute.c	1999/04/11 22:21:27	1.13
+++ pexecute.c	1999/06/15 00:33:22
@@ -228,6 +228,17 @@
   return last_pid;
 }
 
+/* MSDOS does not support retrieving resource usage.  */
+int
+pwaitr (pid, status, flags, rusage)
+     int pid;
+     int *status;
+     int flags;
+     void *rusage;
+{
+  return pwait (pid, status, flags);
+}
+
 #endif /* MSDOS */
 
 #if defined (_WIN32) && ! defined (_UWIN)
@@ -419,6 +430,18 @@
 #endif /* __CYGWIN__ */
 }
 
+/* Win32 probably supports retrieving resource usage, but I don't
+   know how to do it.  FIXME */
+int
+pwaitr (pid, status, flags, rusage)
+     int pid;
+     int *status;
+     int flags;
+     void *rusage;
+{
+  return pwait (pid, status, flags);
+}
+
 #endif /* _WIN32 && ! _UWIN */
 
 #ifdef OS2
@@ -463,6 +486,18 @@
   return pid;
 }
 
+/* OS/2 probably supports retrieving resource usage, but I don't
+   know how to do it.  FIXME */
+int
+pwaitr (pid, status, flags, rusage)
+     int pid;
+     int *status;
+     int flags;
+     void *rusage;
+{
+  return pwait (pid, status, flags);
+}
+
 #endif /* OS2 */
 
 #ifdef MPW
@@ -589,6 +624,17 @@
   return 0;
 }
 
+/* MPW does not support retrieving resource usage.  */
+int
+pwaitr (pid, status, flags, rusage)
+     int pid;
+     int *status;
+     int flags;
+     void *rusage;
+{
+  return pwait (pid, status, flags);
+}
+
 /* Write out commands that will exit with the correct error code
    if something in the script failed.  */
 
@@ -730,5 +776,21 @@
 #endif
   return pid;
 }
+
+/* XXX Assumes wait4 exists if HAVE_GETRUSAGE - probably wrong */
+int
+pwaitr (pid, status, flags, rusage)
+     int pid;
+     int *status;
+     int flags;
+     void *rusage;
+{
+#ifdef HAVE_GETRUSAGE
+  return wait4 (-1, status, 0, rusage);
+#else
+  return pwait (pid, status, flags);
+#endif
+}
+
 
 #endif /* ! __MSDOS__ && ! OS2 && ! MPW && ! (_WIN32 && ! _UWIN) */
Index: gcc/gcc.c
===================================================================
RCS file: /cvs/egcs/egcs/gcc/gcc.c,v
retrieving revision 1.102
diff -u -r1.102 gcc.c
--- gcc.c	1999/05/17 23:37:17	1.102
+++ gcc.c	1999/06/15 00:33:38
@@ -43,6 +43,10 @@
 #define exit __posix_exit
 #endif
 
+#ifdef HAVE_SYS_RESOURCE_H
+#include <sys/resource.h>
+#endif
+
 /* By default there is no special suffix for executables.  */
 #ifdef EXECUTABLE_SUFFIX
 #define HAVE_EXECUTABLE_SUFFIX
@@ -125,6 +129,11 @@
 
 static int verbose_flag;
 
+/* Flag indicating whether we should report subprocess execution times
+   (if this is supported by the system - see pexecute.c).  */
+
+static int report_times;
+
 /* Nonzero means write "temp" files in source directory
    and use the source file's name in them, and don't delete them.  */
 
@@ -874,6 +883,7 @@
    {"--std", "-std=", "aj"},
    {"--symbolic", "-symbolic", 0},
    {"--target", "-b", "a"},
+   {"--time", "-time", 0},
    {"--trace-includes", "-H", 0},
    {"--traditional", "-traditional", 0},
    {"--traditional-cpp", "-traditional-cpp", 0},
@@ -2209,6 +2219,9 @@
     };
 
   struct command *commands;	/* each command buffer with above info.  */
+#ifdef HAVE_SYS_RESOURCE_H
+  struct rusage rus;
+#endif
 
   /* Count # of piped commands.  */
   for (n_commands = 1, i = 0; i < argbuf_index; i++)
@@ -2322,6 +2335,14 @@
 	int status;
 	int pid;
 
+#ifdef HAVE_SYS_RESOURCE_H
+	if (report_times)
+	  {
+	    bzero (&rus, sizeof (struct rusage));
+	    pid = pwaitr (commands[i].pid, &status, 0, &rus);
+	  }
+	else
+#endif		   
 	pid = pwait (commands[i].pid, &status, 0);
 	if (pid < 0)
 	  abort ();
@@ -2343,6 +2364,16 @@
 			   && WEXITSTATUS (status) >= MIN_FATAL_STATUS)
 		    ret_code = -1;
 		}
+#ifdef HAVE_SYS_RESOURCE_H
+	      if (report_times
+		  && rus.ru_utime.tv_sec + rus.ru_utime.tv_usec != 0)
+		notice ("# %s %.2f %.2f\n",
+			commands[j].prog,
+			(double)rus.ru_utime.tv_sec +
+			(double)rus.ru_utime.tv_usec / 1.0e6,
+			(double)rus.ru_stime.tv_sec +
+			(double)rus.ru_stime.tv_usec / 1.0e6);
+#endif
 	      break;
 	    }
       }
@@ -2867,6 +2898,8 @@
 	    user_specs_head = user;
 	  user_specs_tail = user;
 	}
+      else if (strcmp (argv[i], "-time") == 0)
+	report_times = 1;
       else if (argv[i][0] == '-' && argv[i][1] != 0)
 	{
 	  register char *p = &argv[i][1];
@@ -3206,6 +3239,8 @@
       else if (strcmp (argv[i], "-specs") == 0)
 	i++;
       else if (strncmp (argv[i], "-specs=", 7) == 0)
+	;
+      else if (strcmp (argv[i], "-time") == 0)
 	;
       /* -save-temps overrides -pipe, so that temp files are produced */
       else if (save_temps_flag && strcmp (argv[i], "-pipe") == 0)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]