Skip to content

Commit

Permalink
perf tools: Add data object to handle perf data file
Browse files Browse the repository at this point in the history
This patch is adding 'struct perf_data_file' object as a placeholder for
all attributes regarding perf.data file handling. Changing
perf_session__new to take it as an argument.

The rest of the functionality will be added later to keep this change
simple enough, because all the places using perf_session are changed
now.

Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
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/r/1381847254-28809-2-git-send-email-jolsa@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Jiri Olsa authored and Arnaldo Carvalho de Melo committed Oct 21, 2013
1 parent 09600e0 commit f5fc141
Show file tree
Hide file tree
Showing 21 changed files with 186 additions and 73 deletions.
9 changes: 7 additions & 2 deletions tools/perf/builtin-annotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "util/hist.h"
#include "util/session.h"
#include "util/tool.h"
#include "util/data.h"
#include "arch/common.h"

#include <dlfcn.h>
Expand Down Expand Up @@ -199,9 +200,13 @@ static int __cmd_annotate(struct perf_annotate *ann)
struct perf_session *session;
struct perf_evsel *pos;
u64 total_nr_samples;
struct perf_data_file file = {
.path = input_name,
.mode = PERF_DATA_MODE_READ,
.force = ann->force,
};

session = perf_session__new(input_name, O_RDONLY,
ann->force, false, &ann->tool);
session = perf_session__new(&file, false, &ann->tool);
if (session == NULL)
return -ENOMEM;

Expand Down
8 changes: 6 additions & 2 deletions tools/perf/builtin-buildid-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,12 @@ static bool dso__missing_buildid_cache(struct dso *dso, int parm __maybe_unused)

