mirror of
https://github.com/adulau/aha.git
synced 2024-12-28 11:46:19 +00:00
perf session: Reduce the number of parms to perf_session__process_events
By having the cwd/cwdlen in the perf_session struct and full_paths in perf_event_ops. Now its just a matter of passing the ops. Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Frédéric Weisbecker <fweisbec@gmail.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Paul Mackerras <paulus@samba.org> LKML-Reference: <1260741029-4430-4-git-send-email-acme@infradead.org> Signed-off-by: Ingo Molnar <mingo@elte.hu>
This commit is contained in:
parent
13df45ca1c
commit
ec91336973
10 changed files with 35 additions and 37 deletions
|
@ -469,8 +469,7 @@ static int __cmd_annotate(void)
|
||||||
if (session == NULL)
|
if (session == NULL)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
ret = perf_session__process_events(session, &event_ops, 0,
|
ret = perf_session__process_events(session, &event_ops);
|
||||||
&event__cwdlen, &event__cwd);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out_delete;
|
goto out_delete;
|
||||||
|
|
||||||
|
|
|
@ -372,8 +372,7 @@ static int read_events(void)
|
||||||
if (session == NULL)
|
if (session == NULL)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
err = perf_session__process_events(session, &event_ops, 0,
|
err = perf_session__process_events(session, &event_ops);
|
||||||
&event__cwdlen, &event__cwd);
|
|
||||||
perf_session__delete(session);
|
perf_session__delete(session);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,6 @@ static struct strlist *dso_list, *comm_list, *sym_list;
|
||||||
|
|
||||||
static int force;
|
static int force;
|
||||||
|
|
||||||
static int full_paths;
|
|
||||||
static int show_nr_samples;
|
static int show_nr_samples;
|
||||||
|
|
||||||
static int show_threads;
|
static int show_threads;
|
||||||
|
@ -771,8 +770,7 @@ static int __cmd_report(void)
|
||||||
if (show_threads)
|
if (show_threads)
|
||||||
perf_read_values_init(&show_threads_values);
|
perf_read_values_init(&show_threads_values);
|
||||||
|
|
||||||
ret = perf_session__process_events(session, &event_ops, full_paths,
|
ret = perf_session__process_events(session, &event_ops);
|
||||||
&event__cwdlen, &event__cwd);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out_delete;
|
goto out_delete;
|
||||||
|
|
||||||
|
@ -877,7 +875,7 @@ static const struct option options[] = {
|
||||||
"pretty printing style key: normal raw"),
|
"pretty printing style key: normal raw"),
|
||||||
OPT_STRING('s', "sort", &sort_order, "key[,key2...]",
|
OPT_STRING('s', "sort", &sort_order, "key[,key2...]",
|
||||||
"sort by key(s): pid, comm, dso, symbol, parent"),
|
"sort by key(s): pid, comm, dso, symbol, parent"),
|
||||||
OPT_BOOLEAN('P', "full-paths", &full_paths,
|
OPT_BOOLEAN('P', "full-paths", &event_ops.full_paths,
|
||||||
"Don't shorten the pathnames taking into account the cwd"),
|
"Don't shorten the pathnames taking into account the cwd"),
|
||||||
OPT_STRING('p', "parent", &parent_pattern, "regex",
|
OPT_STRING('p', "parent", &parent_pattern, "regex",
|
||||||
"regex filter to identify parent, see: '--sort parent'"),
|
"regex filter to identify parent, see: '--sort parent'"),
|
||||||
|
|
|
@ -1670,8 +1670,7 @@ static int read_events(void)
|
||||||
if (session == NULL)
|
if (session == NULL)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
err = perf_session__process_events(session, &event_ops, 0,
|
err = perf_session__process_events(session, &event_ops);
|
||||||
&event__cwdlen, &event__cwd);
|
|
||||||
perf_session__delete(session);
|
perf_session__delete(session);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1062,8 +1062,7 @@ static int __cmd_timechart(void)
|
||||||
if (session == NULL)
|
if (session == NULL)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
ret = perf_session__process_events(session, &event_ops, 0,
|
ret = perf_session__process_events(session, &event_ops);
|
||||||
&event__cwdlen, &event__cwd);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out_delete;
|
goto out_delete;
|
||||||
|
|
||||||
|
|
|
@ -125,8 +125,7 @@ static struct perf_event_ops event_ops = {
|
||||||
|
|
||||||
static int __cmd_trace(struct perf_session *session)
|
static int __cmd_trace(struct perf_session *session)
|
||||||
{
|
{
|
||||||
return perf_session__process_events(session, &event_ops, 0,
|
return perf_session__process_events(session, &event_ops);
|
||||||
&event__cwdlen, &event__cwd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct script_spec {
|
struct script_spec {
|
||||||
|
|
|
@ -4,9 +4,6 @@
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
#include "session.h"
|
#include "session.h"
|
||||||
|
|
||||||
static unsigned long mmap_window = 32;
|
|
||||||
static char __cwd[PATH_MAX];
|
|
||||||
|
|
||||||
static int process_event_stub(event_t *event __used,
|
static int process_event_stub(event_t *event __used,
|
||||||
struct perf_session *session __used)
|
struct perf_session *session __used)
|
||||||
{
|
{
|
||||||
|
@ -141,8 +138,7 @@ static struct thread *perf_session__register_idle_thread(struct perf_session *se
|
||||||
}
|
}
|
||||||
|
|
||||||
int perf_session__process_events(struct perf_session *self,
|
int perf_session__process_events(struct perf_session *self,
|
||||||
struct perf_event_ops *ops,
|
struct perf_event_ops *ops)
|
||||||
int full_paths, int *cwdlen, char **cwd)
|
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
unsigned long head, shift;
|
unsigned long head, shift;
|
||||||
|
@ -168,17 +164,21 @@ int perf_session__process_events(struct perf_session *self,
|
||||||
ops->sample_type_check(sample_type) < 0)
|
ops->sample_type_check(sample_type) < 0)
|
||||||
goto out_err;
|
goto out_err;
|
||||||
|
|
||||||
if (!full_paths) {
|
if (!ops->full_paths) {
|
||||||
if (getcwd(__cwd, sizeof(__cwd)) == NULL) {
|
char bf[PATH_MAX];
|
||||||
pr_err("failed to get the current directory\n");
|
|
||||||
|
if (getcwd(bf, sizeof(bf)) == NULL) {
|
||||||
err = -errno;
|
err = -errno;
|
||||||
|
out_getcwd_err:
|
||||||
|
pr_err("failed to get the current directory\n");
|
||||||
goto out_err;
|
goto out_err;
|
||||||
}
|
}
|
||||||
*cwd = __cwd;
|
self->cwd = strdup(bf);
|
||||||
*cwdlen = strlen(*cwd);
|
if (self->cwd == NULL) {
|
||||||
} else {
|
err = -ENOMEM;
|
||||||
*cwd = NULL;
|
goto out_getcwd_err;
|
||||||
*cwdlen = 0;
|
}
|
||||||
|
self->cwdlen = strlen(self->cwd);
|
||||||
}
|
}
|
||||||
|
|
||||||
shift = page_size * (head / page_size);
|
shift = page_size * (head / page_size);
|
||||||
|
@ -186,7 +186,7 @@ int perf_session__process_events(struct perf_session *self,
|
||||||
head -= shift;
|
head -= shift;
|
||||||
|
|
||||||
remap:
|
remap:
|
||||||
buf = mmap(NULL, page_size * mmap_window, PROT_READ,
|
buf = mmap(NULL, page_size * self->mmap_window, PROT_READ,
|
||||||
MAP_SHARED, self->fd, offset);
|
MAP_SHARED, self->fd, offset);
|
||||||
if (buf == MAP_FAILED) {
|
if (buf == MAP_FAILED) {
|
||||||
pr_err("failed to mmap file\n");
|
pr_err("failed to mmap file\n");
|
||||||
|
@ -201,12 +201,12 @@ more:
|
||||||
if (!size)
|
if (!size)
|
||||||
size = 8;
|
size = 8;
|
||||||
|
|
||||||
if (head + event->header.size >= page_size * mmap_window) {
|
if (head + event->header.size >= page_size * self->mmap_window) {
|
||||||
int munmap_ret;
|
int munmap_ret;
|
||||||
|
|
||||||
shift = page_size * (head / page_size);
|
shift = page_size * (head / page_size);
|
||||||
|
|
||||||
munmap_ret = munmap(buf, page_size * mmap_window);
|
munmap_ret = munmap(buf, page_size * self->mmap_window);
|
||||||
assert(munmap_ret == 0);
|
assert(munmap_ret == 0);
|
||||||
|
|
||||||
offset += shift;
|
offset += shift;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include <linux/types.h>
|
#include <linux/types.h>
|
||||||
#include "event.h"
|
#include "event.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
#include "session.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
|
|
||||||
|
@ -186,9 +187,6 @@ void event__synthesize_threads(int (*process)(event_t *event,
|
||||||
closedir(proc);
|
closedir(proc);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *event__cwd;
|
|
||||||
int event__cwdlen;
|
|
||||||
|
|
||||||
struct events_stats event__stats;
|
struct events_stats event__stats;
|
||||||
|
|
||||||
int event__process_comm(event_t *self, struct perf_session *session __used)
|
int event__process_comm(event_t *self, struct perf_session *session __used)
|
||||||
|
@ -212,11 +210,11 @@ int event__process_lost(event_t *self, struct perf_session *session __used)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int event__process_mmap(event_t *self, struct perf_session *session __used)
|
int event__process_mmap(event_t *self, struct perf_session *session)
|
||||||
{
|
{
|
||||||
struct thread *thread = threads__findnew(self->mmap.pid);
|
struct thread *thread = threads__findnew(self->mmap.pid);
|
||||||
struct map *map = map__new(&self->mmap, MAP__FUNCTION,
|
struct map *map = map__new(&self->mmap, MAP__FUNCTION,
|
||||||
event__cwd, event__cwdlen);
|
session->cwd, session->cwdlen);
|
||||||
|
|
||||||
dump_printf(" %d/%d: [%p(%p) @ %p]: %s\n",
|
dump_printf(" %d/%d: [%p(%p) @ %p]: %s\n",
|
||||||
self->mmap.pid, self->mmap.tid,
|
self->mmap.pid, self->mmap.tid,
|
||||||
|
|
|
@ -61,6 +61,9 @@ struct perf_session *perf_session__new(const char *filename, int mode,
|
||||||
goto out_delete;
|
goto out_delete;
|
||||||
|
|
||||||
memcpy(self->filename, filename, len);
|
memcpy(self->filename, filename, len);
|
||||||
|
self->mmap_window = 32;
|
||||||
|
self->cwd = NULL;
|
||||||
|
self->cwdlen = 0;
|
||||||
|
|
||||||
if (mode == O_RDONLY && perf_session__open(self, force) < 0) {
|
if (mode == O_RDONLY && perf_session__open(self, force) < 0) {
|
||||||
perf_session__delete(self);
|
perf_session__delete(self);
|
||||||
|
@ -77,5 +80,6 @@ void perf_session__delete(struct perf_session *self)
|
||||||
{
|
{
|
||||||
perf_header__exit(&self->header);
|
perf_header__exit(&self->header);
|
||||||
close(self->fd);
|
close(self->fd);
|
||||||
|
free(self->cwd);
|
||||||
free(self);
|
free(self);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,10 @@
|
||||||
struct perf_session {
|
struct perf_session {
|
||||||
struct perf_header header;
|
struct perf_header header;
|
||||||
unsigned long size;
|
unsigned long size;
|
||||||
|
unsigned long mmap_window;
|
||||||
int fd;
|
int fd;
|
||||||
|
int cwdlen;
|
||||||
|
char *cwd;
|
||||||
char filename[0];
|
char filename[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -25,6 +28,7 @@ struct perf_event_ops {
|
||||||
event_op process_unthrottle_event;
|
event_op process_unthrottle_event;
|
||||||
int (*sample_type_check)(u64 sample_type);
|
int (*sample_type_check)(u64 sample_type);
|
||||||
unsigned long total_unknown;
|
unsigned long total_unknown;
|
||||||
|
bool full_paths;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct perf_session *perf_session__new(const char *filename, int mode,
|
struct perf_session *perf_session__new(const char *filename, int mode,
|
||||||
|
@ -32,8 +36,7 @@ struct perf_session *perf_session__new(const char *filename, int mode,
|
||||||
void perf_session__delete(struct perf_session *self);
|
void perf_session__delete(struct perf_session *self);
|
||||||
|
|
||||||
int perf_session__process_events(struct perf_session *self,
|
int perf_session__process_events(struct perf_session *self,
|
||||||
struct perf_event_ops *event_ops,
|
struct perf_event_ops *event_ops);
|
||||||
int full_paths, int *cwdlen, char **cwd);
|
|
||||||
|
|
||||||
int perf_header__read_build_ids(int input, u64 offset, u64 file_size);
|
int perf_header__read_build_ids(int input, u64 offset, u64 file_size);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue