Skip to content

Commit

Permalink
Merge tag 'perf-core-for-mingo' of git://git.kernel.org/pub/scm/linux…
Browse files Browse the repository at this point in the history
…/kernel/git/acme/linux into perf/core

Pull perf/core improvements, fixes and code move from Arnaldo Carvalho de Melo:

 * Initialize 'page_size' variable in the python binding, this was sent
   for perf/urgent by mistake, then when merging Ingo removed it, fixing
   the problem for perf/urgent, but when perf/urgent was merged with
   perf/core, where that initialization is needed, made the python
   binding mmap call to fail, fix it by initializing page_size again.

 * Add a browser for 'perf script' and make it available from the report
   and annotate browsers. It does filtering to find the scripts that
   handle events found in the perf.data file used. From Feng Tang

 * Move some functions from symbol.c to more appropriate files, creating
   dso.[ch] in the process, no code changes. From Jiri Olsa

 * Fix mmap error output message for when perf_mmap fails and returns
   !-EPERM, where the default for mmap_pages, INT_MAX, was causing a
   !power of 2 error message, fix from Jiri Olsa.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
  • Loading branch information
Ingo Molnar committed Oct 30, 2012
2 parents 9db5506 + 0da2e9c commit 8748dd9
Show file tree
Hide file tree
Showing 34 changed files with 1,196 additions and 829 deletions.
6 changes: 6 additions & 0 deletions tools/perf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ LIB_H += util/svghelper.h
LIB_H += util/tool.h
LIB_H += util/run-command.h
LIB_H += util/sigchain.h
LIB_H += util/dso.h
LIB_H += util/symbol.h
LIB_H += util/color.h
LIB_H += util/values.h
Expand Down Expand Up @@ -385,6 +386,7 @@ LIB_OBJS += $(OUTPUT)util/top.o
LIB_OBJS += $(OUTPUT)util/usage.o
LIB_OBJS += $(OUTPUT)util/wrapper.o
LIB_OBJS += $(OUTPUT)util/sigchain.o
LIB_OBJS += $(OUTPUT)util/dso.o
LIB_OBJS += $(OUTPUT)util/symbol.o
LIB_OBJS += $(OUTPUT)util/symbol-elf.o
LIB_OBJS += $(OUTPUT)util/dso-test-data.o
Expand Down Expand Up @@ -591,6 +593,7 @@ ifndef NO_NEWT
LIB_OBJS += $(OUTPUT)ui/browsers/annotate.o
LIB_OBJS += $(OUTPUT)ui/browsers/hists.o
LIB_OBJS += $(OUTPUT)ui/browsers/map.o
LIB_OBJS += $(OUTPUT)ui/browsers/scripts.o
LIB_OBJS += $(OUTPUT)ui/progress.o
LIB_OBJS += $(OUTPUT)ui/util.o
LIB_OBJS += $(OUTPUT)ui/tui/setup.o
Expand Down Expand Up @@ -907,6 +910,9 @@ $(OUTPUT)ui/browsers/hists.o: ui/browsers/hists.c $(OUTPUT)PERF-CFLAGS
$(OUTPUT)ui/browsers/map.o: ui/browsers/map.c $(OUTPUT)PERF-CFLAGS
$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $<

$(OUTPUT)ui/browsers/scripts.o: ui/browsers/scripts.c $(OUTPUT)PERF-CFLAGS
$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $<

$(OUTPUT)util/rbtree.o: ../../lib/rbtree.c $(OUTPUT)PERF-CFLAGS
$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -Wno-unused-parameter -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<

Expand Down
5 changes: 2 additions & 3 deletions tools/perf/builtin-annotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

