提交 0433ffbe 编写于 作者: A Arnaldo Carvalho de Melo

perf kmem: Don't use globals where not needed to

Some variables were global but used in just one function, so move it to
where it belongs.

Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-wu8lz0g2qg26aqgi51xgzkpp@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
上级 2bae1d1b
...@@ -21,8 +21,6 @@ ...@@ -21,8 +21,6 @@
struct alloc_stat; struct alloc_stat;
typedef int (*sort_fn_t)(struct alloc_stat *, struct alloc_stat *); typedef int (*sort_fn_t)(struct alloc_stat *, struct alloc_stat *);
static const char *input_name;
static int alloc_flag; static int alloc_flag;
static int caller_flag; static int caller_flag;
...@@ -31,8 +29,6 @@ static int caller_lines = -1; ...@@ -31,8 +29,6 @@ static int caller_lines = -1;
static bool raw_ip; static bool raw_ip;
static char default_sort_order[] = "frag,hit,bytes";
static int *cpunode_map; static int *cpunode_map;
static int max_cpu_num; static int max_cpu_num;
...@@ -481,7 +477,7 @@ static void sort_result(void) ...@@ -481,7 +477,7 @@ static void sort_result(void)
__sort_result(&root_caller_stat, &root_caller_sorted, &caller_sort); __sort_result(&root_caller_stat, &root_caller_sorted, &caller_sort);
} }
static int __cmd_kmem(void) static int __cmd_kmem(const char *input_name)
{ {
int err = -EINVAL; int err = -EINVAL;
struct perf_session *session; struct perf_session *session;
...@@ -520,11 +516,6 @@ static int __cmd_kmem(void) ...@@ -520,11 +516,6 @@ static int __cmd_kmem(void)
return err; return err;
} }
static const char * const kmem_usage[] = {
"perf kmem [<options>] {record|stat}",
NULL
};
static int ptr_cmp(struct alloc_stat *l, struct alloc_stat *r) static int ptr_cmp(struct alloc_stat *l, struct alloc_stat *r)
{ {
if (l->ptr < r->ptr) if (l->ptr < r->ptr)
...@@ -720,41 +711,17 @@ static int parse_line_opt(const struct option *opt __maybe_unused, ...@@ -720,41 +711,17 @@ static int parse_line_opt(const struct option *opt __maybe_unused,
return 0; return 0;
} }
static const struct option kmem_options[] = { static int __cmd_record(int argc, const char **argv)
OPT_STRING('i', "input", &input_name, "file", {
"input file name"), const char * const record_args[] = {
OPT_CALLBACK_NOOPT(0, "caller", NULL, NULL, "record", "-a", "-R", "-f", "-c", "1",
"show per-callsite statistics",
parse_caller_opt),
OPT_CALLBACK_NOOPT(0, "alloc", NULL, NULL,
"show per-allocation statistics",
parse_alloc_opt),
OPT_CALLBACK('s', "sort", NULL, "key[,key2...]",
"sort by keys: ptr, call_site, bytes, hit, pingpong, frag",
parse_sort_opt),
OPT_CALLBACK('l', "line", NULL, "num",
"show n lines",
parse_line_opt),
OPT_BOOLEAN(0, "raw-ip", &raw_ip, "show raw ip instead of symbol"),
OPT_END()
};
static const char *record_args[] = {
"record",
"-a",
"-R",
"-f",
"-c", "1",
"-e", "kmem:kmalloc", "-e", "kmem:kmalloc",
"-e", "kmem:kmalloc_node", "-e", "kmem:kmalloc_node",
"-e", "kmem:kfree", "-e", "kmem:kfree",
"-e", "kmem:kmem_cache_alloc", "-e", "kmem:kmem_cache_alloc",
"-e", "kmem:kmem_cache_alloc_node", "-e", "kmem:kmem_cache_alloc_node",
"-e", "kmem:kmem_cache_free", "-e", "kmem:kmem_cache_free",
}; };
static int __cmd_record(int argc, const char **argv)
{
unsigned int rec_argc, i, j; unsigned int rec_argc, i, j;
const char **rec_argv; const char **rec_argv;
...@@ -775,6 +742,25 @@ static int __cmd_record(int argc, const char **argv) ...@@ -775,6 +742,25 @@ static int __cmd_record(int argc, const char **argv)
int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused) 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,
"show per-callsite statistics", parse_caller_opt),
OPT_CALLBACK_NOOPT(0, "alloc", NULL, NULL,
"show per-allocation statistics", parse_alloc_opt),
OPT_CALLBACK('s', "sort", NULL, "key[,key2...]",
"sort by keys: ptr, call_site, bytes, hit, pingpong, frag",
parse_sort_opt),
OPT_CALLBACK('l', "line", NULL, "num", "show n lines", parse_line_opt),
OPT_BOOLEAN(0, "raw-ip", &raw_ip, "show raw ip instead of symbol"),
OPT_END()
};
const char * const kmem_usage[] = {
"perf kmem [<options>] {record|stat}",
NULL
};
argc = parse_options(argc, argv, kmem_options, kmem_usage, 0); argc = parse_options(argc, argv, kmem_options, kmem_usage, 0);
if (!argc) if (!argc)
...@@ -793,7 +779,7 @@ int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused) ...@@ -793,7 +779,7 @@ int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused)
if (list_empty(&alloc_sort)) if (list_empty(&alloc_sort))
setup_sorting(&alloc_sort, default_sort_order); setup_sorting(&alloc_sort, default_sort_order);
return __cmd_kmem(); return __cmd_kmem(input_name);
} else } else
usage_with_options(kmem_usage, kmem_options); usage_with_options(kmem_usage, kmem_options);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册