{
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*
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);
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;
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
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;