libltt compiles
[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 uint16_t event_id;
141 uint16_t event_size;
142 } LTT_PACKED_STRUCT;
143
144 struct ltt_event_header_nohb {
145 uint64_t timestamp;
146 uint16_t event_id;
147 uint16_t event_size;
148 } LTT_PACKED_STRUCT;
149
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 */
164 uint32_t freq_scale;
165 } LTT_PACKED_STRUCT;
166
167 struct ltt_trace_header_1_0 {
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
188
189 struct ltt_block_start_header {
190 struct {
191 uint64_t cycle_count;
192 uint64_t freq;
193 } begin;
194 struct {
195 uint64_t cycle_count;
196 uint64_t freq;
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 */
200 struct ltt_trace_header_any trace[0];
201 } LTT_PACKED_STRUCT;
202
203
204 struct _LttType{
205 // LTTV does not care about type names. Everything is a field.
206 // GQuark type_name; //type name if it is a named type
207 gchar * fmt;
208 guint size;
209 LttTypeEnum type_class; //which type
210 GHashTable *enum_map; //maps enum labels to numbers.
211 gint32 highest_value; //For enum
212 gint32 lowest_value; //For enum
213 GArray *fields; // Array of LttFields, for array, sequence, union, struct.
214 GData *fields_by_name;
215 guint network; // Is the type in network byte order ?
216 //part added by gaby for fmt:
217 char *header;
218 char *separator;
219 char *footer;
220 };
221
222 struct _LttEventType{
223 GQuark name;
224 gchar * description;
225 guint index; //id of the event type within the facility
226 struct marker_info *info;
227 GArray * fields; //event's fields (LttField)
228 GData *fields_by_name;
229 int has_compact_data; //event header contains compact data (first field)
230 };
231
232 /* Structure LttEvent and LttEventPosition must begin with the _exact_ same
233 * fields in the exact same order. LttEventPosition is a parent of LttEvent. */
234 struct _LttEvent{
235
236 /* Begin of LttEventPosition fields */
237 LttTracefile *tracefile;
238 unsigned int block;
239 unsigned int offset;
240
241 /* Timekeeping */
242 uint64_t tsc; /* Current timestamp counter */
243
244 /* End of LttEventPosition fields */
245
246 guint32 timestamp; /* truncated timestamp */
247
248 guint16 event_id;
249
250 LttTime event_time;
251
252 void * data; //event data
253 guint data_size;
254 guint event_size; //event_size field of the header :
255 //used to verify data_size from facility.
256 uint32_t compact_data;
257
258 int count; //the number of overflow of cycle count
259 gint64 overflow_nsec; //precalculated nsec for overflows
260 };
261
262 struct _LttEventPosition{
263 LttTracefile *tracefile;
264 unsigned int block;
265 unsigned int offset;
266
267 /* Timekeeping */
268 uint64_t tsc; /* Current timestamp counter */
269 };
270
271
272 enum field_status { FIELD_UNKNOWN, FIELD_VARIABLE, FIELD_FIXED };
273
274 struct _LttField{
275 GQuark name;
276 gchar *description;
277 LttType field_type; //field type
278
279 off_t offset_root; //offset from the root
280 enum field_status fixed_root; //offset fixed according to the root
281
282 guint field_size; // size of the field
283 // Only if field type size is set to 0
284 // (it's variable), then the field_size should be
285 // dynamically calculated while reading the trace
286 // and put here. Otherwise, the field_size always
287 // equals the type size.
288 off_t array_offset; // offset of the beginning of the array (for array
289 // and sequences)
290 GArray * dynamic_offsets; // array of offsets calculated dynamically at
291 // each event for sequences and arrays that
292 // contain variable length fields.
293 };
294
295 #if 0
296 struct _LttFacility{
297 LttTrace *trace;
298 GQuark name;
299 guint32 checksum; //checksum of the facility
300 guint32 id; //id of the facility
301
302 guint32 int_size;
303 guint32 long_size;
304 guint32 pointer_size;
305 guint32 size_t_size;
306 guint32 alignment;
307
308 GArray *events;
309 GData *events_by_name;
310 // not necessary in LTTV GData *named_types;
311
312 unsigned char exists; /* 0 does not exist, 1 exists */
313 };
314 #endif //0
315
316 typedef struct _LttBuffer {
317 void * head;
318 unsigned int index;
319
320 struct {
321 LttTime timestamp;
322 uint64_t cycle_count;
323 uint64_t freq; /* Frequency in khz */
324 } begin;
325 struct {
326 LttTime timestamp;
327 uint64_t cycle_count;
328 uint64_t freq; /* Frequency in khz */
329 } end;
330 uint32_t lost_size; /* Size unused at the end of the buffer */
331
332 /* Timekeeping */
333 uint64_t tsc; /* Current timestamp counter */
334 uint64_t freq; /* Frequency in khz */
335 //double nsecs_per_cycle; /* Precalculated from freq */
336 guint32 cyc2ns_scale;
337 } LttBuffer;
338
339 struct _LttTracefile{
340 gboolean cpu_online; //is the cpu online ?
341 GQuark long_name; //tracefile complete filename
342 GQuark name; //tracefile name
343 guint cpu_num; //cpu number of the tracefile
344 guint tid; //Usertrace tid, else 0
345 guint pgid; //Usertrace pgid, else 0
346 guint64 creation; //Usertrace creation, else 0
347 LttTrace * trace; //trace containing the tracefile
348 int fd; //file descriptor
349 off_t file_size; //file size
350 //unsigned block_size; //block_size
351 guint num_blocks; //number of blocks in the file
352 gboolean reverse_bo; //must we reverse byte order ?
353 gboolean float_word_order; //what is the byte order of floats ?
354 size_t has_alignment; //alignment of events in the tracefile.
355 // 0 or the architecture size in bytes.
356
357 guint8 has_heartbeat;
358 size_t buffer_header_size;
359 int compact; //compact tracefile ?
360 uint8_t tsc_lsb_truncate;
361 uint8_t tscbits;
362 uint8_t tsc_msb_cutoff;
363 uint64_t tsc_mask;
364 uint64_t tsc_mask_next_bit; //next MSB after the mask
365
366 /* Current event */
367 LttEvent event; //Event currently accessible in the trace
368
369 /* Current block */
370 LttBuffer buffer; //current buffer
371 guint32 buf_size; /* The size of blocks */
372
373 /* Time flow */
374 //unsigned int count; //the number of overflow of cycle count
375 //double nsec_per_cycle; //Nsec per cycle
376 //TimeHeartbeat * last_heartbeat; //last heartbeat
377
378 //LttCycleCount cycles_per_nsec_reciprocal; // Optimisation for speed
379 //void * last_event_pos;
380
381 //LttTime prev_block_end_time; //the end time of previous block
382 //LttTime prev_event_time; //the time of the previous event
383 //LttCycleCount pre_cycle_count; //previous cycle count of the event
384 };
385
386 struct _LttTrace{
387 GQuark pathname; //the pathname of the trace
388 //LttSystemDescription * system_description;//system description
389
390 GArray *facilities_by_num; /* fac_id as index in array */
391 GData *facilities_by_name; /* fac name (GQuark) as index */
392 /* Points to array of fac_id of all the
393 * facilities that has this name. */
394 guint num_cpu;
395
396 guint32 arch_type;
397 guint32 arch_variant;
398 guint8 arch_size;
399 guint8 ltt_major_version;
400 guint8 ltt_minor_version;
401 guint8 flight_recorder;
402 guint32 freq_scale;
403 uint64_t start_freq;
404 uint64_t start_tsc;
405 uint64_t start_monotonic;
406 LttTime start_time;
407 LttTime start_time_from_tsc;
408 uint8_t compact_event_bits;
409
410 GData *tracefiles; //tracefiles groups
411 /* Support for markers */
412 GArray *markers; //indexed by marker ID
413 GHashTable *markers_hash; //indexed by name hash
414 };
415
416 /* The characteristics of the system on which the trace was obtained
417 is described in a LttSystemDescription structure. */
418
419 struct _LttSystemDescription {
420 gchar *description;
421 gchar *node_name;
422 gchar *domain_name;
423 unsigned nb_cpu;
424 LttArchSize size;
425 LttArchEndian endian;
426 gchar *kernel_name;
427 gchar *kernel_release;
428 gchar *kernel_version;
429 gchar *machine;
430 gchar *processor;
431 gchar *hardware_platform;
432 gchar *operating_system;
433 LttTime trace_start;
434 LttTime trace_end;
435 };
436
437 /*****************************************************************************
438 macro for size of some data types
439 *****************************************************************************/
440 // alignment -> dynamic!
441
442 //#define TIMESTAMP_SIZE sizeof(guint32)
443 //#define EVENT_ID_SIZE sizeof(guint16)
444 //#define EVENT_HEADER_SIZE (TIMESTAMP_SIZE + EVENT_ID_SIZE)
445
446
447 off_t get_alignment(LttField *field);
448
449 /* Calculate the offset needed to align the type.
450 * If has_alignment is 0, alignment is disactivated.
451 * else, the function returns the offset needed to
452 * align align_drift on the has_alignment value (should be
453 * the size of the architecture). */
454 static inline unsigned int ltt_align(size_t align_drift,
455 size_t size_of_type,
456 size_t has_alignment)
457 {
458 size_t alignment = min(has_alignment, size_of_type);
459
460 if(!has_alignment) return 0;
461
462 g_assert(size_of_type != 0);
463 return ((alignment - align_drift) & (alignment-1));
464 }
465
466
467 #endif /* LTT_PRIVATE_H */
This page took 0.055093 seconds and 4 git commands to generate.