Skip to contentSkip to conversation

perf: Add option to specify time window of interest

PATCH Superseded David Ahern 4 participants 18 messages Nov 25, 2016 – Nov 29, 2016 perf events

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover perf: Add option to specify time window of interest

From: David Ahern <[email protected]>

This series allows users to collect data and analyze a time window of interest within the file.

David Ahern (6):
perf tool: Add time-based utility functions
perf tool: Move parse_nsec_time to time-utils.c
perf script: Add option to specify time window of interest perf sched timehist: Add option to specify time window of interest perf kmem: Add option to specify time window of interest perf report: Add option to specify time window of interest

 tools/perf/Documentation/perf-kmem.txt   |   7 ++
 tools/perf/Documentation/perf-report.txt |   7 ++
 tools/perf/Documentation/perf-sched.txt  |   8 +++
 tools/perf/Documentation/perf-script.txt |   7 ++
 tools/perf/builtin-kmem.c                |  24 +++++++
 tools/perf/builtin-report.c              |  14 +++-
 tools/perf/builtin-sched.c               |  51 +++++++++++--
 tools/perf/builtin-script.c              |  15 +++-
 tools/perf/util/Build                    |   1 +
 tools/perf/util/time-utils.c             | 118 +++++++++++++++++++++++++++++++
 tools/perf/util/time-utils.h             |  14 ++++
 tools/perf/util/util.c                   |  33 ---------
 tools/perf/util/util.h                   |   2 -
 13 files changed, 258 insertions(+), 43 deletions(-)
 create mode 100644 tools/perf/util/time-utils.c
 create mode 100644 tools/perf/util/time-utils.h
Signature · 1 line
2.7.4 (Apple Git-66)
#1 lore raw

PATCH 1/6 perf tool: Add time-based utility functions

From: David Ahern <[email protected]>

Add function to parse a user time string of the form <start>,<stop> where start and stop are time in sec.nsec format. Both start and stop times are optional.

Add function to determine if a sample time is within a given time time window of interest.

---
 tools/perf/util/Build        |  1 +
 tools/perf/util/time-utils.c | 85 ++++++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/time-utils.h | 12 +++++++
 3 files changed, 98 insertions(+)
 create mode 100644 tools/perf/util/time-utils.c
 create mode 100644 tools/perf/util/time-utils.h
tools/perf/util/Build +1 -0
index 1dc67efad634..78f139978e7a 100644
@@ -87,6 +87,7 @@ libperf-y += help-unknown-cmd.o
 libperf-y += mem-events.o
 libperf-y += vsprintf.o
 libperf-y += drv_configs.o
+libperf-y += time-utils.o
 
 libperf-$(CONFIG_LIBBPF) += bpf-loader.o
 libperf-$(CONFIG_BPF_PROLOGUE) += bpf-prologue.o
tools/perf/util/time-utils.c new file +85 -0

85 lines not on this page · raw message

tools/perf/util/time-utils.h new file +12 -0
new file mode 100644
index 000000000000..4368a481251d
@@ -0,0 +1,12 @@
+#ifndef _TIME_UTILS_H_
+#define _TIME_UTILS_H_
+
+struct perf_time {
+	u64 start, end;
+};
+
+int perf_time__parse_str(struct perf_time *ptime, const char *ostr);
+
+bool perf_time__skip_sample(struct perf_time *ptime, u64 timestamp);
+
+#endif
Signature · 1 line
2.7.4 (Apple Git-66)
#11 lore raw

PATCH 2/6 perf tool: Move parse_nsec_time to time-utils.c

In reply to David Ahern

From: David Ahern <[email protected]>

Code move only; no functional change intended.

---
 tools/perf/util/time-utils.c | 35 ++++++++++++++++++++++++++++++++++-
 tools/perf/util/time-utils.h |  2 ++
 tools/perf/util/util.c       | 33 ---------------------------------
 tools/perf/util/util.h       |  2 --
 4 files changed, 36 insertions(+), 36 deletions(-)
tools/perf/util/time-utils.c +34 -1
index e584aeae9834..0453a7beeef4 100644
@@ -1,5 +1,6 @@
 #include <string.h>
 #include <sys/time.h>
+#include <linux/time64.h>
 #include <time.h>
 #include <errno.h>
 #include <inttypes.h>
@@ -7,7 +8,39 @@
 #include "../perf.h"
 #include "debug.h"
 #include "time-utils.h"
-#include "util.h"
+
+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;
+}
 
 static int parse_timestr_sec_nsec(struct perf_time *ptime,
 				  char *start_str, char *end_str)
tools/perf/util/time-utils.h +2 -0
index 4368a481251d..d110d4d98854 100644
@@ -5,6 +5,8 @@ struct perf_time {
 	u64 start, end;
 };
 
+int parse_nsec_time(const char *str, u64 *ptime);
+
 int perf_time__parse_str(struct perf_time *ptime, const char *ostr);
 
 bool perf_time__skip_sample(struct perf_time *ptime, u64 timestamp);
tools/perf/util/util.c +0 -33
index 67ac765da27a..9ddd98827d12 100644
@@ -400,39 +400,6 @@ void sighandler_dump_stack(int sig)
 	raise(sig);
 }
 
-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;
-}
-
 int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz)
 {
 	u64  sec = timestamp / NSEC_PER_SEC;
tools/perf/util/util.h +0 -2
index 79662d67891e..1d639e38aa82 100644
@@ -179,8 +179,6 @@ static inline void *zalloc(size_t size)
 #undef tolower
 #undef toupper
 
-int parse_nsec_time(const char *str, u64 *ptime);
-
 extern unsigned char sane_ctype[256];
 #define GIT_SPACE		0x01
 #define GIT_DIGIT		0x02
Signature · 1 line
2.7.4 (Apple Git-66)
#17 lore raw

PATCH 6/6 perf report: Add option to specify time window of interest

In reply to David Ahern

From: David Ahern <[email protected]>

Add option to allow user to control analysis window. e.g., collect data for time window and analyze a segment of interest within that window.

---
 tools/perf/Documentation/perf-report.txt |  7 +++++++
 tools/perf/builtin-report.c              | 14 +++++++++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-report.txt +7 -0
index 2d1746295abf..3a166ae4a4d3 100644
@@ -382,6 +382,13 @@ OPTIONS
 --header-only::
 	Show only perf.data header (forces --stdio).
 
+--time::
+	Only analyze samples within given time window: <start>,<stop>. Times
+	have the format seconds.microseconds. If start is not given (i.e., time
+	string is ',x.y') then analysis starts at the beginning of the file. If
+	stop time is not given (i.e, time string is 'x.y,') then analysis goes
+	to end of file.
+
 --itrace::
 	Options for decoding instruction tracing data. The options are:
 
tools/perf/builtin-report.c +13 -1
index 3dfbfffe2ecd..6565a263a275 100644
@@ -36,7 +36,7 @@
 #include "util/hist.h"
 #include "util/data.h"
 #include "arch/common.h"
-
+#include "util/time-utils.h"
 #include "util/auxtrace.h"
 
 #include <dlfcn.h>
@@ -59,6 +59,8 @@ struct report {
 	const char		*pretty_printing_style;
 	const char		*cpu_list;
 	const char		*symbol_filter_str;
+	const char              *time_str;
+	struct                  perf_time ptime;
 	float			min_percent;
 	u64			nr_entries;
 	u64			queue_size;
@@ -158,6 +160,9 @@ static int process_sample_event(struct perf_tool *tool,
 	};
 	int ret = 0;
 
+	if (perf_time__skip_sample(&rep->ptime, sample->time))
+		return 0;
+
 	if (machine__resolve(machine, &al, sample) < 0) {
 		pr_debug("problem processing %d event, skipping it.\n",
 			 event->header.type);
@@ -830,6 +835,8 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
 	OPT_CALLBACK_DEFAULT(0, "stdio-color", NULL, "mode",
 			     "'always' (default), 'never' or 'auto' only applicable to --stdio mode",
 			     stdio__config_color, "always"),
+	OPT_STRING(0, "time", &report.time_str, "str",
+		   "Time span of interest (start,stop)"),
 	OPT_END()
 	};
 	struct perf_data_file file = {
@@ -1015,6 +1022,11 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
 	if (symbol__init(&session->header.env) < 0)
 		goto error;
 
+	if (perf_time__parse_str(&report.ptime, report.time_str) != 0) {
+		pr_err("Invalid time string\n");
+		return -EINVAL;
+	}
+
 	sort__setup_elide(stdout);
 
 	ret = __cmd_report(&report);
Signature · 1 line
2.7.4 (Apple Git-66)
#16 lore raw

PATCH 5/6 perf kmem: Add option to specify time window of interest

In reply to David Ahern

From: David Ahern <[email protected]>

Add option to allow user to control analysis window. e.g., collect data for time window and analyze a segment of interest within that window.

---
 tools/perf/Documentation/perf-kmem.txt |  7 +++++++
 tools/perf/builtin-kmem.c              | 24 ++++++++++++++++++++++++
 2 files changed, 31 insertions(+)
tools/perf/Documentation/perf-kmem.txt +7 -0
index ff0f433b3fce..479fc3261a50 100644
@@ -61,6 +61,13 @@ OPTIONS
 	default, but this option shows live (currently allocated) pages
 	instead.  (This option works with --page option only)
 
+--time::
+	Only analyze samples within given time window: <start>,<stop>. Times
+	have the format seconds.microseconds. If start is not given (i.e., time
+	string is ',x.y') then analysis starts at the beginning of the file. If
+	stop time is not given (i.e, time string is 'x.y,') then analysis goes
+	to end of file.
+
 SEE ALSO
 --------
 linkperf:perf-record[1]
tools/perf/builtin-kmem.c +24 -0
index d426dcb18ce9..f184ecf9b0b3 100644
@@ -11,6 +11,7 @@
 #include "util/session.h"
 #include "util/tool.h"
 #include "util/callchain.h"
+#include "util/time-utils.h"
 
 #include <subcmd/parse-options.h>
 #include "util/trace-event.h"
@@ -65,6 +66,10 @@ static struct rb_root root_caller_sorted;
 static unsigned long total_requested, total_allocated;
 static unsigned long nr_allocs, nr_cross_allocs;
 
+/* filters for controlling start and stop of time of analysis */
+static struct perf_time ptime;
+const char *time_str;
+
 static int insert_alloc_stat(unsigned long call_site, unsigned long ptr,
 			     int bytes_req, int bytes_alloc, int cpu)
 {
@@ -907,6 +912,15 @@ static int perf_evsel__process_page_free_event(struct perf_evsel *evsel,
 	return 0;
 }
 
+static bool perf_kmem__skip_sample(struct perf_sample *sample)
+{
+	/* skip sample based on time? */
+	if (perf_time__skip_sample(&ptime, sample->time))
+		return true;
+
+	return false;
+}
+
 typedef int (*tracepoint_handler)(struct perf_evsel *evsel,
 				  struct perf_sample *sample);
 
@@ -926,6 +940,9 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
 		return -1;
 	}
 
+	if (perf_kmem__skip_sample(sample))
+		return 0;
+
 	dump_printf(" ... thread: %s:%d\n", thread__comm_str(thread), thread->tid);
 
 	if (evsel->handler != NULL) {
@@ -1884,6 +1901,8 @@ int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused)
 	OPT_CALLBACK_NOOPT(0, "page", NULL, NULL, "Analyze page allocator",
 			   parse_page_opt),
 	OPT_BOOLEAN(0, "live", &live_page, "Show live page stat"),
+	OPT_STRING(0, "time", &time_str, "str",
+		   "Time span of interest (start,stop)"),
 	OPT_END()
 	};
 	const char *const kmem_subcommands[] = { "record", "stat", NULL };
@@ -1944,6 +1963,11 @@ int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused)
 
 	symbol__init(&session->header.env);
 
+	if (perf_time__parse_str(&ptime, time_str) != 0) {
+		pr_err("Invalid time string\n");
+		return -EINVAL;
+	}
+
 	if (!strcmp(argv[0], "stat")) {
 		setlocale(LC_ALL, "");
 
Signature · 1 line
2.7.4 (Apple Git-66)
#15 lore raw

PATCH 4/6 perf sched timehist: Add option to specify time window of interest

In reply to David Ahern

From: David Ahern <[email protected]>

Add option to allow user to control analysis window. e.g., collect data for time window and analyze a segment of interest within that window.

---
 tools/perf/Documentation/perf-sched.txt |  8 ++++++
 tools/perf/builtin-sched.c              | 51 +++++++++++++++++++++++++++++----
 2 files changed, 53 insertions(+), 6 deletions(-)
tools/perf/Documentation/perf-sched.txt +8 -0
index 121c60da03e5..7775b1eb2bee 100644
@@ -132,6 +132,14 @@ OPTIONS for 'perf sched timehist'
 --migrations::
 	Show migration events.
 
+--time::
+	Only analyze samples within given time window: <start>,<stop>. Times
+	have the format seconds.microseconds. If start is not given (i.e., time
+	string is ',x.y') then analysis starts at the beginning of the file. If
+	stop time is not given (i.e, time string is 'x.y,') then analysis goes
+	to end of file.
+
+
 SEE ALSO
 --------
 linkperf:perf-record[1]
tools/perf/builtin-sched.c +45 -6

108 lines not on this page · raw message

Signature · 1 line
2.7.4 (Apple Git-66)
#14 lore raw

PATCH 3/6 perf script: Add option to specify time window of interest

In reply to David Ahern

From: David Ahern <[email protected]>

Add option to allow user to control analysis window. e.g., collect data for some amount of time and analyze a segment of interest within that window.

---
 tools/perf/Documentation/perf-script.txt |  7 +++++++
 tools/perf/builtin-script.c              | 15 ++++++++++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-script.txt +7 -0
index 0f6ee09f7256..5dc5c6a09ac4 100644
@@ -292,6 +292,13 @@ include::itrace.txt[]
 --force::
 	Don't do ownership validation.
 
+--time::
+	Only analyze samples within given time window: <start>,<stop>. Times
+	have the format seconds.microseconds. If start is not given (i.e., time
+	string is ',x.y') then analysis starts at the beginning of the file. If
+	stop time is not given (i.e, time string is 'x.y,') then analysis goes
+	to end of file.
+
 SEE ALSO
 --------
 linkperf:perf-record[1], linkperf:perf-script-perl[1],
tools/perf/builtin-script.c +14 -1
index 066b4bf73780..52d6a020346a 100644
@@ -22,6 +22,7 @@
 #include "util/thread_map.h"
 #include "util/stat.h"
 #include "util/thread-stack.h"
+#include "util/time-utils.h"
 #include <linux/bitmap.h>
 #include <linux/stringify.h>
 #include <linux/time64.h>
@@ -833,6 +834,8 @@ struct perf_script {
 	struct cpu_map		*cpus;
 	struct thread_map	*threads;
 	int			name_width;
+	const char              *time_str;
+	struct                  perf_time ptime;
 };
 
 static int perf_evlist__max_name_len(struct perf_evlist *evlist)
@@ -1014,6 +1017,9 @@ static int process_sample_event(struct perf_tool *tool,
 	struct perf_script *scr = container_of(tool, struct perf_script, tool);
 	struct addr_location al;
 
+	if (perf_time__skip_sample(&scr->ptime, sample->time))
+		return 0;
+
 	if (debug_mode) {
 		if (sample->time < last_timestamp) {
 			pr_err("Samples misordered, previous: %" PRIu64
@@ -2186,7 +2192,8 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
 			"Enable symbol demangling"),
 	OPT_BOOLEAN(0, "demangle-kernel", &symbol_conf.demangle_kernel,
 			"Enable kernel symbol demangling"),
-
+	OPT_STRING(0, "time", &script.time_str, "str",
+		   "Time span of interest (start,stop)"),
 	OPT_END()
 	};
 	const char * const script_subcommands[] = { "record", "report", NULL };
@@ -2465,6 +2472,12 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
 	if (err < 0)
 		goto out_delete;
 
+	/* needs to be parsed after looking up reference time */
+	if (perf_time__parse_str(&script.ptime, script.time_str) != 0) {
+		pr_err("Invalid time string\n");
+		return -EINVAL;
+	}
+
 	err = __cmd_script(&script);
 
 	flush_scripting();
Signature · 1 line
2.7.4 (Apple Git-66)
#12 lore raw

Re: [PATCH 2/6] perf tool: Move parse_nsec_time to time-utils.c

In reply to David Ahern

On Fri, Nov 25, 2016 at 02:39:55PM -0700, David Ahern wrote:

SNIP

Quoted 19 lines
tools/perf/util/util.c +0 -11
-
-		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;
-}
-
 int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz)
 {
 	u64  sec = timestamp / NSEC_PER_SEC;
tools/perf/util/util.h +0 -0
index 79662d67891e..1d639e38aa82 100644

tools/perf/util/util.h static inline void *zalloc(size_t size) · line 182

Quoted 4 lines
tools/perf/util/util.h +0 -1
@@ -179,8 +179,6 @@ static inline void *zalloc(size_t size)
 #undef tolower
 #undef toupper
 
-int parse_nsec_time(const char *str, u64 *ptime);

strange, can't see any current user of this function other than in your patch

could you please also add some automated tests for this function?

thanks,
jirka

#2 lore raw

Re: [PATCH 1/6] perf tool: Add time-based utility functions

In reply to David Ahern
Quoted 23 lines · David Ahern

From: David Ahern <[email protected]>

Add function to parse a user time string of the form <start>,<stop> where start and stop are time in sec.nsec format. Both start and stop times are optional.

Add function to determine if a sample time is within a given time time window of interest.

---
 tools/perf/util/Build        |  1 +
 tools/perf/util/time-utils.c | 85 ++++++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/time-utils.h | 12 +++++++
 3 files changed, 98 insertions(+)
 create mode 100644 tools/perf/util/time-utils.c
 create mode 100644 tools/perf/util/time-utils.h
tools/perf/util/Build +0 -0
index 1dc67efad634..78f139978e7a 100644

tools/perf/util/Build libperf-y += help-unknown-cmd.o · line 90

Quoted 4 lines
tools/perf/util/Build +1 -0
@@ -87,6 +87,7 @@ libperf-y += help-unknown-cmd.o
 libperf-y += mem-events.o
 libperf-y += vsprintf.o
 libperf-y += drv_configs.o
+libperf-y += time-utils.o

I think we should call it just time.c, it's already in 'util' directory

jirka

#6 lore raw

Re: [PATCH 1/6] perf tool: Add time-based utility functions

In reply to David Ahern
Quoted 36 lines · David Ahern

From: David Ahern <[email protected]>

Add function to parse a user time string of the form <start>,<stop> where start and stop are time in sec.nsec format. Both start and stop times are optional.

Add function to determine if a sample time is within a given time time window of interest.

---
 tools/perf/util/Build        |  1 +
 tools/perf/util/time-utils.c | 85 ++++++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/time-utils.h | 12 +++++++
 3 files changed, 98 insertions(+)
 create mode 100644 tools/perf/util/time-utils.c
 create mode 100644 tools/perf/util/time-utils.h
tools/perf/util/Build +1 -0
index 1dc67efad634..78f139978e7a 100644
@@ -87,6 +87,7 @@ libperf-y += help-unknown-cmd.o
 libperf-y += mem-events.o
 libperf-y += vsprintf.o
 libperf-y += drv_configs.o
+libperf-y += time-utils.o
 
 libperf-$(CONFIG_LIBBPF) += bpf-loader.o
 libperf-$(CONFIG_BPF_PROLOGUE) += bpf-prologue.o
tools/perf/util/time-utils.c new file +0 -0
new file mode 100644
index 000000000000..e584aeae9834

tools/perf/util/time-utils.c line 7

Quoted 7 lines
tools/perf/util/time-utils.c new file +7 -0
@@ -0,0 +1,85 @@
+#include <string.h>
+#include <sys/time.h>
+#include <time.h>
+#include <errno.h>
+#include <inttypes.h>
+
+#include "../perf.h"

could be just "perf.h"

jirka

#7 lore raw

Re: [PATCH 1/6] perf tool: Add time-based utility functions

In reply to David Ahern

On Fri, Nov 25, 2016 at 02:39:54PM -0700, David Ahern wrote:

SNIP

tools/perf/util/time-utils.h line 6

Quoted 12 lines
tools/perf/util/time-utils.h new file +6 -0
new file mode 100644
index 000000000000..4368a481251d
@@ -0,0 +1,12 @@
+#ifndef _TIME_UTILS_H_
+#define _TIME_UTILS_H_
+
+struct perf_time {
+	u64 start, end;
+};

hum, it's more interval rather than 'time' would perf_interval, perf_time_interval suit better?

thanks,
jirka

#8 lore raw

Re: [PATCH 1/6] perf tool: Add time-based utility functions

Quoted 4 lines · Jiri Olsa

On Fri, Nov 25, 2016 at 02:39:54PM -0700, David Ahern wrote:

SNIP

Quoted 15 lines

tools/perf/util/time-utils.h line 6

Quoted 12 lines
tools/perf/util/time-utils.h new file +6 -0
new file mode 100644
index 000000000000..4368a481251d
@@ -0,0 +1,12 @@
+#ifndef _TIME_UTILS_H_
+#define _TIME_UTILS_H_
+
+struct perf_time {
+	u64 start, end;
+};

hum, it's more interval rather than 'time' would perf_interval, perf_time_interval suit better?

I'll flip to perf_interval.

ack to the other 2 comments on this patch.

#13 lore raw

Re: [PATCH 2/6] perf tool: Move parse_nsec_time to time-utils.c

In reply to Jiri Olsa
Quoted 11 lines · Jiri Olsa

tools/perf/util/util.h static inline void *zalloc(size_t size) · line 182

Quoted 9 lines
tools/perf/util/util.h +0 -1
index 79662d67891e..1d639e38aa82 100644
@@ -179,8 +179,6 @@ static inline void *zalloc(size_t size)
 #undef tolower
 #undef toupper
 
-int parse_nsec_time(const char *str, u64 *ptime);

strange, can't see any current user of this function other than in your patch

Added a few years back. I switched my code to it at that point. odd that there are no other users, but it has worked for me since it was added.

Quoted 2 lines

could you please also add some automated tests for this function?

Why? It is basically a fancy wrapper around strtoul for sec.usec strings.

#3 lore raw

Re: [PATCH 1/6] perf tool: Add time-based utility functions

In reply to Jiri Olsa
Quoted 19 lines · Jiri Olsa
Quoted 18 lines · David Ahern

From: David Ahern <[email protected]>

Add function to parse a user time string of the form <start>,<stop> where start and stop are time in sec.nsec format. Both start and stop times are optional.

Add function to determine if a sample time is within a given time time window of interest.

---
 tools/perf/util/Build        |  1 +
 tools/perf/util/time-utils.c | 85 ++++++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/time-utils.h | 12 +++++++
 3 files changed, 98 insertions(+)
 create mode 100644 tools/perf/util/time-utils.c
 create mode 100644 tools/perf/util/time-utils.h
Quoted 11 lines

tools/perf/util/Build libperf-y += help-unknown-cmd.o · line 90

Quoted 9 lines
tools/perf/util/Build +1 -0
index 1dc67efad634..78f139978e7a 100644
@@ -87,6 +87,7 @@ libperf-y += help-unknown-cmd.o
 libperf-y += mem-events.o
 libperf-y += vsprintf.o
 libperf-y += drv_configs.o
+libperf-y += time-utils.o

I think we should call it just time.c, it's already in 'util' directory

can't rename time-utils.h to time.h because the include will get confused with <time.h> and if the header is named time-utils.h why not keep the c-file as time-utils.c?

#4 lore raw

Re: [PATCH 1/6] perf tool: Add time-based utility functions

Quoted 32 lines · David Ahern
Quoted 19 lines · Jiri Olsa
Quoted 18 lines · David Ahern

From: David Ahern <[email protected]>

Add function to parse a user time string of the form <start>,<stop> where start and stop are time in sec.nsec format. Both start and stop times are optional.

Add function to determine if a sample time is within a given time time window of interest.

---
 tools/perf/util/Build        |  1 +
 tools/perf/util/time-utils.c | 85 ++++++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/time-utils.h | 12 +++++++
 3 files changed, 98 insertions(+)
 create mode 100644 tools/perf/util/time-utils.c
 create mode 100644 tools/perf/util/time-utils.h
Quoted 11 lines

tools/perf/util/Build libperf-y += help-unknown-cmd.o · line 90

Quoted 9 lines
tools/perf/util/Build +1 -0
index 1dc67efad634..78f139978e7a 100644
@@ -87,6 +87,7 @@ libperf-y += help-unknown-cmd.o
 libperf-y += mem-events.o
 libperf-y += vsprintf.o
 libperf-y += drv_configs.o
+libperf-y += time-utils.o

I think we should call it just time.c, it's already in 'util' directory

Quoted 2 lines

can't rename time-utils.h to time.h because the include will get confused with <time.h> and if the header is named time-utils.h why not keep the c-file as time-utils.c?

ok, haven't realized that.. can't think of another name ;-)

there are some time related functions in util.[ch], maybe you coudl move them as well

int fetch_current_timestamp(char *buf, size_t sz);
int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz);

jirka

#5 lore raw

Re: [PATCH 1/6] perf tool: Add time-based utility functions

Quoted 5 lines · Jiri Olsa

there are some time related functions in util.[ch], maybe you coudl move them as well

int fetch_current_timestamp(char *buf, size_t sz);
int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz);

