linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@infradead.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, Jiri Olsa <jolsa@redhat.com>,
	Corey Ashford <cjashfor@linux.vnet.ibm.com>,
	David Ahern <dsahern@gmail.com>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Ingo Molnar <mingo@elte.hu>, Namhyung Kim <namhyung@kernel.org>,
	Paul Mackerras <paulus@samba.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Steven Rostedt <rostedt@goodmis.org>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 28/38] tools lib traceevent: Add sched_switch plugin
Date: Wed,  4 Dec 2013 17:06:52 -0300	[thread overview]
Message-ID: <1386187622-2928-29-git-send-email-acme@infradead.org> (raw)
In-Reply-To: <1386187622-2928-1-git-send-email-acme@infradead.org>

From: Jiri Olsa <jolsa@redhat.com>

Backporting sched_switch plugin.

Backported from Steven Rostedt's trace-cmd repo (HEAD 0f2c2fb):
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/trace-cmd.git

This plugin adds fields resolving for sched:sched_switch tracepoint
event.

The diff of 'perf script' output generated by old and new code:
(data was generated by 'perf record -e sched:sched_switch -a')

  --- script.sched_switch.old
  +++ script.sched_switch.new
  -            perf   577 [002] 30965.311852: sched:sched_switch: prev_comm=perf prev_pid=577 prev_prio=120 prev_state=S ==> next_comm=swapper/2 next_pid=0 next_prio=120
  +            perf   577 [002] 30965.311852: sched:sched_switch: perf:577 [120] S ==> swapper/2:0 [120]

Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/1386076182-14484-18-git-send-email-jolsa@redhat.com
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/lib/traceevent/Makefile              |   1 +
 tools/lib/traceevent/plugin_sched_switch.c | 148 +++++++++++++++++++++++++++++
 2 files changed, 149 insertions(+)
 create mode 100644 tools/lib/traceevent/plugin_sched_switch.c

diff --git a/tools/lib/traceevent/Makefile b/tools/lib/traceevent/Makefile
index d0e0ca12aa10..1c319a8cf1b0 100644
--- a/tools/lib/traceevent/Makefile
+++ b/tools/lib/traceevent/Makefile
@@ -217,6 +217,7 @@ PLUGIN_OBJS += plugin_hrtimer.o
 PLUGIN_OBJS += plugin_kmem.o
 PLUGIN_OBJS += plugin_kvm.o
 PLUGIN_OBJS += plugin_mac80211.o
+PLUGIN_OBJS += plugin_sched_switch.o
 
 PLUGINS := $(PLUGIN_OBJS:.o=.so)
 
