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 |
42 | elapsed_time |
43 | wait_time |
44 | bytes_written |
45 | packets_sent |
46 | ... |
47 | |
48 | The events for several different execution modes are joined together to |
49 | form the "execution modes tree". The name "execution mode" is to be replaced |
50 | by "system call", "trap", "irq", "user mode" or "kernel thread". |
51 | The name "submode" is to be replaced by the specific system call, trap or |
52 | irq name. The "submode" is an empty string if none is applicable, which is |
53 | the case for "user mode" and "kernel thread". |
54 | |
55 | An "events tree" for each "execution mode" contains the sum for all its |
56 | different submodes. An "events tree" in the "execution modes tree" contains |
57 | the sum for all its different execution modes. |
58 | |
59 | mode_types/ |
60 | "execution mode"/ |
61 | submodes/ |
62 | "submode"/ |
63 | Events Tree |
64 | events/ |
65 | Event Tree |
66 | events/ |
67 | Events Tree |
68 | |
69 | Each trace set contains an "execution modes tree". While the traces |
70 | come from possibly different systems, which may differ in their system |
71 | calls..., most of the system calls will have the same name, even if their |
72 | actual internal numeric id differs. Categories such as cpu id and process |
73 | id are not kept since these are specific to each system. When several |
74 | traces are taken from the same system, these categories may make sense and |
75 | could eventually be considered. |
76 | |
77 | Each trace contains a global "execution modes tree", one for each |
78 | cpu and process, and one for each process/cpu combination. The name |
79 | "cpu number" stands for the cpu identifier, and "process_id-start_time" |
80 | is a unique process identifier composed of the process id |
81 | (unique at any given time but which may be reused over time) concatenated |
82 | with the process start time. |
83 | |
84 | modes/ |
85 | Execution Modes Tree |
86 | cpu/ |
87 | "cpu number"/ |
88 | Execution Modes Tree |
89 | processes/ |
90 | "process_id-start_time"/ |
91 | exec_file_name |
92 | parent |
93 | start_time |
94 | end_time |
95 | modes/ |
96 | Execution Modes Tree |
97 | cpu/ |
98 | "cpu number"/ |
99 | Execution Modes Tree |
100 | |
101 | All the events and derived values (cpu, elapsed and wait time) are |
102 | added during the trace analysis in the relevant |
103 | trace / processes / * / cpu / * / mode_types / * /submodes / * |
104 | "events tree". To achieve this efficiently, each tracefile context |
105 | contains a pointer to the current relevant "events tree" and "event_types" |
106 | tree within it. |
107 | |
108 | Once all the events are processed, the total number of events is computed |
109 | within each trace / processes / * / cpu / * / mode_types / * / submodes / *. |
110 | Then, the "events tree" are summed for all submodes within each mode type |
111 | and for all mode types within a processes / * / cpu / * |
112 | "execution modes tree". |
113 | |
114 | Finally, the "execution modes trees" for all cpu within a process, |
115 | for all processes, and for all traces are computed. Separately, |
116 | the "execution modes tree" for each cpu but for all processes within a |
117 | trace are summed in the trace / cpu / * subtrees. |
118 | |
119 | */ |
120 | |
121 | |
122 | /* The various statistics branch names are GQuarks. They are pre-computed for |
123 | easy and efficient access */ |
124 | |
359b2948 |
125 | #define LTTV_PRIO_STATS_BEFORE_STATE LTTV_PRIO_STATE-5 |
126 | #define LTTV_PRIO_STATS_AFTER_STATE LTTV_PRIO_STATE+5 |
127 | |
128 | |
b445142a |
129 | extern GQuark |
130 | LTTV_STATS_PROCESS_UNKNOWN, |
131 | LTTV_STATS_PROCESSES, |
132 | LTTV_STATS_CPU, |
133 | LTTV_STATS_MODE_TYPES, |
134 | LTTV_STATS_SUBMODES, |
135 | LTTV_STATS_EVENT_TYPES, |
136 | LTTV_STATS_CPU_TIME, |
137 | LTTV_STATS_ELAPSED_TIME, |
138 | LTTV_STATS_EVENTS, |
139 | LTTV_STATS_EVENTS_COUNT, |
140 | LTTV_STATS_BEFORE_HOOKS, |
141 | LTTV_STATS_AFTER_HOOKS; |
142 | |
143 | |
144 | typedef struct _LttvTracesetStats LttvTracesetStats; |
145 | typedef struct _LttvTracesetStatsClass LttvTracesetStatsClass; |
146 | |
147 | typedef struct _LttvTraceStats LttvTraceStats; |
148 | typedef struct _LttvTraceStatsClass LttvTraceStatsClass; |
149 | |
150 | typedef struct _LttvTracefileStats LttvTracefileStats; |
151 | typedef struct _LttvTracefileStatsClass LttvTracefileStatsClass; |
152 | |
d3e01c7a |
153 | |
154 | |
155 | // Hook wrapper. call_data is a trace context. |
00e74b69 |
156 | gboolean lttv_stats_hook_add_event_hooks(void *hook_data, void *call_data); |
157 | void lttv_stats_add_event_hooks(LttvTracesetStats *self); |
b445142a |
158 | |
d3e01c7a |
159 | // Hook wrapper. call_data is a trace context. |
00e74b69 |
160 | gboolean lttv_stats_hook_remove_event_hooks(void *hook_data, void *call_data); |
161 | void lttv_stats_remove_event_hooks(LttvTracesetStats *self); |
b445142a |
162 | |
d3e01c7a |
163 | gboolean lttv_stats_sum_traceset_hook(void *hook_data, void *call_data); |
f95bc830 |
164 | void lttv_stats_sum_traceset(LttvTracesetStats *self); |
9f797243 |
165 | |
f95bc830 |
166 | void lttv_stats_sum_trace(LttvTraceStats *self); |
9f797243 |
167 | |
d730b5c8 |
168 | /* Reset all statistics containers */ |
169 | void lttv_stats_reset(LttvTracesetStats *self); |
170 | |
b445142a |
171 | |
172 | /* The LttvTracesetStats, LttvTraceStats and LttvTracefileStats types |
173 | inherit from the corresponding State objects defined in state.h.. */ |
174 | |
175 | #define LTTV_TRACESET_STATS_TYPE (lttv_traceset_stats_get_type ()) |
176 | #define LTTV_TRACESET_STATS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_TRACESET_STATS_TYPE, LttvTracesetStats)) |
177 | #define LTTV_TRACESET_STATS_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_TRACESET_STATS_TYPE, LttvTracesetStatsClass)) |
178 | #define LTTV_IS_TRACESET_STATS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LTTV_TRACESET_STATS_TYPE)) |
179 | #define LTTV_IS_TRACESET_STATS_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACESET_STATS_TYPE)) |
180 | #define LTTV_TRACESET_STATS_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACESET_STATS_TYPE, LttvTracesetStatsClass)) |
181 | |
182 | struct _LttvTracesetStats { |
183 | LttvTracesetState parent; |
184 | |
185 | LttvAttribute *stats; |
186 | }; |
187 | |
188 | struct _LttvTracesetStatsClass { |
189 | LttvTracesetStateClass parent; |
190 | }; |
191 | |
192 | GType lttv_traceset_stats_get_type (void); |
193 | |
194 | |
195 | #define LTTV_TRACE_STATS_TYPE (lttv_trace_stats_get_type ()) |
196 | #define LTTV_TRACE_STATS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_TRACE_STATS_TYPE, LttvTraceStats)) |
197 | #define LTTV_TRACE_STATS_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_TRACE_STATS_TYPE, LttvTraceStatsClass)) |
198 | #define LTTV_IS_TRACE_STATS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LTTV_TRACE_STATS_TYPE)) |
199 | #define LTTV_IS_TRACE_STATS_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACE_STATS_TYPE)) |
200 | #define LTTV_TRACE_STATS_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACE_STATS_TYPE, LttvTraceStatsClass)) |
201 | |
202 | struct _LttvTraceStats { |
203 | LttvTraceState parent; |
204 | |
205 | LttvAttribute *stats; |
206 | }; |
207 | |
208 | struct _LttvTraceStatsClass { |
209 | LttvTraceStateClass parent; |
210 | }; |
211 | |
212 | GType lttv_trace_stats_get_type (void); |
213 | |
214 | |
215 | #define LTTV_TRACEFILE_STATS_TYPE (lttv_tracefile_stats_get_type ()) |
216 | #define LTTV_TRACEFILE_STATS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_TRACEFILE_STATS_TYPE, LttvTracefileStats)) |
217 | #define LTTV_TRACEFILE_STATS_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_TRACEFILE_STATS_TYPE, LttvTracefileStatsClass)) |
218 | #define LTTV_IS_TRACEFILE_STATS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LTTV_TRACEFILE_STATS_TYPE)) |
219 | #define LTTV_IS_TRACEFILE_STATS_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACEFILE_STATS_TYPE)) |
220 | #define LTTV_TRACEFILE_STATS_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACEFILE_STATS_TYPE, LttvTracefileStatsClass)) |
221 | |
222 | struct _LttvTracefileStats { |
223 | LttvTracefileState parent; |
224 | |
225 | LttvAttribute *stats; |
226 | LttvAttribute *current_events_tree; |
227 | LttvAttribute *current_event_types_tree; |
228 | }; |
229 | |
230 | struct _LttvTracefileStatsClass { |
231 | LttvTracefileStateClass parent; |
232 | }; |
233 | |
234 | GType lttv_tracefile_stats_get_type (void); |
235 | |
dc877563 |
236 | |
b445142a |
237 | #endif // STATS_H |