Skip to content

Commit 9ede473

Browse files
Jiri Olsaacmel
authored andcommitted
perf tools: Add support for parsing PERF_SAMPLE_READ sample type
Adding support to parse out the PERF_SAMPLE_READ sample bits. The code contains both single and group format specification. This code parse out and prepare PERF_SAMPLE_READ data into the perf_sample struct. It will be used for group leader sampling feature comming in shortly. Signed-off-by: Jiri Olsa <jolsa@redhat.com> Acked-by: Namhyung Kim <namhyung@kernel.org> Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lkml.kernel.org/n/tip-0tgdoln5rwk3wocshb442cl3@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent e2b5abe commit 9ede473

5 files changed

Lines changed: 112 additions & 2 deletions

File tree

‎tools/perf/util/event.h‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,23 @@ struct stack_dump {
8080
char *data;
8181
};
8282

83+
struct sample_read_value {
84+
u64 value;
85+
u64 id;
86+
};
87+
88+
struct sample_read {
89+
u64 time_enabled;
90+
u64 time_running;
91+
union {
92+
struct {
93+
u64 nr;
94+
struct sample_read_value *values;
95+
} group;
96+
struct sample_read_value one;
97+
};
98+
};
99+
83100
struct perf_sample {
84101
u64 ip;
85102
u32 pid, tid;
@@ -97,6 +114,7 @@ struct perf_sample {
97114
struct branch_stack *branch_stack;
98115
struct regs_dump user_regs;
99116
struct stack_dump user_stack;
117+
struct sample_read read;
100118
};
101119

102120
#define PERF_MEM_DATA_SRC_NONE \

‎tools/perf/util/evlist.c‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,32 @@ u64 perf_evlist__sample_type(struct perf_evlist *evlist)
676676
return first->attr.sample_type;
677677
}
678678

679+
bool perf_evlist__valid_read_format(struct perf_evlist *evlist)
680+
{
681+
struct perf_evsel *first = perf_evlist__first(evlist), *pos = first;
682+
u64 read_format = first->attr.read_format;
683+
u64 sample_type = first->attr.sample_type;
684+
685+
list_for_each_entry_continue(pos, &evlist->entries, node) {
686+
if (read_format != pos->attr.read_format)
687+
return false;
688+
}
689+
690+
/* PERF_SAMPLE_READ imples PERF_FORMAT_ID. */
691+
if ((sample_type & PERF_SAMPLE_READ) &&
692+
!(read_format & PERF_FORMAT_ID)) {
693+
return false;
694+
}
695+
696+
return true;
697+
}
698+
699+
u64 perf_evlist__read_format(struct perf_evlist *evlist)
700+
{
701+
struct perf_evsel *first = perf_evlist__first(evlist);
702+
return first->attr.read_format;
703+
}
704+
679705
u16 perf_evlist__id_hdr_size(struct perf_evlist *evlist)
680706
{
681707
struct perf_evsel *first = perf_evlist__first(evlist);

‎tools/perf/util/evlist.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ int perf_evlist__apply_filters(struct perf_evlist *evlist);
118118
void __perf_evlist__set_leader(struct list_head *list);
119119
void perf_evlist__set_leader(struct perf_evlist *evlist);
120120

121+
u64 perf_evlist__read_format(struct perf_evlist *evlist);
121122
u64 perf_evlist__sample_type(struct perf_evlist *evlist);
122123
bool perf_evlist__sample_id_all(struct perf_evlist *evlist);
123124
u16 perf_evlist__id_hdr_size(struct perf_evlist *evlist);
@@ -127,6 +128,7 @@ int perf_evlist__parse_sample(struct perf_evlist *evlist, union perf_event *even
127128

128129
bool perf_evlist__valid_sample_type(struct perf_evlist *evlist);
129130
bool perf_evlist__valid_sample_id_all(struct perf_evlist *evlist);
131+
bool perf_evlist__valid_read_format(struct perf_evlist *evlist);
130132

131133
void perf_evlist__splice_list_tail(struct perf_evlist *evlist,
132134
struct list_head *list,

‎tools/perf/util/evsel.c‎

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,8 +1096,34 @@ int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
10961096
}
10971097

10981098
if (type & PERF_SAMPLE_READ) {
1099-
fprintf(stderr, "PERF_SAMPLE_READ is unsupported for now\n");
1100-
return -1;
1099+
u64 read_format = evsel->attr.read_format;
1100+
1101+
if (read_format & PERF_FORMAT_GROUP)
1102+
data->read.group.nr = *array;
1103+
else
1104+
data->read.one.value = *array;
1105+
1106+
array++;
1107+
1108+
if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
1109+
data->read.time_enabled = *array;
1110+
array++;
1111+
}
1112+
1113+
if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
1114+
data->read.time_running = *array;
1115+
array++;
1116+
}
1117+
1118+
/* PERF_FORMAT_ID is forced for PERF_SAMPLE_READ */
1119+
if (read_format & PERF_FORMAT_GROUP) {
1120+
data->read.group.values = (struct sample_read_value *) array;
1121+
array = (void *) array + data->read.group.nr *
1122+
sizeof(struct sample_read_value);
1123+
} else {
1124+
data->read.one.id = *array;
1125+
array++;
1126+
}
11011127
}
11021128

11031129
if (type & PERF_SAMPLE_CALLCHAIN) {

‎tools/perf/util/session.c‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ static int perf_session__open(struct perf_session *self, bool force)
7171
goto out_close;
7272
}
7373

74+
if (!perf_evlist__valid_read_format(self->evlist)) {
75+
pr_err("non matching read_format");
76+
goto out_close;
77+
}
78+
7479
self->size = input_stat.st_size;
7580
return 0;
7681

@@ -749,6 +754,36 @@ static void perf_session__print_tstamp(struct perf_session *session,
749754
printf("%" PRIu64 " ", sample->time);
750755
}
751756

757+
static void sample_read__printf(struct perf_sample *sample, u64 read_format)
758+
{
759+
printf("... sample_read:\n");
760+
761+
if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED)
762+
printf("...... time enabled %016" PRIx64 "\n",
763+
sample->read.time_enabled);
764+
765+
if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING)
766+
printf("...... time running %016" PRIx64 "\n",
767+
sample->read.time_running);
768+
769+
if (read_format & PERF_FORMAT_GROUP) {
770+
u64 i;
771+
772+
printf(".... group nr %" PRIu64 "\n", sample->read.group.nr);
773+
774+
for (i = 0; i < sample->read.group.nr; i++) {
775+
struct sample_read_value *value;
776+
777+
value = &sample->read.group.values[i];
778+
printf("..... id %016" PRIx64
779+
", value %016" PRIx64 "\n",
780+
value->id, value->value);
781+
}
782+
} else
783+
printf("..... id %016" PRIx64 ", value %016" PRIx64 "\n",
784+
sample->read.one.id, sample->read.one.value);
785+
}
786+
752787
static void dump_event(struct perf_session *session, union perf_event *event,
753788
u64 file_offset, struct perf_sample *sample)
754789
{
@@ -798,6 +833,9 @@ static void dump_sample(struct perf_evsel *evsel, union perf_event *event,
798833

799834
if (sample_type & PERF_SAMPLE_DATA_SRC)
800835
printf(" . data_src: 0x%"PRIx64"\n", sample->data_src);
836+
837+
if (sample_type & PERF_SAMPLE_READ)
838+
sample_read__printf(sample, evsel->attr.read_format);
801839
}
802840

803841
static struct machine *

0 commit comments

Comments
 (0)