linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Joonwoo Park <joonwoop@codeaurora.org>
Cc: Ingo Molnar <mingo@kernel.org>,
	linux-kernel@vger.kernel.org, Namhyung Kim <namhyung@kernel.org>,
	David Ahern <dsahern@gmail.com>, Jiri Olsa <jolsa@kernel.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: Re: [PATCH 08/15] perf tools: Introduce timestamp_in_usec()
Date: Fri, 28 Oct 2016 11:30:41 -0200	[thread overview]
Message-ID: <20161028133041.GC28694@kernel.org> (raw)
In-Reply-To: <20161028125338.GA28694@kernel.org>

Em Fri, Oct 28, 2016 at 10:53:38AM -0200, Arnaldo Carvalho de Melo escreveu:
> Em Thu, Oct 27, 2016 at 04:14:55PM -0700, Joonwoo Park escreveu:
> > 
> > 
> > On 10/27/2016 01:40 PM, Arnaldo Carvalho de Melo wrote:
> > > From: Namhyung Kim <namhyung@kernel.org>
> > > 
> > > Joonwoo reported that there's a mismatch between timestamps in script
> > > and sched commands.  This was because of difference in printing the
> > > timestamp.  Factor out the code and share it so that they can be in
> > > sync.  Also I found that sched map has similar problem, fix it too.
> > > 
> > > Reported-and-Acked-by: Joonwoo Park <joonwoop@codeaurora.org>
> > 
> > Hmm.. I didn't ACK this patch because of bug I commented at
> > https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1256724.html
> > 
> > s/work_list->max_lat/work_list->max_lat_at/
> 
> Sorry about that, I took the "thanks for taking care of this" as an ack,
> now that I re-read that message I saw your points later on in that
> e-mail.
> 
> Since Ingo hasn't pulled this, I'll try fixing it, will check that other
> naming issue,

So, here is how it ended up, it fixes the problem you pointed out and
renames the function to follow the scnprintf() convention, as used
elsewhere in tools/perf (tools/perf/util/annotate.h has several
examples).

