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