Skip to content

Commit

Permalink
perf data: Add global path holder
Browse files Browse the repository at this point in the history
Add a 'path' member to 'struct perf_data'. It will keep the configured
path for the data (const char *). The path in struct perf_data_file is
now dynamically allocated (duped) from it.

This scheme is useful/used in following patches where struct
perf_data::path holds the 'configure' directory path and struct
perf_data_file::path holds the allocated path for specific files.

Also it actually makes the code little simpler.

Signed-off-by: Jiri Olsa <[email protected]>
Cc: Adrian Hunter <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Alexey Budankov <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
[ Fixup data-convert-bt.c missing conversion ]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
olsajiri authored and acmel committed Feb 22, 2019
1 parent 45112e8 commit 2d4f279
Show file tree
Hide file tree
Showing 21 changed files with 87 additions and 93 deletions.
4 changes: 2 additions & 2 deletions tools/perf/builtin-annotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ static int __cmd_annotate(struct perf_annotate *ann)
}

if (total_nr_samples == 0) {
ui__error("The %s file has no samples!\n", session->data->file.path);
ui__error("The %s data has no samples!\n", session->data->path);
goto out;
}

Expand Down Expand Up @@ -578,7 +578,7 @@ int cmd_annotate(int argc, const char **argv)
if (quiet)
perf_quiet_option();

data.file.path = input_name;
data.path = input_name;

annotate.session = perf_session__new(&data, false, &annotate.tool);
if (annotate.session == NULL)
Expand Down
4 changes: 2 additions & 2 deletions tools/perf/builtin-buildid-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,8 @@ int cmd_buildid_cache(int argc, const char **argv)
nsi = nsinfo__new(ns_id);

