From 6156580d2ebc5c4fb264173651d80bd45a645c27 Mon Sep 17 00:00:00 2001 From: Jim Wilson Date: Wed, 29 Nov 1995 19:03:54 -0800 Subject: [PATCH] (_mcleanup): Add support for PROFDIR environment variable. From-SVN: r10637 --- gcc/config/sparc/gmon-sol2.c | 37 ++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/gcc/config/sparc/gmon-sol2.c b/gcc/config/sparc/gmon-sol2.c index ba1549b036e..9b41c649297 100644 --- a/gcc/config/sparc/gmon-sol2.c +++ b/gcc/config/sparc/gmon-sol2.c @@ -39,11 +39,11 @@ static char sccsid[] = "@(#)gmon.c 5.3 (Berkeley) 5/22/91"; #endif /* not lint */ -#include - -#ifdef DEBUG #include -#endif +#include +#include +#include +#include #if 0 #include "sparc/gmon.h" @@ -172,6 +172,7 @@ monstartup(lowpc, highpc) moncontrol(1); } +void _mcleanup() { int fd; @@ -180,11 +181,35 @@ _mcleanup() char *frompc; int toindex; struct rawarc rawarc; + char *profdir; + char *proffile; + char *progname; + char buf[PATH_MAX]; + extern char **___Argv; moncontrol(0); - fd = creat( "gmon.out" , 0666 ); + + if ((profdir = getenv("PROFDIR")) != NULL) { + /* If PROFDIR contains a null value, no profiling output is produced */ + if (*profdir == '\0') { + return; + } + + progname=strrchr(___Argv[0], '/'); + if (progname == NULL) + progname=___Argv[0]; + else + progname++; + + sprintf(buf, "%s/%d.%s", profdir, getpid(), progname); + proffile = buf; + } else { + proffile = "gmon.out"; + } + + fd = creat( proffile, 0666 ); if ( fd < 0 ) { - perror( "mcount: gmon.out" ); + perror( proffile ); return; } # ifdef DEBUG