2009-09-12 11:05:17

by Arjan van de Ven

[permalink] [raw]
Subject: [PATCH 7/8] perf: Add a perf record --timechart option

>From 2f2ee48c6cbf556724929c55b6c0842f737e9658 Mon Sep 17 00:00:00 2001
From: Arjan van de Ven <[email protected]>
Date: Sat, 12 Sep 2009 12:52:13 +0200
Subject: [PATCH] perf: Add a perf record --timechart option

This patch adds a "perf record --timechart" option, to make it easy
to capture traces for use by the timechart tool.

Signed-off-by: Arjan van de Ven <[email protected]>
---
tools/perf/builtin-record.c | 28 ++++++++++++++++++++++++++++
1 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 99a12fe..f06a447 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -47,6 +47,7 @@ static int append_file = 0;
static int call_graph = 0;
static int inherit_stat = 0;
static int no_samples = 0;
+static int timechart = 0;
static int sample_address = 0;

static long samples;
@@ -385,6 +386,12 @@ static void create_counter(int counter, int cpu, pid_t pid)

attr->sample_type |= PERF_SAMPLE_IP | PERF_SAMPLE_TID;

+ if (timechart) {
+ attr->sample_type |= PERF_SAMPLE_CPU;
+ attr->sample_type |= PERF_SAMPLE_TIME;
+ attr->sample_type |= PERF_SAMPLE_RAW;
+ }
+
if (freq) {
attr->sample_type |= PERF_SAMPLE_PERIOD;
attr->freq = 1;
@@ -637,6 +644,24 @@ static int __cmd_record(int argc, const char **argv)
return 0;
}

+static int do_timechart(const struct option *opt __used, const char *str __used, int unset __used)
+{
+ parse_events(NULL, "power:power_start", 0);
+ parse_events(NULL, "power:power_end", 0);
+ parse_events(NULL, "power:power_frequency", 0);
+ parse_events(NULL, "sched:sched_wakeup", 0);
+ parse_events(NULL, "sched:sched_switch", 0);
+ default_interval = 1;
+ system_wide = 1;
+ timechart = 1;
+ if (!nr_counters) {
+ printf("No counters found.. is debugfs mounted?\n");
+ exit(0);
+ }
+ return 0;
+}
+
+
static const char * const record_usage[] = {
"perf record [<options>] [<command>]",
"perf record [<options>] -- <command> [<options>]",
@@ -681,6 +706,9 @@ static const struct option options[] = {
"Sample addresses"),
OPT_BOOLEAN('n', "no-samples", &no_samples,
"don't sample"),
+ OPT_CALLBACK_NOOPT('t', "timechart", NULL, NULL,
+ "create a timechart recording",
+ do_timechart),
OPT_END()
};

--
1.6.0.6




--
Arjan van de Ven Intel Open Source Technology Centre
For development, discussion and tips for power savings,
visit http://www.lesswatts.org


2009-09-14 08:06:01

by Peter Zijlstra

[permalink] [raw]
Subject: Re: [PATCH 7/8] perf: Add a perf record --timechart option

On Sat, 2009-09-12 at 13:06 +0200, Arjan van de Ven wrote:
> This patch adds a "perf record --timechart" option, to make it easy
> to capture traces for use by the timechart tool.

Would it perhaps make sense to make that:

perf timechart record

?

2009-09-14 20:29:27

by Arjan van de Ven

[permalink] [raw]
Subject: Re: [PATCH 7/8] perf: Add a perf record --timechart option

On Mon, 14 Sep 2009 10:06:00 +0200
Peter Zijlstra <[email protected]> wrote:

> On Sat, 2009-09-12 at 13:06 +0200, Arjan van de Ven wrote:
> > This patch adds a "perf record --timechart" option, to make it easy
> > to capture traces for use by the timechart tool.
>
> Would it perhaps make sense to make that:
>
> perf timechart record

well yes, but it would just be an alias for the former, since it's the
record code that has to do the recording... and that's a rather obscene
layering violation in how perf is set up I think.


