if (session == NULL)
return -ENOMEM;
- ret = perf_session__process_events(session, &event_ops, 0,
- &event__cwdlen, &event__cwd);
+ ret = perf_session__process_events(session, &event_ops);
if (ret)
goto out_delete;
if (session == NULL)
return -ENOMEM;
- err = perf_session__process_events(session, &event_ops, 0,
- &event__cwdlen, &event__cwd);
+ err = perf_session__process_events(session, &event_ops);
perf_session__delete(session);
return err;
}
static int force;
-static int full_paths;
static int show_nr_samples;
static int show_threads;
if (show_threads)
perf_read_values_init(&show_threads_values);
- ret = perf_session__process_events(session, &event_ops, full_paths,
- &event__cwdlen, &event__cwd);
+ ret = perf_session__process_events(session, &event_ops);
if (ret)
goto out_delete;
"pretty printing style key: normal raw"),
OPT_STRING('s', "sort", &sort_order, "key[,key2...]",
"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"),
OPT_STRING('p', "parent", &parent_pattern, "regex",
"regex filter to identify parent, see: '--sort parent'"),
if (session == NULL)
return -ENOMEM;
- err = perf_session__process_events(session, &event_ops, 0,
- &event__cwdlen, &event__cwd);
+ err = perf_session__process_events(session, &event_ops);
perf_session__delete(session);
return err;
}
if (session == NULL)
return -ENOMEM;
- ret = perf_session__process_events(session, &event_ops, 0,
- &event__cwdlen, &event__cwd);
+ ret = perf_session__process_events(session, &event_ops);
if (ret)
goto out_delete;
static int __cmd_trace(struct perf_session *session)
{
- return perf_session__process_events(session, &event_ops, 0,
- &event__cwdlen, &event__cwd);
+ return perf_session__process_events(session, &event_ops);
}
struct script_spec {
#include "thread.h"
#include "session.h"
-static unsigned long mmap_window = 32;
-static char __cwd[PATH_MAX];
-
static int process_event_stub(event_t *event __used,
struct perf_session *session __used)
{
}
int perf_session__process_events(struct perf_session *self,
- struct perf_event_ops *ops,
- int full_paths, int *cwdlen, char **cwd)
+ struct perf_event_ops *ops)
{
int err;
unsigned long head, shift;
ops->sample_type_check(sample_type) < 0)
goto out_err;
- if (!full_paths) {
- if (getcwd(__cwd, sizeof(__cwd)) == NULL) {
- pr_err("failed to get the current directory\n");
+ if (!ops->full_paths) {
+ char bf[PATH_MAX];
+
+ if (getcwd(bf, sizeof(bf)) == NULL) {
err = -errno;
+out_getcwd_err:
+ pr_err("failed to get the current directory\n");
goto out_err;
}
- *cwd = __cwd;
- *cwdlen = strlen(*cwd);
- } else {
- *cwd = NULL;
- *cwdlen = 0;
+ self->cwd = strdup(bf);
+ if (self->cwd == NULL) {
+ err = -ENOMEM;
+ goto out_getcwd_err;
+ }
+ self->cwdlen = strlen(self->cwd);
}
shift = page_size * (head / page_size);
head -= shift;
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);
if (buf == MAP_FAILED) {
pr_err("failed to mmap file\n");
if (!size)
size = 8;
- if (head + event->header.size >= page_size * mmap_window) {
+ if (head + event->header.size >= page_size * self->mmap_window) {
int munmap_ret;
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);
offset += shift;
#include <linux/types.h>
#include "event.h"
#include "debug.h"
+#include "session.h"
#include "string.h"
#include "thread.h"
closedir(proc);
}
-char *event__cwd;
-int event__cwdlen;
-
struct events_stats event__stats;
int event__process_comm(event_t *self, struct perf_session *session __used)
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 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",
self->mmap.pid, self->mmap.tid,
goto out_delete;
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) {
perf_session__delete(self);
{
perf_header__exit(&self->header);
close(self->fd);
+ free(self->cwd);
free(self);
}
struct perf_session {
struct perf_header header;
unsigned long size;
+ unsigned long mmap_window;
int fd;
+ int cwdlen;
+ char *cwd;
char filename[0];
};
event_op process_unthrottle_event;
int (*sample_type_check)(u64 sample_type);
unsigned long total_unknown;
+ bool full_paths;
};
struct perf_session *perf_session__new(const char *filename, int mode,
void perf_session__delete(struct perf_session *self);
int perf_session__process_events(struct perf_session *self,
- struct perf_event_ops *event_ops,
- int full_paths, int *cwdlen, char **cwd);
+ struct perf_event_ops *event_ops);
int perf_header__read_build_ids(int input, u64 offset, u64 file_size);