From 5ea94df40fc1bcf2d5f6a5e700945ccec389d28d Mon Sep 17 00:00:00 2001 From: Paolo Molaro Date: Fri, 12 Nov 2010 19:22:55 +0100 Subject: [PATCH] Log profiler: use the output value as a filename when report is specified. * 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 | 25 +++++++++++++++++++------ mono/profiler/log-profiler.txt | 4 +++- mono/profiler/proflog.c | 23 +++++++++++++++++------ 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/mono/profiler/decode.c b/mono/profiler/decode.c index 37b88878cf3..44d3ad1f3ed 100644 --- a/mono/profiler/decode.c +++ b/mono/profiler/decode.c @@ -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; diff --git a/mono/profiler/log-profiler.txt b/mono/profiler/log-profiler.txt index 8fcc602bcde..5ae4496d807 100644 --- a/mono/profiler/log-profiler.txt +++ b/mono/profiler/log-profiler.txt @@ -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 diff --git a/mono/profiler/proflog.c b/mono/profiler/proflog.c index 7d7f9320de8..303b9a716c1 100644 --- a/mono/profiler/proflog.c +++ b/mono/profiler/proflog.c @@ -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; -- 2.25.1