Skip to content

Commit 2d4f279

Browse files
olsajiriacmel
authored andcommitted
perf data: Add global path holder
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]>
1 parent 45112e8 commit 2d4f279

21 files changed

+87
-93
lines changed

tools/perf/builtin-annotate.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ static int __cmd_annotate(struct perf_annotate *ann)
441441
}
442442

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

@@ -578,7 +578,7 @@ int cmd_annotate(int argc, const char **argv)
578578
if (quiet)
579579
perf_quiet_option();
580580

581-
data.file.path = input_name;
581+
data.path = input_name;
582582

583583
annotate.session = perf_session__new(&data, false, &annotate.tool);
584584
if (annotate.session == NULL)

tools/perf/builtin-buildid-cache.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,8 @@ int cmd_buildid_cache(int argc, const char **argv)
416416
nsi = nsinfo__new(ns_id);
417417

418418
if (missing_filename) {
419-
data.file.path = missing_filename;
420-
data.force = force;
419+
data.path = missing_filename;
420+
data.force = force;
421421

422422
session = perf_session__new(&data, false, NULL);
423423
if (session == NULL)

tools/perf/builtin-buildid-list.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,9 @@ static int perf_session__list_build_ids(bool force, bool with_hits)
5252
{
5353
struct perf_session *session;
5454
struct perf_data data = {
55-
.file = {
56-
.path = input_name,
57-
},
58-
.mode = PERF_DATA_MODE_READ,
59-
.force = force,
55+
.path = input_name,
56+
.mode = PERF_DATA_MODE_READ,
57+
.force = force,
6058
};
6159

6260
symbol__elf_init();

tools/perf/builtin-c2c.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2750,8 +2750,8 @@ static int perf_c2c__report(int argc, const char **argv)
27502750
if (!input_name || !strlen(input_name))
27512751
input_name = "perf.data";
27522752

2753-
data.file.path = input_name;
2754-
data.force = symbol_conf.force;
2753+
data.path = input_name;
2754+
data.force = symbol_conf.force;
27552755

27562756
err = setup_display(display);
27572757
if (err)

tools/perf/builtin-diff.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ static void data__fprintf(void)
708708

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

714714
fprintf(stdout, "#\n");
@@ -779,14 +779,14 @@ static int __cmd_diff(void)
779779
data__for_each_file(i, d) {
780780
d->session = perf_session__new(&d->data, false, &tool);
781781
if (!d->session) {
782-
pr_err("Failed to open %s\n", d->data.file.path);
782+
pr_err("Failed to open %s\n", d->data.path);
783783
ret = -1;
784784
goto out_delete;
785785
}
786786

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

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

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

12961296
d->idx = i;
12971297
}

tools/perf/builtin-evlist.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ static int __cmd_evlist(const char *file_name, struct perf_attr_details *details
2323
struct perf_session *session;
2424
struct perf_evsel *pos;
2525
struct perf_data data = {
26-
.file = {
27-
.path = file_name,
28-
},
26+
.path = file_name,
2927
.mode = PERF_DATA_MODE_READ,
3028
.force = details->force,
3129
};

tools/perf/builtin-inject.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -770,10 +770,8 @@ int cmd_inject(int argc, const char **argv)
770770
.input_name = "-",
771771
.samples = LIST_HEAD_INIT(inject.samples),
772772
.output = {
773-
.file = {
774-
.path = "-",
775-
},
776-
.mode = PERF_DATA_MODE_WRITE,
773+
.path = "-",
774+
.mode = PERF_DATA_MODE_WRITE,
777775
},
778776
};
779777
struct perf_data data = {
@@ -786,7 +784,7 @@ int cmd_inject(int argc, const char **argv)
786784
"Inject build-ids into the output stream"),
787785
OPT_STRING('i', "input", &inject.input_name, "file",
788786
"input file name"),
789-
OPT_STRING('o', "output", &inject.output.file.path, "file",
787+
OPT_STRING('o', "output", &inject.output.path, "file",
790788
"output file name"),
791789
OPT_BOOLEAN('s', "sched-stat", &inject.sched_stat,
792790
"Merge sched-stat and sched-switch for getting events "
@@ -834,7 +832,7 @@ int cmd_inject(int argc, const char **argv)
834832

835833
inject.tool.ordered_events = inject.sched_stat;
836834

837-
data.file.path = inject.input_name;
835+
data.path = inject.input_name;
838836
inject.session = perf_session__new(&data, true, &inject.tool);
839837
if (inject.session == NULL)
840838
return -1;

tools/perf/builtin-kmem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1949,7 +1949,7 @@ int cmd_kmem(int argc, const char **argv)
19491949
return __cmd_record(argc, argv);
19501950
}
19511951

1952-
data.file.path = input_name;
1952+
data.path = input_name;
19531953

19541954
kmem_session = session = perf_session__new(&data, false, &perf_kmem);
19551955
if (session == NULL)

tools/perf/builtin-kvm.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,11 +1080,9 @@ static int read_events(struct perf_kvm_stat *kvm)
10801080
.ordered_events = true,
10811081
};
10821082
struct perf_data file = {
1083-
.file = {
1084-
.path = kvm->file_name,
1085-
},
1086-
.mode = PERF_DATA_MODE_READ,
1087-
.force = kvm->force,
1083+
.path = kvm->file_name,
1084+
.mode = PERF_DATA_MODE_READ,
1085+
.force = kvm->force,
10881086
};
10891087

10901088
kvm->tool = eops;

tools/perf/builtin-lock.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -866,11 +866,9 @@ static int __cmd_report(bool display_info)
866866
.ordered_events = true,
867867
};
868868
struct perf_data data = {
869-
.file = {
870-
.path = input_name,
871-
},
872-
.mode = PERF_DATA_MODE_READ,
873-
.force = force,
869+
.path = input_name,
870+
.mode = PERF_DATA_MODE_READ,
871+
.force = force,
874872
};
875873

876874
session = perf_session__new(&data, false, &eops);

tools/perf/builtin-mem.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,9 @@ static int process_sample_event(struct perf_tool *tool,
239239
static int report_raw_events(struct perf_mem *mem)
240240
{
241241
struct perf_data data = {
242-
.file = {
243-
.path = input_name,
244-
},
245-
.mode = PERF_DATA_MODE_READ,
246-
.force = mem->force,
242+
.path = input_name,
243+
.mode = PERF_DATA_MODE_READ,
244+
.force = mem->force,
247245
};
248246
int ret;
249247
struct perf_session *session = perf_session__new(&data, false,

tools/perf/builtin-record.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ record__switch_output(struct record *rec, bool at_exit)
918918

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

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

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

14671467
out_delete_session:
@@ -1862,7 +1862,7 @@ static struct option __record_options[] = {
18621862
OPT_STRING('C', "cpu", &record.opts.target.cpu_list, "cpu",
18631863
"list of cpus to monitor"),
18641864
OPT_U64('c', "count", &record.opts.user_interval, "event period to sample"),
1865-
OPT_STRING('o', "output", &record.data.file.path, "file",
1865+
OPT_STRING('o', "output", &record.data.path, "file",
18661866
"output file name"),
18671867
OPT_BOOLEAN_SET('i', "no-inherit", &record.opts.no_inherit,
18681868
&record.opts.no_inherit_set,

tools/perf/builtin-report.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ static int __cmd_report(struct report *rep)
899899
rep->nr_entries += evsel__hists(pos)->nr_entries;
900900

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

@@ -1207,8 +1207,8 @@ int cmd_report(int argc, const char **argv)
12071207
input_name = "perf.data";
12081208
}
12091209

1210-
data.file.path = input_name;
1211-
data.force = symbol_conf.force;
1210+
data.path = input_name;
1211+
data.force = symbol_conf.force;
12121212

12131213
repeat:
12141214
session = perf_session__new(&data, false, &report.tool);

tools/perf/builtin-sched.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,11 +1785,9 @@ static int perf_sched__read_events(struct perf_sched *sched)
17851785
};
17861786
struct perf_session *session;
17871787
struct perf_data data = {
1788-
.file = {
1789-
.path = input_name,
1790-
},
1791-
.mode = PERF_DATA_MODE_READ,
1792-
.force = sched->force,
1788+
.path = input_name,
1789+
.mode = PERF_DATA_MODE_READ,
1790+
.force = sched->force,
17931791
};
17941792
int rc = -1;
17951793

@@ -2958,11 +2956,9 @@ static int perf_sched__timehist(struct perf_sched *sched)
29582956
{ "sched:sched_migrate_task", timehist_migrate_task_event, },
29592957
};
29602958
struct perf_data data = {
2961-
.file = {
2962-
.path = input_name,
2963-
},
2964-
.mode = PERF_DATA_MODE_READ,
2965-
.force = sched->force,
2959+
.path = input_name,
2960+
.mode = PERF_DATA_MODE_READ,
2961+
.force = sched->force,
29662962
};
29672963

29682964
struct perf_session *session;

tools/perf/builtin-script.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2951,10 +2951,8 @@ int find_scripts(char **scripts_array, char **scripts_path_array)
29512951
DIR *scripts_dir, *lang_dir;
29522952
struct perf_session *session;
29532953
struct perf_data data = {
2954-
.file = {
2955-
.path = input_name,
2956-
},
2957-
.mode = PERF_DATA_MODE_READ,
2954+
.path = input_name,
2955+
.mode = PERF_DATA_MODE_READ,
29582956
};
29592957
char *temp;
29602958
int i = 0;
@@ -3427,8 +3425,8 @@ int cmd_script(int argc, const char **argv)
34273425
argc = parse_options_subcommand(argc, argv, options, script_subcommands, script_usage,
34283426
PARSE_OPT_STOP_AT_NON_OPTION);
34293427

3430-
data.file.path = input_name;
3431-
data.force = symbol_conf.force;
3428+
data.path = input_name;
3429+
data.force = symbol_conf.force;
34323430

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

3657-
input = open(data.file.path, O_RDONLY); /* input_name */
3655+
input = open(data.path, O_RDONLY); /* input_name */
36583656
if (input < 0) {
36593657
err = -errno;
36603658
perror("failed to open file");

tools/perf/builtin-stat.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,7 +1322,7 @@ static int __cmd_record(int argc, const char **argv)
13221322
PARSE_OPT_STOP_AT_NON_OPTION);
13231323

13241324
if (output_name)
1325-
data->file.path = output_name;
1325+
data->path = output_name;
13261326

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

1526-
perf_stat.data.file.path = input_name;
1527-
perf_stat.data.mode = PERF_DATA_MODE_READ;
1526+
perf_stat.data.path = input_name;
1527+
perf_stat.data.mode = PERF_DATA_MODE_READ;
15281528

15291529
session = perf_session__new(&perf_stat.data, false, &perf_stat.tool);
15301530
if (session == NULL)

tools/perf/builtin-timechart.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,11 +1602,9 @@ static int __cmd_timechart(struct timechart *tchart, const char *output_name)
16021602
{ "syscalls:sys_exit_select", process_exit_poll },
16031603
};
16041604
struct perf_data data = {
1605-
.file = {
1606-
.path = input_name,
1607-
},
1608-
.mode = PERF_DATA_MODE_READ,
1609-
.force = tchart->force,
1605+
.path = input_name,
1606+
.mode = PERF_DATA_MODE_READ,
1607+
.force = tchart->force,
16101608
};
16111609

16121610
struct perf_session *session = perf_session__new(&data, false,

tools/perf/builtin-trace.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3154,11 +3154,9 @@ static int trace__replay(struct trace *trace)
31543154
{ "probe:vfs_getname", trace__vfs_getname, },
31553155
};
31563156
struct perf_data data = {
3157-
.file = {
3158-
.path = input_name,
3159-
},
3160-
.mode = PERF_DATA_MODE_READ,
3161-
.force = trace->force,
3157+
.path = input_name,
3158+
.mode = PERF_DATA_MODE_READ,
3159+
.force = trace->force,
31623160
};
31633161
struct perf_session *session;
31643162
struct perf_evsel *evsel;

tools/perf/util/data-convert-bt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,7 +1578,7 @@ int bt_convert__perf2ctf(const char *input, const char *path,
15781578
{
15791579
struct perf_session *session;
15801580
struct perf_data data = {
1581-
.file = { .path = input, .fd = -1 },
1581+
.path = input,
15821582
.mode = PERF_DATA_MODE_READ,
15831583
.force = opts->force,
15841584
};
@@ -1650,7 +1650,7 @@ int bt_convert__perf2ctf(const char *input, const char *path,
16501650

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

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

0 commit comments

Comments
 (0)