perf: Convert a FILE* instead of a filename
authorBarret Rhoden <brho@cs.berkeley.edu>
Fri, 17 Jun 2016 16:15:38 +0000 (12:15 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Fri, 17 Jun 2016 16:17:53 +0000 (12:17 -0400)
This will make perf stat (upcoming patch) easier.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
tools/profile/perf/perf.c
tools/profile/perf/perf_core.c
tools/profile/perf/perf_core.h

index 6546387..8f5e116 100644 (file)
@@ -38,7 +38,7 @@ static struct perfconv_context *cctx;
 static struct perf_context *pctx;
 
 struct perf_opts {
-       const char                                      *output_file;
+       FILE                                            *outfile;
        const char                                      *events;
        char                                            **cmd_argv;
        int                                                     cmd_argc;
@@ -290,7 +290,7 @@ static error_t parse_record_opt(int key, char *arg, struct argp_state *state)
                /* Our default operation is to record backtraces. */
                break;
        case 'o':
-               p_opts->output_file = arg;
+               p_opts->outfile = xfopen(arg, "wb");
                break;
        case 'q':
                p_opts->record_quiet = TRUE;
@@ -298,8 +298,8 @@ static error_t parse_record_opt(int key, char *arg, struct argp_state *state)
        case ARGP_KEY_END:
                if (!p_opts->events)
                        p_opts->events = "cycles";
-               if (!p_opts->output_file)
-                       p_opts->output_file = "perf.data";
+               if (!p_opts->outfile)
+                       p_opts->outfile = xfopen("perf.data", "wb");
                if (!p_opts->record_period)
                        p_opts->record_period = freq_to_period(1000);
                break;
@@ -330,7 +330,8 @@ static int perf_record(struct perf_cmd *cmd, int argc, char *argv[])
        perf_flush_context_traces(pctx);
        /* Generate the Linux perf file format with the traces which have been
         * created during this operation. */
-       perf_convert_trace_data(cctx, perf_cfg.kpdata_file, opts.output_file);
+       perf_convert_trace_data(cctx, perf_cfg.kpdata_file, opts.outfile);
+       fclose(opts.outfile);
        return 0;
 }
 
index 1b82cc1..3e60fda 100644 (file)
@@ -752,21 +752,17 @@ void perf_show_events(const char *rx, FILE *file)
 }
 
 void perf_convert_trace_data(struct perfconv_context *cctx, const char *input,
-                                                        const char *output)
+                                                        FILE *outfile)
 {
-       FILE *infile, *outfile;
+       FILE *infile;
        size_t ksize;
        char kpath[1024];
 
        infile = xfopen(input, "rb");
        if (xfsize(infile) > 0) {
-               outfile = xfopen(output, "wb");
-
                perfconv_add_kernel_mmap(cctx);
                perfconv_add_kernel_buildid(cctx);
                perfconv_process_input(cctx, infile, outfile);
-
-               fclose(outfile);
        }
        fclose(infile);
 }
index d0ac55f..a3590f6 100644 (file)
@@ -67,7 +67,7 @@ void perf_context_event_submit(struct perf_context *pctx,
 void perf_context_show_values(struct perf_context *pctx, FILE *file);
 void perf_show_events(const char *rx, FILE *file);
 void perf_convert_trace_data(struct perfconv_context *cctx, const char *input,
-                                                        const char *output);
+                                                        FILE *outfile);
 
 static inline const struct perf_arch_info *perf_context_get_arch_info(
        const struct perf_context *pctx)