I'd like to defer that to a follow on patch.

I only move parse_nsec_time in this set because there are no other users but the one introduced in patch 1.

#9 lore raw

Re: [PATCH 1/6] perf tool: Add time-based utility functions

In reply to David Ahern

Em Mon, Nov 28, 2016 at 10:27:08AM -0700, David Ahern escreveu:

Quoted 21 lines · Jiri Olsa
Quoted 19 lines · David Ahern

SNIP

tools/perf/util/time-utils.h line 6

Quoted 12 lines
tools/perf/util/time-utils.h new file +6 -0
new file mode 100644
index 000000000000..4368a481251d
@@ -0,0 +1,12 @@
+#ifndef _TIME_UTILS_H_
+#define _TIME_UTILS_H_
+
+struct perf_time {
+	u64 start, end;
+};

hum, it's more interval rather than 'time' would perf_interval, perf_time_interval suit better?

Quoted 1 line

I'll flip to perf_interval.

Humm, I'd prefer 'time_interval' or 'perf_time_interval', plain 'interval' doesn't convey what kind if interval is this, we could be talking about counter values intervals, etc.

I was even expecting libc or POSIX to have something like this, but from a quick look I couldn't find anything :-\

Quoted 1 line

ack to the other 2 comments on this patch.

Ok, waiting for v2 then.

- Arnaldo

#10 lore raw

Re: [PATCH 1/6] perf tool: Add time-based utility functions

Quoted 3 lines · Arnaldo Carvalho de Melo

Humm, I'd prefer 'time_interval' or 'perf_time_interval', plain 'interval' doesn't convey what kind if interval is this, we could be talking about counter values intervals, etc.

agreed, perf_time_interval makes more sense.