* [PATCH v2 1/4] perf util: Add parse_nsec_time() function
@ 2013-06-03 4:44 Namhyung Kim
2013-06-03 4:44 ` [PATCH v2 2/4] perf script: Add --time-filter option Namhyung Kim
` (4 more replies)
0 siblings, 5 replies; 11+ messages in thread
From: Namhyung Kim @ 2013-06-03 4:44 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Peter Zijlstra, Paul Mackerras, Ingo Molnar, Namhyung Kim, LKML,
David Ahern, Andi Kleen, Jiri Olsa, Stephane Eranian
From: Namhyung Kim <namhyung.kim@lge.com>
The parse_nsec_time() function is for parsing a string of time into
64-bit nsec value. It's a preparation of time filtering in some of
perf commands.
Cc: David Ahern <dsahern@gmail.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/util/util.c | 30 ++++++++++++++++++++++++++++++
tools/perf/util/util.h | 2 ++
2 files changed, 32 insertions(+)
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index 59d868add275..4a207c40d7bc 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -269,3 +269,33 @@ void perf_debugfs_set_path(const char *mntpt)
snprintf(debugfs_mountpoint, strlen(debugfs_mountpoint), "%s", mntpt);
set_tracing_events_path(mntpt);
}
+
+int parse_nsec_time(const char *str, u64 *ptime)
+{
+ u64 time_sec, time_nsec;
+ char *end;
+
+ time_sec = strtoul(str, &end, 10);
+ if (*end != '.' && *end != '\0')
+ return -1;
+
+ if (*end == '.') {
+ int i;
+ char nsec_buf[10];
+
+ strncpy(nsec_buf, end + 1, 9);
+ nsec_buf[9] = '\0';
+
+ /* make it nsec precision */
+ for (i = strlen(nsec_buf); i < 9; i++)
+ nsec_buf[i] = '0';
+
+ time_nsec = strtoul(nsec_buf, &end, 10);
+ if (*end != '\0')
+ return -1;
+ } else
+ time_nsec = 0;
+
+ *ptime = time_sec * NSEC_PER_SEC + time_nsec;
+ return 0;
+}
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 7a484c97e500..6c8baf312c8a 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -204,6 +204,8 @@ static inline int has_extension(const char *filename, const char *ext)
#define NSEC_PER_MSEC 1000000L
#endif
+int parse_nsec_time(const char *str, u64 *ptime);
+
extern unsigned char sane_ctype[256];
#define GIT_SPACE 0x01
#define GIT_DIGIT 0x02
--
1.7.11.7
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 2/4] perf script: Add --time-filter option
2013-06-03 4:44 [PATCH v2 1/4] perf util: Add parse_nsec_time() function Namhyung Kim
@ 2013-06-03 4:44 ` Namhyung Kim
2013-06-06 1:32 ` David Ahern
2013-06-03 4:44 ` [PATCH v2 3/4] perf report: " Namhyung Kim
` (3 subsequent siblings)
4 siblings, 1 reply; 11+ messages in thread
From: Namhyung Kim @ 2013-06-03 4:44 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Peter Zijlstra, Paul Mackerras, Ingo Molnar, Namhyung Kim, LKML,
David Ahern, Andi Kleen, Jiri Olsa, Stephane Eranian,
Joonsoo Kim
From: Namhyung Kim <namhyung.kim@lge.com>
The --time-filter option is for limiting samples within a range of
time. A time range looks like <time1>-<time2> and at most one of them
can be omitted. For instance:
$ perf script --time-filter -2178446.12
...
xchat 1772 [002] 2178446.070330: sched:sched_switch: prev_comm=xchat prev_pid=177
swapper 0 [002] 2178446.070338: power:cpu_idle: state=4 cpu_id=2
swapper 0 [001] 2178446.091952: sched:sched_wakeup: comm=synergys pid=1488 prio=
swapper 0 [001] 2178446.091958: power:cpu_idle: state=4294967295 cpu_id=1
swapper 0 [001] 2178446.091970: sched:sched_switch: prev_comm=swapper/1 prev_pid
synergys 1488 [001] 2178446.091995: sched:sched_switch: prev_comm=synergys prev_pid=
swapper 0 [001] 2178446.092003: power:cpu_idle: state=4 cpu_id=1
swapper 0 [001] 2178446.116997: sched:sched_wakeup: comm=synergys pid=1488 prio=
swapper 0 [001] 2178446.117004: power:cpu_idle: state=4294967295 cpu_id=1
swapper 0 [001] 2178446.117016: sched:sched_switch: prev_comm=swapper/1 prev_pid
synergys 1488 [001] 2178446.117040: sched:sched_switch: prev_comm=synergys prev_pid=
swapper 0 [001] 2178446.117048: power:cpu_idle: state=4 cpu_id=1
Above example only displays samples which have a timestamp before
2178446.120000.
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: David Ahern <dsahern@gmail.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/Documentation/perf-script.txt | 7 +++++++
tools/perf/builtin-script.c | 32 ++++++++++++++++++++++++++++++++
2 files changed, 39 insertions(+)
diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
index e9cbfcddfa3f..c4994c5f27ff 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -203,6 +203,13 @@ OPTIONS
--show-kernel-path::
Try to resolve the path of [kernel.kallsyms]
+-X::
+--time-filter::
+ Display samples within a range of time only. A time range can be given
+ like 'time1-time2' and treated as a start time and end time
+ respectively. The time format is like "<sec>.<usec>". Either of time1
+ or time2 can be omitted.
+
SEE ALSO
--------
linkperf:perf-record[1], linkperf:perf-script-perl[1],
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 92d4658f56fb..d598765e59cb 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -28,6 +28,13 @@ static bool system_wide;
static const char *cpu_list;
static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
+struct time_range {
+ u64 start;
+ u64 end;
+};
+
+static struct time_range trange;
+
enum perf_output_field {
PERF_OUTPUT_COMM = 1U << 0,
PERF_OUTPUT_TID = 1U << 1,
@@ -510,6 +517,12 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
if (cpu_list && !test_bit(sample->cpu, cpu_bitmap))
return 0;
+ if (trange.start && trange.start > sample->time)
+ return 0;
+
+ if (trange.end && trange.end < sample->time)
+ return 0;
+
scripting_ops->process_event(event, sample, evsel, machine, &al);
evsel->hists.stats.total_period += sample->period;
@@ -1236,6 +1249,23 @@ static int have_cmd(int argc, const char **argv)
return 0;
}
+static int
+parse_time_filter(const struct option *opt, const char *str,
+ int unset __maybe_unused)
+{
+ struct time_range *time_range = opt->value;
+ char *sep = strchr(str, '-');
+
+ if (sep == NULL)
+ return parse_nsec_time(str, &time_range->start);
+ else if (sep == str)
+ return parse_nsec_time(++str, &time_range->end);
+
+ *sep++ = '\0';
+ return parse_nsec_time(str, &time_range->start) ||
+ parse_nsec_time(sep, &time_range->end);
+}
+
int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
{
bool show_full_info = false;
@@ -1286,6 +1316,8 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
"display extended information from perf.data file"),
OPT_BOOLEAN('\0', "show-kernel-path", &symbol_conf.show_kernel_path,
"Show the path of [kernel.kallsyms]"),
+ OPT_CALLBACK('X', "time-filter", &trange, "time[-time]",
+ "Only display entries in the time range", parse_time_filter),
OPT_END()
};
const char * const script_usage[] = {
--
1.7.11.7
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 3/4] perf report: Add --time-filter option
2013-06-03 4:44 [PATCH v2 1/4] perf util: Add parse_nsec_time() function Namhyung Kim
2013-06-03 4:44 ` [PATCH v2 2/4] perf script: Add --time-filter option Namhyung Kim
@ 2013-06-03 4:44 ` Namhyung Kim
2013-06-06 1:33 ` David Ahern
2013-06-03 4:44 ` [PATCH/RFC v2 4/4] perf inject: " Namhyung Kim
` (2 subsequent siblings)
4 siblings, 1 reply; 11+ messages in thread
From: Namhyung Kim @ 2013-06-03 4:44 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Peter Zijlstra, Paul Mackerras, Ingo Molnar, Namhyung Kim, LKML,
David Ahern, Andi Kleen, Jiri Olsa, Stephane Eranian,
Joonsoo Kim
From: Namhyung Kim <namhyung.kim@lge.com>
The --time-filter option is for limiting samples within a range of
time. A time range looks like <time1>-<time2> and at most one of them
can be omitted. This can be useful when analyzing a part of a huge
data only.
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: David Ahern <dsahern@gmail.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/Documentation/perf-report.txt | 7 +++++++
tools/perf/builtin-report.c | 27 +++++++++++++++++++++++++++
2 files changed, 34 insertions(+)
diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt
index 66dab7410c1d..04a96f657ca7 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -214,6 +214,13 @@ OPTIONS
Do not show entries which have an overhead under that percent.
(Default: 0).
+-X::
+--time-filter::
+ Report samples within a range of time only. A time range can be given
+ like 'time1-time2' and treated as a start time and end time
+ respectively. The time format is like "<sec>.<usec>". Either of time1
+ or time2 can be omitted.
+
SEE ALSO
--------
linkperf:perf-stat[1], linkperf:perf-annotate[1]
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index ca98d34cd58b..e09e1bdb1401 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -53,6 +53,7 @@ struct perf_report {
const char *cpu_list;
const char *symbol_filter_str;
float min_percent;
+ u64 time_start, time_end;
DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
};
@@ -318,6 +319,12 @@ static int process_sample_event(struct perf_tool *tool,
if (rep->cpu_list && !test_bit(sample->cpu, rep->cpu_bitmap))
return 0;
+ if (rep->time_start && rep->time_start > sample->time)
+ return 0;
+
+ if (rep->time_end && rep->time_end < sample->time)
+ return 0;
+
if (sort__mode == SORT_MODE__BRANCH) {
ret = perf_report__add_branch_hist_entry(tool, &al, sample,
evsel, machine);
@@ -714,6 +721,24 @@ parse_percent_limit(const struct option *opt, const char *str,
return 0;
}
+static int
+parse_time_filter(const struct option *opt, const char *str,
+ int unset __maybe_unused)
+{
+ struct perf_report *rep = opt->value;
+ char *sep;
+
+ sep = strchr(str, '-');
+ if (sep == NULL)
+ return parse_nsec_time(str, &rep->time_start);
+ else if (sep == str)
+ return parse_nsec_time(++str, &rep->time_end);
+
+ *sep++ = '\0';
+ return parse_nsec_time(str, &rep->time_start) ||
+ parse_nsec_time(sep , &rep->time_end);
+}
+
int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
{
struct perf_session *session;
@@ -825,6 +850,8 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
OPT_BOOLEAN(0, "mem-mode", &report.mem_mode, "mem access profile"),
OPT_CALLBACK(0, "percent-limit", &report, "percent",
"Don't show entries under that percent", parse_percent_limit),
+ OPT_CALLBACK('X', "time-filter", &report, "time[-time]",
+ "Only display entries in the time range", parse_time_filter),
OPT_END()
};
--
1.7.11.7
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH/RFC v2 4/4] perf inject: Add --time-filter option
2013-06-03 4:44 [PATCH v2 1/4] perf util: Add parse_nsec_time() function Namhyung Kim
2013-06-03 4:44 ` [PATCH v2 2/4] perf script: Add --time-filter option Namhyung Kim
2013-06-03 4:44 ` [PATCH v2 3/4] perf report: " Namhyung Kim
@ 2013-06-03 4:44 ` Namhyung Kim
2013-06-03 15:46 ` [PATCH v2 1/4] perf util: Add parse_nsec_time() function David Ahern
2013-07-04 7:45 ` [PATCH v2 1/4] " Namhyung Kim
4 siblings, 0 replies; 11+ messages in thread
From: Namhyung Kim @ 2013-06-03 4:44 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Peter Zijlstra, Paul Mackerras, Ingo Molnar, Namhyung Kim, LKML,
David Ahern, Andi Kleen, Jiri Olsa, Stephane Eranian
From: Namhyung Kim <namhyung.kim@lge.com>
The --time-filter option is for limiting samples within a range of
time. A time range looks like <time1>-<time2> and at most one of them
can be omitted. This can be useful when analyzing a part of a huge
data only.
It's unclear how to specify a time range when used with a pipe. It
seems that we need to support relative time too.
Cc: David Ahern <dsahern@gmail.com>
Cc: Andi Kleen <andi@firstfloor.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/Documentation/perf-inject.txt | 7 +++++++
tools/perf/builtin-inject.c | 35 ++++++++++++++++++++++++++++++++
2 files changed, 42 insertions(+)
diff --git a/tools/perf/Documentation/perf-inject.txt b/tools/perf/Documentation/perf-inject.txt
index a00a34276c54..5bc474369dfb 100644
--- a/tools/perf/Documentation/perf-inject.txt
+++ b/tools/perf/Documentation/perf-inject.txt
@@ -41,6 +41,13 @@ OPTIONS
tasks slept. sched_switch contains a callchain where a task slept and
sched_stat contains a timeslice how long a task slept.
+-X::
+--time-filter::
+ Display samples within a range of time only. A time range can be given
+ like 'time1-time2' and treated as a start time and an end time
+ respectively. The time format is like "<sec>.<usec>". Either of time1
+ or time2 can be omitted.
+
SEE ALSO
--------
linkperf:perf-record[1], linkperf:perf-report[1], linkperf:perf-archive[1]
diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index 84ad6abe4258..4fcd75508b24 100644
--- a/tools/perf/builtin-inject.c
+++ b/tools/perf/builtin-inject.c
@@ -28,6 +28,7 @@ struct perf_inject {
int pipe_output,
output;
u64 bytes_written;
+ u64 time_start, time_end;
struct list_head samples;
};
@@ -112,6 +113,14 @@ static int perf_event__repipe_sample(struct perf_tool *tool,
struct perf_evsel *evsel,
struct machine *machine)
{
+ struct perf_inject *inject = container_of(tool, struct perf_inject, tool);
+
+ if (inject->time_start && inject->time_start > sample->time)
+ return 0;
+
+ if (inject->time_end && inject->time_end < sample->time)
+ return 0;
+
if (evsel->handler.func) {
inject_handler f = evsel->handler.func;
return f(tool, event, sample, evsel, machine);
@@ -206,6 +215,13 @@ static int perf_event__inject_buildid(struct perf_tool *tool,
struct addr_location al;
struct thread *thread;
u8 cpumode;
+ struct perf_inject *inject = container_of(tool, struct perf_inject, tool);
+
+ if (inject->time_start && inject->time_start > sample->time)
+ return 0;
+
+ if (inject->time_end && inject->time_end < sample->time)
+ return 0;
cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
@@ -393,6 +409,23 @@ static int __cmd_inject(struct perf_inject *inject)
return ret;
}
+static int
+parse_time_filter(const struct option *opt, const char *str,
+ int unset __maybe_unused)
+{
+ struct perf_inject *inject = opt->value;
+ char *sep = strchr(str, '-');
+
+ if (sep == NULL)
+ return parse_nsec_time(str, &inject->time_start);
+ else if (sep == str)
+ return parse_nsec_time(++str, &inject->time_end);
+
+ *sep++ = '\0';
+ return parse_nsec_time(str, &inject->time_start) ||
+ parse_nsec_time(sep, &inject->time_end);
+}
+
int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused)
{
struct perf_inject inject = {
@@ -427,6 +460,8 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused)
"where and how long tasks slept"),
OPT_INCR('v', "verbose", &verbose,
"be more verbose (show build ids, etc)"),
+ OPT_CALLBACK('X', "time-filter", &inject, "time[-time]",
+ "Only display entries in the time range", parse_time_filter),
OPT_END()
};
const char * const inject_usage[] = {
--
1.7.11.7
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v2 1/4] perf util: Add parse_nsec_time() function
2013-06-03 4:44 [PATCH v2 1/4] perf util: Add parse_nsec_time() function Namhyung Kim
` (2 preceding siblings ...)
2013-06-03 4:44 ` [PATCH/RFC v2 4/4] perf inject: " Namhyung Kim
@ 2013-06-03 15:46 ` David Ahern
2013-06-04 1:50 ` [PATCH v3 " Namhyung Kim
2013-07-04 7:45 ` [PATCH v2 1/4] " Namhyung Kim
4 siblings, 1 reply; 11+ messages in thread
From: David Ahern @ 2013-06-03 15:46 UTC (permalink / raw)
To: Namhyung Kim
Cc: Arnaldo Carvalho de Melo, Peter Zijlstra, Paul Mackerras,
Ingo Molnar, Namhyung Kim, LKML, Andi Kleen, Jiri Olsa,
Stephane Eranian
On 6/2/13 10:44 PM, Namhyung Kim wrote:
> From: Namhyung Kim <namhyung.kim@lge.com>
>
> The parse_nsec_time() function is for parsing a string of time into
> 64-bit nsec value. It's a preparation of time filtering in some of
> perf commands.
>
> Cc: David Ahern <dsahern@gmail.com>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
> tools/perf/util/util.c | 30 ++++++++++++++++++++++++++++++
> tools/perf/util/util.h | 2 ++
> 2 files changed, 32 insertions(+)
>
> diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
> index 59d868add275..4a207c40d7bc 100644
> --- a/tools/perf/util/util.c
> +++ b/tools/perf/util/util.c
> @@ -269,3 +269,33 @@ void perf_debugfs_set_path(const char *mntpt)
> snprintf(debugfs_mountpoint, strlen(debugfs_mountpoint), "%s", mntpt);
> set_tracing_events_path(mntpt);
> }
> +
> +int parse_nsec_time(const char *str, u64 *ptime)
> +{
> + u64 time_sec, time_nsec;
> + char *end;
> +
> + time_sec = strtoul(str, &end, 10);
> + if (*end != '.' && *end != '\0')
> + return -1;
> +
> + if (*end == '.') {
> + int i;
> + char nsec_buf[10];
> +
catch garbage nsec times too:
if strlen(end+1) > 9)
return -1;
David
> + strncpy(nsec_buf, end + 1, 9);
> + nsec_buf[9] = '\0';
> +
> + /* make it nsec precision */
> + for (i = strlen(nsec_buf); i < 9; i++)
> + nsec_buf[i] = '0';
> +
> + time_nsec = strtoul(nsec_buf, &end, 10);
> + if (*end != '\0')
> + return -1;
> + } else
> + time_nsec = 0;
> +
> + *ptime = time_sec * NSEC_PER_SEC + time_nsec;
> + return 0;
> +}
> diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
> index 7a484c97e500..6c8baf312c8a 100644
> --- a/tools/perf/util/util.h
> +++ b/tools/perf/util/util.h
> @@ -204,6 +204,8 @@ static inline int has_extension(const char *filename, const char *ext)
> #define NSEC_PER_MSEC 1000000L
> #endif
>
> +int parse_nsec_time(const char *str, u64 *ptime);
> +
> extern unsigned char sane_ctype[256];
> #define GIT_SPACE 0x01
> #define GIT_DIGIT 0x02
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v3 1/4] perf util: Add parse_nsec_time() function
2013-06-03 15:46 ` [PATCH v2 1/4] perf util: Add parse_nsec_time() function David Ahern
@ 2013-06-04 1:50 ` Namhyung Kim
2013-06-06 1:31 ` David Ahern
2013-08-12 10:18 ` [tip:perf/core] " tip-bot for Namhyung Kim
0 siblings, 2 replies; 11+ messages in thread
From: Namhyung Kim @ 2013-06-04 1:50 UTC (permalink / raw)
To: David Ahern
Cc: Arnaldo Carvalho de Melo, Peter Zijlstra, Paul Mackerras,
Ingo Molnar, LKML, Andi Kleen, Jiri Olsa, Stephane Eranian,
Namhyung Kim
From: Namhyung Kim <namhyung.kim@lge.com>
The parse_nsec_time() function is for parsing a string of time into
64-bit nsec value. It's a preparation of time filtering in some of
perf commands.
Cc: David Ahern <dsahern@gmail.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/util/util.c | 33 +++++++++++++++++++++++++++++++++
tools/perf/util/util.h | 2 ++
2 files changed, 35 insertions(+)
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index 59d868add275..205972f6addb 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -269,3 +269,36 @@ void perf_debugfs_set_path(const char *mntpt)
snprintf(debugfs_mountpoint, strlen(debugfs_mountpoint), "%s", mntpt);
set_tracing_events_path(mntpt);
}
+
+int parse_nsec_time(const char *str, u64 *ptime)
+{
+ u64 time_sec, time_nsec;
+ char *end;
+
+ time_sec = strtoul(str, &end, 10);
+ if (*end != '.' && *end != '\0')
+ return -1;
+
+ if (*end == '.') {
+ int i;
+ char nsec_buf[10];
+
+ if (strlen(++end) > 9)
+ return -1;
+
+ strncpy(nsec_buf, end, 9);
+ nsec_buf[9] = '\0';
+
+ /* make it nsec precision */
+ for (i = strlen(nsec_buf); i < 9; i++)
+ nsec_buf[i] = '0';
+
+ time_nsec = strtoul(nsec_buf, &end, 10);
+ if (*end != '\0')
+ return -1;
+ } else
+ time_nsec = 0;
+
+ *ptime = time_sec * NSEC_PER_SEC + time_nsec;
+ return 0;
+}
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 7a484c97e500..6c8baf312c8a 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -204,6 +204,8 @@ static inline int has_extension(const char *filename, const char *ext)
#define NSEC_PER_MSEC 1000000L
#endif
+int parse_nsec_time(const char *str, u64 *ptime);
+
extern unsigned char sane_ctype[256];
#define GIT_SPACE 0x01
#define GIT_DIGIT 0x02
--
1.7.11.7
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v3 1/4] perf util: Add parse_nsec_time() function
2013-06-04 1:50 ` [PATCH v3 " Namhyung Kim
@ 2013-06-06 1:31 ` David Ahern
2013-08-12 10:18 ` [tip:perf/core] " tip-bot for Namhyung Kim
1 sibling, 0 replies; 11+ messages in thread
From: David Ahern @ 2013-06-06 1:31 UTC (permalink / raw)
To: Namhyung Kim
Cc: Arnaldo Carvalho de Melo, Peter Zijlstra, Paul Mackerras,
Ingo Molnar, LKML, Andi Kleen, Jiri Olsa, Stephane Eranian,
Namhyung Kim
On 6/3/13 7:50 PM, Namhyung Kim wrote:
> From: Namhyung Kim <namhyung.kim@lge.com>
>
> The parse_nsec_time() function is for parsing a string of time into
> 64-bit nsec value. It's a preparation of time filtering in some of
> perf commands.
>
> Cc: David Ahern <dsahern@gmail.com>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-Tested-by: David Ahern <dsahern@gmail.com>
> ---
> tools/perf/util/util.c | 33 +++++++++++++++++++++++++++++++++
> tools/perf/util/util.h | 2 ++
> 2 files changed, 35 insertions(+)
>
> diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
> index 59d868add275..205972f6addb 100644
> --- a/tools/perf/util/util.c
> +++ b/tools/perf/util/util.c
> @@ -269,3 +269,36 @@ void perf_debugfs_set_path(const char *mntpt)
> snprintf(debugfs_mountpoint, strlen(debugfs_mountpoint), "%s", mntpt);
> set_tracing_events_path(mntpt);
> }
> +
> +int parse_nsec_time(const char *str, u64 *ptime)
> +{
> + u64 time_sec, time_nsec;
> + char *end;
> +
> + time_sec = strtoul(str, &end, 10);
> + if (*end != '.' && *end != '\0')
> + return -1;
> +
> + if (*end == '.') {
> + int i;
> + char nsec_buf[10];
> +
> + if (strlen(++end) > 9)
> + return -1;
> +
> + strncpy(nsec_buf, end, 9);
> + nsec_buf[9] = '\0';
> +
> + /* make it nsec precision */
> + for (i = strlen(nsec_buf); i < 9; i++)
> + nsec_buf[i] = '0';
> +
> + time_nsec = strtoul(nsec_buf, &end, 10);
> + if (*end != '\0')
> + return -1;
> + } else
> + time_nsec = 0;
> +
> + *ptime = time_sec * NSEC_PER_SEC + time_nsec;
> + return 0;
> +}
> diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
> index 7a484c97e500..6c8baf312c8a 100644
> --- a/tools/perf/util/util.h
> +++ b/tools/perf/util/util.h
> @@ -204,6 +204,8 @@ static inline int has_extension(const char *filename, const char *ext)
> #define NSEC_PER_MSEC 1000000L
> #endif
>
> +int parse_nsec_time(const char *str, u64 *ptime);
> +
> extern unsigned char sane_ctype[256];
> #define GIT_SPACE 0x01
> #define GIT_DIGIT 0x02
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 2/4] perf script: Add --time-filter option
2013-06-03 4:44 ` [PATCH v2 2/4] perf script: Add --time-filter option Namhyung Kim
@ 2013-06-06 1:32 ` David Ahern
0 siblings, 0 replies; 11+ messages in thread
From: David Ahern @ 2013-06-06 1:32 UTC (permalink / raw)
To: Namhyung Kim, Arnaldo Carvalho de Melo
Cc: Peter Zijlstra, Paul Mackerras, Ingo Molnar, Namhyung Kim, LKML,
Andi Kleen, Jiri Olsa, Stephane Eranian, Joonsoo Kim
On 6/2/13 10:44 PM, Namhyung Kim wrote:
> From: Namhyung Kim <namhyung.kim@lge.com>
>
> The --time-filter option is for limiting samples within a range of
> time. A time range looks like <time1>-<time2> and at most one of them
> can be omitted. For instance:
>
> $ perf script --time-filter -2178446.12
> ...
> xchat 1772 [002] 2178446.070330: sched:sched_switch: prev_comm=xchat prev_pid=177
> swapper 0 [002] 2178446.070338: power:cpu_idle: state=4 cpu_id=2
> swapper 0 [001] 2178446.091952: sched:sched_wakeup: comm=synergys pid=1488 prio=
> swapper 0 [001] 2178446.091958: power:cpu_idle: state=4294967295 cpu_id=1
> swapper 0 [001] 2178446.091970: sched:sched_switch: prev_comm=swapper/1 prev_pid
> synergys 1488 [001] 2178446.091995: sched:sched_switch: prev_comm=synergys prev_pid=
> swapper 0 [001] 2178446.092003: power:cpu_idle: state=4 cpu_id=1
> swapper 0 [001] 2178446.116997: sched:sched_wakeup: comm=synergys pid=1488 prio=
> swapper 0 [001] 2178446.117004: power:cpu_idle: state=4294967295 cpu_id=1
> swapper 0 [001] 2178446.117016: sched:sched_switch: prev_comm=swapper/1 prev_pid
> synergys 1488 [001] 2178446.117040: sched:sched_switch: prev_comm=synergys prev_pid=
> swapper 0 [001] 2178446.117048: power:cpu_idle: state=4 cpu_id=1
>
> Above example only displays samples which have a timestamp before
> 2178446.120000.
>
> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
> Cc: David Ahern <dsahern@gmail.com>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-Tested-by: David Ahern <dsahern@gmail.com>
> ---
> tools/perf/Documentation/perf-script.txt | 7 +++++++
> tools/perf/builtin-script.c | 32 ++++++++++++++++++++++++++++++++
> 2 files changed, 39 insertions(+)
>
> diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
> index e9cbfcddfa3f..c4994c5f27ff 100644
> --- a/tools/perf/Documentation/perf-script.txt
> +++ b/tools/perf/Documentation/perf-script.txt
> @@ -203,6 +203,13 @@ OPTIONS
> --show-kernel-path::
> Try to resolve the path of [kernel.kallsyms]
>
> +-X::
> +--time-filter::
> + Display samples within a range of time only. A time range can be given
> + like 'time1-time2' and treated as a start time and end time
> + respectively. The time format is like "<sec>.<usec>". Either of time1
> + or time2 can be omitted.
> +
> SEE ALSO
> --------
> linkperf:perf-record[1], linkperf:perf-script-perl[1],
> diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
> index 92d4658f56fb..d598765e59cb 100644
> --- a/tools/perf/builtin-script.c
> +++ b/tools/perf/builtin-script.c
> @@ -28,6 +28,13 @@ static bool system_wide;
> static const char *cpu_list;
> static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
>
> +struct time_range {
> + u64 start;
> + u64 end;
> +};
> +
> +static struct time_range trange;
> +
> enum perf_output_field {
> PERF_OUTPUT_COMM = 1U << 0,
> PERF_OUTPUT_TID = 1U << 1,
> @@ -510,6 +517,12 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
> if (cpu_list && !test_bit(sample->cpu, cpu_bitmap))
> return 0;
>
> + if (trange.start && trange.start > sample->time)
> + return 0;
> +
> + if (trange.end && trange.end < sample->time)
> + return 0;
> +
> scripting_ops->process_event(event, sample, evsel, machine, &al);
>
> evsel->hists.stats.total_period += sample->period;
> @@ -1236,6 +1249,23 @@ static int have_cmd(int argc, const char **argv)
> return 0;
> }
>
> +static int
> +parse_time_filter(const struct option *opt, const char *str,
> + int unset __maybe_unused)
> +{
> + struct time_range *time_range = opt->value;
> + char *sep = strchr(str, '-');
> +
> + if (sep == NULL)
> + return parse_nsec_time(str, &time_range->start);
> + else if (sep == str)
> + return parse_nsec_time(++str, &time_range->end);
> +
> + *sep++ = '\0';
> + return parse_nsec_time(str, &time_range->start) ||
> + parse_nsec_time(sep, &time_range->end);
> +}
> +
> int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
> {
> bool show_full_info = false;
> @@ -1286,6 +1316,8 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
> "display extended information from perf.data file"),
> OPT_BOOLEAN('\0', "show-kernel-path", &symbol_conf.show_kernel_path,
> "Show the path of [kernel.kallsyms]"),
> + OPT_CALLBACK('X', "time-filter", &trange, "time[-time]",
> + "Only display entries in the time range", parse_time_filter),
> OPT_END()
> };
> const char * const script_usage[] = {
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 3/4] perf report: Add --time-filter option
2013-06-03 4:44 ` [PATCH v2 3/4] perf report: " Namhyung Kim
@ 2013-06-06 1:33 ` David Ahern
0 siblings, 0 replies; 11+ messages in thread
From: David Ahern @ 2013-06-06 1:33 UTC (permalink / raw)
To: Namhyung Kim
Cc: Arnaldo Carvalho de Melo, Peter Zijlstra, Paul Mackerras,
Ingo Molnar, Namhyung Kim, LKML, Andi Kleen, Jiri Olsa,
Stephane Eranian, Joonsoo Kim
On 6/2/13 10:44 PM, Namhyung Kim wrote:
> From: Namhyung Kim <namhyung.kim@lge.com>
>
> The --time-filter option is for limiting samples within a range of
> time. A time range looks like <time1>-<time2> and at most one of them
> can be omitted. This can be useful when analyzing a part of a huge
> data only.
>
> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
> Cc: David Ahern <dsahern@gmail.com>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-Tested-by: David Ahern <dsahern@gmail.com>
> ---
> tools/perf/Documentation/perf-report.txt | 7 +++++++
> tools/perf/builtin-report.c | 27 +++++++++++++++++++++++++++
> 2 files changed, 34 insertions(+)
>
> diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt
> index 66dab7410c1d..04a96f657ca7 100644
> --- a/tools/perf/Documentation/perf-report.txt
> +++ b/tools/perf/Documentation/perf-report.txt
> @@ -214,6 +214,13 @@ OPTIONS
> Do not show entries which have an overhead under that percent.
> (Default: 0).
>
> +-X::
> +--time-filter::
> + Report samples within a range of time only. A time range can be given
> + like 'time1-time2' and treated as a start time and end time
> + respectively. The time format is like "<sec>.<usec>". Either of time1
> + or time2 can be omitted.
> +
> SEE ALSO
> --------
> linkperf:perf-stat[1], linkperf:perf-annotate[1]
> diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
> index ca98d34cd58b..e09e1bdb1401 100644
> --- a/tools/perf/builtin-report.c
> +++ b/tools/perf/builtin-report.c
> @@ -53,6 +53,7 @@ struct perf_report {
> const char *cpu_list;
> const char *symbol_filter_str;
> float min_percent;
> + u64 time_start, time_end;
> DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
> };
>
> @@ -318,6 +319,12 @@ static int process_sample_event(struct perf_tool *tool,
> if (rep->cpu_list && !test_bit(sample->cpu, rep->cpu_bitmap))
> return 0;
>
> + if (rep->time_start && rep->time_start > sample->time)
> + return 0;
> +
> + if (rep->time_end && rep->time_end < sample->time)
> + return 0;
> +
> if (sort__mode == SORT_MODE__BRANCH) {
> ret = perf_report__add_branch_hist_entry(tool, &al, sample,
> evsel, machine);
> @@ -714,6 +721,24 @@ parse_percent_limit(const struct option *opt, const char *str,
> return 0;
> }
>
> +static int
> +parse_time_filter(const struct option *opt, const char *str,
> + int unset __maybe_unused)
> +{
> + struct perf_report *rep = opt->value;
> + char *sep;
> +
> + sep = strchr(str, '-');
> + if (sep == NULL)
> + return parse_nsec_time(str, &rep->time_start);
> + else if (sep == str)
> + return parse_nsec_time(++str, &rep->time_end);
> +
> + *sep++ = '\0';
> + return parse_nsec_time(str, &rep->time_start) ||
> + parse_nsec_time(sep , &rep->time_end);
> +}
> +
> int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
> {
> struct perf_session *session;
> @@ -825,6 +850,8 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
> OPT_BOOLEAN(0, "mem-mode", &report.mem_mode, "mem access profile"),
> OPT_CALLBACK(0, "percent-limit", &report, "percent",
> "Don't show entries under that percent", parse_percent_limit),
> + OPT_CALLBACK('X', "time-filter", &report, "time[-time]",
> + "Only display entries in the time range", parse_time_filter),
> OPT_END()
> };
>
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 1/4] perf util: Add parse_nsec_time() function
2013-06-03 4:44 [PATCH v2 1/4] perf util: Add parse_nsec_time() function Namhyung Kim
` (3 preceding siblings ...)
2013-06-03 15:46 ` [PATCH v2 1/4] perf util: Add parse_nsec_time() function David Ahern
@ 2013-07-04 7:45 ` Namhyung Kim
4 siblings, 0 replies; 11+ messages in thread
From: Namhyung Kim @ 2013-07-04 7:45 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Peter Zijlstra, Paul Mackerras, Ingo Molnar, Namhyung Kim, LKML,
David Ahern, Andi Kleen, Jiri Olsa, Stephane Eranian
Hi Arnaldo,
Could you pick these up or give a comment?
Thanks,
Namhyung
On Mon, 3 Jun 2013 13:44:10 +0900, Namhyung Kim wrote:
> From: Namhyung Kim <namhyung.kim@lge.com>
>
> The parse_nsec_time() function is for parsing a string of time into
> 64-bit nsec value. It's a preparation of time filtering in some of
> perf commands.
>
> Cc: David Ahern <dsahern@gmail.com>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
> tools/perf/util/util.c | 30 ++++++++++++++++++++++++++++++
> tools/perf/util/util.h | 2 ++
> 2 files changed, 32 insertions(+)
>
> diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
> index 59d868add275..4a207c40d7bc 100644
> --- a/tools/perf/util/util.c
> +++ b/tools/perf/util/util.c
> @@ -269,3 +269,33 @@ void perf_debugfs_set_path(const char *mntpt)
> snprintf(debugfs_mountpoint, strlen(debugfs_mountpoint), "%s", mntpt);
> set_tracing_events_path(mntpt);
> }
> +
> +int parse_nsec_time(const char *str, u64 *ptime)
> +{
> + u64 time_sec, time_nsec;
> + char *end;
> +
> + time_sec = strtoul(str, &end, 10);
> + if (*end != '.' && *end != '\0')
> + return -1;
> +
> + if (*end == '.') {
> + int i;
> + char nsec_buf[10];
> +
> + strncpy(nsec_buf, end + 1, 9);
> + nsec_buf[9] = '\0';
> +
> + /* make it nsec precision */
> + for (i = strlen(nsec_buf); i < 9; i++)
> + nsec_buf[i] = '0';
> +
> + time_nsec = strtoul(nsec_buf, &end, 10);
> + if (*end != '\0')
> + return -1;
> + } else
> + time_nsec = 0;
> +
> + *ptime = time_sec * NSEC_PER_SEC + time_nsec;
> + return 0;
> +}
> diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
> index 7a484c97e500..6c8baf312c8a 100644
> --- a/tools/perf/util/util.h
> +++ b/tools/perf/util/util.h
> @@ -204,6 +204,8 @@ static inline int has_extension(const char *filename, const char *ext)
> #define NSEC_PER_MSEC 1000000L
> #endif
>
> +int parse_nsec_time(const char *str, u64 *ptime);
> +
> extern unsigned char sane_ctype[256];
> #define GIT_SPACE 0x01
> #define GIT_DIGIT 0x02
^ permalink raw reply [flat|nested] 11+ messages in thread
* [tip:perf/core] perf util: Add parse_nsec_time() function
2013-06-04 1:50 ` [PATCH v3 " Namhyung Kim
2013-06-06 1:31 ` David Ahern
@ 2013-08-12 10:18 ` tip-bot for Namhyung Kim
1 sibling, 0 replies; 11+ messages in thread
From: tip-bot for Namhyung Kim @ 2013-08-12 10:18 UTC (permalink / raw)
To: linux-tip-commits
Cc: acme, linux-kernel, eranian, paulus, hpa, mingo, andi,
a.p.zijlstra, namhyung.kim, namhyung, jolsa, dsahern, tglx
Commit-ID: 3b47abe1b5f5446ab41a3a139b6075f46f77f21f
Gitweb: http://git.kernel.org/tip/3b47abe1b5f5446ab41a3a139b6075f46f77f21f
Author: Namhyung Kim <namhyung.kim@lge.com>
AuthorDate: Tue, 4 Jun 2013 10:50:29 +0900
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 7 Aug 2013 17:35:26 -0300
perf util: Add parse_nsec_time() function
The parse_nsec_time() function is for parsing a string of time into
64-bit nsec value. It's a preparation of time filtering in some of perf
commands.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: David Ahern <dsahern@gmail.com>
Acked-by: David Ahern <dsahern@gmail.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1370310629-9642-1-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/util.c | 33 +++++++++++++++++++++++++++++++++
tools/perf/util/util.h | 2 ++
2 files changed, 35 insertions(+)
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index 9a06584..6d17b18 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -328,3 +328,36 @@ void put_tracing_file(char *file)
{
free(file);
}
+
+int parse_nsec_time(const char *str, u64 *ptime)
+{
+ u64 time_sec, time_nsec;
+ char *end;
+
+ time_sec = strtoul(str, &end, 10);
+ if (*end != '.' && *end != '\0')
+ return -1;
+
+ if (*end == '.') {
+ int i;
+ char nsec_buf[10];
+
+ if (strlen(++end) > 9)
+ return -1;
+
+ strncpy(nsec_buf, end, 9);
+ nsec_buf[9] = '\0';
+
+ /* make it nsec precision */
+ for (i = strlen(nsec_buf); i < 9; i++)
+ nsec_buf[i] = '0';
+
+ time_nsec = strtoul(nsec_buf, &end, 10);
+ if (*end != '\0')
+ return -1;
+ } else
+ time_nsec = 0;
+
+ *ptime = time_sec * NSEC_PER_SEC + time_nsec;
+ return 0;
+}
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index cc1574e..a535359 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -208,6 +208,8 @@ static inline int has_extension(const char *filename, const char *ext)
#define NSEC_PER_MSEC 1000000L
#endif
+int parse_nsec_time(const char *str, u64 *ptime);
+
extern unsigned char sane_ctype[256];
#define GIT_SPACE 0x01
#define GIT_DIGIT 0x02
^ permalink raw reply related [flat|nested] 11+ messages in thread
end of thread, other threads:[~2013-08-12 10:19 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-03 4:44 [PATCH v2 1/4] perf util: Add parse_nsec_time() function Namhyung Kim
2013-06-03 4:44 ` [PATCH v2 2/4] perf script: Add --time-filter option Namhyung Kim
2013-06-06 1:32 ` David Ahern
2013-06-03 4:44 ` [PATCH v2 3/4] perf report: " Namhyung Kim
2013-06-06 1:33 ` David Ahern
2013-06-03 4:44 ` [PATCH/RFC v2 4/4] perf inject: " Namhyung Kim
2013-06-03 15:46 ` [PATCH v2 1/4] perf util: Add parse_nsec_time() function David Ahern
2013-06-04 1:50 ` [PATCH v3 " Namhyung Kim
2013-06-06 1:31 ` David Ahern
2013-08-12 10:18 ` [tip:perf/core] " tip-bot for Namhyung Kim
2013-07-04 7:45 ` [PATCH v2 1/4] " Namhyung Kim
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).