Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1225030imm; Tue, 5 Jun 2018 10:58:54 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJuhqKR4Uogvif7h/y39fp0Vx+QpQNEQIBdKcZag4VSawM6/FrGomxOUKKAQm/SQ7X+pI59 X-Received: by 2002:a62:4e07:: with SMTP id c7-v6mr26724546pfb.149.1528221534078; Tue, 05 Jun 2018 10:58:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528221534; cv=none; d=google.com; s=arc-20160816; b=uERsZ/lTnEcDrbBgvafvJdry8yrVMt/MtY7apBmale+ki44Zj5EI6Dm9+//MRfKpn2 Sro38nANsupFQHzZYX+Pozn/EULf3zLEqB7lt9bBcYgpQivEOSeS+F2WNrpcgct2QT/G iGMP6xk6+ErcoJN5hmy4ugczOI0XvNjSQ/UYZ3DJ/e/Kww3Qx5uduFfKnTaO5GO2h4PP oHLdUE0kL/EVNhJN3HaPkS46gXDwXiQ+TJbNuuM7TyM3OWV2UuR3oJ7QinMcVcClzPZy 1RS/xpwyocXe/hKlqqDnz9HSWVlNqnxrc/68J3Ulq9wu7m7rOgY1OKSG2BdXYseNcas4 z4rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=PKENgJ/l2RZLTZdRXbNg8SdSjKVkU5/kenNCiWuA92U=; b=emKt6cNsDjlMP/X/9yBLA5kTHcsSE6A53J7h8dL3Y5KHsIYjc5zePg4r9fUBYj1uAL s6Ws6LTp8xfnbKB1WL7qlxPdjY/Tlne8R8GcSZvI932Mdd2VAW2rvtx9XNjjJqL8c2qU kNAGaVuASkDNBhV6L11mnhs3eWYSLipm1ouJoXhTnO8svFkodgtvGp5Xu5JOGvo8PySm TUVfvXrnsJHB0vvZi/qmVYlnt87DIAjp+r1nNldjF4jkjjWGGlOveSa6hHDeINEeDYW/ mhOD61t8OZDo4JGrbF7yJAuKyXb8e4rD+yRaiOD2YRYad87V3M3EbFOBGB4RDxpS0PE1 509w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dSSylZPA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h193-v6si39541332pgc.57.2018.06.05.10.58.39; Tue, 05 Jun 2018 10:58:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dSSylZPA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753382AbeFER5r (ORCPT + 99 others); Tue, 5 Jun 2018 13:57:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:46558 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752963AbeFERwa (ORCPT ); Tue, 5 Jun 2018 13:52:30 -0400 Received: from jouet.infradead.org (unknown [179.97.41.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D6B822075B; Tue, 5 Jun 2018 17:52:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1528221150; bh=GiCKJ+KQQ2m0rTV4++bmtdMWE8bjI+9FO2O3/Ld3cu8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dSSylZPAox0EG4vzzkqgm6fBHdRi7uUT5V/2WVXhZGPigMM71CgkaHBPBCucAZGyr ZjZ2Z1CD6wie2wOX3UbXLxyMZhs2StyZCMbpKdQ6vA3zv7JxCE85fciz84ZW2GutPP xffAo+lwLwH4OKn8OuDN7+4asF8OcG1U8GdcejlA= From: Arnaldo Carvalho de Melo To: Ingo Molnar Cc: Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Jiri Olsa , Alexander Shishkin , David Ahern , Namhyung Kim , Peter Zijlstra , Arnaldo Carvalho de Melo Subject: [PATCH 37/46] perf stat: Display user and system time Date: Tue, 5 Jun 2018 14:50:21 -0300 Message-Id: <20180605175030.32549-38-acme@kernel.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180605175030.32549-1-acme@kernel.org> References: <20180605175030.32549-1-acme@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jiri Olsa Adding the support to read rusage data once the workload is finished and display the system/user time values: $ perf stat --null perf bench sched pipe ... Performance counter stats for 'perf bench sched pipe': 5.342599256 seconds time elapsed 2.544434000 seconds user 4.549691000 seconds sys It works only in non -r mode and only for workload target. So as of now, for workload targets, we display 3 types of timings. The time we meassure in perf stat from enable to disable+period: 5.342599256 seconds time elapsed The time spent in user and system lands, displayed only for workload session/target: 2.544434000 seconds user 4.549691000 seconds sys Those times are the very same displayed by 'time' tool. They are returned by wait4 call via the getrusage struct interface. Committer notes: Had to rename some variables to avoid this on older systems such as centos:6: builtin-stat.c: In function 'print_footer': builtin-stat.c:1831: warning: declaration of 'stime' shadows a global declaration /usr/include/time.h:297: warning: shadowed declaration is here Committer testing: # perf stat --null time perf bench sched pipe # Running 'sched/pipe' benchmark: # Executed 1000000 pipe operations between two processes Total time: 5.526 [sec] 5.526534 usecs/op 180945 ops/sec 1.00user 6.25system 0:05.52elapsed 131%CPU (0avgtext+0avgdata 8056maxresident)k 0inputs+0outputs (0major+606minor)pagefaults 0swaps Performance counter stats for 'time perf bench sched pipe': 5.530978744 seconds time elapsed 1.004037000 seconds user 6.259937000 seconds sys # Suggested-by: Ingo Molnar Signed-off-by: Jiri Olsa Tested-by: Arnaldo Carvalho de Melo Cc: Alexander Shishkin Cc: David Ahern Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/20180605121313.31337-1-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/Documentation/perf-stat.txt | 40 ++++++++++++++++++++++++---------- tools/perf/builtin-stat.c | 28 +++++++++++++++++++++++- 2 files changed, 56 insertions(+), 12 deletions(-) diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt index 3a822f308e6d..5dfe102fb5b5 100644 --- a/tools/perf/Documentation/perf-stat.txt +++ b/tools/perf/Documentation/perf-stat.txt @@ -310,20 +310,38 @@ Users who wants to get the actual value can apply --no-metric-only. EXAMPLES -------- -$ perf stat -- make -j +$ perf stat -- make - Performance counter stats for 'make -j': + Performance counter stats for 'make': - 8117.370256 task clock ticks # 11.281 CPU utilization factor - 678 context switches # 0.000 M/sec - 133 CPU migrations # 0.000 M/sec - 235724 pagefaults # 0.029 M/sec - 24821162526 CPU cycles # 3057.784 M/sec - 18687303457 instructions # 2302.138 M/sec - 172158895 cache references # 21.209 M/sec - 27075259 cache misses # 3.335 M/sec + 83723.452481 task-clock:u (msec) # 1.004 CPUs utilized + 0 context-switches:u # 0.000 K/sec + 0 cpu-migrations:u # 0.000 K/sec + 3,228,188 page-faults:u # 0.039 M/sec + 229,570,665,834 cycles:u # 2.742 GHz + 313,163,853,778 instructions:u # 1.36 insn per cycle + 69,704,684,856 branches:u # 832.559 M/sec + 2,078,861,393 branch-misses:u # 2.98% of all branches - Wall-clock time elapsed: 719.554352 msecs + 83.409183620 seconds time elapsed + + 74.684747000 seconds user + 8.739217000 seconds sys + +TIMINGS +------- +As displayed in the example above we can display 3 types of timings. +We always display the time the counters were enabled/alive: + + 83.409183620 seconds time elapsed + +For workload sessions we also display time the workloads spent in +user/system lands: + + 74.684747000 seconds user + 8.739217000 seconds sys + +Those times are the very same as displayed by the 'time' tool. CSV FORMAT ---------- diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index a4f662a462c6..096ccb25c11f 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -80,6 +80,9 @@ #include #include #include +#include +#include +#include #include "sane_ctype.h" @@ -175,6 +178,8 @@ static int output_fd; static int print_free_counters_hint; static int print_mixed_hw_group_error; static u64 *walltime_run; +static bool ru_display = false; +static struct rusage ru_data; struct perf_stat { bool record; @@ -726,7 +731,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx) break; } } - waitpid(child_pid, &status, 0); + wait4(child_pid, &status, 0, &ru_data); if (workload_exec_errno) { const char *emsg = str_error_r(workload_exec_errno, msg, sizeof(msg)); @@ -1804,6 +1809,11 @@ static void print_table(FILE *output, int precision, double avg) fprintf(output, "\n%*s# Final result:\n", indent, ""); } +static double timeval2double(struct timeval *t) +{ + return t->tv_sec + (double) t->tv_usec/USEC_PER_SEC; +} + static void print_footer(void) { double avg = avg_stats(&walltime_nsecs_stats) / NSEC_PER_SEC; @@ -1815,6 +1825,15 @@ static void print_footer(void) if (run_count == 1) { fprintf(output, " %17.9f seconds time elapsed", avg); + + if (ru_display) { + double ru_utime = timeval2double(&ru_data.ru_utime); + double ru_stime = timeval2double(&ru_data.ru_stime); + + fprintf(output, "\n\n"); + fprintf(output, " %17.9f seconds user\n", ru_utime); + fprintf(output, " %17.9f seconds sys\n", ru_stime); + } } else { double sd = stddev_stats(&walltime_nsecs_stats) / NSEC_PER_SEC; /* @@ -2950,6 +2969,13 @@ int cmd_stat(int argc, const char **argv) setup_system_wide(argc); + /* + * Display user/system times only for single + * run and when there's specified tracee. + */ + if ((run_count == 1) && target__none(&target)) + ru_display = true; + if (run_count < 0) { pr_err("Run count must be a positive number\n"); parse_options_usage(stat_usage, stat_options, "r", 1); -- 2.14.3