| 1 | /* This file is part of the Linux Trace Toolkit viewer |
| 2 | * Copyright (C) 2003-2004 Michel Dagenais |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License Version 2 as |
| 6 | * published by the Free Software Foundation; |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this program; if not, write to the Free Software |
| 15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
| 16 | * MA 02111-1307, USA. |
| 17 | */ |
| 18 | |
| 19 | #ifndef STATS_H |
| 20 | #define STATS_H |
| 21 | |
| 22 | #error "stats not supported." |
| 23 | |
| 24 | #include <glib.h> |
| 25 | #include <lttv/state.h> |
| 26 | |
| 27 | /* The statistics are for a complete time interval. These structures differ |
| 28 | from the system state since they relate to static components of the |
| 29 | system (all processes which existed instead of just the currently |
| 30 | existing processes). |
| 31 | |
| 32 | The basic attributes tree to gather for several different execution modes |
| 33 | (e.g., user mode, syscall, irq), thereafter called the "events tree", |
| 34 | contains the following attributes: the number of events of each type, |
| 35 | the total number of events, the number of bytes written, the time spent |
| 36 | executing, waiting for a resource, waiting for a cpu, and possibly many |
| 37 | others. The name "facility-event_type" below is to be replaced |
| 38 | by specific event types (e.g., core-schedchange, code-syscall_entry...). |
| 39 | |
| 40 | event_types/ |
| 41 | "facility-event_type" |
| 42 | events_count |
| 43 | cpu_time |
| 44 | cumulative_cpu_time |
| 45 | elapsed_time |
| 46 | wait_time |
| 47 | bytes_written |
| 48 | packets_sent |
| 49 | ... |
| 50 | |
| 51 | The events for several different execution modes are joined together to |
| 52 | form the "execution modes tree". The name "execution mode" is to be replaced |
| 53 | by "system call", "trap", "irq", "user mode" or "kernel thread". |
| 54 | The name "submode" is to be replaced by the specific system call, trap or |
| 55 | irq name. The "submode" is an empty string if none is applicable, which is |
| 56 | the case for "user mode" and "kernel thread". |
| 57 | |
| 58 | An "events tree" for each "execution mode" contains the sum for all its |
| 59 | different submodes. An "events tree" in the "execution modes tree" contains |
| 60 | the sum for all its different execution modes. |
| 61 | |
| 62 | mode_types/ |
| 63 | "execution mode"/ |
| 64 | submodes/ |
| 65 | "submode"/ |
| 66 | Events Tree |
| 67 | events/ |
| 68 | Event Tree |
| 69 | events/ |
| 70 | Events Tree |
| 71 | |
| 72 | Each trace set contains an "execution modes tree". While the traces |
| 73 | come from possibly different systems, which may differ in their system |
| 74 | calls..., most of the system calls will have the same name, even if their |
| 75 | actual internal numeric id differs. Categories such as cpu id and process |
| 76 | id are not kept since these are specific to each system. When several |
| 77 | traces are taken from the same system, these categories may make sense and |
| 78 | could eventually be considered. |
| 79 | |
| 80 | Each trace contains a global "execution modes tree", one for each |
| 81 | cpu and process, and one for each process/cpu combination. The name |
| 82 | "cpu number" stands for the cpu identifier, and "process_id-start_time" |
| 83 | is a unique process identifier composed of the process id |
| 84 | (unique at any given time but which may be reused over time) concatenated |
| 85 | with the process start time. Each process has a "functions" tree which |
| 86 | contains each process'function address (when the information is available). |
| 87 | If not, only the 0x0 function will appear. |
| 88 | |
| 89 | modes/ |
| 90 | Execution Modes Tree |
| 91 | cpu/ |
| 92 | "cpu number"/ |
| 93 | Execution Modes Tree |
| 94 | processes/ |
| 95 | "process_id-start_time"/ |
| 96 | exec_file_name |
| 97 | parent |
| 98 | start_time |
| 99 | end_time |
| 100 | modes/ |
| 101 | Execution Modes Tree |
| 102 | cpu/ |
| 103 | "cpu number"/ |
| 104 | Execution Modes Tree |
| 105 | functions/ |
| 106 | "function address"/ |
| 107 | Execution Modes Tree |
| 108 | functions/ |
| 109 | "function address"/ |
| 110 | Execution Modes Tree |
| 111 | |
| 112 | All the events and derived values (cpu, elapsed and wait time) are |
| 113 | added during the trace analysis in the relevant |
| 114 | trace/processes/ * /cpu/ * /functions/ * /mode_types/ * /submodes/ * |
| 115 | "events tree". To achieve this efficiently, each tracefile context |
| 116 | contains a pointer to the current relevant "events tree" and "event_types" |
| 117 | tree within it. |
| 118 | |
| 119 | Once all the events are processed, the total number of events is computed |
| 120 | within each |
| 121 | trace/processes/ * /cpu/ * /functions/ * /mode_types/ * /submodes/ *. |
| 122 | Then, the "events tree" are summed for all submodes within each mode type |
| 123 | and for all mode types within a processes/ * /cpu/ * /functions/ * |
| 124 | "execution modes tree". |
| 125 | |
| 126 | Then, the "execution modes trees" for all functions within a |
| 127 | trace/processes/ * /cpu for all cpu within a process, for all processes, |
| 128 | and for all traces are computed. Separately, the "execution modes tree" for |
| 129 | each function (over all cpus) for all processes, and for all traces are |
| 130 | summed in the trace/processes/ * /functions/ * subtree. |
| 131 | |
| 132 | Finally, the "execution modes trees" for all cpu within a process, |
| 133 | for all processes, and for all traces are computed. Separately, |
| 134 | the "execution modes tree" for each cpu but for all processes within a |
| 135 | trace are summed in the trace / cpu / * subtrees. |
| 136 | |
| 137 | */ |
| 138 | |
| 139 | |
| 140 | /* The various statistics branch names are GQuarks. They are pre-computed for |
| 141 | easy and efficient access */ |
| 142 | |
| 143 | #define LTTV_PRIO_STATS_BEFORE_STATE LTTV_PRIO_STATE-5 |
| 144 | #define LTTV_PRIO_STATS_AFTER_STATE LTTV_PRIO_STATE+5 |
| 145 | |
| 146 | |
| 147 | extern GQuark |
| 148 | LTTV_STATS_PROCESS_UNKNOWN, |
| 149 | LTTV_STATS_PROCESSES, |
| 150 | LTTV_STATS_CPU, |
| 151 | LTTV_STATS_MODE_TYPES, |
| 152 | LTTV_STATS_SUBMODES, |
| 153 | LTTV_STATS_FUNCTIONS, |
| 154 | LTTV_STATS_EVENT_TYPES, |
| 155 | LTTV_STATS_CPU_TIME, |
| 156 | LTTV_STATS_CUMULATIVE_CPU_TIME, |
| 157 | LTTV_STATS_ELAPSED_TIME, |
| 158 | LTTV_STATS_EVENTS, |
| 159 | LTTV_STATS_EVENTS_COUNT, |
| 160 | LTTV_STATS_BEFORE_HOOKS, |
| 161 | LTTV_STATS_AFTER_HOOKS; |
| 162 | |
| 163 | |
| 164 | typedef struct _LttvTracesetStats LttvTracesetStats; |
| 165 | typedef struct _LttvTracesetStatsClass LttvTracesetStatsClass; |
| 166 | |
| 167 | typedef struct _LttvTraceStats LttvTraceStats; |
| 168 | typedef struct _LttvTraceStatsClass LttvTraceStatsClass; |
| 169 | |
| 170 | typedef struct _LttvTracefileStats LttvTracefileStats; |
| 171 | typedef struct _LttvTracefileStatsClass LttvTracefileStatsClass; |
| 172 | |
| 173 | typedef struct _LttvCPUStats LttvCPUStats; |
| 174 | |
| 175 | // Hook wrapper. call_data is a trace context. |
| 176 | gboolean lttv_stats_hook_add_event_hooks(void *hook_data, void *call_data); |
| 177 | void lttv_stats_add_event_hooks(LttvTracesetStats *self); |
| 178 | |
| 179 | // Hook wrapper. call_data is a trace context. |
| 180 | gboolean lttv_stats_hook_remove_event_hooks(void *hook_data, void *call_data); |
| 181 | void lttv_stats_remove_event_hooks(LttvTracesetStats *self); |
| 182 | |
| 183 | gboolean lttv_stats_sum_traceset_hook(void *hook_data, void *call_data); |
| 184 | void lttv_stats_sum_traceset(LttvTracesetStats *self, LttTime current_time); |
| 185 | |
| 186 | void lttv_stats_sum_trace(LttvTraceStats *self, LttvAttribute *ts_stats, |
| 187 | LttTime current_time); |
| 188 | |
| 189 | /* Reset all statistics containers */ |
| 190 | void lttv_stats_reset(LttvTracesetStats *self); |
| 191 | |
| 192 | |
| 193 | /* The LttvTracesetStats, LttvTraceStats and LttvTracefileStats types |
| 194 | inherit from the corresponding State objects defined in state.h.. */ |
| 195 | |
| 196 | #define LTTV_TRACESET_STATS_TYPE (lttv_traceset_stats_get_type ()) |
| 197 | #define LTTV_TRACESET_STATS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_TRACESET_STATS_TYPE, LttvTracesetStats)) |
| 198 | #define LTTV_TRACESET_STATS_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_TRACESET_STATS_TYPE, LttvTracesetStatsClass)) |
| 199 | #define LTTV_IS_TRACESET_STATS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LTTV_TRACESET_STATS_TYPE)) |
| 200 | #define LTTV_IS_TRACESET_STATS_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACESET_STATS_TYPE)) |
| 201 | #define LTTV_TRACESET_STATS_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACESET_STATS_TYPE, LttvTracesetStatsClass)) |
| 202 | |
| 203 | struct _LttvTracesetStats { |
| 204 | LttvTracesetState parent; |
| 205 | |
| 206 | LttvAttribute *stats; |
| 207 | }; |
| 208 | |
| 209 | struct _LttvTracesetStatsClass { |
| 210 | LttvTracesetStateClass parent; |
| 211 | }; |
| 212 | |
| 213 | GType lttv_traceset_stats_get_type (void); |
| 214 | |
| 215 | struct _LttvCPUStats { |
| 216 | LttvAttribute *current_events_tree; |
| 217 | LttvAttribute *current_event_types_tree; |
| 218 | LttvTraceStats *tcs; |
| 219 | guint cpu; |
| 220 | }; |
| 221 | |
| 222 | #define LTTV_TRACE_STATS_TYPE (lttv_trace_stats_get_type ()) |
| 223 | #define LTTV_TRACE_STATS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_TRACE_STATS_TYPE, LttvTraceStats)) |
| 224 | #define LTTV_TRACE_STATS_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_TRACE_STATS_TYPE, LttvTraceStatsClass)) |
| 225 | #define LTTV_IS_TRACE_STATS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LTTV_TRACE_STATS_TYPE)) |
| 226 | #define LTTV_IS_TRACE_STATS_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACE_STATS_TYPE)) |
| 227 | #define LTTV_TRACE_STATS_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACE_STATS_TYPE, LttvTraceStatsClass)) |
| 228 | |
| 229 | struct _LttvTraceStats { |
| 230 | LttvTraceState parent; |
| 231 | |
| 232 | LttvAttribute *stats; |
| 233 | LttvCPUStats *cpu_stats; /* Array indexed by CPU */ |
| 234 | }; |
| 235 | |
| 236 | struct _LttvTraceStatsClass { |
| 237 | LttvTraceStateClass parent; |
| 238 | }; |
| 239 | |
| 240 | GType lttv_trace_stats_get_type (void); |
| 241 | |
| 242 | |
| 243 | #define LTTV_TRACEFILE_STATS_TYPE (lttv_tracefile_stats_get_type ()) |
| 244 | #define LTTV_TRACEFILE_STATS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_TRACEFILE_STATS_TYPE, LttvTracefileStats)) |
| 245 | #define LTTV_TRACEFILE_STATS_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_TRACEFILE_STATS_TYPE, LttvTracefileStatsClass)) |
| 246 | #define LTTV_IS_TRACEFILE_STATS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LTTV_TRACEFILE_STATS_TYPE)) |
| 247 | #define LTTV_IS_TRACEFILE_STATS_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACEFILE_STATS_TYPE)) |
| 248 | #define LTTV_TRACEFILE_STATS_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACEFILE_STATS_TYPE, LttvTracefileStatsClass)) |
| 249 | |
| 250 | struct _LttvTracefileStats { |
| 251 | LttvTracefileState parent; |
| 252 | |
| 253 | LttvCPUStats *cpu_stats; /* "weak" reference */ |
| 254 | }; |
| 255 | |
| 256 | struct _LttvTracefileStatsClass { |
| 257 | LttvTracefileStateClass parent; |
| 258 | }; |
| 259 | |
| 260 | GType lttv_tracefile_stats_get_type (void); |
| 261 | |
| 262 | struct sum_traceset_closure { |
| 263 | LttvTracesetStats *tss; |
| 264 | LttTime current_time; |
| 265 | }; |
| 266 | |
| 267 | |
| 268 | #endif // STATS_H |