summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-02-10 18:01:00 +0000
committerChris Lattner <sabre@nondot.org>2004-02-10 18:01:00 +0000
commitebd02a8cfad1ddd8b5348aaad6ad0e19acba096a (patch)
treeccece898a1b996638e3b06e0ac232c61bd18ae3c /runtime
parent81d1a2207d96163a81afc6a7ad11cba41ea72dff (diff)
downloadllvm-ebd02a8cfad1ddd8b5348aaad6ad0e19acba096a.tar.gz
llvm-ebd02a8cfad1ddd8b5348aaad6ad0e19acba096a.tar.bz2
llvm-ebd02a8cfad1ddd8b5348aaad6ad0e19acba096a.tar.xz
Allow the program to take a '-llvmprof-output filename' option to specify
where to output the profiling data, if llvmprof.out is not good enough. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11264 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'runtime')
-rw-r--r--runtime/libprofile/CommonProfiling.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/runtime/libprofile/CommonProfiling.c b/runtime/libprofile/CommonProfiling.c
index 5569a66414..7e9e12e423 100644
--- a/runtime/libprofile/CommonProfiling.c
+++ b/runtime/libprofile/CommonProfiling.c
@@ -24,6 +24,8 @@
static char *SavedArgs = 0;
static unsigned SavedArgsLength = 0;
+static const char *OutputFilename = "llvmprof.out";
+
/* save_arguments - Save argc and argv as passed into the program for the file
* we output.
*/
@@ -31,6 +33,30 @@ int save_arguments(int argc, const char **argv) {
unsigned Length, i;
if (SavedArgs || !argv) return argc; /* This can be called multiple times */
+ /* Check to see if there are any arguments passed into the program for the
+ * profiler. If there are, strip them off and remember their settings.
+ */
+ while (argc > 1 && !strncmp(argv[1], "-llvmprof-", 10)) {
+ /* Ok, we have an llvmprof argument. Remove it from the arg list and decide
+ * what to do with it.
+ */
+ const char *Arg = argv[1];
+ memmove(&argv[1], &argv[2], (argc-2)*sizeof(char*));
+ --argc;
+
+ if (!strcmp(Arg, "-llvmprof-output")) {
+ if (argc == 1)
+ puts("-llvmprof-output requires a filename argument!");
+ else {
+ OutputFilename = strdup(argv[1]);
+ memmove(&argv[1], &argv[2], (argc-2)*sizeof(char*));
+ --argc;
+ }
+ } else {
+ printf("Unknown option to the profiler runtime: '%s' - ignored.\n", Arg);
+ }
+ }
+
for (Length = 0, i = 0; i != (unsigned)argc; ++i)
Length += strlen(argv[i])+1;
@@ -63,9 +89,11 @@ void write_profiling_data(enum ProfilingType PT, unsigned *Start,
*/
if (OutFile == -1) {
off_t Offset;
- OutFile = open("llvmprof.out", O_CREAT | O_WRONLY | O_APPEND, 0666);
+ OutFile = open(OutputFilename, O_CREAT | O_WRONLY | O_APPEND, 0666);
if (OutFile == -1) {
- perror("LLVM profiling: while opening 'llvmprof.out'");
+ fprintf(stderr, "LLVM profiling runtime: while opening '%s': ",
+ OutputFilename);
+ perror("");
return;
}