зеркало из https://github.com/mozilla/gecko-dev.git
Factored code to NS_TraceMallocStartupWithArgs(). r=brendan
This commit is contained in:
Родитель
9a0a7705c3
Коммит
b2752f9263
|
@ -66,9 +66,6 @@
|
|||
#include "nsIWebBrowserChrome.h"
|
||||
|
||||
#ifdef NS_TRACE_MALLOC
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include "nsTraceMalloc.h"
|
||||
#endif
|
||||
|
||||
|
@ -1027,105 +1024,6 @@ static PRBool GetWantSplashScreen(int argc, char* argv[])
|
|||
}
|
||||
|
||||
|
||||
static int
|
||||
SetupMallocTracing(int argc, char* argv[])
|
||||
{
|
||||
#ifdef NS_TRACE_MALLOC
|
||||
int i, logfd = -1;
|
||||
|
||||
/*
|
||||
* Look for the --trace-malloc <logfile> option early, to avoid missing
|
||||
* early mallocs (we miss static constructors whose output overflows the
|
||||
* log file's static 16K output buffer; see xpcom/base/nsTraceMalloc.c).
|
||||
*/
|
||||
for (i = 1; i < argc; i++)
|
||||
{
|
||||
if (PL_strcasecmp(argv[i], "--trace-malloc") == 0 && i < argc-1) {
|
||||
char *logfile;
|
||||
int pipefds[2];
|
||||
|
||||
logfile = argv[i+1];
|
||||
switch (*logfile) {
|
||||
case '|':
|
||||
if (pipe(pipefds) == 0) {
|
||||
pid_t pid = fork();
|
||||
if (pid == 0) {
|
||||
/* In child: set up stdin, parse args from logfile, and exec. */
|
||||
int maxargc, nargc;
|
||||
char **nargv, *token;
|
||||
|
||||
if (pipefds[0] != 0) {
|
||||
dup2(pipefds[0], 0);
|
||||
close(pipefds[0]);
|
||||
}
|
||||
close(pipefds[1]);
|
||||
|
||||
logfile = strtok(logfile + 1, " \t");
|
||||
maxargc = 3;
|
||||
nargv = (char **) malloc((maxargc + 1) * sizeof(char *));
|
||||
if (!nargv) exit(1);
|
||||
nargc = 0;
|
||||
nargv[nargc++] = logfile;
|
||||
while ((token = strtok(NULL, " \t")) != NULL) {
|
||||
if (nargc == maxargc) {
|
||||
maxargc *= 2;
|
||||
nargv = (char**) realloc(nargv, (maxargc+1) * sizeof(char*));
|
||||
if (!nargv) exit(1);
|
||||
}
|
||||
nargv[nargc++] = token;
|
||||
}
|
||||
nargv[nargc] = NULL;
|
||||
|
||||
(void) setsid();
|
||||
execvp(logfile, nargv);
|
||||
exit(127);
|
||||
}
|
||||
|
||||
if (pid > 0) {
|
||||
/* In parent: set logfd to the write side of the pipe. */
|
||||
close(pipefds[0]);
|
||||
logfd = pipefds[1];
|
||||
}
|
||||
}
|
||||
if (logfd < 0) {
|
||||
fprintf(stderr,
|
||||
"%s: can't pipe to trace-malloc child process %s: %s\n",
|
||||
argv[0], logfile, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
|
||||
case '-':
|
||||
/* Don't log from startup, but do prepare to log later. */
|
||||
if (logfile[1] == '\0')
|
||||
break;
|
||||
/* FALL THROUGH */
|
||||
|
||||
default:
|
||||
logfd = open(logfile, O_CREAT | O_WRONLY | O_TRUNC, 0644);
|
||||
if (logfd < 0) {
|
||||
fprintf(stderr,
|
||||
"%s: can't create trace-malloc logfile %s: %s\n",
|
||||
argv[0], logfile, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/* Now remove --trace-malloc and its argument from argv. */
|
||||
for (argc -= 2; i < argc; i++)
|
||||
argv[i] = argv[i+2];
|
||||
argv[argc] = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
NS_TraceMallocStartup(logfd);
|
||||
#endif /* NS_TRACE_MALLOC */
|
||||
|
||||
return argc;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
#if defined(XP_UNIX)
|
||||
|
@ -1137,7 +1035,9 @@ int main(int argc, char* argv[])
|
|||
if (HandleDumpArguments(argc, argv))
|
||||
return 0;
|
||||
|
||||
argc = SetupMallocTracing(argc, argv);
|
||||
#ifdef NS_TRACE_MALLOC
|
||||
argc = NS_TraceMallocStartupArgs(argc, argv);
|
||||
#endif
|
||||
|
||||
// Call the code to install our handler
|
||||
#ifdef MOZ_JPROF
|
||||
|
|
Загрузка…
Ссылка в новой задаче