gcc.c: Include sys/resource.h.

1999-09-13 12:13 -0700  Zack Weinberg  <zack@bitmover.com>

	* gcc.c: Include sys/resource.h.
	(report_times): New flag.
	(execute):  If report_times is set, calculate and report the
	CPU time consumed by each subprocess.

	(rus, prus): New globals.
	(option_map): Add --time.
	(display_help): Document -time.
	(process_command): Set report_times if -time is given.
	Turn off -pipe if -time is given.

	* invoke.texi: Document new option -time.

	* configure.in: Check for getrusage.  Check if we have to
	prototype getrusage.
	* acconfig.h: Add NEED_DECLARATION_GETRUSAGE.
	* configure: Regenerate.
	* config.in: Regenerate.

From-SVN: r29381
This commit is contained in:
Zack Weinberg 1999-09-13 19:16:24 +00:00 committed by Zack Weinberg
parent 503cb43627
commit 03c41c05ec
7 changed files with 331 additions and 232 deletions

View File

@ -1,3 +1,24 @@
1999-09-13 12:13 -0700 Zack Weinberg <zack@bitmover.com>
* gcc.c: Include sys/resource.h.
(report_times): New flag.
(execute): If report_times is set, calculate and report the
CPU time consumed by each subprocess.
(rus, prus): New globals.
(option_map): Add --time.
(display_help): Document -time.
(process_command): Set report_times if -time is given.
Turn off -pipe if -time is given.
* invoke.texi: Document new option -time.
* configure.in: Check for getrusage. Check if we have to
prototype getrusage.
* acconfig.h: Add NEED_DECLARATION_GETRUSAGE.
* configure: Regenerate.
* config.in: Regenerate.
Mon Sep 13 12:57:06 1999 Dave Brolley <brolley@cygnus.com>
* cppinit.c (append_include_chain): Initialize 'next' and 'alloc'

View File

@ -121,6 +121,9 @@
/* Whether setrlimit must be declared even if <sys/resource.h> is included. */
#undef NEED_DECLARATION_SETRLIMIT
/* Whether getrusage must be declared even if <sys/resource.h> is included. */
#undef NEED_DECLARATION_GETRUSAGE
/* Whether putc_unlocked must be declared even if <stdio.h> is included. */
#undef NEED_DECLARATION_PUTC_UNLOCKED

View File

@ -122,6 +122,9 @@
/* Whether setrlimit must be declared even if <sys/resource.h> is included. */
#undef NEED_DECLARATION_SETRLIMIT
/* Whether getrusage must be declared even if <sys/resource.h> is included. */
#undef NEED_DECLARATION_GETRUSAGE
/* Whether putc_unlocked must be declared even if <stdio.h> is included. */
#undef NEED_DECLARATION_PUTC_UNLOCKED
@ -252,6 +255,9 @@
/* Define if you have the getrlimit function. */
#undef HAVE_GETRLIMIT
/* Define if you have the getrusage function. */
#undef HAVE_GETRUSAGE
/* Define if you have the gettimeofday function. */
#undef HAVE_GETTIMEOFDAY

438
gcc/configure vendored

File diff suppressed because it is too large Load Diff

View File

@ -333,7 +333,10 @@ AC_HEADER_STDC
AC_HEADER_TIME
GCC_HEADER_STRING
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(limits.h stddef.h string.h strings.h stdlib.h time.h fcntl.h unistd.h stab.h sys/file.h sys/time.h sys/resource.h sys/param.h sys/times.h sys/stat.h direct.h malloc.h)
AC_CHECK_HEADERS(limits.h stddef.h string.h strings.h stdlib.h time.h \
fcntl.h unistd.h stab.h sys/file.h sys/time.h \
sys/resource.h sys/param.h sys/times.h sys/stat.h \
direct.h malloc.h)
# Check for thread headers.
AC_CHECK_HEADER(thread.h, [have_thread_h=yes], [have_thread_h=])
@ -373,7 +376,7 @@ fi
AC_CHECK_FUNCS(strtoul bsearch strerror putenv popen bcopy bzero bcmp \
index rindex strchr strrchr kill getrlimit setrlimit atoll atoq \
sysconf isascii gettimeofday strsignal putc_unlocked fputc_unlocked \
fputs_unlocked)
fputs_unlocked getrusage)
# Make sure wchar_t is available
#AC_CHECK_TYPE(wchar_t, unsigned int)
@ -401,7 +404,7 @@ GCC_NEED_DECLARATIONS(malloc realloc calloc free, [
#endif
])
GCC_NEED_DECLARATIONS(getrlimit setrlimit, [
GCC_NEED_DECLARATIONS(getrlimit setrlimit getrusage, [
#include <sys/types.h>
#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>

View File

@ -44,6 +44,13 @@ compilation is specified by a string called a "spec". */
#define exit __posix_exit
#endif
#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif
#ifdef NEED_DECLARATION_GETRUSAGE
extern int getrusage(int, struct rusage *);
#endif
/* By default there is no special suffix for executables. */
#ifdef EXECUTABLE_SUFFIX
#define HAVE_EXECUTABLE_SUFFIX
@ -126,6 +133,11 @@ static int print_help_list;
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. */
@ -167,6 +179,12 @@ static struct obstack obstack;
static struct obstack collect_obstack;
/* These structs are used to collect resource usage information for
subprocesses. */
#ifdef HAVE_GETRUSAGE
static struct rusage rus, prus;
#endif
extern char *version_string;
/* Forward declaration for prototypes. */
@ -863,6 +881,7 @@ struct option_map option_map[] =
{"--std", "-std=", "aj"},
{"--symbolic", "-symbolic", 0},
{"--target", "-b", "a"},
{"--time", "-time", 0},
{"--trace-includes", "-H", 0},
{"--traditional", "-traditional", 0},
{"--traditional-cpp", "-traditional-cpp", 0},
@ -2289,6 +2308,10 @@ execute ()
{
int ret_code = 0;
#ifdef HAVE_GETRUSAGE
struct timeval d;
double ut, st;
#endif
for (i = 0; i < n_commands; )
{
@ -2300,6 +2323,25 @@ execute ()
if (pid < 0)
abort ();
#ifdef HAVE_GETRUSAGE
if (report_times)
{
/* getrusage returns the total resource usage of all children
up to now. Copy the previous values into prus, get the
current statistics, then take the difference. */
prus = rus;
getrusage (RUSAGE_CHILDREN, &rus);
d.tv_sec = rus.ru_utime.tv_sec - prus.ru_utime.tv_sec;
d.tv_usec = rus.ru_utime.tv_usec - prus.ru_utime.tv_usec;
ut = (double)d.tv_sec + (double)d.tv_usec / 1.0e6;
d.tv_sec = rus.ru_stime.tv_sec - prus.ru_stime.tv_sec;
d.tv_usec = rus.ru_stime.tv_usec - prus.ru_stime.tv_usec;
st = (double)d.tv_sec + (double)d.tv_usec / 1.0e6;
}
#endif
for (j = 0; j < n_commands; j++)
if (commands[j].pid == pid)
{
@ -2317,6 +2359,10 @@ execute ()
&& WEXITSTATUS (status) >= MIN_FATAL_STATUS)
ret_code = -1;
}
#ifdef HAVE_GETRUSAGE
if (report_times && ut + st != 0)
notice ("# %s %.2f %.2f\n", commands[j].prog, ut, st);
#endif
break;
}
}
@ -2457,6 +2503,7 @@ display_help ()
printf (" -Xlinker <arg> Pass <arg> on to the linker\n");
printf (" -save-temps Do not delete intermediate files\n");
printf (" -pipe Use pipes rather than intermediate files\n");
printf (" -time Time the execution of each subprocess\n");
printf (" -specs=<file> Override builtin specs with the contents of <file>\n");
printf (" -std=<standard> Assume that the input sources are for <standard>\n");
printf (" -B <directory> Add <directory> to the compiler's search paths\n");
@ -2841,6 +2888,8 @@ process_command (argc, argv)
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];
@ -3181,9 +3230,19 @@ process_command (argc, argv)
i++;
else if (strncmp (argv[i], "-specs=", 7) == 0)
;
/* -save-temps overrides -pipe, so that temp files are produced */
else if (save_temps_flag && strcmp (argv[i], "-pipe") == 0)
error ("Warning: -pipe ignored since -save-temps specified");
else if (strcmp (argv[i], "-time") == 0)
;
else if ((save_temps_flag || report_times)
&& strcmp (argv[i], "-pipe") == 0)
{
/* -save-temps overrides -pipe, so that temp files are produced */
if (save_temps_flag)
error ("Warning: -pipe ignored since -save-temps specified");
/* -time overrides -pipe because we can't get correct stats when
multiple children are running at once. */
else if (report_times)
error ("Warning: -pipe ignored since -time specified");
}
else if (argv[i][0] == '-' && argv[i][1] != 0)
{
register char *p = &argv[i][1];
@ -5253,8 +5312,7 @@ pfatal_pexecute (errmsg_fmt, errmsg_arg)
pfatal_with_name (errmsg_fmt);
}
/* More 'friendly' abort that prints the line and file.
config.h can #define abort fancy_abort if you like that sort of thing. */
/* Output an error message and exit */
void
fancy_abort ()

View File

@ -144,7 +144,7 @@ in the following sections.
-g -g@var{level} -gcoff -gdwarf -gdwarf-1 -gdwarf-1+ -gdwarf-2
-ggdb -gstabs -gstabs+ -gxcoff -gxcoff+
-p -pg -print-file-name=@var{library} -print-libgcc-file-name
-print-prog-name=@var{program} -print-search-dirs -save-temps
-print-prog-name=@var{program} -print-search-dirs -save-temps -time
@end smallexample
@item Optimization Options
@ -2165,6 +2165,22 @@ in the current directory and name them based on the source file. Thus,
compiling @file{foo.c} with @samp{-c -save-temps} would produce files
@file{foo.i} and @file{foo.s}, as well as @file{foo.o}.
@item -time
Report the CPU time taken by each subprocess in the compilation
sequence. For C source files, this is the preprocessor, compiler
proper, and assembler. The output looks like this:
@smallexample
# cpp 0.04 0.04
# cc1 0.12 0.01
# as 0.00 0.01
@end smallexample
The first number on each line is the ``user time,'' that is time spent
executing the program itself. The second number is ``system time,''
time spent executing operating system routines on behalf of the program.
Both numbers are in seconds.
@item -print-file-name=@var{library}
Print the full absolute name of the library file @var{library} that
would be used when linking---and don't do anything else. With this