Skip to content

Commit

Permalink
perf session: Adopt the sample_type variable
Browse files Browse the repository at this point in the history
All tools had copies, and perf diff would have to specify a
sample_type_check method just for copying it.

Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
Cc: Frédéric Weisbecker <[email protected]>
Cc: Mike Galbraith <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Paul Mackerras <[email protected]>
LKML-Reference: <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
  • Loading branch information
acmel authored and Ingo Molnar committed Dec 14, 2009
1 parent a328626 commit c019879
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 58 deletions.
10 changes: 3 additions & 7 deletions tools/perf/builtin-kmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ typedef int (*sort_fn_t)(struct alloc_stat *, struct alloc_stat *);

static char const *input_name = "perf.data";

static u64 sample_type;

static int alloc_flag;
static int caller_flag;

Expand Down Expand Up @@ -321,7 +319,7 @@ static int process_sample_event(event_t *event, struct perf_session *session)
data.cpu = -1;
data.period = 1;

event__parse_sample(event, sample_type, &data);
event__parse_sample(event, session->sample_type, &data);

dump_printf("(IP, %d): %d/%d: %p period: %Ld\n",
event->header.misc,
Expand All @@ -344,11 +342,9 @@ static int process_sample_event(event_t *event, struct perf_session *session)
return 0;
}

