Skip to content

Commit 09b0fd4

Browse files
Jiri Olsaacmel
authored andcommitted
perf record: Split -g and --call-graph
Splitting -g and --call-graph for record command, so we could use '-g' with no option. The '-g' option now takes NO argument and enables the configured unwind method, which is currently the frame pointers method. It will be possible to configure unwind method via config file in upcoming patches. All current '-g' arguments is overtaken by --call-graph option. Signed-off-by: Jiri Olsa <jolsa@redhat.com> Tested-by: David Ahern <dsahern@gmail.com> Tested-by: Ingo Molnar <mingo@kernel.org> Reviewed-by: David Ahern <dsahern@gmail.com> Acked-by: Ingo Molnar <mingo@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: 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/1382797536-32303-2-git-send-email-jolsa@redhat.com [ reordered -g/--call-graph on --help and expanded the man page according to comments by David Ahern and Namhyung Kim ] Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 9754c4f commit 09b0fd4

File tree

3 files changed

+67
-23
lines changed

3 files changed

+67
-23
lines changed

tools/perf/Documentation/perf-record.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,20 @@ OPTIONS
9090
Number of mmap data pages. Must be a power of two.
9191

9292
-g::
93+
Enables call-graph (stack chain/backtrace) recording.
94+
9395
--call-graph::
94-
Do call-graph (stack chain/backtrace) recording.
96+
Setup and enable call-graph (stack chain/backtrace) recording,
97+
implies -g.
98+
99+
Allows specifying "fp" (frame pointer) or "dwarf"
100+
(DWARF's CFI - Call Frame Information) as the method to collect
101+
the information used to show the call graphs.
102+
103+
In some systems, where binaries are build with gcc
104+
--fomit-frame-pointer, using the "fp" method will produce bogus
105+
call graphs, using "dwarf", if available (perf tools linked to
106+
the libunwind library) should be used instead.
95107

96108
-q::
97109
--quiet::

tools/perf/builtin-record.c

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -712,21 +712,12 @@ static int get_stack_size(char *str, unsigned long *_size)
712712
}
713713
#endif /* LIBUNWIND_SUPPORT */
714714

715-
int record_parse_callchain_opt(const struct option *opt,
716-
const char *arg, int unset)
715+
int record_parse_callchain(const char *arg, struct perf_record_opts *opts)
717716
{
718-
struct perf_record_opts *opts = opt->value;
719717
char *tok, *name, *saveptr = NULL;
720718
char *buf;
721719
int ret = -1;
722720

723-
/* --no-call-graph */
724-
if (unset)
725-
return 0;
726-
727-
/* We specified default option if none is provided. */
728-
BUG_ON(!arg);
729-
730721
/* We need buffer that we know we can write to. */
731722
buf = malloc(strlen(arg) + 1);
732723
if (!buf)
@@ -764,27 +755,62 @@ int record_parse_callchain_opt(const struct option *opt,
764755
ret = get_stack_size(tok, &size);
765756
opts->stack_dump_size = size;
766757
}
767-
768-
if (!ret)
769-
pr_debug("callchain: stack dump size %d\n",
770-
opts->stack_dump_size);
771758
#endif /* LIBUNWIND_SUPPORT */
772759
} else {
773-
pr_err("callchain: Unknown -g option "
760+
pr_err("callchain: Unknown --call-graph option "
774761
"value: %s\n", arg);
775762
break;
776763
}
777764

778765
} while (0);
779766

780767
free(buf);
768+
return ret;
769+
}
770+
771+
static void callchain_debug(struct perf_record_opts *opts)
772+
{
773+
pr_debug("callchain: type %d\n", opts->call_graph);
781774

775+
if (opts->call_graph == CALLCHAIN_DWARF)
776+
pr_debug("callchain: stack dump size %d\n",
777+
opts->stack_dump_size);
778+
}
779+
780+
int record_parse_callchain_opt(const struct option *opt,
781+
const char *arg,
782+
int unset)
783+
{
784+
struct perf_record_opts *opts = opt->value;
785+
int ret;
786+
787+
/* --no-call-graph */
788+
if (unset) {
789+
opts->call_graph = CALLCHAIN_NONE;
790+
pr_debug("callchain: disabled\n");
791+
return 0;
792+
}
793+
794+
ret = record_parse_callchain(arg, opts);
782795
if (!ret)
783-
pr_debug("callchain: type %d\n", opts->call_graph);
796+
callchain_debug(opts);
784797

785798
return ret;
786799
}
787800

801+
int record_callchain_opt(const struct option *opt,
802+
const char *arg __maybe_unused,
803+
int unset __maybe_unused)
804+
{
805+
struct perf_record_opts *opts = opt->value;
806+
807+
if (opts->call_graph == CALLCHAIN_NONE)
808+
opts->call_graph = CALLCHAIN_FP;
809+
810+
callchain_debug(opts);
811+
return 0;
812+
}
813+
788814
static const char * const record_usage[] = {
789815
"perf record [<options>] [<command>]",
790816
"perf record [<options>] -- <command> [<options>]",
@@ -813,12 +839,12 @@ static struct perf_record record = {
813839
},
814840
};
815841

816-
#define CALLCHAIN_HELP "do call-graph (stack chain/backtrace) recording: "
842+
#define CALLCHAIN_HELP "setup and enables call-graph (stack chain/backtrace) recording: "
817843

818844
#ifdef LIBUNWIND_SUPPORT
819-
const char record_callchain_help[] = CALLCHAIN_HELP "[fp] dwarf";
845+
const char record_callchain_help[] = CALLCHAIN_HELP "fp dwarf";
820846
#else
821-
const char record_callchain_help[] = CALLCHAIN_HELP "[fp]";
847+
const char record_callchain_help[] = CALLCHAIN_HELP "fp";
822848
#endif
823849

824850
/*
@@ -858,9 +884,12 @@ const struct option record_options[] = {
858884
"number of mmap data pages"),
859885
OPT_BOOLEAN(0, "group", &record.opts.group,
860886
"put the counters into a counter group"),
861-
OPT_CALLBACK_DEFAULT('g', "call-graph", &record.opts,
862-
"mode[,dump_size]", record_callchain_help,
863-
&record_parse_callchain_opt, "fp"),
887+
OPT_CALLBACK_NOOPT('g', NULL, &record.opts,
888+
NULL, "enables call-graph recording" ,
889+
&record_callchain_opt),
890+
OPT_CALLBACK(0, "call-graph", &record.opts,
891+
"mode[,dump_size]", record_callchain_help,
892+
&record_parse_callchain_opt),
864893
OPT_INCR('v', "verbose", &verbose,
865894
"be more verbose (show counter open errors, etc)"),
866895
OPT_BOOLEAN('q', "quiet", &quiet, "don't print any message"),

tools/perf/util/callchain.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ static inline void callchain_cursor_advance(struct callchain_cursor *cursor)
147147

148148
struct option;
149149

150+
int record_parse_callchain(const char *arg, struct perf_record_opts *opts);
150151
int record_parse_callchain_opt(const struct option *opt, const char *arg, int unset);
152+
int record_callchain_opt(const struct option *opt, const char *arg, int unset);
153+
151154
extern const char record_callchain_help[];
152155
#endif /* __PERF_CALLCHAIN_H */

0 commit comments

Comments
 (0)