linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Jiri Olsa <jolsa@kernel.org>, LKML <linux-kernel@vger.kernel.org>,
	David Ahern <dsahern@gmail.com>, Andi Kleen <andi@firstfloor.org>,
	Minchan Kim <minchan@kernel.org>
Subject: [PATCH v2 5/6] perf sched timehist: Add -I/--idle-hist option
Date: Thu,  8 Dec 2016 23:47:54 +0900	[thread overview]
Message-ID: <20161208144755.16673-6-namhyung@kernel.org> (raw)
In-Reply-To: <20161208144755.16673-1-namhyung@kernel.org>

The --idle-hist option is to analyze system idle state so which process
makes cpu to go idle.  If this option is specified, non-idle events will
be skipped and processes switching to/from idle will be shown.

This option is mostly useful when used with --summary(-only) option.  In
the idle-time summary view, idle time is accounted to previous thread
which is run before idle task.

The example output looks like following:

  Idle-time summary
                          comm  parent  sched-out    idle-time   min-idle    avg-idle    max-idle  stddev  migrations
                                          (count)       (msec)     (msec)      (msec)      (msec)       %
  -------------------------------------------------------------------------------------------------------------------
                rcu_preempt[7]       2         95      550.872      0.011       5.798      23.146    7.63       0
               migration/1[16]       2          1       15.558     15.558      15.558      15.558    0.00       0
                khugepaged[39]       2          1        3.062      3.062       3.062       3.062    0.00       0
             kworker/0:1H[124]       2          2        4.728      0.611       2.364       4.116   74.12       0
          systemd-journal[167]       1          1        4.510      4.510       4.510       4.510    0.00       0
            kworker/u16:3[558]       2         13       74.737      0.080       5.749      12.960   21.96       0
           irq/34-iwlwifi[628]       2         21      118.403      0.032       5.638      23.990   24.00       0
            kworker/u17:0[673]       2          1        3.523      3.523       3.523       3.523    0.00       0
              dbus-daemon[722]       1          1        6.743      6.743       6.743       6.743    0.00       0
                  ifplugd[741]       1          1       58.826     58.826      58.826      58.826    0.00       0
          wpa_supplicant[1490]       1          1       13.302     13.302      13.302      13.302    0.00       0
             wpa_actiond[1492]       1          2        4.064      0.168       2.032       3.896   91.72       0
                 dockerd[1500]       1          1        0.055      0.055       0.055       0.055    0.00       0
  ...

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/Documentation/perf-sched.txt |  4 ++++
 tools/perf/builtin-sched.c              | 38 ++++++++++++++++++++++++++++-----
 2 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/tools/perf/Documentation/perf-sched.txt b/tools/perf/Documentation/perf-sched.txt
index 7775b1eb2bee..76173969ab80 100644
--- a/tools/perf/Documentation/perf-sched.txt
+++ b/tools/perf/Documentation/perf-sched.txt
@@ -132,6 +132,10 @@ OPTIONS for 'perf sched timehist'
 --migrations::
 	Show migration events.
 
+-I::
+--idle-hist::
+	Show idle-related events 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
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index da3ff3253741..6dc9e00d6392 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -2420,7 +2420,28 @@ static int timehist_sched_change_event(struct perf_tool *tool,
 			t = ptime->end;
 	}
 
-	timehist_update_runtime_stats(tr, t, tprev);
+	if (!sched->idle_hist || thread->tid == 0) {
+		timehist_update_runtime_stats(tr, t, tprev);
+
+		if (sched->idle_hist) {
+			struct idle_thread_runtime *itr = (void *)tr;
+			struct thread_runtime *last_tr;
+
+			BUG_ON(thread->tid != 0);
+
+			if (itr->last_thread == NULL)
+				goto out;
+
+			/* add current idle time as last thread's runtime */
+			last_tr = thread__get_runtime(itr->last_thread);
+			if (last_tr == NULL)
+				goto out;
+
+			timehist_update_runtime_stats(last_tr, t, tprev);
+
+			itr->last_thread = NULL;
+		}
+	}
 
 	if (!sched->summary_only)
 		timehist_print_sample(sched, sample, &al, thread, t);