commit 99620a5d0cc8e2dd9aedb629a6e81825f0db020e
Author: Namhyung Kim <namhyung@kernel.org>
Date:   Mon Oct 24 11:02:45 2016 +0900

    perf tools: Introduce timestamp__scnprintf_usec()
    
    Joonwoo reported that there's a mismatch between timestamps in script
    and sched commands.  This was because of difference in printing the
    timestamp.  Factor out the code and share it so that they can be in
    sync.  Also I found that sched map has similar problem, fix it too.
    
    Committer notes:
    
    Fixed the max_lat_at bug introduced by Namhyung's original patch, as
    pointed out by Joonwoo, and made it a function following the scnprintf()
    model, i.e. returning the number of bytes formatted, and receiving as
    the first parameter the object from where the data to the formatting is
    obtained, renaming it from:
    
       char *timestamp_in_usec(char *bf, size_t size, u64 timestamp)
    
    to
    
       int timestamp__scnprintf_usec(u64 timestamp, char *bf, size_t size)
    
    Reported-by: Joonwoo Park <joonwoop@codeaurora.org>
    Signed-off-by: Namhyung Kim <namhyung@kernel.org>
    Cc: David Ahern <dsahern@gmail.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
    Link: http://lkml.kernel.org/r/20161024020246.14928-3-namhyung@kernel.org
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 1f33d15314a5..fb3441211e4b 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -1191,6 +1191,7 @@ static void output_lat_thread(struct perf_sched *sched, struct work_atoms *work_
 	int i;
 	int ret;
 	u64 avg;
+	char max_lat_at[32];
 
 	if (!work_list->nb_atoms)
 		return;
@@ -1212,12 +1213,13 @@ static void output_lat_thread(struct perf_sched *sched, struct work_atoms *work_
 		printf(" ");
 
 	avg = work_list->total_lat / work_list->nb_atoms;
+	timestamp__scnprintf_usec(work_list->max_lat_at, max_lat_at, sizeof(max_lat_at));
 
-	printf("|%11.3f ms |%9" PRIu64 " | avg:%9.3f ms | max:%9.3f ms | max at: %13.6f s\n",
+	printf("|%11.3f ms |%9" PRIu64 " | avg:%9.3f ms | max:%9.3f ms | max at: %13s s\n",
 	      (double)work_list->total_runtime / NSEC_PER_MSEC,
 		 work_list->nb_atoms, (double)avg / NSEC_PER_MSEC,
 		 (double)work_list->max_lat / NSEC_PER_MSEC,
-		 (double)work_list->max_lat_at / NSEC_PER_SEC);
+		 max_lat_at);
 }
 
 static int pid_cmp(struct work_atoms *l, struct work_atoms *r)
@@ -1402,6 +1404,7 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,
 	int cpus_nr;
 	bool new_cpu = false;
 	const char *color = PERF_COLOR_NORMAL;
+	char stimestamp[32];
 
 	BUG_ON(this_cpu >= MAX_CPUS || this_cpu < 0);
 
@@ -1492,7 +1495,8 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,
 	if (sched->map.cpus && !cpu_map__has(sched->map.cpus, this_cpu))
 		goto out;
 
-	color_fprintf(stdout, color, "  %12.6f secs ", (double)timestamp / NSEC_PER_SEC);
+	timestamp__scnprintf_usec(timestamp, stimestamp, sizeof(stimestamp));
+	color_fprintf(stdout, color, "  %12s secs ", stimestamp);
 	if (new_shortname || (verbose && sched_in->tid)) {
 		const char *pid_color = color;
 
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 412fb6e65ac0..e1daff36d070 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -441,7 +441,6 @@ static void print_sample_start(struct perf_sample *sample,
 {
 	struct perf_event_attr *attr = &evsel->attr;
 	unsigned long secs;
-	unsigned long usecs;
 	unsigned long long nsecs;
 
 	if (PRINT_FIELD(COMM)) {
@@ -471,11 +470,14 @@ static void print_sample_start(struct perf_sample *sample,
 		nsecs = sample->time;
 		secs = nsecs / NSEC_PER_SEC;
 		nsecs -= secs * NSEC_PER_SEC;
-		usecs = nsecs / NSEC_PER_USEC;
+
 		if (nanosecs)
 			printf("%5lu.%09llu: ", secs, nsecs);
-		else
-			printf("%5lu.%06lu: ", secs, usecs);
+		else {
+			char sample_time[32];
+			timestamp__scnprintf_usec(sample->time, sample_time, sizeof(sample_time));
+			printf("%12s: ", sample_time);
+		}
 	}
 }
 
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index 85c56800f17a..5bbd1f609f1f 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -433,6 +433,14 @@ int parse_nsec_time(const char *str, u64 *ptime)
 	return 0;
 }
 
+int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz)
+{
+	u64  sec = timestamp / NSEC_PER_SEC;
+	u64 usec = (timestamp % NSEC_PER_SEC) / NSEC_PER_USEC;
+
+	return scnprintf(buf, sz, "%"PRIu64".%06"PRIu64, sec, usec);
+}
+
 unsigned long parse_tag_value(const char *str, struct parse_tag *tags)
 {
 	struct parse_tag *i = tags;
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 71b6992f1d98..79662d67891e 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -362,4 +362,7 @@ extern int sched_getcpu(void);
 #endif
 
 int is_printable_array(char *p, unsigned int len);
+
+int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz);
+
 #endif /* GIT_COMPAT_UTIL_H */

  reply	other threads:[~2016-10-28 13:30 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-27 20:40 [GIT PULL 00/15] perf/core improvements and fixes Arnaldo Carvalho de Melo
2016-10-27 20:40 ` [PATCH 01/15] perf bench futex: Avoid worker cacheline bouncing Arnaldo Carvalho de Melo
2016-10-27 20:40 ` [PATCH 02/15] perf bench futex: Sanitize numeric parameters Arnaldo Carvalho de Melo
2016-10-27 20:40 ` [PATCH 03/15] perf hist browser: Fix hierarchy column counts Arnaldo Carvalho de Melo
2016-10-27 20:40 ` [PATCH 04/15] tools lib subcmd: Suppport cascading options Arnaldo Carvalho de Melo
2016-10-27 20:40 ` [PATCH 05/15] perf sched: Make common options cascading Arnaldo Carvalho de Melo
2016-10-27 20:40 ` [PATCH 06/15] perf sched map: Apply cpu color when there's an activity Arnaldo Carvalho de Melo
2016-10-27 20:40 ` [PATCH 07/15] perf sched map: Always show task comm with -v Arnaldo Carvalho de Melo
2016-10-27 20:40 ` [PATCH 08/15] perf tools: Introduce timestamp_in_usec() Arnaldo Carvalho de Melo
2016-10-27 23:14   ` Joonwoo Park
2016-10-28 12:53     ` Arnaldo Carvalho de Melo
2016-10-28 13:30       ` Arnaldo Carvalho de Melo [this message]
2016-10-28 14:42         ` [GIT PULL] " Arnaldo Carvalho de Melo
2016-10-28 17:39           ` Ingo Molnar
2016-10-28 17:46             ` Joonwoo Park
2016-10-27 20:40 ` [PATCH 09/15] perf list: Support matching by topic Arnaldo Carvalho de Melo
2016-10-27 20:40 ` [PATCH 10/15] perf bench mem: Ignore export.h related changes to mem{cpy,set}.S Arnaldo Carvalho de Melo
2016-10-27 20:40 ` [PATCH 11/15] tools: Update asm-generic/mman-common.h copy from the kernel Arnaldo Carvalho de Melo
2016-10-27 20:40 ` [PATCH 12/15] perf tools: Update x86's syscall_64.tbl, adding pkey_(alloc,free,mprotect) Arnaldo Carvalho de Melo
2016-10-27 20:40 ` [PATCH 13/15] perf scripting: Avoid leaking the scripting_context variable Arnaldo Carvalho de Melo
2016-10-27 20:40 ` [PATCH 14/15] perf scripting: Don't die if scripting can't be setup, disable it Arnaldo Carvalho de Melo
2016-10-27 20:40 ` [PATCH 15/15] perf tools: Add missing object file to the python binding linkage list Arnaldo Carvalho de Melo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161028133041.GC28694@kernel.org \
    --to=acme@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=dsahern@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=joonwoop@codeaurora.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).