apply patch by Gabriel Matni to add format string support for event fields
[lttv.git] / ltt / branches / poly / ltt / ltt-private.h
1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Xiangxiu Yang
3 * 2006 Mathieu Desnoyers
4 *
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.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
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.
18 */
19
20 #ifndef LTT_PRIVATE_H
21 #define LTT_PRIVATE_H
22
23 #include <glib.h>
24 #include <sys/types.h>
25 #include <ltt/ltt.h>
26 #include <endian.h>
27
28
29 #ifndef max
30 #define max(a,b) ((a)>(b)?(a):(b))
31 #endif
32
33 #ifndef min
34 #define min(a,b) ((a)<(b)?(a):(b))
35 #endif
36
37
38
39 #define LTT_MAGIC_NUMBER 0x00D6B7ED
40 #define LTT_REV_MAGIC_NUMBER 0xEDB7D600
41
42 #define NSEC_PER_USEC 1000
43
44 #define LTT_PACKED_STRUCT __attribute__ ((packed))
45
46 /* Hardcoded facilities */
47 #define LTT_FACILITY_CORE 0
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
56 #define SEQUENCE_AVG_ELEMENTS 1000
57
58 /* Hardcoded core events */
59 enum ltt_core_events {
60 LTT_EVENT_FACILITY_LOAD,
61 LTT_EVENT_FACILITY_UNLOAD,
62 LTT_EVENT_HEARTBEAT,
63 LTT_EVENT_HEARTBEAT_FULL,
64 LTT_EVENT_STATE_DUMP_FACILITY_LOAD
65 };
66
67
68 #if 0
69 /* enumeration definition */
70
71 typedef enum _BuildinEvent{
72 TRACE_FACILITY_LOAD = 0,
73 TRACE_BLOCK_START = 17,
74 TRACE_BLOCK_END = 18,
75 TRACE_TIME_HEARTBEAT= 19
76 } BuildinEvent;
77
78
79 /* structure definition */
80
81 typedef struct _FacilityLoad{
82 gchar * name;
83 LttChecksum checksum;
84 guint32 base_code;
85 } LTT_PACKED_STRUCT FacilityLoad;
86
87 typedef struct _BlockStart {
88 LttTime time; //Time stamp of this block
89 LttCycleCount cycle_count; //cycle count of the event
90 guint32 block_id; //block id
91 } LTT_PACKED_STRUCT BlockStart;
92
93 typedef struct _BlockEnd {
94 LttTime time; //Time stamp of this block
95 LttCycleCount cycle_count; //cycle count of the event
96 guint32 block_id; //block id
97 } LTT_PACKED_STRUCT BlockEnd;
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
106 /* Hardcoded facility load event : this plus an preceding "name" string */
107 struct LttFacilityLoad {
108 guint32 checksum;
109 guint32 id;
110 guint32 int_size;
111 guint32 long_size;
112 guint32 pointer_size;
113 guint32 size_t_size;
114 guint32 has_alignment;
115 } LTT_PACKED_STRUCT;
116
117 struct LttFacilityUnload {
118 guint32 id;
119 } LTT_PACKED_STRUCT;
120
121 struct LttStateDumpFacilityLoad {
122 guint32 checksum;
123 guint32 id;
124 guint32 int_size;
125 guint32 long_size;
126 guint32 pointer_size;
127 guint32 size_t_size;
128 guint32 has_alignment;
129 } LTT_PACKED_STRUCT;
130
131 /* Empty event */
132 typedef struct _TimeHeartbeat {
133 } LTT_PACKED_STRUCT TimeHeartbeat;
134
135 typedef struct _TimeHeartbeatFull {
136 guint64 tsc;
137 } LTT_PACKED_STRUCT TimeHeartbeatFull;
138
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;
144 } LTT_PACKED_STRUCT;
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;
151 } LTT_PACKED_STRUCT;
152
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 */
167 uint32_t freq_scale;
168 } LTT_PACKED_STRUCT;
169
170
171 /* For version 0.3 */
172
173 struct ltt_trace_header_0_3 {
174 uint32_t magic_number;
175 uint32_t arch_type;
176 uint32_t arch_variant;
177 uint32_t float_word_order;
178 uint8_t arch_size;
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 */
184 uint32_t freq_scale;
185 } LTT_PACKED_STRUCT;
186
187 /* For version 0.7 */
188
189 struct ltt_trace_header_0_7 {
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 */
200 uint32_t freq_scale;
201 uint64_t start_freq;
202 uint64_t start_tsc;
203 uint64_t start_monotonic;
204 uint64_t start_time_sec;
205 uint64_t start_time_usec;
206 } LTT_PACKED_STRUCT;
207
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
231
232 struct ltt_block_start_header {
233 struct {
234 uint64_t cycle_count;
235 uint64_t freq;
236 } begin;
237 struct {
238 uint64_t cycle_count;
239 uint64_t freq;
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 */
243 struct ltt_trace_header_any trace[0];
244 } LTT_PACKED_STRUCT;
245
246
247 struct _LttType{
248 // LTTV does not care about type names. Everything is a field.
249 // GQuark type_name; //type name if it is a named type
250 gchar * fmt;
251 guint size;
252 LttTypeEnum type_class; //which type
253 GHashTable *enum_map; //maps enum labels to numbers.
254 gint32 highest_value; //For enum
255 gint32 lowest_value; //For enum
256 GArray *fields; // Array of LttFields, for array, sequence, union, struct.
257 GData *fields_by_name;
258 guint network; // Is the type in network byte order ?
259 //part added by gaby for fmt:
260 char *header;
261 char *separator;
262 char *footer;
263 };
264
265 struct _LttEventType{
266 GQuark name;
267 gchar * description;
268 guint index; //id of the event type within the facility
269 LttFacility * facility; //the facility that contains the event type
270 GArray * fields; //event's fields (LttField)
271 GData *fields_by_name;
272 int has_compact_data; //event header contains compact data (first field)
273 };
274
275 /* Structure LttEvent and LttEventPosition must begin with the _exact_ same
276 * fields in the exact same order. LttEventPosition is a parent of LttEvent. */
277 struct _LttEvent{
278
279 /* Begin of LttEventPosition fields */
280 LttTracefile *tracefile;
281 unsigned int block;
282 unsigned int offset;
283
284 /* Timekeeping */
285 uint64_t tsc; /* Current timestamp counter */
286
287 /* End of LttEventPosition fields */
288
289 guint32 timestamp; /* truncated timestamp */
290
291 unsigned char facility_id; /* facility ID are never reused. */
292 unsigned char event_id;
293
294 LttTime event_time;
295
296 void * data; //event data
297 guint data_size;
298 guint event_size; //event_size field of the header :
299 //used to verify data_size from facility.
300 uint32_t compact_data;
301
302 int count; //the number of overflow of cycle count
303 gint64 overflow_nsec; //precalculated nsec for overflows
304 };
305
306 struct _LttEventPosition{
307 LttTracefile *tracefile;
308 unsigned int block;
309 unsigned int offset;
310
311 /* Timekeeping */
312 uint64_t tsc; /* Current timestamp counter */
313 };
314
315
316 enum field_status { FIELD_UNKNOWN, FIELD_VARIABLE, FIELD_FIXED };
317
318 struct _LttField{
319 GQuark name;
320 gchar *description;
321 LttType field_type; //field type
322
323 off_t offset_root; //offset from the root
324 enum field_status fixed_root; //offset fixed according to the root
325
326 guint field_size; // size of the field
327 // Only if field type size is set to 0
328 // (it's variable), then the field_size should be
329 // dynamically calculated while reading the trace
330 // and put here. Otherwise, the field_size always
331 // equals the type size.
332 off_t array_offset; // offset of the beginning of the array (for array
333 // and sequences)
334 GArray * dynamic_offsets; // array of offsets calculated dynamically at
335 // each event for sequences and arrays that
336 // contain variable length fields.
337 };
338
339 struct _LttFacility{
340 LttTrace *trace;
341 GQuark name;
342 guint32 checksum; //checksum of the facility
343 guint32 id; //id of the facility
344
345 guint32 int_size;
346 guint32 long_size;
347 guint32 pointer_size;
348 guint32 size_t_size;
349 guint32 alignment;
350
351 GArray *events;
352 GData *events_by_name;
353 // not necessary in LTTV GData *named_types;
354
355 unsigned char exists; /* 0 does not exist, 1 exists */
356 };
357
358 typedef struct _LttBuffer {
359 void * head;
360 unsigned int index;
361
362 struct {
363 LttTime timestamp;
364 uint64_t cycle_count;
365 uint64_t freq; /* Frequency in khz */
366 } begin;
367 struct {
368 LttTime timestamp;
369 uint64_t cycle_count;
370 uint64_t freq; /* Frequency in khz */
371 } end;
372 uint32_t lost_size; /* Size unused at the end of the buffer */
373
374 /* Timekeeping */
375 uint64_t tsc; /* Current timestamp counter */
376 uint64_t freq; /* Frequency in khz */
377 //double nsecs_per_cycle; /* Precalculated from freq */
378 guint32 cyc2ns_scale;
379 } LttBuffer;
380
381 struct _LttTracefile{
382 gboolean cpu_online; //is the cpu online ?
383 GQuark long_name; //tracefile complete filename
384 GQuark name; //tracefile name
385 guint cpu_num; //cpu number of the tracefile
386 guint tid; //Usertrace tid, else 0
387 guint pgid; //Usertrace pgid, else 0
388 guint64 creation; //Usertrace creation, else 0
389 LttTrace * trace; //trace containing the tracefile
390 int fd; //file descriptor
391 off_t file_size; //file size
392 //unsigned block_size; //block_size
393 guint num_blocks; //number of blocks in the file
394 gboolean reverse_bo; //must we reverse byte order ?
395 gboolean float_word_order; //what is the byte order of floats ?
396 size_t has_alignment; //alignment of events in the tracefile.
397 // 0 or the architecture size in bytes.
398
399 guint8 has_heartbeat;
400 size_t buffer_header_size;
401 int compact; //compact tracefile ?
402 uint8_t tsc_lsb_truncate;
403 uint8_t tscbits;
404 uint8_t tsc_msb_cutoff;
405 uint64_t tsc_mask;
406 uint64_t tsc_mask_next_bit; //next MSB after the mask
407
408 /* Current event */
409 LttEvent event; //Event currently accessible in the trace
410
411 /* Current block */
412 LttBuffer buffer; //current buffer
413 guint32 buf_size; /* The size of blocks */
414
415 /* Time flow */
416 //unsigned int count; //the number of overflow of cycle count
417 //double nsec_per_cycle; //Nsec per cycle
418 //TimeHeartbeat * last_heartbeat; //last heartbeat
419
420 //LttCycleCount cycles_per_nsec_reciprocal; // Optimisation for speed
421 //void * last_event_pos;
422
423 //LttTime prev_block_end_time; //the end time of previous block
424 //LttTime prev_event_time; //the time of the previous event
425 //LttCycleCount pre_cycle_count; //previous cycle count of the event
426 };
427
428 struct _LttTrace{
429 GQuark pathname; //the pathname of the trace
430 //LttSystemDescription * system_description;//system description
431
432 GArray *facilities_by_num; /* fac_id as index in array */
433 GData *facilities_by_name; /* fac name (GQuark) as index */
434 /* Points to array of fac_id of all the
435 * facilities that has this name. */
436 guint num_cpu;
437
438 guint32 arch_type;
439 guint32 arch_variant;
440 guint8 arch_size;
441 guint8 ltt_major_version;
442 guint8 ltt_minor_version;
443 guint8 flight_recorder;
444 guint32 freq_scale;
445 uint64_t start_freq;
446 uint64_t start_tsc;
447 uint64_t start_monotonic;
448 LttTime start_time;
449 LttTime start_time_from_tsc;
450 GArray *compact_facilities;
451 uint8_t compact_event_bits;
452
453 GData *tracefiles; //tracefiles groups
454 };
455
456 /* The characteristics of the system on which the trace was obtained
457 is described in a LttSystemDescription structure. */
458
459 struct _LttSystemDescription {
460 gchar *description;
461 gchar *node_name;
462 gchar *domain_name;
463 unsigned nb_cpu;
464 LttArchSize size;
465 LttArchEndian endian;
466 gchar *kernel_name;
467 gchar *kernel_release;
468 gchar *kernel_version;
469 gchar *machine;
470 gchar *processor;
471 gchar *hardware_platform;
472 gchar *operating_system;
473 LttTime trace_start;
474 LttTime trace_end;
475 };
476
477 /*****************************************************************************
478 macro for size of some data types
479 *****************************************************************************/
480 // alignment -> dynamic!
481
482 //#define TIMESTAMP_SIZE sizeof(guint32)
483 //#define EVENT_ID_SIZE sizeof(guint16)
484 //#define EVENT_HEADER_SIZE (TIMESTAMP_SIZE + EVENT_ID_SIZE)
485
486
487 off_t get_alignment(LttField *field);
488
489 /* Calculate the offset needed to align the type.
490 * If has_alignment is 0, alignment is disactivated.
491 * else, the function returns the offset needed to
492 * align align_drift on the has_alignment value (should be
493 * the size of the architecture). */
494 static inline unsigned int ltt_align(size_t align_drift,
495 size_t size_of_type,
496 size_t has_alignment)
497 {
498 size_t alignment = min(has_alignment, size_of_type);
499
500 if(!has_alignment) return 0;
501
502 g_assert(size_of_type != 0);
503 return ((alignment - align_drift) & (alignment-1));
504 }
505
506
507 #endif /* LTT_PRIVATE_H */
This page took 0.03973 seconds and 4 git commands to generate.