Re: [PATCH v2 4/4] Make all print functions receive the fp argument, and opens a dump file in process_event.

From: Jiri Olsa
Date: Tue Oct 03 2017 - 06:44:37 EST


On Tue, Sep 26, 2017 at 02:53:17PM +0800, yuzhoujian wrote:

SNIP

> - fprint_sample_start(sample, thread, evsel, stdout);
> + /* the dump file name is <ORIGINAL PERF DATA FILE NAME>-script-dump-<EVENT NAME>.txt */
> + evname = perf_evsel__name(evsel);
> + if (script->tool.per_event_dump) {
> + if (asprintf(&filename, "%s%s%s%s", file_name, "-script-dump-", evname, ".txt") < 0)
> + filename = NULL;
> + fp = fopen(filename, "a+");
> + if (!fp)
> + return;
> + free(filename);
> + }
> + fprint_sample_start(sample, thread, evsel, fp);
>

SNIP

>
> if (PRINT_FIELD(PHYS_ADDR))
> - fprintf(stdout, "%16" PRIx64, sample->phys_addr);
> - fprintf(stdout, "\n");
> + fprintf(fp, "%16" PRIx64, sample->phys_addr);
> + fprintf(fp, "\n");
> + if (script->tool.per_event_dump)
> + fclose(fp);

so you open and close the file for each sample.. I think
we should store the FILE* in perf_evsel::priv

open it at the first time sample/event is processed
and close at the end of the perf script

jirka