if (missing_filename) {
data.file.path = missing_filename;
data.force = force;
data.path = missing_filename;
data.force = force;

session = perf_session__new(&data, false, NULL);
if (session == NULL)
Expand Down
8 changes: 3 additions & 5 deletions tools/perf/builtin-buildid-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,9 @@ static int perf_session__list_build_ids(bool force, bool with_hits)
{
struct perf_session *session;
struct perf_data data = {
.file = {
.path = input_name,
},
.mode = PERF_DATA_MODE_READ,
.force = force,
.path = input_name,
.mode = PERF_DATA_MODE_READ,
.force = force,
};

symbol__elf_init();
Expand Down
4 changes: 2 additions & 2 deletions tools/perf/builtin-c2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -2750,8 +2750,8 @@ static int perf_c2c__report(int argc, const char **argv)
if (!input_name || !strlen(input_name))
input_name = "perf.data";

data.file.path = input_name;
data.force = symbol_conf.force;
data.path = input_name;
data.force = symbol_conf.force;

err = setup_display(display);
if (err)
Expand Down
12 changes: 6 additions & 6 deletions tools/perf/builtin-diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ static void data__fprintf(void)

data__for_each_file(i, d)
fprintf(stdout, "# [%d] %s %s\n",
d->idx, d->data.file.path,
d->idx, d->data.path,
!d->idx ? "(Baseline)" : "");

fprintf(stdout, "#\n");
Expand Down Expand Up @@ -779,14 +779,14 @@ static int __cmd_diff(void)
data__for_each_file(i, d) {
d->session = perf_session__new(&d->data, false, &tool);
if (!d->session) {
pr_err("Failed to open %s\n", d->data.file.path);
pr_err("Failed to open %s\n", d->data.path);
ret = -1;
goto out_delete;
}

ret = perf_session__process_events(d->session);
if (ret) {
pr_err("Failed to process %s\n", d->data.file.path);
pr_err("Failed to process %s\n", d->data.path);
goto out_delete;
}

Expand Down Expand Up @@ -1289,9 +1289,9 @@ static int data_init(int argc, const char **argv)
data__for_each_file(i, d) {
struct perf_data *data = &d->data;

data->file.path = use_default ? defaults[i] : argv[i];
data->mode = PERF_DATA_MODE_READ,
data->force = force,
data->path = use_default ? defaults[i] : argv[i];
data->mode = PERF_DATA_MODE_READ,
data->force = force,

d->idx = i;
}
Expand Down
4 changes: 1 addition & 3 deletions tools/perf/builtin-evlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ static int __cmd_evlist(const char *file_name, struct perf_attr_details *details
struct perf_session *session;
struct perf_evsel *pos;
struct perf_data data = {
.file = {
.path = file_name,
},
.path = file_name,
.mode = PERF_DATA_MODE_READ,
.force = details->force,
};
Expand Down
10 changes: 4 additions & 6 deletions tools/perf/builtin-inject.c
Original file line number Diff line number Diff line change
Expand Up @@ -770,10 +770,8 @@ int cmd_inject(int argc, const char **argv)
.input_name = "-",
.samples = LIST_HEAD_INIT(inject.samples),
.output = {
.file = {
.path = "-",
},
.mode = PERF_DATA_MODE_WRITE,
.path = "-",
.mode = PERF_DATA_MODE_WRITE,
},
};
struct perf_data data = {
Expand All @@ -786,7 +784,7 @@ int cmd_inject(int argc, const char **argv)
"Inject build-ids into the output stream"),
OPT_STRING('i', "input", &inject.input_name, "file",
"input file name"),
OPT_STRING('o', "output", &inject.output.file.path, "file",
OPT_STRING('o', "output", &inject.output.path, "file",
"output file name"),
OPT_BOOLEAN('s', "sched-stat", &inject.sched_stat,
"Merge sched-stat and sched-switch for getting events "
Expand Down Expand Up @@ -834,7 +832,7 @@ int cmd_inject(int argc, const char **argv)

inject.tool.ordered_events = inject.sched_stat;

data.file.path = inject.input_name;
data.path = inject.input_name;
inject.session = perf_session__new(&data, true, &inject.tool);
if (inject.session == NULL)
return -1;
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/builtin-kmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -1949,7 +1949,7 @@ int cmd_kmem(int argc, const char **argv)
return __cmd_record(argc, argv);
}

data.file.path = input_name;
data.path = input_name;

kmem_session = session = perf_session__new(&data, false, &perf_kmem);
if (session == NULL)
Expand Down
8 changes: 3 additions & 5 deletions tools/perf/builtin-kvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1080,11 +1080,9 @@ static int read_events(struct perf_kvm_stat *kvm)
.ordered_events = true,
};
struct perf_data file = {
.file = {
.path = kvm->file_name,
},
.mode = PERF_DATA_MODE_READ,
.force = kvm->force,
.path = kvm->file_name,
.mode = PERF_DATA_MODE_READ,
.force = kvm->force,
};

kvm->tool = eops;
Expand Down
8 changes: 3 additions & 5 deletions tools/perf/builtin-lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -866,11 +866,9 @@ static int __cmd_report(bool display_info)
.ordered_events = true,
};
struct perf_data data = {
.file = {
.path = input_name,
},
.mode = PERF_DATA_MODE_READ,
.force = force,
.path = input_name,
.mode = PERF_DATA_MODE_READ,
.force = force,
};

session = perf_session__new(&data, false, &eops);
Expand Down
8 changes: 3 additions & 5 deletions tools/perf/builtin-mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,9 @@ static int process_sample_event(struct perf_tool *tool,
static int report_raw_events(struct perf_mem *mem)
{
struct perf_data data = {
.file = {
.path = input_name,
},
.mode = PERF_DATA_MODE_READ,
.force = mem->force,
.path = input_name,
.mode = PERF_DATA_MODE_READ,
.force = mem->force,
};
int ret;
struct perf_session *session = perf_session__new(&data, false,
Expand Down
6 changes: 3 additions & 3 deletions tools/perf/builtin-record.c
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ record__switch_output(struct record *rec, bool at_exit)

if (!quiet)
fprintf(stderr, "[ perf record: Dump %s.%s ]\n",
data->file.path, timestamp);
data->path, timestamp);

/* Output tracking events */
if (!at_exit) {
Expand Down Expand Up @@ -1461,7 +1461,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)

fprintf(stderr, "[ perf record: Captured and wrote %.3f MB %s%s%s ]\n",
perf_data__size(data) / 1024.0 / 1024.0,
data->file.path, postfix, samples);
data->path, postfix, samples);
}

out_delete_session:
Expand Down Expand Up @@ -1862,7 +1862,7 @@ static struct option __record_options[] = {
OPT_STRING('C', "cpu", &record.opts.target.cpu_list, "cpu",
"list of cpus to monitor"),
OPT_U64('c', "count", &record.opts.user_interval, "event period to sample"),
OPT_STRING('o', "output", &record.data.file.path, "file",
OPT_STRING('o', "output", &record.data.path, "file",
"output file name"),
OPT_BOOLEAN_SET('i', "no-inherit", &record.opts.no_inherit,
&record.opts.no_inherit_set,
Expand Down
6 changes: 3 additions & 3 deletions tools/perf/builtin-report.c
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ static int __cmd_report(struct report *rep)
rep->nr_entries += evsel__hists(pos)->nr_entries;

if (rep->nr_entries == 0) {
ui__error("The %s file has no samples!\n", data->file.path);
ui__error("The %s data has no samples!\n", data->path);
return 0;
}

Expand Down Expand Up @@ -1207,8 +1207,8 @@ int cmd_report(int argc, const char **argv)
input_name = "perf.data";
}

data.file.path = input_name;
data.force = symbol_conf.force;
data.path = input_name;
data.force = symbol_conf.force;

repeat:
session = perf_session__new(&data, false, &report.tool);
Expand Down
16 changes: 6 additions & 10 deletions tools/perf/builtin-sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -1785,11 +1785,9 @@ static int perf_sched__read_events(struct perf_sched *sched)
};
struct perf_session *session;
struct perf_data data = {
.file = {
.path = input_name,
},
.mode = PERF_DATA_MODE_READ,
.force = sched->force,
.path = input_name,
.mode = PERF_DATA_MODE_READ,
.force = sched->force,
};
int rc = -1;

Expand Down Expand Up @@ -2958,11 +2956,9 @@ static int perf_sched__timehist(struct perf_sched *sched)
{ "sched:sched_migrate_task", timehist_migrate_task_event, },
};
struct perf_data data = {
.file = {
.path = input_name,
},
.mode = PERF_DATA_MODE_READ,
.force = sched->force,
.path = input_name,
.mode = PERF_DATA_MODE_READ,
.force = sched->force,
};

struct perf_session *session;
Expand Down
12 changes: 5 additions & 7 deletions tools/perf/builtin-script.c
Original file line number Diff line number Diff line change
Expand Up @@ -2951,10 +2951,8 @@ int find_scripts(char **scripts_array, char **scripts_path_array)
DIR *scripts_dir, *lang_dir;
struct perf_session *session;
struct perf_data data = {
.file = {
.path = input_name,
},
.mode = PERF_DATA_MODE_READ,
.path = input_name,
.mode = PERF_DATA_MODE_READ,
};
char *temp;
int i = 0;
Expand Down Expand Up @@ -3427,8 +3425,8 @@ int cmd_script(int argc, const char **argv)
argc = parse_options_subcommand(argc, argv, options, script_subcommands, script_usage,
PARSE_OPT_STOP_AT_NON_OPTION);

data.file.path = input_name;
data.force = symbol_conf.force;
data.path = input_name;
data.force = symbol_conf.force;

if (argc > 1 && !strncmp(argv[0], "rec", strlen("rec"))) {
rec_script_path = get_script_path(argv[1], RECORD_SUFFIX);
Expand Down Expand Up @@ -3654,7 +3652,7 @@ int cmd_script(int argc, const char **argv)
goto out_delete;
}

input = open(data.file.path, O_RDONLY); /* input_name */
input = open(data.path, O_RDONLY); /* input_name */
if (input < 0) {
err = -errno;
perror("failed to open file");
Expand Down
6 changes: 3 additions & 3 deletions tools/perf/builtin-stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -1322,7 +1322,7 @@ static int __cmd_record(int argc, const char **argv)
PARSE_OPT_STOP_AT_NON_OPTION);

if (output_name)
data->file.path = output_name;
data->path = output_name;

if (stat_config.run_count != 1 || forever) {
pr_err("Cannot use -r option with perf stat record.\n");
Expand Down Expand Up @@ -1523,8 +1523,8 @@ static int __cmd_report(int argc, const char **argv)
input_name = "perf.data";
}

perf_stat.data.file.path = input_name;
perf_stat.data.mode = PERF_DATA_MODE_READ;
perf_stat.data.path = input_name;
perf_stat.data.mode = PERF_DATA_MODE_READ;

session = perf_session__new(&perf_stat.data, false, &perf_stat.tool);
if (session == NULL)
Expand Down
8 changes: 3 additions & 5 deletions tools/perf/builtin-timechart.c
Original file line number Diff line number Diff line change
Expand Up @@ -1602,11 +1602,9 @@ static int __cmd_timechart(struct timechart *tchart, const char *output_name)
{ "syscalls:sys_exit_select", process_exit_poll },
};
struct perf_data data = {
.file = {
.path = input_name,
},
.mode = PERF_DATA_MODE_READ,
.force = tchart->force,
.path = input_name,
.mode = PERF_DATA_MODE_READ,
.force = tchart->force,
};

struct perf_session *session = perf_session__new(&data, false,
Expand Down
8 changes: 3 additions & 5 deletions tools/perf/builtin-trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -3154,11 +3154,9 @@ static int trace__replay(struct trace *trace)
{ "probe:vfs_getname", trace__vfs_getname, },
};
struct perf_data data = {
.file = {
.path = input_name,
},
.mode = PERF_DATA_MODE_READ,
.force = trace->force,
.path = input_name,
.mode = PERF_DATA_MODE_READ,
.force = trace->force,
};
struct perf_session *session;
struct perf_evsel *evsel;
Expand Down
4 changes: 2 additions & 2 deletions tools/perf/util/data-convert-bt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1578,7 +1578,7 @@ int bt_convert__perf2ctf(const char *input, const char *path,
{
struct perf_session *session;
struct perf_data data = {
.file = { .path = input, .fd = -1 },
.path = input,
.mode = PERF_DATA_MODE_READ,
.force = opts->force,
};
Expand Down Expand Up @@ -1650,7 +1650,7 @@ int bt_convert__perf2ctf(const char *input, const char *path,

fprintf(stderr,
"[ perf data convert: Converted '%s' into CTF data '%s' ]\n",
data.file.path, path);
data.path, path);

fprintf(stderr,
"[ perf data convert: Converted and wrote %.3f MB (%" PRIu64 " samples",
Expand Down
Loading

0 comments on commit 2d4f279

Please sign in to comment.