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 and fixes:

User visible changes:

  - Change default selection TUI background color to yellow (Ingo Molnar)

Infrastructure changes:

  - Start paving the way to reuse some cmdline functions with other tools/
    living utilities (Josh Poimboeuf)

  - Reference count fixes using the refcount debugger, unleaking some objects
    (Masami Hiramatsu)

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
  • Loading branch information
Ingo Molnar committed Dec 10, 2015
2 parents a30c99a + 0a4bb5d commit d18929e
Show file tree
Hide file tree
Showing 20 changed files with 88 additions and 69 deletions.
1 change: 1 addition & 0 deletions tools/perf/Build
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ perf-y += builtin-kvm.o
perf-y += builtin-inject.o
perf-y += builtin-mem.o
perf-y += builtin-data.o
perf-y += builtin-version.o

perf-$(CONFIG_AUDIT) += builtin-trace.o
perf-$(CONFIG_LIBELF) += builtin-probe.o
Expand Down
9 changes: 9 additions & 0 deletions tools/perf/builtin-stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,14 @@ static int perf_stat_init_aggr_mode(void)
return cpus_aggr_map ? 0 : -ENOMEM;
}

static void perf_stat__exit_aggr_mode(void)
{
cpu_map__put(aggr_map);
cpu_map__put(cpus_aggr_map);
aggr_map = NULL;
cpus_aggr_map = NULL;
}

/*
* Add default attributes, if there were no attributes specified or
* if -d/--detailed, -d -d or -d -d -d is used:
Expand Down Expand Up @@ -1442,6 +1450,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
if (!forever && status != -1 && !interval)
print_counters(NULL, argc, argv);

perf_stat__exit_aggr_mode();
perf_evlist__free_stats(evsel_list);
out:
perf_evlist__delete(evsel_list);
Expand Down
10 changes: 10 additions & 0 deletions tools/perf/builtin-version.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "util/util.h"
#include "builtin.h"
#include "perf.h"

int cmd_version(int argc __maybe_unused, const char **argv __maybe_unused,
const char *prefix __maybe_unused)
{
printf("perf version %s\n", perf_version_string);
return 0;
}
1 change: 1 addition & 0 deletions tools/perf/perf.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
use_pager = 1;
commit_pager_choice();

perf_env__set_cmdline(&perf_env, argc, argv);
status = p->fn(argc, argv, prefix);
exit_browser(status);
perf_env__exit(&perf_env);
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/ui/browser.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ static struct ui_browser_colorset {
.colorset = HE_COLORSET_SELECTED,
.name = "selected",
.fg = "black",
.bg = "lightgray",
.bg = "yellow",
},
{
.colorset = HE_COLORSET_CODE,
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/util/Build
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ libperf-y += config.o
libperf-y += ctype.o
libperf-y += db-export.o
libperf-y += env.o
libperf-y += environment.o
libperf-y += event.o
libperf-y += evlist.o
libperf-y += evsel.o
Expand Down Expand Up @@ -87,6 +86,7 @@ libperf-$(CONFIG_AUXTRACE) += intel-pt.o
libperf-$(CONFIG_AUXTRACE) += intel-bts.o
libperf-y += parse-branch-options.o
libperf-y += parse-regs-options.o
libperf-y += term.o

libperf-$(CONFIG_LIBBPF) += bpf-loader.o
libperf-$(CONFIG_BPF_PROLOGUE) += bpf-prologue.o
Expand Down
1 change: 0 additions & 1 deletion tools/perf/util/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ extern const char *perf_config_dirname(const char *, const char *);
/* pager.c */
extern void setup_pager(void);
extern int pager_in_use(void);
extern int pager_use_color;

char *alias_lookup(const char *alias);
int split_cmdline(char *cmdline, const char ***argv);
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/util/color.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ int perf_config_colorbool(const char *var, const char *value, int stdout_is_tty)
auto_color:
if (stdout_is_tty < 0)
stdout_is_tty = isatty(1);
if (stdout_is_tty || (pager_in_use() && pager_use_color)) {
if (stdout_is_tty || pager_in_use()) {
char *term = getenv("TERM");
if (term && strcmp(term, "dumb"))
return 1;
Expand Down
9 changes: 0 additions & 9 deletions tools/perf/util/env.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@ int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[])
{
int i;

/*
* If env->cmdline_argv has already been set, do not override it. This allows
* a command to set the cmdline, parse args and then call another
* builtin function that implements a command -- e.g, cmd_kvm calling
* cmd_record.
*/
if (env->cmdline_argv != NULL)
return 0;

/* do not include NULL termination */
env->cmdline_argv = calloc(argc, sizeof(char *));
if (env->cmdline_argv == NULL)
Expand Down
8 changes: 0 additions & 8 deletions tools/perf/util/environment.c

This file was deleted.

2 changes: 1 addition & 1 deletion tools/perf/util/header.c
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ static int write_numa_topology(int fd, struct perf_header *h __maybe_unused,
done:
free(buf);
fclose(fp);
free(node_map);
cpu_map__put(node_map);
return ret;
}

Expand Down
7 changes: 0 additions & 7 deletions tools/perf/util/help.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,3 @@ const char *help_unknown_cmd(const char *cmd)

exit(1);
}

int cmd_version(int argc __maybe_unused, const char **argv __maybe_unused,
const char *prefix __maybe_unused)
{
printf("perf version %s\n", perf_version_string);
return 0;
}
10 changes: 9 additions & 1 deletion tools/perf/util/hist.c
Original file line number Diff line number Diff line change
Expand Up @@ -1567,6 +1567,13 @@ static int hists_evsel__init(struct perf_evsel *evsel)
return 0;
}

