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