diff --git a/tools/lib/traceevent/plugin_sched_switch.c b/tools/lib/traceevent/plugin_sched_switch.c
new file mode 100644
index 000000000000..fea3724aa24f
--- /dev/null
+++ b/tools/lib/traceevent/plugin_sched_switch.c
@@ -0,0 +1,148 @@
+/*
+ * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License (not later!)
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not,  see <http://www.gnu.org/licenses>
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "event-parse.h"
+
+static void write_state(struct trace_seq *s, int val)
+{
+	const char states[] = "SDTtZXxW";
+	int found = 0;
+	int i;
+
+	for (i = 0; i < (sizeof(states) - 1); i++) {
+		if (!(val & (1 << i)))
+			continue;
+
+		if (found)
+			trace_seq_putc(s, '|');
+
+		found = 1;
+		trace_seq_putc(s, states[i]);
+	}
+
+	if (!found)
+		trace_seq_putc(s, 'R');
+}
+
+static void write_and_save_comm(struct format_field *field,
+				struct pevent_record *record,
+				struct trace_seq *s, int pid)
+{
+	const char *comm;
+	int len;
+
+	comm = (char *)(record->data + field->offset);
+	len = s->len;
+	trace_seq_printf(s, "%.*s",
+			 field->size, comm);
+
+	/* make sure the comm has a \0 at the end. */
+	trace_seq_terminate(s);
+	comm = &s->buffer[len];
+
+	/* Help out the comm to ids. This will handle dups */
+	pevent_register_comm(field->event->pevent, comm, pid);
+}
+
+static int sched_wakeup_handler(struct trace_seq *s,
+				struct pevent_record *record,
+				struct event_format *event, void *context)
+{
+	struct format_field *field;
+	unsigned long long val;
+
+	if (pevent_get_field_val(s, event, "pid", record, &val, 1))
+		return trace_seq_putc(s, '!');
+
+	field = pevent_find_any_field(event, "comm");
+	if (field) {
+		write_and_save_comm(field, record, s, val);
+		trace_seq_putc(s, ':');
+	}
+	trace_seq_printf(s, "%lld", val);
+
+	if (pevent_get_field_val(s, event, "prio", record, &val, 0) == 0)
+		trace_seq_printf(s, " [%lld]", val);
+
+	if (pevent_get_field_val(s, event, "success", record, &val, 1) == 0)
+		trace_seq_printf(s, " success=%lld", val);
+
+	if (pevent_get_field_val(s, event, "target_cpu", record, &val, 0) == 0)
+		trace_seq_printf(s, " CPU:%03llu", val);
+
+	return 0;
+}
+
+static int sched_switch_handler(struct trace_seq *s,
+				struct pevent_record *record,
+				struct event_format *event, void *context)
+{
+	struct format_field *field;
+	unsigned long long val;
+
+	if (pevent_get_field_val(s, event, "prev_pid", record, &val, 1))
+		return trace_seq_putc(s, '!');
+
+	field = pevent_find_any_field(event, "prev_comm");
+	if (field) {
+		write_and_save_comm(field, record, s, val);
+		trace_seq_putc(s, ':');
+	}
+	trace_seq_printf(s, "%lld ", val);
+
+	if (pevent_get_field_val(s, event, "prev_prio", record, &val, 0) == 0)
+		trace_seq_printf(s, "[%lld] ", val);
+
+	if (pevent_get_field_val(s,  event, "prev_state", record, &val, 0) == 0)
+		write_state(s, val);
+
+	trace_seq_puts(s, " ==> ");
+
+	if (pevent_get_field_val(s, event, "next_pid", record, &val, 1))
+		return trace_seq_putc(s, '!');
+
+	field = pevent_find_any_field(event, "next_comm");
+	if (field) {
+		write_and_save_comm(field, record, s, val);
+		trace_seq_putc(s, ':');
+	}
+	trace_seq_printf(s, "%lld", val);
+
+	if (pevent_get_field_val(s, event, "next_prio", record, &val, 0) == 0)
+		trace_seq_printf(s, " [%lld]", val);
+
+	return 0;
+}
+
+int PEVENT_PLUGIN_LOADER(struct pevent *pevent)
+{
+	pevent_register_event_handler(pevent, -1, "sched", "sched_switch",
+				      sched_switch_handler, NULL);
+
+	pevent_register_event_handler(pevent, -1, "sched", "sched_wakeup",
+				      sched_wakeup_handler, NULL);
+
+	pevent_register_event_handler(pevent, -1, "sched", "sched_wakeup_new",
+				      sched_wakeup_handler, NULL);
+	return 0;
+}
-- 
1.8.1.4


  parent reply	other threads:[~2013-12-04 20:14 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-04 20:06 [GIT PULL 00/38] perf/core improvements and fixes Arnaldo Carvalho de Melo
2013-12-04 20:06 ` [PATCH 01/38] perf tools: Use asprintf instead of malloc plus snprintf Arnaldo Carvalho de Melo
2013-12-11 22:16   ` Andi Kleen
2013-12-12 14:57     ` Arnaldo Carvalho de Melo
2013-12-04 20:06 ` [PATCH 02/38] perf symbols: Retain bfd reference to lookup source line numbers Arnaldo Carvalho de Melo
2013-12-04 20:06 ` [PATCH 03/38] perf symbols: Retain symbol source file name " Arnaldo Carvalho de Melo
2013-12-04 20:06 ` [PATCH 04/38] perf tools: Do not disable source line lookup just because of 1 failure Arnaldo Carvalho de Melo
2013-12-04 20:06 ` [PATCH 05/38] perf tools: Remove stackprotector feature check Arnaldo Carvalho de Melo
2013-12-04 20:06 ` [PATCH 06/38] perf tools: Remove condition in machine__get_kernel_start_addr Arnaldo Carvalho de Melo
2013-12-04 20:06 ` [PATCH 07/38] perf target: Move the checking of which map function to call into function Arnaldo Carvalho de Melo
2013-12-04 20:06 ` [PATCH 08/38] perf kvm: Add more detail about buildid-list in man page Arnaldo Carvalho de Melo
2013-12-04 20:06 ` [PATCH 09/38] perf kvm: Fix spurious '=' use " Arnaldo Carvalho de Melo
2013-12-04 20:06 ` [PATCH 10/38] perf kvm: Update the 'record' man page entry for new --guest/--host behavior Arnaldo Carvalho de Melo
2013-12-04 20:06 ` [PATCH 11/38] perf symbols: Fix random fd closing with no libelf Arnaldo Carvalho de Melo
2013-12-04 20:06 ` [PATCH 12/38] perf script: Do not call perf_event__preprocess_sample() twice) Arnaldo Carvalho de Melo
2013-12-04 20:06 ` [PATCH 13/38] tools lib traceevent: Add plugin support Arnaldo Carvalho de Melo
2013-12-04 20:06 ` [PATCH 14/38] tools lib traceevent: Add plugin build support Arnaldo Carvalho de Melo
2013-12-04 20:06 ` [PATCH 15/38] tools lib traceevent: Add traceevent_host_bigendian function Arnaldo Carvalho de Melo
2013-12-04 20:06 ` [PATCH 16/38] tools lib traceevent: Change pevent_parse_format to include pevent handle Arnaldo Carvalho de Melo
2013-12-04 20:06 ` [PATCH 17/38] tools lib traceevent: Harmonize the install messages in lib-traceevent Arnaldo Carvalho de Melo
2013-12-04 20:06 ` [PATCH 18/38] perf tools: Add build and install plugins targets Arnaldo Carvalho de Melo
2013-12-04 20:06 ` [PATCH 19/38] perf tools: Add filename__read_str util function Arnaldo Carvalho de Melo
2013-12-04 20:06 ` [PATCH 20/38] perf tools: Add trace-event object Arnaldo Carvalho de Melo
2013-12-04 20:06 ` [PATCH 21/38] perf tools: Add trace-event global object for tracepoint interface Arnaldo Carvalho de Melo
2013-12-04 20:06 ` [PATCH 22/38] perf tools: Overload pr_stat traceevent print function Arnaldo Carvalho de Melo
2013-12-04 20:06 ` [PATCH 23/38] tools lib traceevent: Add jbd2 plugin Arnaldo Carvalho de Melo
2013-12-04 20:06 ` [PATCH 24/38] tools lib traceevent: Add hrtimer plugin Arnaldo Carvalho de Melo
2013-12-04 20:06 ` [PATCH 25/38] tools lib traceevent: Add kmem plugin Arnaldo Carvalho de Melo
2013-12-04 20:06 ` [PATCH 26/38] tools lib traceevent: Add kvm plugin Arnaldo Carvalho de Melo
2013-12-04 20:06 ` [PATCH 27/38] tools lib traceevent: Add mac80211 plugin Arnaldo Carvalho de Melo
2014-06-13  3:13   ` Steven Rostedt
2014-06-13 17:57     ` Johannes Berg
2014-06-13 18:18       ` Steven Rostedt
2013-12-04 20:06 ` Arnaldo Carvalho de Melo [this message]
2013-12-04 20:06 ` [PATCH 29/38] tools lib traceevent: Add function plugin Arnaldo Carvalho de Melo
2013-12-04 20:06 ` [PATCH 30/38] tools lib traceevent: Add xen plugin Arnaldo Carvalho de Melo
2013-12-04 20:06 ` [PATCH 31/38] tools lib traceevent: Add scsi plugin Arnaldo Carvalho de Melo
2013-12-04 20:06 ` [PATCH 32/38] tools lib traceevent: Add cfg80211 plugin Arnaldo Carvalho de Melo
2013-12-04 20:06 ` [PATCH 33/38] tools lib traceevent: Remove malloc_or_die from event-plugin.c Arnaldo Carvalho de Melo
2013-12-04 20:06 ` [PATCH 34/38] tools lib traceevent: Use static functions in jbd2 plugin Arnaldo Carvalho de Melo
2013-12-04 20:06 ` [PATCH 35/38] tools lib traceevent: Use pevent_print_func_field in hrtimer_start handler Arnaldo Carvalho de Melo
2013-12-04 20:07 ` [PATCH 36/38] tools lib traceevent: Several cleanups for function plugin Arnaldo Carvalho de Melo
2013-12-04 20:07 ` [PATCH 37/38] tools lib traceevent: Remove malloc_or_die from plugin_function.c Arnaldo Carvalho de Melo
2013-12-04 20:07 ` [PATCH 38/38] tools lib traceevent: Update kvm plugin with is_writable_pte helper Arnaldo Carvalho de Melo
2013-12-05 10:04 ` [GIT PULL 00/38] perf/core improvements and fixes Ingo Molnar
2013-12-05 10:37   ` Jiri Olsa
2013-12-05 10:53     ` Ingo Molnar
2013-12-05 10:59       ` Ingo Molnar
2013-12-05 11:13         ` Jiri Olsa
2013-12-05 12:27           ` Ingo Molnar
2013-12-05 12:35             ` Jiri Olsa
2013-12-05 11:05       ` Jiri Olsa

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=1386187622-2928-29-git-send-email-acme@infradead.org \
    --to=acme@infradead.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=cjashfor@linux.vnet.ibm.com \
    --cc=dsahern@gmail.com \
    --cc=fweisbec@gmail.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=paulus@samba.org \
    --cc=rostedt@goodmis.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).