| 1 | |
| 2 | /* This file is part of the Linux Trace Toolkit viewer |
| 3 | * Copyright (C) 2003-2004 Michel Dagenais |
| 4 | * 2005 Mathieu Desnoyers |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License Version 2 as |
| 8 | * published by the Free Software Foundation; |
| 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 General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
| 18 | * MA 02111-1307, USA. |
| 19 | */ |
| 20 | |
| 21 | /* print.c |
| 22 | * |
| 23 | * Event printing routines. |
| 24 | */ |
| 25 | |
| 26 | #ifdef HAVE_CONFIG_H |
| 27 | #include <config.h> |
| 28 | #endif |
| 29 | |
| 30 | #include <lttv/lttv.h> |
| 31 | #include <lttv/option.h> |
| 32 | #include <lttv/module.h> |
| 33 | #include <lttv/hook.h> |
| 34 | #include <lttv/attribute.h> |
| 35 | #include <lttv/iattribute.h> |
| 36 | #include <lttv/stats.h> |
| 37 | #include <lttv/filter.h> |
| 38 | #include <lttv/print.h> |
| 39 | #include <ltt/ltt.h> |
| 40 | #include <ltt/event.h> |
| 41 | #include <ltt/type.h> |
| 42 | #include <ltt/trace.h> |
| 43 | #include <ltt/facility.h> |
| 44 | #include <stdio.h> |
| 45 | |
| 46 | |
| 47 | void lttv_print_field(LttEvent *e, LttField *f, GString *s, |
| 48 | gboolean field_names) { |
| 49 | |
| 50 | LttType *type; |
| 51 | |
| 52 | LttField *element; |
| 53 | |
| 54 | GQuark name; |
| 55 | |
| 56 | int nb, i; |
| 57 | |
| 58 | type = ltt_field_type(f); |
| 59 | switch(ltt_type_class(type)) { |
| 60 | case LTT_INT: |
| 61 | case LTT_LONG: |
| 62 | case LTT_SSIZE_T: |
| 63 | g_string_append_printf(s, " %lld", ltt_event_get_long_int(e,f)); |
| 64 | break; |
| 65 | |
| 66 | case LTT_UINT: |
| 67 | case LTT_ULONG: |
| 68 | case LTT_SIZE_T: |
| 69 | case LTT_OFF_T: |
| 70 | g_string_append_printf(s, " %llu", ltt_event_get_long_unsigned(e,f)); |
| 71 | break; |
| 72 | |
| 73 | case LTT_FLOAT: |
| 74 | g_string_append_printf(s, " %g", ltt_event_get_double(e,f)); |
| 75 | break; |
| 76 | |
| 77 | case LTT_POINTER: |
| 78 | g_string_append_printf(s, " 0x%llx", ltt_event_get_long_unsigned(e,f)); |
| 79 | break; |
| 80 | |
| 81 | case LTT_STRING: |
| 82 | g_string_append_printf(s, " \"%s\"", ltt_event_get_string(e,f)); |
| 83 | break; |
| 84 | |
| 85 | case LTT_ENUM: |
| 86 | g_string_append_printf(s, " %s", |
| 87 | g_quark_to_string(ltt_enum_string_get(type, |
| 88 | ltt_event_get_unsigned(e,f)-1))); |
| 89 | break; |
| 90 | |
| 91 | case LTT_ARRAY: |
| 92 | case LTT_SEQUENCE: |
| 93 | g_string_append_printf(s, " {"); |
| 94 | nb = ltt_event_field_element_number(e,f); |
| 95 | element = ltt_field_element(f); |
| 96 | for(i = 0 ; i < nb ; i++) { |
| 97 | ltt_event_field_element_select(e,f,i); |
| 98 | lttv_print_field(e, element, s, field_names); |
| 99 | } |
| 100 | g_string_append_printf(s, " }"); |
| 101 | break; |
| 102 | |
| 103 | case LTT_STRUCT: |
| 104 | g_string_append_printf(s, " {"); |
| 105 | nb = ltt_type_member_number(type); |
| 106 | for(i = 0 ; i < nb ; i++) { |
| 107 | element = ltt_field_member(f,i); |
| 108 | if(field_names) { |
| 109 | ltt_type_member_type(type, i, &name); |
| 110 | g_string_append_printf(s, " %s = ", g_quark_to_string(name)); |
| 111 | } |
| 112 | lttv_print_field(e, element, s, field_names); |
| 113 | } |
| 114 | g_string_append_printf(s, " }"); |
| 115 | break; |
| 116 | |
| 117 | case LTT_UNION: |
| 118 | g_string_append_printf(s, " {"); |
| 119 | nb = ltt_type_member_number(type); |
| 120 | for(i = 0 ; i < nb ; i++) { |
| 121 | element = ltt_field_member(f,i); |
| 122 | if(field_names) { |
| 123 | ltt_type_member_type(type, i, &name); |
| 124 | g_string_append_printf(s, " %s = ", g_quark_to_string(name)); |
| 125 | } |
| 126 | lttv_print_field(e, element, s, field_names); |
| 127 | } |
| 128 | g_string_append_printf(s, " }"); |
| 129 | break; |
| 130 | |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | |
| 135 | void lttv_event_to_string(LttEvent *e, GString *s, |
| 136 | gboolean mandatory_fields, gboolean field_names, LttvTracefileState *tfs) |
| 137 | { |
| 138 | LttFacility *facility; |
| 139 | |
| 140 | LttEventType *event_type; |
| 141 | |
| 142 | LttField *field; |
| 143 | |
| 144 | LttTime time; |
| 145 | |
| 146 | guint cpu = ltt_tracefile_num(tfs->parent.tf); |
| 147 | LttvTraceState *ts = (LttvTraceState*)tfs->parent.t_context; |
| 148 | LttvProcessState *process = ts->running_process[cpu]; |
| 149 | |
| 150 | g_string_set_size(s,0); |
| 151 | |
| 152 | facility = ltt_event_facility(e); |
| 153 | event_type = ltt_event_eventtype(e); |
| 154 | field = ltt_event_field(e); |
| 155 | |
| 156 | if(mandatory_fields) { |
| 157 | time = ltt_event_time(e); |
| 158 | g_string_append_printf(s,"%s.%s: %ld.%09ld (%s_%u)", |
| 159 | g_quark_to_string(ltt_facility_name(facility)), |
| 160 | g_quark_to_string(ltt_eventtype_name(event_type)), |
| 161 | (long)time.tv_sec, time.tv_nsec, |
| 162 | g_quark_to_string(ltt_tracefile_name(tfs->parent.tf)), |
| 163 | cpu); |
| 164 | /* Print the process id and the state/interrupt type of the process */ |
| 165 | g_string_append_printf(s,", %u, %u, %s", process->pid, |
| 166 | process->ppid, |
| 167 | g_quark_to_string(process->state->t)); |
| 168 | } |
| 169 | |
| 170 | if(field) |
| 171 | lttv_print_field(e, field, s, field_names); |
| 172 | } |
| 173 | |
| 174 | static void init() |
| 175 | { |
| 176 | } |
| 177 | |
| 178 | static void destroy() |
| 179 | { |
| 180 | } |
| 181 | |
| 182 | LTTV_MODULE("print", "Print events", \ |
| 183 | "Produce a detailed text printout of events", \ |
| 184 | init, destroy) |
| 185 | |