static int sample_type_check(u64 type, struct perf_session *session __used)
static int sample_type_check(struct perf_session *session)
{
sample_type = type;

if (!(sample_type & PERF_SAMPLE_RAW)) {
if (!(session->sample_type & PERF_SAMPLE_RAW)) {
fprintf(stderr,
"No trace sample to read. Did you call perf record "
"without -R?");
Expand Down
12 changes: 4 additions & 8 deletions tools/perf/builtin-report.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ static int exclude_other = 1;

static char callchain_default_opt[] = "fractal,0.5";

static u64 sample_type;

struct symbol_conf symbol_conf;


Expand Down Expand Up @@ -557,15 +555,15 @@ static int process_sample_event(event_t *event, struct perf_session *session)
memset(&data, 0, sizeof(data));
data.period = 1;

event__parse_sample(event, sample_type, &data);
event__parse_sample(event, session->sample_type, &data);

dump_printf("(IP, %d): %d/%d: %p period: %Ld\n",
event->header.misc,
data.pid, data.tid,
(void *)(long)data.ip,
(long long)data.period);

if (sample_type & PERF_SAMPLE_CALLCHAIN) {
if (session->sample_type & PERF_SAMPLE_CALLCHAIN) {
unsigned int i;

dump_printf("... chain: nr:%Lu\n", data.callchain->nr);
Expand Down Expand Up @@ -664,11 +662,9 @@ static int process_read_event(event_t *event, struct perf_session *session __use
return 0;
}

static int sample_type_check(u64 type, struct perf_session *session)
static int sample_type_check(struct perf_session *session)
{
sample_type = type;

if (!(sample_type & PERF_SAMPLE_CALLCHAIN)) {
if (!(session->sample_type & PERF_SAMPLE_CALLCHAIN)) {
if (sort__has_parent) {
fprintf(stderr, "selected --sort parent, but no"
" callchain data. Did you call"
Expand Down
12 changes: 4 additions & 8 deletions tools/perf/builtin-sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

static char const *input_name = "perf.data";

static u64 sample_type;

static char default_sort_order[] = "avg, max, switch, runtime";
static char *sort_order = default_sort_order;

Expand Down Expand Up @@ -1613,15 +1611,15 @@ static int process_sample_event(event_t *event, struct perf_session *session)
struct sample_data data;
struct thread *thread;

if (!(sample_type & PERF_SAMPLE_RAW))
if (!(session->sample_type & PERF_SAMPLE_RAW))
return 0;

memset(&data, 0, sizeof(data));
data.time = -1;
data.cpu = -1;
data.period = -1;

event__parse_sample(event, sample_type, &data);
event__parse_sample(event, session->sample_type, &data);

dump_printf("(IP, %d): %d/%d: %p period: %Ld\n",
event->header.misc,
Expand Down Expand Up @@ -1655,11 +1653,9 @@ static int process_lost_event(event_t *event __used,
return 0;
}

static int sample_type_check(u64 type, struct perf_session *session __used)
static int sample_type_check(struct perf_session *session __used)
{
sample_type = type;

if (!(sample_type & PERF_SAMPLE_RAW)) {
if (!(session->sample_type & PERF_SAMPLE_RAW)) {
fprintf(stderr,
"No trace sample to read. Did you call perf record "
"without -R?");
Expand Down
36 changes: 15 additions & 21 deletions tools/perf/builtin-timechart.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@
static char const *input_name = "perf.data";
static char const *output_name = "output.svg";


static u64 sample_type;

static unsigned int numcpus;
static u64 min_freq; /* Lowest CPU frequency seen */
static u64 max_freq; /* Highest CPU frequency seen */
Expand Down Expand Up @@ -478,25 +475,24 @@ static void sched_switch(int cpu, u64 timestamp, struct trace_entry *te)
}


static int
process_sample_event(event_t *event)
static int process_sample_event(event_t *event, struct perf_session *session)
{
struct sample_data data;
struct trace_entry *te;

memset(&data, 0, sizeof(data));

event__parse_sample(event, sample_type, &data);
event__parse_sample(event, session->sample_type, &data);

if (sample_type & PERF_SAMPLE_TIME) {
if (session->sample_type & PERF_SAMPLE_TIME) {
if (!first_time || first_time > data.time)
first_time = data.time;
if (last_time < data.time)
last_time = data.time;
}

te = (void *)data.raw_data;
if (sample_type & PERF_SAMPLE_RAW && data.raw_size > 0) {
if (session->sample_type & PERF_SAMPLE_RAW && data.raw_size > 0) {
char *event_str;
struct power_entry *pe;

Expand Down Expand Up @@ -573,16 +569,16 @@ static void end_sample_processing(void)
}
}

static u64 sample_time(event_t *event)
static u64 sample_time(event_t *event, const struct perf_session *session)
{
int cursor;

cursor = 0;
if (sample_type & PERF_SAMPLE_IP)
if (session->sample_type & PERF_SAMPLE_IP)
cursor++;
if (sample_type & PERF_SAMPLE_TID)
if (session->sample_type & PERF_SAMPLE_TID)
cursor++;
if (sample_type & PERF_SAMPLE_TIME)
if (session->sample_type & PERF_SAMPLE_TIME)
return event->sample.array[cursor];
return 0;
}
Expand All @@ -592,7 +588,7 @@ static u64 sample_time(event_t *event)
* We first queue all events, sorted backwards by insertion.
* The order will get flipped later.
*/
static int queue_sample_event(event_t *event, struct perf_session *session __used)
static int queue_sample_event(event_t *event, struct perf_session *session)
{
struct sample_wrapper *copy, *prev;
int size;
Expand All @@ -606,7 +602,7 @@ static int queue_sample_event(event_t *event, struct perf_session *session __use
memset(copy, 0, size);

copy->next = NULL;
copy->timestamp = sample_time(event);
copy->timestamp = sample_time(event, session);

memcpy(&copy->data, event, event->sample.header.size);

Expand Down Expand Up @@ -1018,7 +1014,7 @@ static void write_svg_file(const char *filename)
svg_close();
}

static void process_samples(void)
static void process_samples(struct perf_session *session)
{
struct sample_wrapper *cursor;
event_t *event;
Expand All @@ -1029,15 +1025,13 @@ static void process_samples(void)
while (cursor) {
event = (void *)&cursor->data;
cursor = cursor->next;
process_sample_event(event);
process_sample_event(event, session);
}
}

static int sample_type_check(u64 type, struct perf_session *session __used)
static int sample_type_check(struct perf_session *session)
{
sample_type = type;

if (!(sample_type & PERF_SAMPLE_RAW)) {
if (!(session->sample_type & PERF_SAMPLE_RAW)) {
fprintf(stderr, "No trace samples found in the file.\n"
"Have you used 'perf timechart record' to record it?\n");
return -1;
Expand Down Expand Up @@ -1067,7 +1061,7 @@ static int __cmd_timechart(void)
if (ret)
goto out_delete;

process_samples();
process_samples(session);

end_sample_processing();

Expand Down
12 changes: 4 additions & 8 deletions tools/perf/builtin-trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ static int cleanup_scripting(void)

static char const *input_name = "perf.data";

static u64 sample_type;

static int process_sample_event(event_t *event, struct perf_session *session)
{
struct sample_data data;
Expand All @@ -73,7 +71,7 @@ static int process_sample_event(event_t *event, struct perf_session *session)
data.cpu = -1;
data.period = 1;

event__parse_sample(event, sample_type, &data);
event__parse_sample(event, session->sample_type, &data);

dump_printf("(IP, %d): %d/%d: %p period: %Ld\n",
event->header.misc,
Expand All @@ -88,7 +86,7 @@ static int process_sample_event(event_t *event, struct perf_session *session)
return -1;
}

if (sample_type & PERF_SAMPLE_RAW) {
if (session->sample_type & PERF_SAMPLE_RAW) {
/*
* FIXME: better resolve from pid from the struct trace_entry
* field, although it should be the same than this perf
Expand All @@ -103,11 +101,9 @@ static int process_sample_event(event_t *event, struct perf_session *session)
return 0;
}

static int sample_type_check(u64 type, struct perf_session *session __used)
static int sample_type_check(struct perf_session *session)
{
sample_type = type;

if (!(sample_type & PERF_SAMPLE_RAW)) {
if (!(session->sample_type & PERF_SAMPLE_RAW)) {
fprintf(stderr,
"No trace sample to read. Did you call perf record "
"without -R?");
Expand Down
6 changes: 2 additions & 4 deletions tools/perf/util/data_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ int perf_session__process_events(struct perf_session *self,
unsigned long head, shift;
unsigned long offset = 0;
size_t page_size;
u64 sample_type;
event_t *event;
uint32_t size;
char *buf;
Expand All @@ -157,11 +156,10 @@ int perf_session__process_events(struct perf_session *self,
page_size = getpagesize();

head = self->header.data_offset;
sample_type = perf_header__sample_type(&self->header);
self->sample_type = perf_header__sample_type(&self->header);

err = -EINVAL;
if (ops->sample_type_check &&
ops->sample_type_check(sample_type, self) < 0)
if (ops->sample_type_check && ops->sample_type_check(self) < 0)
goto out_err;

if (!ops->full_paths) {
Expand Down
4 changes: 2 additions & 2 deletions tools/perf/util/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct perf_session {
struct rb_root threads;
struct thread *last_match;
struct rb_root hists;
u64 sample_type;
int fd;
int cwdlen;
char *cwd;
Expand All @@ -39,8 +40,7 @@ struct perf_event_ops {
event_op process_read_event;
event_op process_throttle_event;
event_op process_unthrottle_event;
int (*sample_type_check)(u64 sample_type,
struct perf_session *session);
int (*sample_type_check)(struct perf_session *session);
unsigned long total_unknown;
bool full_paths;
};
Expand Down

0 comments on commit c019879

Please sign in to comment.