Log profiler: use the output value as a filename when report is specified.
authorPaolo Molaro <lupus@oddwiz.org>
Fri, 12 Nov 2010 18:22:55 +0000 (19:22 +0100)
committerPaolo Molaro <lupus@oddwiz.org>
Fri, 12 Nov 2010 20:38:04 +0000 (21:38 +0100)
* proflog.c: if the output option is used together with report, the report
is saved to the named file instead of being printed to stdout.
* decode.c: zlib seems to get confused with a non-compressed strem
coming from stdin: disable it in that case...
Also deal with reading 0 bytes from a buffer.

mono/profiler/decode.c
mono/profiler/log-profiler.txt
mono/profiler/proflog.c

index 37b88878cf3beefa7c8b010e76f0fac59e61c0e1..44d3ad1f3ed869b2bf7114faa17453e7abbe5331 100644 (file)
@@ -658,11 +658,18 @@ load_data (ProfContext *ctx, int size)
 {
        ensure_buffer (ctx, size);
 #if defined (HAVE_SYS_ZLIB)
-       if (ctx->gzfile)
-               return gzread (ctx->gzfile, ctx->buf, size) == size;
-       else
+       if (ctx->gzfile) {
+               int r = gzread (ctx->gzfile, ctx->buf, size);
+               if (r == 0)
+                       return size == 0? 1: 0;
+               return r == size;
+       } else {
 #endif
-               return fread (ctx->buf, size, 1, ctx->file);
+               int r = fread (ctx->buf, size, 1, ctx->file);
+               if (r == 0)
+                       return size == 0? 1: 0;
+               return r;
+       }
 }
 
 static ThreadContext*
@@ -1058,8 +1065,13 @@ decode_buffer (ProfContext *ctx)
        if (!load_data (ctx, 48))
                return 0;
        p = ctx->buf;
-       if (read_int32 (p) != BUF_ID)
+       if (read_int32 (p) != BUF_ID) {
+               fprintf (outfile, "Incorrect buffer id: 0x%x\n", read_int32 (p));
+               for (i = 0; i < 48; ++i) {
+                       fprintf (outfile, "0x%x%s", p [i], i % 8?" ":"\n");
+               }
                return 0;
+       }
        len = read_int32 (p + 4);
        time_base = read_int64 (p + 8);
        ptr_base = read_int64 (p + 16);
@@ -1464,7 +1476,8 @@ load_file (char *name)
                exit (1);
        }
 #if defined (HAVE_SYS_ZLIB)
-       ctx->gzfile = gzdopen (fileno (ctx->file), "rb");
+       if (ctx->file != stdin)
+               ctx->gzfile = gzdopen (fileno (ctx->file), "rb");
 #endif
        if (!load_data (ctx, 32))
                return NULL;
index 8fcc602bcde7adaa824f23dd93f9e07804b0c6c6..5ae4496d8078c88ad35ee44249752beb437cd49a 100644 (file)
@@ -117,7 +117,9 @@ date and time, then do according to *OUTSPEC*:
        name already exists, a warning is issued and profiling is disabled.
 
 * *report*: the profiling data is sent to mprof-report, which will print a summary
-report. This is equivalent to the option: `output=mprof-report -`.
+report. This is equivalent to the option: `output=mprof-report -`. If the *output*
+option is specified as well, the report will be written to the output file instead of
+the console.
 
 ## Analyzing the profile data
 
index 7d7f9320de8a57bf373ac9f8054423a0eb95c2b2..303b9a716c1ee2b24226039f3ce210f48db81543 100644 (file)
@@ -1038,16 +1038,27 @@ create_profiler (const char *filename)
        char *nf;
        int force_delete = 0;
        prof = calloc (1, sizeof (MonoProfiler));
-       if (do_report) /* FIXME: use filename as output */
-               filename = "|mprof-report -";
 
-       if (!filename)
-               filename = "output.mlpd";
-       if (*filename == '-') {
+       if (filename && *filename == '-') {
                force_delete = 1;
                filename++;
        }
-       nf = new_filename (filename);
+       if (!filename) {
+               if (do_report)
+                       filename = "|mprof-report -";
+               else
+                       filename = "output.mlpd";
+               nf = filename;
+       } else {
+               nf = new_filename (filename);
+               if (do_report) {
+                       int s = strlen (nf) + 32;
+                       char *p = malloc (s);
+                       snprintf (p, s, "|mprof-report '--out=%s' -", nf);
+                       free (nf);
+                       nf = p;
+               }
+       }
        if (*nf == '|') {
                prof->file = popen (nf + 1, "w");
                prof->pipe_output = 1;