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