static void hists_evsel__exit(struct perf_evsel *evsel)
{
struct hists *hists = evsel__hists(evsel);

hists__delete_entries(hists);
}

/*
* XXX We probably need a hists_evsel__exit() to free the hist_entries
* stored in the rbtree...
Expand All @@ -1575,7 +1582,8 @@ static int hists_evsel__init(struct perf_evsel *evsel)
int hists__init(void)
{
int err = perf_evsel__object_config(sizeof(struct hists_evsel),
hists_evsel__init, NULL);
hists_evsel__init,
hists_evsel__exit);
if (err)
fputs("FATAL ERROR: Couldn't setup hists class\n", stderr);

Expand Down
5 changes: 5 additions & 0 deletions tools/perf/util/machine.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ int machine__init(struct machine *machine, const char *root_dir, pid_t pid)
machine->comm_exec = false;
machine->kernel_start = 0;

memset(machine->vmlinux_maps, 0, sizeof(machine->vmlinux_maps));

machine->root_dir = strdup(root_dir);
if (machine->root_dir == NULL)
return -ENOMEM;
Expand Down Expand Up @@ -770,6 +772,9 @@ int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel)
enum map_type type;
u64 start = machine__get_running_kernel_start(machine, NULL);

/* In case of renewal the kernel map, destroy previous one */
machine__destroy_kernel_maps(machine);

for (type = 0; type < MAP__NR_TYPES; ++type) {
struct kmap *kmap;
struct map *map;
Expand Down
3 changes: 3 additions & 0 deletions tools/perf/util/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,7 @@ static int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp
__map_groups__insert(pos->groups, before);
if (verbose >= 2)
map__fprintf(before, fp);
map__put(before);
}

if (map->end < pos->end) {
Expand All @@ -705,6 +706,7 @@ static int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp
__map_groups__insert(pos->groups, after);
if (verbose >= 2)
map__fprintf(after, fp);
map__put(after);
}
put_map:
map__put(pos);
Expand Down Expand Up @@ -742,6 +744,7 @@ int map_groups__clone(struct map_groups *mg,
if (new == NULL)
goto out_unlock;
map_groups__insert(mg, new);
map__put(new);
}

err = 0;
Expand Down
2 changes: 0 additions & 2 deletions tools/perf/util/parse-options.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,6 @@ int parse_options_subcommand(int argc, const char **argv, const struct option *o
{
struct parse_opt_ctx_t ctx;

perf_env__set_cmdline(&perf_env, argc, argv);

/* build usage string if it's not provided */
if (subcommands && !usagestr[0]) {
struct strbuf buf = STRBUF_INIT;
Expand Down
35 changes: 35 additions & 0 deletions tools/perf/util/term.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "util.h"

void get_term_dimensions(struct winsize *ws)
{
char *s = getenv("LINES");

if (s != NULL) {
ws->ws_row = atoi(s);
s = getenv("COLUMNS");
if (s != NULL) {
ws->ws_col = atoi(s);
if (ws->ws_row && ws->ws_col)
return;
}
}
#ifdef TIOCGWINSZ
if (ioctl(1, TIOCGWINSZ, ws) == 0 &&
ws->ws_row && ws->ws_col)
return;
#endif
ws->ws_row = 25;
ws->ws_col = 80;
}

void set_term_quiet_input(struct termios *old)
{
struct termios tc;

tcgetattr(0, old);
tc = *old;
tc.c_lflag &= ~(ICANON | ECHO);
tc.c_cc[VMIN] = 0;
tc.c_cc[VTIME] = 0;
tcsetattr(0, TCSANOW, &tc);
}
10 changes: 10 additions & 0 deletions tools/perf/util/term.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef __PERF_TERM_H
#define __PERF_TERM_H

struct termios;
struct winsize;

void get_term_dimensions(struct winsize *ws);
void set_term_quiet_input(struct termios *old);

#endif /* __PERF_TERM_H */
34 changes: 0 additions & 34 deletions tools/perf/util/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,40 +355,6 @@ void sighandler_dump_stack(int sig)
exit(sig);
}

void get_term_dimensions(struct winsize *ws)
{
char *s = getenv("LINES");

if (s != NULL) {
ws->ws_row = atoi(s);
s = getenv("COLUMNS");
if (s != NULL) {
ws->ws_col = atoi(s);
if (ws->ws_row && ws->ws_col)
return;
}
}
#ifdef TIOCGWINSZ
if (ioctl(1, TIOCGWINSZ, ws) == 0 &&
ws->ws_row && ws->ws_col)
return;
#endif
ws->ws_row = 25;
ws->ws_col = 80;
}

void set_term_quiet_input(struct termios *old)
{
struct termios tc;

tcgetattr(0, old);
tc = *old;
tc.c_lflag &= ~(ICANON | ECHO);
tc.c_cc[VMIN] = 0;
tc.c_cc[VTIME] = 0;
tcsetattr(0, TCSANOW, &tc);
}

int parse_nsec_time(const char *str, u64 *ptime)
{
u64 time_sec, time_nsec;
Expand Down
4 changes: 1 addition & 3 deletions tools/perf/util/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <term.h>
#include <errno.h>
#include <limits.h>
#include <sys/param.h>
Expand Down Expand Up @@ -282,9 +283,6 @@ void sighandler_dump_stack(int sig);
extern unsigned int page_size;
extern int cacheline_size;

void get_term_dimensions(struct winsize *ws);
void set_term_quiet_input(struct termios *old);

struct parse_tag {
char tag;
int mult;
Expand Down

0 comments on commit d18929e

Please sign in to comment.