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