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