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