@@ -2542,9 +2563,15 @@ static void timehist_print_summary(struct perf_sched *sched,
 	if (comm_width < 30)
 		comm_width = 30;
 
-	printf("\nRuntime summary\n");
-	printf("%*s  parent   sched-in  ", comm_width, "comm");
-	printf("   run-time    min-run     avg-run     max-run  stddev  migrations\n");
+	if (sched->idle_hist) {
+		printf("\nIdle-time summary\n");
+		printf("%*s  parent  sched-out  ", comm_width, "comm");
+		printf("  idle-time   min-idle    avg-idle    max-idle  stddev  migrations\n");
+	} else {
+		printf("\nRuntime summary\n");
+		printf("%*s  parent   sched-in  ", comm_width, "comm");
+		printf("   run-time    min-run     avg-run     max-run  stddev  migrations\n");
+	}
 	printf("%*s            (count)  ", comm_width, "");
 	printf("     (msec)     (msec)      (msec)      (msec)       %%\n");
 	printf("%.117s\n", graph_dotted_line);
@@ -2560,7 +2587,7 @@ static void timehist_print_summary(struct perf_sched *sched,
 		printf("<no terminated tasks>\n");
 
 	/* CPU idle stats not tracked when samples were skipped */
-	if (sched->skipped_samples)
+	if (sched->skipped_samples && !sched->idle_hist)
 		return;
 
 	printf("\nIdle stats:\n");
@@ -3106,6 +3133,7 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)
 	OPT_BOOLEAN('w', "wakeups", &sched.show_wakeups, "Show wakeup events"),
 	OPT_BOOLEAN('M', "migrations", &sched.show_migrations, "Show migration events"),
 	OPT_BOOLEAN('V', "cpu-visual", &sched.show_cpu_visual, "Add CPU visual"),
+	OPT_BOOLEAN('I', "idle-hist", &sched.idle_hist, "Show idle events only"),
 	OPT_STRING(0, "time", &sched.time_str, "str",
 		   "Time span for analysis (start,stop)"),
 	OPT_PARENT(sched_options)
-- 
2.10.1

  parent reply	other threads:[~2016-12-08 14:49 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-08 14:47 [PATCHSET 0/6] perf sched timehist: Introduce --idle-hist option (v2) Namhyung Kim
2016-12-08 14:47 ` [PATCH v2 1/6] perf sched timehist: Split is_idle_sample() Namhyung Kim
2016-12-20 19:19   ` [tip:perf/urgent] " tip-bot for Namhyung Kim
2016-12-08 14:47 ` [PATCH v2 2/6] perf sched timehist: Introduce struct idle_time_data Namhyung Kim
2016-12-20 19:20   ` [tip:perf/urgent] " tip-bot for Namhyung Kim
2016-12-08 14:47 ` [PATCH v2 3/6] perf sched timehist: Save callchain when entering idle Namhyung Kim
2016-12-13  8:06   ` [PATCH 1/2] perf sched timehist: Fix --idle-hist when no callchains Namhyung Kim
2016-12-13  8:06     ` [PATCH 2/2] perf sched timehist: Fix invalid runtime in the idle hist Namhyung Kim
2016-12-13 10:32       ` Arnaldo Carvalho de Melo
2016-12-13 10:54         ` Namhyung Kim
2016-12-13 13:12           ` Arnaldo Carvalho de Melo
2016-12-20 19:21       ` [tip:perf/urgent] perf sched timehist: Add -I/--idle-hist option tip-bot for Namhyung Kim
2016-12-13 10:32     ` [PATCH 1/2] perf sched timehist: Fix --idle-hist when no callchains Arnaldo Carvalho de Melo
2016-12-13 10:49       ` Namhyung Kim
2016-12-13 12:03         ` Arnaldo Carvalho de Melo
2016-12-13 13:04         ` Arnaldo Carvalho de Melo
2016-12-20 19:20     ` [tip:perf/urgent] perf sched timehist: Save callchain when entering idle tip-bot for Namhyung Kim
2016-12-08 14:47 ` [PATCH v2 4/6] perf sched timehist: Skip non-idle events when necessary Namhyung Kim
2016-12-20 19:21   ` [tip:perf/urgent] " tip-bot for Namhyung Kim
2016-12-08 14:47 ` Namhyung Kim [this message]
2016-12-08 14:47 ` [PATCH v2 6/6] perf sched timehist: Show callchains for idle stat Namhyung Kim
2016-12-20 19:22   ` [tip:perf/urgent] " tip-bot for Namhyung Kim
2016-12-10 16:32 ` [PATCHSET 0/6] perf sched timehist: Introduce --idle-hist option (v2) David Ahern
2016-12-12 17:26   ` Namhyung Kim
2016-12-12 17:37     ` David Ahern
2016-12-13  8:05       ` Namhyung Kim
2016-12-14 21:33         ` David Ahern
2016-12-15 15:17           ` Namhyung Kim

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=20161208144755.16673-6-namhyung@kernel.org \
    --to=namhyung@kernel.org \
    --cc=acme@kernel.org \
    --cc=andi@firstfloor.org \
    --cc=dsahern@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=minchan@kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.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).