449cb9d7 |
1 | /* This file is part of the Linux Trace Toolkit viewer |
2 | * Copyright (C) 2003-2004 Xiangxiu Yang |
1b44b0b5 |
3 | * 2006 Mathieu Desnoyers |
449cb9d7 |
4 | * |
1b44b0b5 |
5 | * This library is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU Lesser General Public |
7 | * License Version 2.1 as published by the Free Software Foundation. |
449cb9d7 |
8 | * |
1b44b0b5 |
9 | * This library is distributed in the hope that it will be useful, |
449cb9d7 |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1b44b0b5 |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Lesser General Public License for more details. |
449cb9d7 |
13 | * |
1b44b0b5 |
14 | * You should have received a copy of the GNU Lesser General Public |
15 | * License along with this library; if not, write to the |
16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
17 | * Boston, MA 02111-1307, USA. |
449cb9d7 |
18 | */ |
19 | |
fcdf0ec2 |
20 | #ifndef LTT_PRIVATE_H |
21 | #define LTT_PRIVATE_H |
22 | |
858bd80a |
23 | #include <glib.h> |
cbd41522 |
24 | #include <sys/types.h> |
fcdf0ec2 |
25 | #include <ltt/ltt.h> |
3b10b765 |
26 | #include <endian.h> |
e3247aa5 |
27 | |
eed2ef37 |
28 | |
29 | #ifndef max |
30 | #define max(a,b) ((a)>(b)?(a):(b)) |
31 | #endif |
32 | |
2312de30 |
33 | #ifndef min |
34 | #define min(a,b) ((a)<(b)?(a):(b)) |
35 | #endif |
36 | |
37 | |
eed2ef37 |
38 | |
3aee1200 |
39 | #define LTT_MAGIC_NUMBER 0x00D6B7ED |
40 | #define LTT_REV_MAGIC_NUMBER 0xEDB7D600 |
41 | |
42 | #define NSEC_PER_USEC 1000 |
43 | |
cbd41522 |
44 | #define LTT_PACKED_STRUCT __attribute__ ((packed)) |
45 | |
3aee1200 |
46 | /* Hardcoded facilities */ |
47 | #define LTT_FACILITY_CORE 0 |
3b10b765 |
48 | |
49 | /* Byte ordering */ |
50 | #define LTT_GET_BO(t) ((t)->reverse_bo) |
51 | |
52 | #define LTT_HAS_FLOAT(t) ((t)->float_word_order!=0) |
53 | #define LTT_GET_FLOAT_BO(t) \ |
54 | (((t)->float_word_order==__BYTE_ORDER)?0:1) |
55 | |
f104d082 |
56 | #define SEQUENCE_AVG_ELEMENTS 1000 |
57 | |
3aee1200 |
58 | /* Hardcoded core events */ |
59 | enum ltt_core_events { |
60 | LTT_EVENT_FACILITY_LOAD, |
61 | LTT_EVENT_FACILITY_UNLOAD, |
b77d1b57 |
62 | LTT_EVENT_HEARTBEAT, |
d1bb700c |
63 | LTT_EVENT_HEARTBEAT_FULL, |
b77d1b57 |
64 | LTT_EVENT_STATE_DUMP_FACILITY_LOAD |
3aee1200 |
65 | }; |
66 | |
67 | |
68 | #if 0 |
e3247aa5 |
69 | /* enumeration definition */ |
70 | |
71 | typedef enum _BuildinEvent{ |
72 | TRACE_FACILITY_LOAD = 0, |
73 | TRACE_BLOCK_START = 17, |
74 | TRACE_BLOCK_END = 18, |
0d7aac52 |
75 | TRACE_TIME_HEARTBEAT= 19 |
e3247aa5 |
76 | } BuildinEvent; |
fcdf0ec2 |
77 | |
7c6b3cd7 |
78 | |
79 | /* structure definition */ |
80 | |
e3247aa5 |
81 | typedef struct _FacilityLoad{ |
45e14832 |
82 | gchar * name; |
e3247aa5 |
83 | LttChecksum checksum; |
cbd41522 |
84 | guint32 base_code; |
e3247aa5 |
85 | } LTT_PACKED_STRUCT FacilityLoad; |
86 | |
87 | typedef struct _BlockStart { |
3aee1200 |
88 | LttTime time; //Time stamp of this block |
e3247aa5 |
89 | LttCycleCount cycle_count; //cycle count of the event |
cbd41522 |
90 | guint32 block_id; //block id |
e3247aa5 |
91 | } LTT_PACKED_STRUCT BlockStart; |
92 | |
93 | typedef struct _BlockEnd { |
3aee1200 |
94 | LttTime time; //Time stamp of this block |
e3247aa5 |
95 | LttCycleCount cycle_count; //cycle count of the event |
cbd41522 |
96 | guint32 block_id; //block id |
e3247aa5 |
97 | } LTT_PACKED_STRUCT BlockEnd; |
3aee1200 |
98 | #endif //0 |
99 | |
100 | |
101 | typedef guint8 uint8_t; |
102 | typedef guint16 uint16_t; |
103 | typedef guint32 uint32_t; |
104 | typedef guint64 uint64_t; |
105 | |
16fcbb80 |
106 | /* Hardcoded facility load event : this plus an preceding "name" string */ |
3aee1200 |
107 | struct LttFacilityLoad { |
108 | guint32 checksum; |
109 | guint32 id; |
c88ddec5 |
110 | guint32 int_size; |
3aee1200 |
111 | guint32 long_size; |
112 | guint32 pointer_size; |
113 | guint32 size_t_size; |
c88ddec5 |
114 | guint32 has_alignment; |
16fcbb80 |
115 | } LTT_PACKED_STRUCT; |
3aee1200 |
116 | |
117 | struct LttFacilityUnload { |
118 | guint32 id; |
16fcbb80 |
119 | } LTT_PACKED_STRUCT; |
3aee1200 |
120 | |
121 | struct LttStateDumpFacilityLoad { |
122 | guint32 checksum; |
123 | guint32 id; |
c88ddec5 |
124 | guint32 int_size; |
3aee1200 |
125 | guint32 long_size; |
126 | guint32 pointer_size; |
127 | guint32 size_t_size; |
c88ddec5 |
128 | guint32 has_alignment; |
16fcbb80 |
129 | } LTT_PACKED_STRUCT; |
e3247aa5 |
130 | |
78f79181 |
131 | /* Empty event */ |
e3247aa5 |
132 | typedef struct _TimeHeartbeat { |
e3247aa5 |
133 | } LTT_PACKED_STRUCT TimeHeartbeat; |
134 | |
d1bb700c |
135 | typedef struct _TimeHeartbeatFull { |
136 | guint64 tsc; |
137 | } LTT_PACKED_STRUCT TimeHeartbeatFull; |
138 | |
3aee1200 |
139 | struct ltt_event_header_hb { |
140 | uint32_t timestamp; |
141 | unsigned char facility_id; |
142 | unsigned char event_id; |
143 | uint16_t event_size; |
16fcbb80 |
144 | } LTT_PACKED_STRUCT; |
3aee1200 |
145 | |
146 | struct ltt_event_header_nohb { |
147 | uint64_t timestamp; |
148 | unsigned char facility_id; |
149 | unsigned char event_id; |
150 | uint16_t event_size; |
16fcbb80 |
151 | } LTT_PACKED_STRUCT; |
3aee1200 |
152 | |
b7576a11 |
153 | |
154 | /* Block and trace headers */ |
155 | |
156 | struct ltt_trace_header_any { |
157 | uint32_t magic_number; |
158 | uint32_t arch_type; |
159 | uint32_t arch_variant; |
160 | uint32_t float_word_order; |
161 | uint8_t arch_size; |
162 | uint8_t major_version; |
163 | uint8_t minor_version; |
164 | uint8_t flight_recorder; |
165 | uint8_t has_heartbeat; |
166 | uint8_t has_alignment; /* Event header alignment */ |
c88ddec5 |
167 | uint32_t freq_scale; |
b7576a11 |
168 | } LTT_PACKED_STRUCT; |
169 | |
170 | |
171 | /* For version 0.3 */ |
172 | |
173 | struct ltt_trace_header_0_3 { |
3aee1200 |
174 | uint32_t magic_number; |
175 | uint32_t arch_type; |
176 | uint32_t arch_variant; |
79257ba5 |
177 | uint32_t float_word_order; |
3aee1200 |
178 | uint8_t arch_size; |
b7576a11 |
179 | uint8_t major_version; |
180 | uint8_t minor_version; |
181 | uint8_t flight_recorder; |
182 | uint8_t has_heartbeat; |
183 | uint8_t has_alignment; /* Event header alignment */ |
c88ddec5 |
184 | uint32_t freq_scale; |
16fcbb80 |
185 | } LTT_PACKED_STRUCT; |
3aee1200 |
186 | |
cb310b57 |
187 | /* For version 0.7 */ |
986e2a7c |
188 | |
cb310b57 |
189 | struct ltt_trace_header_0_7 { |
e939e5b2 |
190 | uint32_t magic_number; |
191 | uint32_t arch_type; |
192 | uint32_t arch_variant; |
193 | uint32_t float_word_order; |
194 | uint8_t arch_size; |
195 | uint8_t major_version; |
196 | uint8_t minor_version; |
197 | uint8_t flight_recorder; |
198 | uint8_t has_heartbeat; |
199 | uint8_t has_alignment; /* Event header alignment */ |
cb310b57 |
200 | uint32_t freq_scale; |
e939e5b2 |
201 | uint64_t start_freq; |
202 | uint64_t start_tsc; |
203 | uint64_t start_monotonic; |
e939e5b2 |
204 | uint64_t start_time_sec; |
205 | uint64_t start_time_usec; |
206 | } LTT_PACKED_STRUCT; |
207 | |
d1bb700c |
208 | /* For version 0.8 */ |
209 | |
210 | struct ltt_trace_header_0_8 { |
211 | uint32_t magic_number; |
212 | uint32_t arch_type; |
213 | uint32_t arch_variant; |
214 | uint32_t float_word_order; |
215 | uint8_t arch_size; |
216 | uint8_t major_version; |
217 | uint8_t minor_version; |
218 | uint8_t flight_recorder; |
219 | uint8_t has_heartbeat; |
220 | uint8_t has_alignment; /* Event header alignment */ |
221 | uint8_t tsc_lsb_truncate; |
222 | uint8_t tscbits; |
223 | uint32_t freq_scale; |
224 | uint64_t start_freq; |
225 | uint64_t start_tsc; |
226 | uint64_t start_monotonic; |
227 | uint64_t start_time_sec; |
228 | uint64_t start_time_usec; |
229 | } LTT_PACKED_STRUCT; |
230 | |
e939e5b2 |
231 | |
3aee1200 |
232 | struct ltt_block_start_header { |
233 | struct { |
3aee1200 |
234 | uint64_t cycle_count; |
986e2a7c |
235 | uint64_t freq; |
3aee1200 |
236 | } begin; |
237 | struct { |
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; |
c88ddec5 |
256 | guint network; // Is the type in network byte order ? |
7c6b3cd7 |
257 | }; |
258 | |
e3247aa5 |
259 | struct _LttEventType{ |
3aee1200 |
260 | GQuark name; |
45e14832 |
261 | gchar * description; |
f104d082 |
262 | guint index; //id of the event type within the facility |
e3247aa5 |
263 | LttFacility * facility; //the facility that contains the event type |
f104d082 |
264 | GArray * fields; //event's fields (LttField) |
265 | GData *fields_by_name; |
dd3a6d39 |
266 | int has_compact_data; //event header contains compact data (first field) |
7c6b3cd7 |
267 | }; |
268 | |
3aee1200 |
269 | /* Structure LttEvent and LttEventPosition must begin with the _exact_ same |
270 | * fields in the exact same order. LttEventPosition is a parent of LttEvent. */ |
c02ea99f |
271 | struct _LttEvent{ |
3aee1200 |
272 | |
273 | /* Begin of LttEventPosition fields */ |
274 | LttTracefile *tracefile; |
275 | unsigned int block; |
eed2ef37 |
276 | unsigned int offset; |
3aee1200 |
277 | |
278 | /* Timekeeping */ |
279 | uint64_t tsc; /* Current timestamp counter */ |
280 | |
281 | /* End of LttEventPosition fields */ |
282 | |
c88ddec5 |
283 | guint32 timestamp; /* truncated timestamp */ |
3aee1200 |
284 | |
c88ddec5 |
285 | unsigned char facility_id; /* facility ID are never reused. */ |
3aee1200 |
286 | unsigned char event_id; |
287 | |
c02ea99f |
288 | LttTime event_time; |
3aee1200 |
289 | |
c02ea99f |
290 | void * data; //event data |
77175651 |
291 | guint data_size; |
b77d1b57 |
292 | guint event_size; //event_size field of the header : |
293 | //used to verify data_size from facility. |
dd3a6d39 |
294 | uint32_t compact_data; |
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 |
d1bb700c |
325 | // equals the type size. |
f104d082 |
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 |
c88ddec5 |
380 | guint tid; //Usertrace tid, else 0 |
381 | guint pgid; //Usertrace pgid, else 0 |
382 | guint64 creation; //Usertrace creation, else 0 |
e3247aa5 |
383 | LttTrace * trace; //trace containing the tracefile |
384 | int fd; //file descriptor |
385 | off_t file_size; //file size |
f628823c |
386 | //unsigned block_size; //block_size |
f104d082 |
387 | guint num_blocks; //number of blocks in the file |
3aee1200 |
388 | gboolean reverse_bo; //must we reverse byte order ? |
3b10b765 |
389 | gboolean float_word_order; //what is the byte order of floats ? |
c88ddec5 |
390 | size_t has_alignment; //alignment of events in the tracefile. |
391 | // 0 or the architecture size in bytes. |
3aee1200 |
392 | |
823820eb |
393 | size_t buffer_header_size; |
d1bb700c |
394 | int compact; //compact tracefile ? |
395 | uint8_t tsc_lsb_truncate; |
396 | uint8_t tscbits; |
397 | uint8_t tsc_msb_cutoff; |
398 | uint64_t tsc_mask; |
399 | uint64_t tsc_mask_next_bit; //next MSB after the mask |
823820eb |
400 | |
c88ddec5 |
401 | /* Current event */ |
3aee1200 |
402 | LttEvent event; //Event currently accessible in the trace |
403 | |
c88ddec5 |
404 | /* Current block */ |
3aee1200 |
405 | LttBuffer buffer; //current buffer |
406 | guint32 buf_size; /* The size of blocks */ |
407 | |
c88ddec5 |
408 | /* Time flow */ |
3aee1200 |
409 | //unsigned int count; //the number of overflow of cycle count |
410 | //double nsec_per_cycle; //Nsec per cycle |
411 | //TimeHeartbeat * last_heartbeat; //last heartbeat |
412 | |
887208b7 |
413 | //LttCycleCount cycles_per_nsec_reciprocal; // Optimisation for speed |
3aee1200 |
414 | //void * last_event_pos; |
7c6b3cd7 |
415 | |
3aee1200 |
416 | //LttTime prev_block_end_time; //the end time of previous block |
417 | //LttTime prev_event_time; //the time of the previous event |
418 | //LttCycleCount pre_cycle_count; //previous cycle count of the event |
e3247aa5 |
419 | }; |
7c6b3cd7 |
420 | |
3aee1200 |
421 | struct _LttTrace{ |
422 | GQuark pathname; //the pathname of the trace |
423 | //LttSystemDescription * system_description;//system description |
424 | |
425 | GArray *facilities_by_num; /* fac_id as index in array */ |
426 | GData *facilities_by_name; /* fac name (GQuark) as index */ |
427 | /* Points to array of fac_id of all the |
b56dcdf2 |
428 | * facilities that has this name. */ |
429 | guint num_cpu; |
3aee1200 |
430 | |
16fcbb80 |
431 | guint32 arch_type; |
432 | guint32 arch_variant; |
433 | guint8 arch_size; |
3aee1200 |
434 | guint8 ltt_major_version; |
435 | guint8 ltt_minor_version; |
436 | guint8 flight_recorder; |
437 | guint8 has_heartbeat; |
c88ddec5 |
438 | guint32 freq_scale; |
791dffa6 |
439 | uint64_t start_freq; |
440 | uint64_t start_tsc; |
986e2a7c |
441 | uint64_t start_monotonic; |
442 | LttTime start_time; |
88612d17 |
443 | LttTime start_time_from_tsc; |
d1bb700c |
444 | GArray *compact_facilities; |
dd3a6d39 |
445 | uint8_t compact_event_bits; |
3aee1200 |
446 | |
447 | GData *tracefiles; //tracefiles groups |
80da81ad |
448 | }; |
7c6b3cd7 |
449 | |
a5dcde2f |
450 | /* The characteristics of the system on which the trace was obtained |
451 | is described in a LttSystemDescription structure. */ |
452 | |
453 | struct _LttSystemDescription { |
45e14832 |
454 | gchar *description; |
455 | gchar *node_name; |
456 | gchar *domain_name; |
a5dcde2f |
457 | unsigned nb_cpu; |
458 | LttArchSize size; |
459 | LttArchEndian endian; |
45e14832 |
460 | gchar *kernel_name; |
461 | gchar *kernel_release; |
462 | gchar *kernel_version; |
463 | gchar *machine; |
464 | gchar *processor; |
465 | gchar *hardware_platform; |
466 | gchar *operating_system; |
a5dcde2f |
467 | LttTime trace_start; |
468 | LttTime trace_end; |
469 | }; |
470 | |
7c6b3cd7 |
471 | /***************************************************************************** |
472 | macro for size of some data types |
473 | *****************************************************************************/ |
3aee1200 |
474 | // alignment -> dynamic! |
475 | |
476 | //#define TIMESTAMP_SIZE sizeof(guint32) |
477 | //#define EVENT_ID_SIZE sizeof(guint16) |
478 | //#define EVENT_HEADER_SIZE (TIMESTAMP_SIZE + EVENT_ID_SIZE) |
479 | |
7c6b3cd7 |
480 | |
83e160f2 |
481 | off_t get_alignment(LttField *field); |
482 | |
f104d082 |
483 | /* Calculate the offset needed to align the type. |
484 | * If has_alignment is 0, alignment is disactivated. |
485 | * else, the function returns the offset needed to |
486 | * align align_drift on the has_alignment value (should be |
487 | * the size of the architecture). */ |
488 | static inline unsigned int ltt_align(size_t align_drift, |
83e160f2 |
489 | size_t size_of_type, |
490 | size_t has_alignment) |
f104d082 |
491 | { |
c88ddec5 |
492 | size_t alignment = min(has_alignment, size_of_type); |
493 | |
494 | if(!has_alignment) return 0; |
495 | |
496 | g_assert(size_of_type != 0); |
497 | return ((alignment - align_drift) & (alignment-1)); |
f104d082 |
498 | } |
499 | |
f104d082 |
500 | |
fcdf0ec2 |
501 | #endif /* LTT_PRIVATE_H */ |