aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung@kernel.org>2016-10-23 22:02:45 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-10-28 09:29:40 -0400
commit99620a5d0cc8e2dd9aedb629a6e81825f0db020e (patch)
tree4aaa056d98c2114a3af9c7b206c2b28268564d80 /tools
parente107f129e2e0e75ddf1cd7995a9f5ffff2307766 (diff)
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>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/builtin-sched.c10
-rw-r--r--tools/perf/builtin-script.c10
-rw-r--r--tools/perf/util/util.c8
-rw-r--r--tools/perf/util/util.h3
4 files changed, 24 insertions, 7 deletions
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_
1191 int i; 1191 int i;
1192 int ret; 1192 int ret;
1193 u64 avg; 1193 u64 avg;
1194 char max_lat_at[32];
1194 1195
1195 if (!work_list->nb_atoms) 1196 if (!work_list->nb_atoms)
1196 return; 1197 return;
@@ -1212,12 +1213,13 @@ static void output_lat_thread(struct perf_sched *sched, struct work_atoms *work_
1212 printf(" "); 1213 printf(" ");
1213 1214
1214 avg = work_list->total_lat / work_list->nb_atoms; 1215 avg = work_list->total_lat / work_list->nb_atoms;
1216 timestamp__scnprintf_usec(work_list->max_lat_at, max_lat_at, sizeof(max_lat_at));
1215 1217
1216 printf("|%11.3f ms |%9" PRIu64 " | avg:%9.3f ms | max:%9.3f ms | max at: %13.6f s\n", 1218 printf("|%11.3f ms |%9" PRIu64 " | avg:%9.3f ms | max:%9.3f ms | max at: %13s s\n",
1217 (double)work_list->total_runtime / NSEC_PER_MSEC, 1219 (double)work_list->total_runtime / NSEC_PER_MSEC,
1218 work_list->nb_atoms, (double)avg / NSEC_PER_MSEC, 1220 work_list->nb_atoms, (double)avg / NSEC_PER_MSEC,
1219 (double)work_list->max_lat / NSEC_PER_MSEC, 1221 (double)work_list->max_lat / NSEC_PER_MSEC,
1220 (double)work_list->max_lat_at / NSEC_PER_SEC); 1222 max_lat_at);
1221} 1223}
1222 1224
1223static int pid_cmp(struct work_atoms *l, struct work_atoms *r) 1225static 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,
1402 int cpus_nr; 1404 int cpus_nr;
1403 bool new_cpu = false; 1405 bool new_cpu = false;
1404 const char *color = PERF_COLOR_NORMAL; 1406 const char *color = PERF_COLOR_NORMAL;
1407 char stimestamp[32];
1405 1408
1406 BUG_ON(this_cpu >= MAX_CPUS || this_cpu < 0); 1409 BUG_ON(this_cpu >= MAX_CPUS || this_cpu < 0);
1407 1410
@@ -1492,7 +1495,8 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,
1492 if (sched->map.cpus && !cpu_map__has(sched->map.cpus, this_cpu)) 1495 if (sched->map.cpus && !cpu_map__has(sched->map.cpus, this_cpu))
1493 goto out; 1496 goto out;
1494 1497
1495 color_fprintf(stdout, color, " %12.6f secs ", (double)timestamp / NSEC_PER_SEC); 1498 timestamp__scnprintf_usec(timestamp, stimestamp, sizeof(stimestamp));
1499 color_fprintf(stdout, color, " %12s secs ", stimestamp);
1496 if (new_shortname || (verbose && sched_in->tid)) { 1500 if (new_shortname || (verbose && sched_in->tid)) {
1497 const char *pid_color = color; 1501 const char *pid_color = color;
1498 1502
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,
441{ 441{
442 struct perf_event_attr *attr = &evsel->attr; 442 struct perf_event_attr *attr = &evsel->attr;
443 unsigned long secs; 443 unsigned long secs;
444 unsigned long usecs;
445 unsigned long long nsecs; 444 unsigned long long nsecs;
446 445
447 if (PRINT_FIELD(COMM)) { 446 if (PRINT_FIELD(COMM)) {
@@ -471,11 +470,14 @@ static void print_sample_start(struct perf_sample *sample,
471 nsecs = sample->time; 470 nsecs = sample->time;
472 secs = nsecs / NSEC_PER_SEC; 471 secs = nsecs / NSEC_PER_SEC;
473 nsecs -= secs * NSEC_PER_SEC; 472 nsecs -= secs * NSEC_PER_SEC;
474 usecs = nsecs / NSEC_PER_USEC; 473
475 if (nanosecs) 474 if (nanosecs)
476 printf("%5lu.%09llu: ", secs, nsecs); 475 printf("%5lu.%09llu: ", secs, nsecs);
477 else 476 else {
478 printf("%5lu.%06lu: ", secs, usecs); 477 char sample_time[32];
478 timestamp__scnprintf_usec(sample->time, sample_time, sizeof(sample_time));
479 printf("%12s: ", sample_time);
480 }
479 } 481 }
480} 482}
481 483
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)
433 return 0; 433 return 0;
434} 434}
435 435
436int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz)
437{
438 u64 sec = timestamp / NSEC_PER_SEC;
439 u64 usec = (timestamp % NSEC_PER_SEC) / NSEC_PER_USEC;
440
441 return scnprintf(buf, sz, "%"PRIu64".%06"PRIu64, sec, usec);
442}
443
436unsigned long parse_tag_value(const char *str, struct parse_tag *tags) 444unsigned long parse_tag_value(const char *str, struct parse_tag *tags)
437{ 445{
438 struct parse_tag *i = tags; 446 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);
362#endif 362#endif
363 363
364int is_printable_array(char *p, unsigned int len); 364int is_printable_array(char *p, unsigned int len);
365
366int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz);
367
365#endif /* GIT_COMPAT_UTIL_H */ 368#endif /* GIT_COMPAT_UTIL_H */