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