--
Arjan van de Ven Intel Open Source Technology Centre
For development, discussion and tips for power savings,
visit http://www.lesswatts.org

2009-09-19 09:44:59

by Ingo Molnar

[permalink] [raw]
Subject: Re: [PATCH 7/8] perf: Add a perf record --timechart option


* Arjan van de Ven <[email protected]> wrote:

> On Mon, 14 Sep 2009 10:06:00 +0200
> Peter Zijlstra <[email protected]> wrote:
>
> > On Sat, 2009-09-12 at 13:06 +0200, Arjan van de Ven wrote:
> > > This patch adds a "perf record --timechart" option, to make it easy
> > > to capture traces for use by the timechart tool.
> >
> > Would it perhaps make sense to make that:
> >
> > perf timechart record
>
> well yes, but it would just be an alias for the former, since it's the
> record code that has to do the recording... and that's a rather
> obscene layering violation in how perf is set up I think.

No, please do it like 'perf sched record' does - it constructs an
argument list of pre-cooked options. See builtin-sched.c's record_args[]
array.

Ingo

2009-09-19 11:03:54

by Arjan van de Ven

[permalink] [raw]
Subject: [PATCH] perf: Add "perf timechart record"

>From f11a27881ef0fcdf459e6f52dd57885c7af93426 Mon Sep 17 00:00:00 2001
From: Arjan van de Ven <[email protected]>
Date: Sat, 19 Sep 2009 12:59:47 +0200
Subject: [PATCH] perf: Add "perf timechart record"

Add a command line option to record a trace, similar to "perf sched record".

Signed-off-by: Arjan van de Ven <[email protected]>
---
tools/perf/builtin-timechart.c | 47 +++++++++++++++++++++++++++++++++------
1 files changed, 39 insertions(+), 8 deletions(-)

diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
index 00fac1b..58d737e 100644
--- a/tools/perf/builtin-timechart.c
+++ b/tools/perf/builtin-timechart.c
@@ -1086,11 +1086,42 @@ done:
return rc;
}

-static const char * const report_usage[] = {
- "perf report [<options>] <command>",
+static const char * const timechart_usage[] = {
+ "perf timechart [<options>] {record}",
NULL
};

+static const char *record_args[] = {
+ "record",
+ "-a",
+ "-R",
+ "-M",
+ "-f",
+ "-c", "1",
+ "-e", "power:power_start",
+ "-e", "power:power_end",
+ "-e", "power:power_frequency",
+ "-e", "sched:sched_wakeup",
+ "-e", "sched:sched_switch",
+};
+
+static int __cmd_record(int argc, const char **argv)
+{
+ unsigned int rec_argc, i, j;
+ const char **rec_argv;
+
+ rec_argc = ARRAY_SIZE(record_args) + argc - 1;
+ rec_argv = calloc(rec_argc + 1, sizeof(char *));
+
+ for (i = 0; i < ARRAY_SIZE(record_args); i++)
+ rec_argv[i] = strdup(record_args[i]);
+
+ for (j = 1; j < (unsigned int)argc; j++, i++)
+ rec_argv[i] = argv[j];
+
+ return cmd_record(i, rec_argv, NULL);
+}
+
static const struct option options[] = {
OPT_STRING('i', "input", &input_name, "file",
"input file name"),
@@ -1106,13 +1137,13 @@ int cmd_timechart(int argc, const char **argv, const char *prefix __used)

page_size = getpagesize();

- argc = parse_options(argc, argv, options, report_usage, 0);
+ argc = parse_options(argc, argv, options, timechart_usage,
+ PARSE_OPT_STOP_AT_NON_OPTION);

- /*
- * Any (unrecognized) arguments left?
- */
- if (argc)
- usage_with_options(report_usage, options);
+ if (argc && !strncmp(argv[0], "rec", 3))
+ return __cmd_record(argc, argv);
+ else if (argc)
+ usage_with_options(timechart_usage, options);

setup_pager();

--
1.6.0.6



--
Arjan van de Ven Intel Open Source Technology Centre
For development, discussion and tips for power savings,
visit http://www.lesswatts.org