static int build_id_cache__fprintf_missing(const char *filename, bool force, FILE *fp)
{
struct perf_session *session = perf_session__new(filename, O_RDONLY,
force, false, NULL);
struct perf_data_file file = {
.path = filename,
.mode = PERF_DATA_MODE_READ,
.force = force,
};
struct perf_session *session = perf_session__new(&file, false, NULL);
if (session == NULL)
return -1;

Expand Down
9 changes: 7 additions & 2 deletions tools/perf/builtin-buildid-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "util/parse-options.h"
#include "util/session.h"
#include "util/symbol.h"
#include "util/data.h"

static int sysfs__fprintf_build_id(FILE *fp)
{
Expand Down Expand Up @@ -52,6 +53,11 @@ static bool dso__skip_buildid(struct dso *dso, int with_hits)
static int perf_session__list_build_ids(bool force, bool with_hits)
{
struct perf_session *session;
struct perf_data_file file = {
.path = input_name,
.mode = PERF_DATA_MODE_READ,
.force = force,
};

symbol__elf_init();
/*
Expand All @@ -60,8 +66,7 @@ static int perf_session__list_build_ids(bool force, bool with_hits)
if (filename__fprintf_build_id(input_name, stdout))
goto out;

session = perf_session__new(input_name, O_RDONLY, force, false,
&build_id__mark_dso_hit_ops);
session = perf_session__new(&file, false, &build_id__mark_dso_hit_ops);
if (session == NULL)
return -1;
/*
Expand Down
19 changes: 12 additions & 7 deletions tools/perf/builtin-diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "util/sort.h"
#include "util/symbol.h"
#include "util/util.h"
#include "util/data.h"

#include <stdlib.h>
#include <math.h>
Expand All @@ -42,7 +43,7 @@ struct diff_hpp_fmt {

struct data__file {
struct perf_session *session;
const char *file;
struct perf_data_file file;
int idx;
struct hists *hists;
struct diff_hpp_fmt fmt[PERF_HPP_DIFF__MAX_INDEX];
Expand Down Expand Up @@ -601,7 +602,7 @@ static void data__fprintf(void)

data__for_each_file(i, d)
fprintf(stdout, "# [%d] %s %s\n",
d->idx, d->file,
d->idx, d->file.path,
!d->idx ? "(Baseline)" : "");

fprintf(stdout, "#\n");
Expand Down Expand Up @@ -663,17 +664,16 @@ static int __cmd_diff(void)
int ret = -EINVAL, i;

data__for_each_file(i, d) {
d->session = perf_session__new(d->file, O_RDONLY, force,
false, &tool);
d->session = perf_session__new(&d->file, false, &tool);
if (!d->session) {
pr_err("Failed to open %s\n", d->file);
pr_err("Failed to open %s\n", d->file.path);
ret = -ENOMEM;
goto out_delete;
}

ret = perf_session__process_events(d->session, &tool);
if (ret) {
pr_err("Failed to process %s\n", d->file);
pr_err("Failed to process %s\n", d->file.path);
goto out_delete;
}

Expand Down Expand Up @@ -1016,7 +1016,12 @@ static int data_init(int argc, const char **argv)
return -ENOMEM;

data__for_each_file(i, d) {
d->file = use_default ? defaults[i] : argv[i];
struct perf_data_file *file = &d->file;

file->path = use_default ? defaults[i] : argv[i];
file->mode = PERF_DATA_MODE_READ,
file->force = force,

d->idx = i;
}

Expand Down
7 changes: 6 additions & 1 deletion tools/perf/builtin-evlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@
#include "util/parse-events.h"
#include "util/parse-options.h"
#include "util/session.h"
#include "util/data.h"

static int __cmd_evlist(const char *file_name, struct perf_attr_details *details)
{
struct perf_session *session;
struct perf_evsel *pos;
struct perf_data_file file = {
.path = file_name,
.mode = PERF_DATA_MODE_READ,
};

session = perf_session__new(file_name, O_RDONLY, 0, false, NULL);
session = perf_session__new(&file, 0, NULL);
if (session == NULL)
return -ENOMEM;

Expand Down
7 changes: 6 additions & 1 deletion tools/perf/builtin-inject.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "util/tool.h"
#include "util/debug.h"
#include "util/build-id.h"
#include "util/data.h"

#include "util/parse-options.h"

Expand Down Expand Up @@ -345,6 +346,10 @@ static int __cmd_inject(struct perf_inject *inject)
{
struct perf_session *session;
int ret = -EINVAL;
struct perf_data_file file = {
.path = inject->input_name,
.mode = PERF_DATA_MODE_READ,
};

signal(SIGINT, sig_handler);

Expand All @@ -355,7 +360,7 @@ static int __cmd_inject(struct perf_inject *inject)
inject->tool.tracing_data = perf_event__repipe_tracing_data;
}

session = perf_session__new(inject->input_name, O_RDONLY, false, true, &inject->tool);
session = perf_session__new(&file, true, &inject->tool);
if (session == NULL)
return -ENOMEM;

Expand Down
7 changes: 6 additions & 1 deletion tools/perf/builtin-kmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include "util/parse-options.h"
#include "util/trace-event.h"
#include "util/data.h"

#include "util/debug.h"

Expand Down Expand Up @@ -486,8 +487,12 @@ static int __cmd_kmem(void)
{ "kmem:kfree", perf_evsel__process_free_event, },
{ "kmem:kmem_cache_free", perf_evsel__process_free_event, },
};
struct perf_data_file file = {
.path = input_name,
.mode = PERF_DATA_MODE_READ,
};

session = perf_session__new(input_name, O_RDONLY, 0, false, &perf_kmem);
session = perf_session__new(&file, false, &perf_kmem);
if (session == NULL)
return -ENOMEM;

Expand Down
13 changes: 10 additions & 3 deletions tools/perf/builtin-kvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "util/tool.h"
#include "util/stat.h"
#include "util/top.h"
#include "util/data.h"

#include <sys/prctl.h>
#include <sys/timerfd.h>
Expand Down Expand Up @@ -1215,10 +1216,13 @@ static int read_events(struct perf_kvm_stat *kvm)
.comm = perf_event__process_comm,
.ordered_samples = true,
};
struct perf_data_file file = {
.path = input_name,
.mode = PERF_DATA_MODE_READ,
};

kvm->tool = eops;
kvm->session = perf_session__new(kvm->file_name, O_RDONLY, 0, false,
&kvm->tool);
kvm->session = perf_session__new(&file, false, &kvm->tool);
if (!kvm->session) {
pr_err("Initializing perf session failed\n");
return -EINVAL;
Expand Down Expand Up @@ -1450,6 +1454,9 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
"perf kvm stat live [<options>]",
NULL
};
struct perf_data_file file = {
.mode = PERF_DATA_MODE_WRITE,
};


/* event handling */
Expand Down Expand Up @@ -1514,7 +1521,7 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
/*
* perf session
*/
kvm->session = perf_session__new(NULL, O_WRONLY, false, false, &kvm->tool);
kvm->session = perf_session__new(&file, false, &kvm->tool);
if (kvm->session == NULL) {
err = -ENOMEM;
goto out;
Expand Down
7 changes: 6 additions & 1 deletion tools/perf/builtin-lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "util/debug.h"
#include "util/session.h"
#include "util/tool.h"
#include "util/data.h"

#include <sys/types.h>
#include <sys/prctl.h>
Expand Down Expand Up @@ -853,8 +854,12 @@ static int __cmd_report(bool display_info)
.comm = perf_event__process_comm,
.ordered_samples = true,
};
struct perf_data_file file = {
.path = input_name,
.mode = PERF_DATA_MODE_READ,
};

session = perf_session__new(input_name, O_RDONLY, 0, false, &eops);
session = perf_session__new(&file, false, &eops);
if (!session) {
pr_err("Initializing perf session failed\n");
return -ENOMEM;
Expand Down
9 changes: 7 additions & 2 deletions tools/perf/builtin-mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "util/trace-event.h"
#include "util/tool.h"
#include "util/session.h"
#include "util/data.h"

#define MEM_OPERATION_LOAD "load"
#define MEM_OPERATION_STORE "store"
Expand Down Expand Up @@ -119,10 +120,14 @@ static int process_sample_event(struct perf_tool *tool,

static int report_raw_events(struct perf_mem *mem)
{
struct perf_data_file file = {
.path = input_name,
.mode = PERF_DATA_MODE_READ,
};
int err = -EINVAL;
int ret;
struct perf_session *session = perf_session__new(input_name, O_RDONLY,
0, false, &mem->tool);
struct perf_session *session = perf_session__new(&file, false,
&mem->tool);

if (session == NULL)
return -ENOMEM;
Expand Down
Loading

0 comments on commit f5fc141

Please sign in to comment.