449cb9d7 |
1 | /* This file is part of the Linux Trace Toolkit viewer |
2 | * Copyright (C) 2003-2004 Xiangxiu Yang |
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 | |
fcdf0ec2 |
19 | #ifndef LTT_PRIVATE_H |
20 | #define LTT_PRIVATE_H |
21 | |
858bd80a |
22 | #include <glib.h> |
cbd41522 |
23 | #include <sys/types.h> |
fcdf0ec2 |
24 | #include <ltt/ltt.h> |
3b10b765 |
25 | #include <endian.h> |
e3247aa5 |
26 | |
eed2ef37 |
27 | |
28 | #ifndef max |
29 | #define max(a,b) ((a)>(b)?(a):(b)) |
30 | #endif |
31 | |
32 | |
3aee1200 |
33 | #define LTT_MAGIC_NUMBER 0x00D6B7ED |
34 | #define LTT_REV_MAGIC_NUMBER 0xEDB7D600 |
35 | |
36 | #define NSEC_PER_USEC 1000 |
37 | |
cbd41522 |
38 | #define LTT_PACKED_STRUCT __attribute__ ((packed)) |
39 | |
3aee1200 |
40 | /* Hardcoded facilities */ |
41 | #define LTT_FACILITY_CORE 0 |
3b10b765 |
42 | |
43 | /* Byte ordering */ |
44 | #define LTT_GET_BO(t) ((t)->reverse_bo) |
45 | |
46 | #define LTT_HAS_FLOAT(t) ((t)->float_word_order!=0) |
47 | #define LTT_GET_FLOAT_BO(t) \ |
48 | (((t)->float_word_order==__BYTE_ORDER)?0:1) |
49 | |
3aee1200 |
50 | |
51 | /* Hardcoded core events */ |
52 | enum ltt_core_events { |
53 | LTT_EVENT_FACILITY_LOAD, |
54 | LTT_EVENT_FACILITY_UNLOAD, |
b77d1b57 |
55 | LTT_EVENT_HEARTBEAT, |
56 | LTT_EVENT_STATE_DUMP_FACILITY_LOAD |
3aee1200 |
57 | }; |
58 | |
59 | |
60 | #if 0 |
e3247aa5 |
61 | /* enumeration definition */ |
62 | |
63 | typedef enum _BuildinEvent{ |
64 | TRACE_FACILITY_LOAD = 0, |
65 | TRACE_BLOCK_START = 17, |
66 | TRACE_BLOCK_END = 18, |
0d7aac52 |
67 | TRACE_TIME_HEARTBEAT= 19 |
e3247aa5 |
68 | } BuildinEvent; |
fcdf0ec2 |
69 | |
7c6b3cd7 |
70 | |
71 | /* structure definition */ |
72 | |
e3247aa5 |
73 | typedef struct _FacilityLoad{ |
45e14832 |
74 | gchar * name; |
e3247aa5 |
75 | LttChecksum checksum; |
cbd41522 |
76 | guint32 base_code; |
e3247aa5 |
77 | } LTT_PACKED_STRUCT FacilityLoad; |
78 | |
79 | typedef struct _BlockStart { |
3aee1200 |
80 | LttTime time; //Time stamp of this block |
e3247aa5 |
81 | LttCycleCount cycle_count; //cycle count of the event |
cbd41522 |
82 | guint32 block_id; //block id |
e3247aa5 |
83 | } LTT_PACKED_STRUCT BlockStart; |
84 | |
85 | typedef struct _BlockEnd { |
3aee1200 |
86 | LttTime time; //Time stamp of this block |
e3247aa5 |
87 | LttCycleCount cycle_count; //cycle count of the event |
cbd41522 |
88 | guint32 block_id; //block id |
e3247aa5 |
89 | } LTT_PACKED_STRUCT BlockEnd; |
3aee1200 |
90 | #endif //0 |
91 | |
92 | |
93 | typedef guint8 uint8_t; |
94 | typedef guint16 uint16_t; |
95 | typedef guint32 uint32_t; |
96 | typedef guint64 uint64_t; |
97 | |
16fcbb80 |
98 | /* Hardcoded facility load event : this plus an preceding "name" string */ |
3aee1200 |
99 | struct LttFacilityLoad { |
100 | guint32 checksum; |
101 | guint32 id; |
102 | guint32 long_size; |
103 | guint32 pointer_size; |
104 | guint32 size_t_size; |
105 | guint32 alignment; |
16fcbb80 |
106 | } LTT_PACKED_STRUCT; |
3aee1200 |
107 | |
108 | struct LttFacilityUnload { |
109 | guint32 id; |
16fcbb80 |
110 | } LTT_PACKED_STRUCT; |
3aee1200 |
111 | |
112 | struct LttStateDumpFacilityLoad { |
113 | guint32 checksum; |
114 | guint32 id; |
115 | guint32 long_size; |
116 | guint32 pointer_size; |
117 | guint32 size_t_size; |
118 | guint32 alignment; |
16fcbb80 |
119 | } LTT_PACKED_STRUCT; |
e3247aa5 |
120 | |
121 | typedef struct _TimeHeartbeat { |
3aee1200 |
122 | LttTime time; //Time stamp of this block |
123 | uint64_t cycle_count; //cycle count of the event |
e3247aa5 |
124 | } LTT_PACKED_STRUCT TimeHeartbeat; |
125 | |
3aee1200 |
126 | struct ltt_event_header_hb { |
127 | uint32_t timestamp; |
128 | unsigned char facility_id; |
129 | unsigned char event_id; |
130 | uint16_t event_size; |
16fcbb80 |
131 | } LTT_PACKED_STRUCT; |
3aee1200 |
132 | |
133 | struct ltt_event_header_nohb { |
134 | uint64_t timestamp; |
135 | unsigned char facility_id; |
136 | unsigned char event_id; |
137 | uint16_t event_size; |
16fcbb80 |
138 | } LTT_PACKED_STRUCT; |
3aee1200 |
139 | |
b7576a11 |
140 | |
141 | /* Block and trace headers */ |
142 | |
143 | struct ltt_trace_header_any { |
144 | uint32_t magic_number; |
145 | uint32_t arch_type; |
146 | uint32_t arch_variant; |
147 | uint32_t float_word_order; |
148 | uint8_t arch_size; |
149 | uint8_t major_version; |
150 | uint8_t minor_version; |
151 | uint8_t flight_recorder; |
152 | uint8_t has_heartbeat; |
153 | uint8_t has_alignment; /* Event header alignment */ |
154 | uint8_t has_tsc; |
155 | } LTT_PACKED_STRUCT; |
156 | |
157 | |
158 | /* For version 0.3 */ |
159 | |
160 | struct ltt_trace_header_0_3 { |
3aee1200 |
161 | uint32_t magic_number; |
162 | uint32_t arch_type; |
163 | uint32_t arch_variant; |
79257ba5 |
164 | uint32_t float_word_order; |
3aee1200 |
165 | uint8_t arch_size; |
b7576a11 |
166 | uint8_t major_version; |
167 | uint8_t minor_version; |
168 | uint8_t flight_recorder; |
169 | uint8_t has_heartbeat; |
170 | uint8_t has_alignment; /* Event header alignment */ |
171 | uint8_t has_tsc; |
16fcbb80 |
172 | } LTT_PACKED_STRUCT; |
3aee1200 |
173 | |
174 | |
b7576a11 |
175 | |
3aee1200 |
176 | struct ltt_block_start_header { |
177 | struct { |
178 | struct timeval timestamp; |
179 | uint64_t cycle_count; |
180 | } begin; |
181 | struct { |
182 | struct timeval timestamp; |
183 | uint64_t cycle_count; |
184 | } end; |
185 | uint32_t lost_size; /* Size unused at the end of the buffer */ |
186 | uint32_t buf_size; /* The size of this sub-buffer */ |
b7576a11 |
187 | char trace[0]; |
16fcbb80 |
188 | } LTT_PACKED_STRUCT; |
3aee1200 |
189 | |
e3247aa5 |
190 | |
b7576a11 |
191 | |
192 | |
193 | |
194 | |
e3247aa5 |
195 | struct _LttType{ |
3aee1200 |
196 | GQuark type_name; //type name if it is a named type |
197 | GQuark element_name; //elements name of the struct |
45e14832 |
198 | gchar * fmt; |
8d1e6362 |
199 | unsigned int size; |
e3247aa5 |
200 | LttTypeEnum type_class; //which type |
3aee1200 |
201 | GQuark * enum_strings; //for enum labels |
e3247aa5 |
202 | struct _LttType ** element_type; //for array, sequence and struct |
203 | unsigned element_number; //the number of elements |
204 | //for enum, array, sequence and structure |
7c6b3cd7 |
205 | }; |
206 | |
e3247aa5 |
207 | struct _LttEventType{ |
3aee1200 |
208 | GQuark name; |
45e14832 |
209 | gchar * description; |
3aee1200 |
210 | guint index; //id of the event type within the facility |
e3247aa5 |
211 | LttFacility * facility; //the facility that contains the event type |
212 | LttField * root_field; //root field |
7c6b3cd7 |
213 | }; |
214 | |
3aee1200 |
215 | /* Structure LttEvent and LttEventPosition must begin with the _exact_ same |
216 | * fields in the exact same order. LttEventPosition is a parent of LttEvent. */ |
c02ea99f |
217 | struct _LttEvent{ |
3aee1200 |
218 | |
219 | /* Begin of LttEventPosition fields */ |
220 | LttTracefile *tracefile; |
221 | unsigned int block; |
eed2ef37 |
222 | unsigned int offset; |
3aee1200 |
223 | |
224 | /* Timekeeping */ |
225 | uint64_t tsc; /* Current timestamp counter */ |
226 | |
227 | /* End of LttEventPosition fields */ |
228 | |
229 | union { /* choice by trace has_tsc */ |
230 | guint32 timestamp; /* truncated timestamp */ |
231 | LttTime delta; |
232 | } time; |
233 | |
234 | unsigned char facility_id; /* facility ID are never reused. */ |
235 | unsigned char event_id; |
236 | |
c02ea99f |
237 | LttTime event_time; |
3aee1200 |
238 | |
c02ea99f |
239 | void * data; //event data |
77175651 |
240 | guint data_size; |
b77d1b57 |
241 | guint event_size; //event_size field of the header : |
242 | //used to verify data_size from facility. |
3aee1200 |
243 | |
c02ea99f |
244 | int count; //the number of overflow of cycle count |
2dee981d |
245 | gint64 overflow_nsec; //precalculated nsec for overflows |
3aee1200 |
246 | }; |
dfb73233 |
247 | |
3aee1200 |
248 | struct _LttEventPosition{ |
249 | LttTracefile *tracefile; |
250 | unsigned int block; |
eed2ef37 |
251 | unsigned int offset; |
3aee1200 |
252 | |
253 | /* Timekeeping */ |
254 | uint64_t tsc; /* Current timestamp counter */ |
c02ea99f |
255 | }; |
256 | |
257 | |
3aee1200 |
258 | enum field_status { FIELD_UNKNOWN, FIELD_VARIABLE, FIELD_FIXED }; |
259 | |
e3247aa5 |
260 | struct _LttField{ |
3aee1200 |
261 | //guint field_pos; //field position within its parent |
e3247aa5 |
262 | LttType * field_type; //field type, if it is root field |
7c6b3cd7 |
263 | //then it must be struct type |
264 | |
265 | off_t offset_root; //offset from the root, -1:uninitialized |
3aee1200 |
266 | enum field_status fixed_root; //offset fixed according to the root |
7c6b3cd7 |
267 | //-1:uninitialized, 0:unfixed, 1:fixed |
268 | off_t offset_parent; //offset from the parent,-1:uninitialized |
3aee1200 |
269 | enum field_status fixed_parent; //offset fixed according to its parent |
7c6b3cd7 |
270 | //-1:uninitialized, 0:unfixed, 1:fixed |
271 | // void * base_address; //base address of the field ???? |
272 | |
3aee1200 |
273 | guint field_size; // //>0: size of the field, |
274 | // //0 : uncertain |
275 | // //-1: uninitialize |
276 | enum field_status fixed_size; |
277 | |
278 | /* for sequence */ |
279 | gint sequ_number_size; //the size of unsigned used to save the |
0d7aac52 |
280 | //number of elements in the sequence |
281 | |
3aee1200 |
282 | gint element_size; //the element size of the sequence |
283 | //int field_fixed; //0: field has string or sequence |
7c6b3cd7 |
284 | //1: field has no string or sequenc |
285 | //-1: uninitialize |
286 | |
e3247aa5 |
287 | struct _LttField * parent; |
3aee1200 |
288 | struct _LttField ** child; //for array, sequence, struct and union: |
7c6b3cd7 |
289 | //list of fields, it may have only one |
3aee1200 |
290 | //field if the element is not a struct or |
291 | //union |
7c6b3cd7 |
292 | unsigned current_element; //which element is currently processed |
3aee1200 |
293 | // Used for sequences and arrays. |
7c6b3cd7 |
294 | }; |
295 | |
7c6b3cd7 |
296 | |
e3247aa5 |
297 | struct _LttFacility{ |
3aee1200 |
298 | LttTrace *trace; |
299 | //gchar * name; //facility name |
300 | GQuark name; |
301 | guint32 checksum; //checksum of the facility |
302 | guint32 id; //id of the facility |
303 | |
304 | guint32 pointer_size; |
cb03932a |
305 | guint32 long_size; |
3aee1200 |
306 | guint32 size_t_size; |
307 | guint32 alignment; |
308 | |
309 | |
310 | //LttEventType ** events; //array of event types |
311 | //unsigned int event_number; //number of events in the facility |
312 | //LttType ** named_types; |
313 | //unsigned int named_types_number; |
314 | |
315 | GArray *events; |
316 | GData *events_by_name; |
317 | // GArray *named_types; |
318 | //GData *named_types_by_name; |
319 | GData *named_types; |
320 | |
321 | unsigned char exists; /* 0 does not exist, 1 exists */ |
7c6b3cd7 |
322 | }; |
323 | |
3aee1200 |
324 | typedef struct _LttBuffer { |
325 | void * head; |
326 | unsigned int index; |
327 | |
328 | struct { |
329 | LttTime timestamp; |
330 | uint64_t cycle_count; |
331 | } begin; |
332 | struct { |
333 | LttTime timestamp; |
334 | uint64_t cycle_count; |
335 | } end; |
336 | uint32_t lost_size; /* Size unused at the end of the buffer */ |
337 | |
338 | /* Timekeeping */ |
339 | uint64_t tsc; /* Current timestamp counter */ |
340 | double nsecs_per_cycle; |
341 | } LttBuffer; |
342 | |
e3247aa5 |
343 | struct _LttTracefile{ |
3aee1200 |
344 | gboolean cpu_online; //is the cpu online ? |
d3d34f49 |
345 | GQuark long_name; //tracefile complete filename |
3aee1200 |
346 | GQuark name; //tracefile name |
347 | guint cpu_num; //cpu number of the tracefile |
e3247aa5 |
348 | LttTrace * trace; //trace containing the tracefile |
349 | int fd; //file descriptor |
350 | off_t file_size; //file size |
f628823c |
351 | //unsigned block_size; //block_size |
3aee1200 |
352 | unsigned int num_blocks; //number of blocks in the file |
353 | gboolean reverse_bo; //must we reverse byte order ? |
3b10b765 |
354 | gboolean float_word_order; //what is the byte order of floats ? |
3aee1200 |
355 | |
356 | /* Current event */ |
357 | LttEvent event; //Event currently accessible in the trace |
358 | |
359 | /* Current block */ |
360 | LttBuffer buffer; //current buffer |
361 | guint32 buf_size; /* The size of blocks */ |
362 | |
363 | /* Time flow */ |
364 | //unsigned int count; //the number of overflow of cycle count |
365 | //double nsec_per_cycle; //Nsec per cycle |
366 | //TimeHeartbeat * last_heartbeat; //last heartbeat |
367 | |
887208b7 |
368 | //LttCycleCount cycles_per_nsec_reciprocal; // Optimisation for speed |
3aee1200 |
369 | //void * last_event_pos; |
7c6b3cd7 |
370 | |
3aee1200 |
371 | //LttTime prev_block_end_time; //the end time of previous block |
372 | //LttTime prev_event_time; //the time of the previous event |
373 | //LttCycleCount pre_cycle_count; //previous cycle count of the event |
e3247aa5 |
374 | }; |
7c6b3cd7 |
375 | |
3aee1200 |
376 | struct _LttTrace{ |
377 | GQuark pathname; //the pathname of the trace |
378 | //LttSystemDescription * system_description;//system description |
379 | |
380 | GArray *facilities_by_num; /* fac_id as index in array */ |
381 | GData *facilities_by_name; /* fac name (GQuark) as index */ |
382 | /* Points to array of fac_id of all the |
b56dcdf2 |
383 | * facilities that has this name. */ |
384 | guint num_cpu; |
3aee1200 |
385 | |
16fcbb80 |
386 | guint32 arch_type; |
387 | guint32 arch_variant; |
388 | guint8 arch_size; |
3aee1200 |
389 | guint8 ltt_major_version; |
390 | guint8 ltt_minor_version; |
391 | guint8 flight_recorder; |
392 | guint8 has_heartbeat; |
16fcbb80 |
393 | guint8 has_alignment; |
3aee1200 |
394 | guint8 has_tsc; |
395 | |
396 | GData *tracefiles; //tracefiles groups |
80da81ad |
397 | }; |
7c6b3cd7 |
398 | |
a5dcde2f |
399 | /* The characteristics of the system on which the trace was obtained |
400 | is described in a LttSystemDescription structure. */ |
401 | |
402 | struct _LttSystemDescription { |
45e14832 |
403 | gchar *description; |
404 | gchar *node_name; |
405 | gchar *domain_name; |
a5dcde2f |
406 | unsigned nb_cpu; |
407 | LttArchSize size; |
408 | LttArchEndian endian; |
45e14832 |
409 | gchar *kernel_name; |
410 | gchar *kernel_release; |
411 | gchar *kernel_version; |
412 | gchar *machine; |
413 | gchar *processor; |
414 | gchar *hardware_platform; |
415 | gchar *operating_system; |
a5dcde2f |
416 | LttTime trace_start; |
417 | LttTime trace_end; |
418 | }; |
419 | |
7c6b3cd7 |
420 | /***************************************************************************** |
421 | macro for size of some data types |
422 | *****************************************************************************/ |
3aee1200 |
423 | // alignment -> dynamic! |
424 | |
425 | //#define TIMESTAMP_SIZE sizeof(guint32) |
426 | //#define EVENT_ID_SIZE sizeof(guint16) |
427 | //#define EVENT_HEADER_SIZE (TIMESTAMP_SIZE + EVENT_ID_SIZE) |
428 | |
7c6b3cd7 |
429 | |
fcdf0ec2 |
430 | #endif /* LTT_PRIVATE_H */ |