struct perf_annotate {
struct perf_tool tool;
char const *input_name;
bool force, use_tui, use_stdio;
bool full_paths;
bool print_line;
Expand Down Expand Up @@ -175,7 +174,7 @@ static int __cmd_annotate(struct perf_annotate *ann)
struct perf_evsel *pos;
u64 total_nr_samples;

session = perf_session__new(ann->input_name, O_RDONLY,
session = perf_session__new(input_name, O_RDONLY,
ann->force, false, &ann->tool);
if (session == NULL)
return -ENOMEM;
Expand Down Expand Up @@ -260,7 +259,7 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused)
},
};
const struct option options[] = {
OPT_STRING('i', "input", &annotate.input_name, "file",
OPT_STRING('i', "input", &input_name, "file",
"input file name"),
OPT_STRING('d', "dsos", &symbol_conf.dso_list_str, "dso[,dso...]",
"only consider symbols in these dsos"),
Expand Down
1 change: 1 addition & 0 deletions tools/perf/builtin-buildid-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "util/header.h"
#include "util/parse-options.h"
#include "util/strlist.h"
#include "util/build-id.h"
#include "util/symbol.h"

static int build_id_cache__add_file(const char *filename, const char *debugdir)
Expand Down
6 changes: 2 additions & 4 deletions tools/perf/builtin-buildid-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ static int filename__fprintf_build_id(const char *name, FILE *fp)
return fprintf(fp, "%s\n", sbuild_id);
}

static int perf_session__list_build_ids(const char *input_name,
bool force, bool with_hits)
static int perf_session__list_build_ids(bool force, bool with_hits)
{
struct perf_session *session;

Expand Down Expand Up @@ -81,7 +80,6 @@ int cmd_buildid_list(int argc, const char **argv,
bool show_kernel = false;
bool with_hits = false;
bool force = false;
const char *input_name = NULL;
const struct option options[] = {
OPT_BOOLEAN('H', "with-hits", &with_hits, "Show only DSOs with hits"),
OPT_STRING('i', "input", &input_name, "file", "input file name"),
Expand All @@ -101,5 +99,5 @@ int cmd_buildid_list(int argc, const char **argv,
if (show_kernel)
return sysfs__fprintf_build_id(stdout);

return perf_session__list_build_ids(input_name, force, with_hits);
return perf_session__list_build_ids(force, with_hits);
}
5 changes: 2 additions & 3 deletions tools/perf/builtin-evlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ static int __if_print(bool *first, const char *field, u64 value)

#define if_print(field) __if_print(&first, #field, pos->attr.field)

static int __cmd_evlist(const char *input_name, struct perf_attr_details *details)
static int __cmd_evlist(const char *file_name, struct perf_attr_details *details)
{
struct perf_session *session;
struct perf_evsel *pos;

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

Expand Down Expand Up @@ -111,7 +111,6 @@ static int __cmd_evlist(const char *input_name, struct perf_attr_details *detail
int cmd_evlist(int argc, const char **argv, const char *prefix __maybe_unused)
{
struct perf_attr_details details = { .verbose = false, };
const char *input_name = NULL;
const struct option options[] = {
OPT_STRING('i', "input", &input_name, "file", "Input file name"),
OPT_BOOLEAN('F', "freq", &details.freq, "Show the sample frequency"),
Expand Down
5 changes: 2 additions & 3 deletions tools/perf/builtin-kmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ static void sort_result(void)
__sort_result(&root_caller_stat, &root_caller_sorted, &caller_sort);
}

static int __cmd_kmem(const char *input_name)
static int __cmd_kmem(void)
{
int err = -EINVAL;
struct perf_session *session;
Expand Down Expand Up @@ -743,7 +743,6 @@ static int __cmd_record(int argc, const char **argv)
int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused)
{
const char * const default_sort_order = "frag,hit,bytes";
const char *input_name = NULL;
const struct option kmem_options[] = {
OPT_STRING('i', "input", &input_name, "file", "input file name"),
OPT_CALLBACK_NOOPT(0, "caller", NULL, NULL,
Expand Down Expand Up @@ -779,7 +778,7 @@ int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused)
if (list_empty(&alloc_sort))
setup_sorting(&alloc_sort, default_sort_order);

return __cmd_kmem(input_name);
return __cmd_kmem();
} else
usage_with_options(kmem_usage, kmem_options);

Expand Down
2 changes: 0 additions & 2 deletions tools/perf/builtin-lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,6 @@ static struct lock_stat *lock_stat_findnew(void *addr, const char *name)
return NULL;
}

static const char *input_name;

struct trace_lock_handler {
int (*acquire_event)(struct perf_evsel *evsel,
struct perf_sample *sample);
Expand Down
3 changes: 2 additions & 1 deletion tools/perf/builtin-record.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,8 @@ static int perf_record__open(struct perf_record *rec)
"or try again with a smaller value of -m/--mmap_pages.\n"
"(current value: %d)\n", opts->mmap_pages);
rc = -errno;
} else if (!is_power_of_2(opts->mmap_pages)) {
} else if (!is_power_of_2(opts->mmap_pages) &&
(opts->mmap_pages != UINT_MAX)) {
pr_err("--mmap_pages/-m value must be a power of two.");
rc = -EINVAL;
} else {
Expand Down
13 changes: 6 additions & 7 deletions tools/perf/builtin-report.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
struct perf_report {
struct perf_tool tool;
struct perf_session *session;
char const *input_name;
bool force, use_tui, use_gtk, use_stdio;
bool hide_unresolved;
bool dont_use_callchains;
Expand Down Expand Up @@ -571,7 +570,7 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
.pretty_printing_style = "normal",
};
const struct option options[] = {
OPT_STRING('i', "input", &report.input_name, "file",
OPT_STRING('i', "input", &input_name, "file",
"input file name"),
OPT_INCR('v', "verbose", &verbose,
"be more verbose (show symbol address, etc)"),
Expand Down Expand Up @@ -657,13 +656,13 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
if (report.inverted_callchain)
callchain_param.order = ORDER_CALLER;

if (!report.input_name || !strlen(report.input_name)) {
if (!input_name || !strlen(input_name)) {
if (!fstat(STDIN_FILENO, &st) && S_ISFIFO(st.st_mode))
report.input_name = "-";
input_name = "-";
else
report.input_name = "perf.data";
input_name = "perf.data";
}
session = perf_session__new(report.input_name, O_RDONLY,
session = perf_session__new(input_name, O_RDONLY,
report.force, false, &report.tool);
if (session == NULL)
return -ENOMEM;
Expand Down Expand Up @@ -694,7 +693,7 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)

}

if (strcmp(report.input_name, "-") != 0)
if (strcmp(input_name, "-") != 0)
setup_browser(true);
else {
use_browser = 0;
Expand Down
5 changes: 2 additions & 3 deletions tools/perf/builtin-sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ struct trace_sched_handler {

struct perf_sched {
struct perf_tool tool;
const char *input_name;
const char *sort_order;
unsigned long nr_tasks;
struct task_desc *pid_to_task[MAX_PID];
Expand Down Expand Up @@ -1460,7 +1459,7 @@ static int perf_sched__read_events(struct perf_sched *sched, bool destroy,
};
struct perf_session *session;

session = perf_session__new(sched->input_name, O_RDONLY, 0, false, &sched->tool);
session = perf_session__new(input_name, O_RDONLY, 0, false, &sched->tool);
if (session == NULL) {
pr_debug("No Memory for session\n");
return -1;
Expand Down Expand Up @@ -1708,7 +1707,7 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)
OPT_END()
};
const struct option sched_options[] = {
OPT_STRING('i', "input", &sched.input_name, "file",
OPT_STRING('i', "input", &input_name, "file",
"input file name"),
OPT_INCR('v', "verbose", &verbose,
"be more verbose (show symbol address, etc)"),
Expand Down
83 changes: 79 additions & 4 deletions tools/perf/builtin-script.c
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,68 @@ static int list_available_scripts(const struct option *opt __maybe_unused,
exit(0);
}

/*
* Some scripts specify the required events in their "xxx-record" file,
* this function will check if the events in perf.data match those
* mentioned in the "xxx-record".
*
* Fixme: All existing "xxx-record" are all in good formats "-e event ",
* which is covered well now. And new parsing code should be added to
* cover the future complexing formats like event groups etc.
*/
static int check_ev_match(char *dir_name, char *scriptname,
struct perf_session *session)
{
char filename[MAXPATHLEN], evname[128];
char line[BUFSIZ], *p;
struct perf_evsel *pos;
int match, len;
FILE *fp;

sprintf(filename, "%s/bin/%s-record", dir_name, scriptname);

fp = fopen(filename, "r");
if (!fp)
return -1;

while (fgets(line, sizeof(line), fp)) {
p = ltrim(line);
if (*p == '#')
continue;

while (strlen(p)) {
p = strstr(p, "-e");
if (!p)
break;

p += 2;
p = ltrim(p);
len = strcspn(p, " \t");
if (!len)
break;

snprintf(evname, len + 1, "%s", p);

match = 0;
list_for_each_entry(pos,
&session->evlist->entries, node) {
if (!strcmp(perf_evsel__name(pos), evname)) {
match = 1;
break;
}
}

if (!match) {
fclose(fp);
return -1;
}
}
}

fclose(fp);
return 0;
}

/*
* Return -1 if none is found, otherwise the actual scripts number.
*
Expand All @@ -1039,17 +1101,23 @@ static int list_available_scripts(const struct option *opt __maybe_unused,
int find_scripts(char **scripts_array, char **scripts_path_array)
{
struct dirent *script_next, *lang_next, script_dirent, lang_dirent;
char scripts_path[MAXPATHLEN];
char scripts_path[MAXPATHLEN], lang_path[MAXPATHLEN];
DIR *scripts_dir, *lang_dir;
char lang_path[MAXPATHLEN];
struct perf_session *session;
char *temp;
int i = 0;

session = perf_session__new(input_name, O_RDONLY, 0, false, NULL);
if (!session)
return -1;

snprintf(scripts_path, MAXPATHLEN, "%s/scripts", perf_exec_path());

scripts_dir = opendir(scripts_path);
if (!scripts_dir)
if (!scripts_dir) {
perf_session__delete(session);
return -1;
}

for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next) {
snprintf(lang_path, MAXPATHLEN, "%s/%s", scripts_path,
Expand Down Expand Up @@ -1077,10 +1145,18 @@ int find_scripts(char **scripts_array, char **scripts_path_array)
snprintf(scripts_array[i],
(temp - script_dirent.d_name) + 1,
"%s", script_dirent.d_name);

if (check_ev_match(lang_path,
scripts_array[i], session))
continue;

i++;
}
closedir(lang_dir);
}

closedir(scripts_dir);
perf_session__delete(session);
return i;
}

Expand Down Expand Up @@ -1175,7 +1251,6 @@ static int have_cmd(int argc, const char **argv)
int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
{
bool show_full_info = false;
const char *input_name = NULL;
char *rec_script_path = NULL;
char *rep_script_path = NULL;
struct perf_session *session;
Expand Down
5 changes: 2 additions & 3 deletions tools/perf/builtin-timechart.c
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ static void write_svg_file(const char *filename)
svg_close();
}

static int __cmd_timechart(const char *input_name, const char *output_name)
static int __cmd_timechart(const char *output_name)
{
struct perf_tool perf_timechart = {
.comm = process_comm_event,
Expand Down Expand Up @@ -1061,7 +1061,6 @@ parse_process(const struct option *opt __maybe_unused, const char *arg,
int cmd_timechart(int argc, const char **argv,
const char *prefix __maybe_unused)
{
const char *input_name;
const char *output_name = "output.svg";
const struct option options[] = {
OPT_STRING('i', "input", &input_name, "file", "input file name"),
Expand Down Expand Up @@ -1092,5 +1091,5 @@ int cmd_timechart(int argc, const char **argv,

setup_pager();

return __cmd_timechart(input_name, output_name);
return __cmd_timechart(output_name);
}
1 change: 1 addition & 0 deletions tools/perf/perf.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const char perf_more_info_string[] =

int use_browser = -1;
static int use_pager = -1;
const char *input_name;

struct cmd_struct {
const char *cmd;
Expand Down
1 change: 1 addition & 0 deletions tools/perf/perf.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ struct branch_stack {
struct branch_entry entries[0];
};

extern const char *input_name;
extern bool perf_host, perf_guest;
extern const char perf_version_string[];

Expand Down
Loading

0 comments on commit 8748dd9

Please sign in to comment.