Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 182320
b: refs/heads/master
c: d549c76
h: refs/heads/master
v: v3
  • Loading branch information
Arnaldo Carvalho de Melo authored and Ingo Molnar committed Dec 28, 2009
1 parent 06c1854 commit 808febe
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 28 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 27295592c22e71bbd38110c302da8dbb43912a60
refs/heads/master: d549c7690190d9739005e19604faad6da4b802ac
6 changes: 4 additions & 2 deletions trunk/tools/perf/builtin-kmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ static int process_sample_event(event_t *event, struct perf_session *session)
static struct perf_event_ops event_ops = {
.process_sample_event = process_sample_event,
.process_comm_event = event__process_comm,
.sample_type_check = perf_session__has_traces,
};

static double fragmentation(unsigned long n_req, unsigned long n_alloc)
Expand Down Expand Up @@ -492,11 +491,14 @@ static void sort_result(void)

static int __cmd_kmem(void)
{
int err;
int err = -EINVAL;
struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0);
if (session == NULL)
return -ENOMEM;

if (!perf_session__has_traces(session, "kmem record"))
goto out_delete;

setup_pager();
err = perf_session__process_events(session, &event_ops);
if (err != 0)
Expand Down
16 changes: 9 additions & 7 deletions trunk/tools/perf/builtin-report.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,14 @@ static int process_read_event(event_t *event, struct perf_session *session __use
return 0;
}

static int sample_type_check(struct perf_session *session)
static int perf_session__setup_sample_type(struct perf_session *self)
{
if (!(session->sample_type & PERF_SAMPLE_CALLCHAIN)) {
if (!(self->sample_type & PERF_SAMPLE_CALLCHAIN)) {
if (sort__has_parent) {
fprintf(stderr, "selected --sort parent, but no"
" callchain data. Did you call"
" perf record without -g?\n");
return -1;
return -EINVAL;
}
if (symbol_conf.use_callchain) {
fprintf(stderr, "selected -g but no callchain data."
Expand All @@ -176,7 +176,7 @@ static int sample_type_check(struct perf_session *session)
if (register_callchain_param(&callchain_param) < 0) {
fprintf(stderr, "Can't register callchain"
" params\n");
return -1;
return -EINVAL;
}
}

Expand All @@ -191,13 +191,11 @@ static struct perf_event_ops event_ops = {
.process_fork_event = event__process_task,
.process_lost_event = event__process_lost,
.process_read_event = process_read_event,
.sample_type_check = sample_type_check,
};


static int __cmd_report(void)
{
int ret;
int ret = -EINVAL;
struct perf_session *session;

session = perf_session__new(input_name, O_RDONLY, force);
Expand All @@ -207,6 +205,10 @@ static int __cmd_report(void)
if (show_threads)
perf_read_values_init(&show_threads_values);

ret = perf_session__setup_sample_type(session);
if (ret)
goto out_delete;

ret = perf_session__process_events(session, &event_ops);
if (ret)
goto out_delete;
Expand Down
7 changes: 4 additions & 3 deletions trunk/tools/perf/builtin-sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -1657,17 +1657,18 @@ static struct perf_event_ops event_ops = {
.process_sample_event = process_sample_event,
.process_comm_event = event__process_comm,
.process_lost_event = process_lost_event,
.sample_type_check = perf_session__has_traces,
};

static int read_events(void)
{
int err;
int err = -EINVAL;
struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0);
if (session == NULL)
return -ENOMEM;

err = perf_session__process_events(session, &event_ops);
if (perf_session__has_traces(session, "record -R"))
err = perf_session__process_events(session, &event_ops);

perf_session__delete(session);
return err;
}
Expand Down
6 changes: 4 additions & 2 deletions trunk/tools/perf/builtin-timechart.c
Original file line number Diff line number Diff line change
Expand Up @@ -1034,17 +1034,19 @@ static struct perf_event_ops event_ops = {
.process_fork_event = process_fork_event,
.process_exit_event = process_exit_event,
.process_sample_event = queue_sample_event,
.sample_type_check = perf_session__has_traces,
};

static int __cmd_timechart(void)
{
struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0);
int ret;
int ret = -EINVAL;

if (session == NULL)
return -ENOMEM;

if (!perf_session__has_traces(session, "timechart record"))
goto out_delete;

ret = perf_session__process_events(session, &event_ops);
if (ret)
goto out_delete;
Expand Down
4 changes: 3 additions & 1 deletion trunk/tools/perf/builtin-trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ static int process_sample_event(event_t *event, struct perf_session *session)
static struct perf_event_ops event_ops = {
.process_sample_event = process_sample_event,
.process_comm_event = event__process_comm,
.sample_type_check = perf_session__has_traces,
};

static int __cmd_trace(struct perf_session *session)
Expand Down Expand Up @@ -580,6 +579,9 @@ int cmd_trace(int argc, const char **argv, const char *prefix __used)
if (session == NULL)
return -ENOMEM;

if (!perf_session__has_traces(session, "record -R"))
return -EINVAL;

if (generate_script_lang) {
struct stat perf_stat;

Expand Down
16 changes: 6 additions & 10 deletions trunk/tools/perf/util/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ struct perf_session *perf_session__new(const char *filename, int mode, bool forc

if (mode == O_RDONLY && perf_session__open(self, force) < 0)
goto out_delete;

self->sample_type = perf_header__sample_type(&self->header);
out:
return self;
out_free:
Expand Down Expand Up @@ -302,11 +304,6 @@ int perf_session__process_events(struct perf_session *self,
page_size = getpagesize();

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

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

if (!ops->full_paths) {
char bf[PATH_MAX];
Expand Down Expand Up @@ -394,13 +391,12 @@ int perf_session__process_events(struct perf_session *self,
return err;
}

int perf_session__has_traces(struct perf_session *self)
bool perf_session__has_traces(struct perf_session *self, const char *msg)
{
if (!(self->sample_type & PERF_SAMPLE_RAW)) {
pr_err("No trace sample to read. Did you call perf record "
"without -R?");
return -1;
pr_err("No trace sample to read. Did you call 'perf %s'?\n", msg);
return false;
}

return 0;
return true;
}
3 changes: 1 addition & 2 deletions trunk/tools/perf/util/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ struct perf_event_ops {
event_op process_read_event;
event_op process_throttle_event;
event_op process_unthrottle_event;
int (*sample_type_check)(struct perf_session *session);
unsigned long total_unknown;
bool full_paths;
};
Expand All @@ -56,7 +55,7 @@ struct symbol **perf_session__resolve_callchain(struct perf_session *self,
struct ip_callchain *chain,
struct symbol **parent);

int perf_session__has_traces(struct perf_session *self);
bool perf_session__has_traces(struct perf_session *self, const char *msg);

int perf_header__read_build_ids(int input, u64 offset, u64 file_size);

Expand Down

0 comments on commit 808febe

Please sign in to comment.