~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/lib/traceevent/plugin_sched_switch.c

Version: ~ [ linux-5.1-rc5 ] ~ [ linux-5.0.7 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.34 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.111 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.168 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.178 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.138 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.65 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.39.4 ] ~ [ linux-2.6.38.8 ] ~ [ linux-2.6.37.6 ] ~ [ linux-2.6.36.4 ] ~ [ linux-2.6.35.14 ] ~ [ linux-2.6.34.15 ] ~ [ linux-2.6.33.20 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
  3  *
  4  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5  * This program is free software; you can redistribute it and/or
  6  * modify it under the terms of the GNU Lesser General Public
  7  * License as published by the Free Software Foundation;
  8  * version 2.1 of the License (not later!)
  9  *
 10  * This program is distributed in the hope that it will be useful,
 11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  * GNU Lesser General Public License for more details.
 14  *
 15  * You should have received a copy of the GNU Lesser General Public
 16  * License along with this program; if not,  see <http://www.gnu.org/licenses>
 17  *
 18  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 19  */
 20 #include <stdio.h>
 21 #include <stdlib.h>
 22 #include <string.h>
 23 
 24 #include "event-parse.h"
 25 #include "trace-seq.h"
 26 
 27 static void write_state(struct trace_seq *s, int val)
 28 {
 29         const char states[] = "SDTtZXxW";
 30         int found = 0;
 31         int i;
 32 
 33         for (i = 0; i < (sizeof(states) - 1); i++) {
 34                 if (!(val & (1 << i)))
 35                         continue;
 36 
 37                 if (found)
 38                         trace_seq_putc(s, '|');
 39 
 40                 found = 1;
 41                 trace_seq_putc(s, states[i]);
 42         }
 43 
 44         if (!found)
 45                 trace_seq_putc(s, 'R');
 46 }
 47 
 48 static void write_and_save_comm(struct tep_format_field *field,
 49                                 struct tep_record *record,
 50                                 struct trace_seq *s, int pid)
 51 {
 52         const char *comm;
 53         int len;
 54 
 55         comm = (char *)(record->data + field->offset);
 56         len = s->len;
 57         trace_seq_printf(s, "%.*s",
 58                          field->size, comm);
 59 
 60         /* make sure the comm has a \0 at the end. */
 61         trace_seq_terminate(s);
 62         comm = &s->buffer[len];
 63 
 64         /* Help out the comm to ids. This will handle dups */
 65         tep_register_comm(field->event->pevent, comm, pid);
 66 }
 67 
 68 static int sched_wakeup_handler(struct trace_seq *s,
 69                                 struct tep_record *record,
 70                                 struct tep_event *event, void *context)
 71 {
 72         struct tep_format_field *field;
 73         unsigned long long val;
 74 
 75         if (tep_get_field_val(s, event, "pid", record, &val, 1))
 76                 return trace_seq_putc(s, '!');
 77 
 78         field = tep_find_any_field(event, "comm");
 79         if (field) {
 80                 write_and_save_comm(field, record, s, val);
 81                 trace_seq_putc(s, ':');
 82         }
 83         trace_seq_printf(s, "%lld", val);
 84 
 85         if (tep_get_field_val(s, event, "prio", record, &val, 0) == 0)
 86                 trace_seq_printf(s, " [%lld]", val);
 87 
 88         if (tep_get_field_val(s, event, "success", record, &val, 1) == 0)
 89                 trace_seq_printf(s, " success=%lld", val);
 90 
 91         if (tep_get_field_val(s, event, "target_cpu", record, &val, 0) == 0)
 92                 trace_seq_printf(s, " CPU:%03llu", val);
 93 
 94         return 0;
 95 }
 96 
 97 static int sched_switch_handler(struct trace_seq *s,
 98                                 struct tep_record *record,
 99                                 struct tep_event *event, void *context)
100 {
101         struct tep_format_field *field;
102         unsigned long long val;
103 
104         if (tep_get_field_val(s, event, "prev_pid", record, &val, 1))
105                 return trace_seq_putc(s, '!');
106 
107         field = tep_find_any_field(event, "prev_comm");
108         if (field) {
109                 write_and_save_comm(field, record, s, val);
110                 trace_seq_putc(s, ':');
111         }
112         trace_seq_printf(s, "%lld ", val);
113 
114         if (tep_get_field_val(s, event, "prev_prio", record, &val, 0) == 0)
115                 trace_seq_printf(s, "[%d] ", (int) val);
116 
117         if (tep_get_field_val(s,  event, "prev_state", record, &val, 0) == 0)
118                 write_state(s, val);
119 
120         trace_seq_puts(s, " ==> ");
121 
122         if (tep_get_field_val(s, event, "next_pid", record, &val, 1))
123                 return trace_seq_putc(s, '!');
124 
125         field = tep_find_any_field(event, "next_comm");
126         if (field) {
127                 write_and_save_comm(field, record, s, val);
128                 trace_seq_putc(s, ':');
129         }
130         trace_seq_printf(s, "%lld", val);
131 
132         if (tep_get_field_val(s, event, "next_prio", record, &val, 0) == 0)
133                 trace_seq_printf(s, " [%d]", (int) val);
134 
135         return 0;
136 }
137 
138 int TEP_PLUGIN_LOADER(struct tep_handle *pevent)
139 {
140         tep_register_event_handler(pevent, -1, "sched", "sched_switch",
141                                    sched_switch_handler, NULL);
142 
143         tep_register_event_handler(pevent, -1, "sched", "sched_wakeup",
144                                    sched_wakeup_handler, NULL);
145 
146         tep_register_event_handler(pevent, -1, "sched", "sched_wakeup_new",
147                                    sched_wakeup_handler, NULL);
148         return 0;
149 }
150 
151 void TEP_PLUGIN_UNLOADER(struct tep_handle *pevent)
152 {
153         tep_unregister_event_handler(pevent, -1, "sched", "sched_switch",
154                                      sched_switch_handler, NULL);
155 
156         tep_unregister_event_handler(pevent, -1, "sched", "sched_wakeup",
157                                      sched_wakeup_handler, NULL);
158 
159         tep_unregister_event_handler(pevent, -1, "sched", "sched_wakeup_new",
160                                      sched_wakeup_handler, NULL);
161 }
162 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp