Commit 6156580d by Jim Wilson

(_mcleanup): Add support for PROFDIR environment variable.

From-SVN: r10637
parent 8b8def46
...@@ -39,11 +39,11 @@ ...@@ -39,11 +39,11 @@
static char sccsid[] = "@(#)gmon.c 5.3 (Berkeley) 5/22/91"; static char sccsid[] = "@(#)gmon.c 5.3 (Berkeley) 5/22/91";
#endif /* not lint */ #endif /* not lint */
#include <unistd.h>
#ifdef DEBUG
#include <stdio.h> #include <stdio.h>
#endif #include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <unistd.h>
#if 0 #if 0
#include "sparc/gmon.h" #include "sparc/gmon.h"
...@@ -172,6 +172,7 @@ monstartup(lowpc, highpc) ...@@ -172,6 +172,7 @@ monstartup(lowpc, highpc)
moncontrol(1); moncontrol(1);
} }
void
_mcleanup() _mcleanup()
{ {
int fd; int fd;
...@@ -180,11 +181,35 @@ _mcleanup() ...@@ -180,11 +181,35 @@ _mcleanup()
char *frompc; char *frompc;
int toindex; int toindex;
struct rawarc rawarc; struct rawarc rawarc;
char *profdir;
char *proffile;
char *progname;
char buf[PATH_MAX];
extern char **___Argv;
moncontrol(0); 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 ) { if ( fd < 0 ) {
perror( "mcount: gmon.out" ); perror( proffile );
return; return;
} }
# ifdef DEBUG # ifdef DEBUG
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment