Make sure libtraceread is completely licensed LGPL
[lttv.git] / ltt / branches / poly / ltt / ltt-private.h
... / ...
CommitLineData
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 */
59enum ltt_core_events {
60 LTT_EVENT_FACILITY_LOAD,
61 LTT_EVENT_FACILITY_UNLOAD,
62 LTT_EVENT_HEARTBEAT,
63 LTT_EVENT_STATE_DUMP_FACILITY_LOAD
64};
65
66
67#if 0
68/* enumeration definition */
69
70typedef 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
80typedef struct _FacilityLoad{
81 gchar * name;
82 LttChecksum checksum;
83 guint32 base_code;
84} LTT_PACKED_STRUCT FacilityLoad;
85
86typedef 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
92typedef 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
100typedef guint8 uint8_t;
101typedef guint16 uint16_t;
102typedef guint32 uint32_t;
103typedef guint64 uint64_t;
104
105/* Hardcoded facility load event : this plus an preceding "name" string */
106struct 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
116struct LttFacilityUnload {
117 guint32 id;
118} LTT_PACKED_STRUCT;
119
120struct 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
130typedef struct _TimeHeartbeat {
131 LttTime time; //Time stamp of this block
132 uint64_t cycle_count; //cycle count of the event
133} LTT_PACKED_STRUCT TimeHeartbeat;
134
135struct ltt_event_header_hb {
136 uint32_t timestamp;
137 unsigned char facility_id;
138 unsigned char event_id;
139 uint16_t event_size;
140} LTT_PACKED_STRUCT;
141
142struct ltt_event_header_nohb {
143 uint64_t timestamp;
144 unsigned char facility_id;
145 unsigned char event_id;
146 uint16_t event_size;
147} LTT_PACKED_STRUCT;
148
149
150/* Block and trace headers */
151
152struct 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 */
163 uint8_t has_tsc;
164} LTT_PACKED_STRUCT;
165
166
167/* For version 0.3 */
168
169struct ltt_trace_header_0_3 {
170 uint32_t magic_number;
171 uint32_t arch_type;
172 uint32_t arch_variant;
173 uint32_t float_word_order;
174 uint8_t arch_size;
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 */
180 uint8_t has_tsc;
181} LTT_PACKED_STRUCT;
182
183/* For version 0.6 */
184
185struct ltt_trace_header_0_6 {
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 */
196 uint8_t has_tsc;
197 uint64_t start_freq;
198 uint64_t start_tsc;
199 uint64_t start_monotonic;
200 //struct timespec start_time; // not portable
201 uint64_t start_time_sec;
202 uint64_t start_time_usec;
203} LTT_PACKED_STRUCT;
204
205
206struct ltt_block_start_header {
207 struct {
208 //struct timeval timestamp;
209 uint64_t timestamp_sec;
210 uint64_t timestamp_usec;
211 uint64_t cycle_count;
212 uint64_t freq;
213 } begin;
214 struct {
215 //struct timeval timestamp;
216 uint64_t timestamp_sec;
217 uint64_t timestamp_usec;
218 uint64_t cycle_count;
219 uint64_t freq;
220 } end;
221 uint32_t lost_size; /* Size unused at the end of the buffer */
222 uint32_t buf_size; /* The size of this sub-buffer */
223 struct ltt_trace_header_any trace[0];
224} LTT_PACKED_STRUCT;
225
226
227struct _LttType{
228// LTTV does not care about type names. Everything is a field.
229// GQuark type_name; //type name if it is a named type
230 gchar * fmt;
231 guint size;
232 LttTypeEnum type_class; //which type
233 GHashTable *enum_map; //maps enum labels to numbers.
234 GArray *fields; // Array of LttFields, for array, sequence, union, struct.
235 GData *fields_by_name;
236};
237
238struct _LttEventType{
239 GQuark name;
240 gchar * description;
241 guint index; //id of the event type within the facility
242 LttFacility * facility; //the facility that contains the event type
243 GArray * fields; //event's fields (LttField)
244 GData *fields_by_name;
245};
246
247/* Structure LttEvent and LttEventPosition must begin with the _exact_ same
248 * fields in the exact same order. LttEventPosition is a parent of LttEvent. */
249struct _LttEvent{
250
251 /* Begin of LttEventPosition fields */
252 LttTracefile *tracefile;
253 unsigned int block;
254 unsigned int offset;
255
256 /* Timekeeping */
257 uint64_t tsc; /* Current timestamp counter */
258
259 /* End of LttEventPosition fields */
260
261 union { /* choice by trace has_tsc */
262 guint32 timestamp; /* truncated timestamp */
263 LttTime delta;
264 } time;
265
266 unsigned char facility_id; /* facility ID are never reused. */
267 unsigned char event_id;
268
269 LttTime event_time;
270
271 void * data; //event data
272 guint data_size;
273 guint event_size; //event_size field of the header :
274 //used to verify data_size from facility.
275
276 int count; //the number of overflow of cycle count
277 gint64 overflow_nsec; //precalculated nsec for overflows
278};
279
280struct _LttEventPosition{
281 LttTracefile *tracefile;
282 unsigned int block;
283 unsigned int offset;
284
285 /* Timekeeping */
286 uint64_t tsc; /* Current timestamp counter */
287};
288
289
290enum field_status { FIELD_UNKNOWN, FIELD_VARIABLE, FIELD_FIXED };
291
292struct _LttField{
293 GQuark name;
294 gchar *description;
295 LttType field_type; //field type
296
297 off_t offset_root; //offset from the root
298 enum field_status fixed_root; //offset fixed according to the root
299
300 guint field_size; // size of the field
301 // Only if field type size is set to 0
302 // (it's variable), then the field_size should be
303 // dynamically calculated while reading the trace
304 // and put here. Otherwise, the field_size always
305 // equels the type size.
306 off_t array_offset; // offset of the beginning of the array (for array
307 // and sequences)
308 GArray * dynamic_offsets; // array of offsets calculated dynamically at
309 // each event for sequences and arrays that
310 // contain variable length fields.
311};
312
313struct _LttFacility{
314 LttTrace *trace;
315 GQuark name;
316 guint32 checksum; //checksum of the facility
317 guint32 id; //id of the facility
318
319 guint32 int_size;
320 guint32 long_size;
321 guint32 pointer_size;
322 guint32 size_t_size;
323 guint32 alignment;
324
325 GArray *events;
326 GData *events_by_name;
327 // not necessary in LTTV GData *named_types;
328
329 unsigned char exists; /* 0 does not exist, 1 exists */
330};
331
332typedef struct _LttBuffer {
333 void * head;
334 unsigned int index;
335
336 struct {
337 LttTime timestamp;
338 uint64_t cycle_count;
339 uint64_t freq; /* Frequency in khz */
340 } begin;
341 struct {
342 LttTime timestamp;
343 uint64_t cycle_count;
344 uint64_t freq; /* Frequency in khz */
345 } end;
346 uint32_t lost_size; /* Size unused at the end of the buffer */
347
348 /* Timekeeping */
349 uint64_t tsc; /* Current timestamp counter */
350 uint64_t freq; /* Frequency in khz */
351 //double nsecs_per_cycle; /* Precalculated from freq */
352 guint32 cyc2ns_scale;
353} LttBuffer;
354
355struct _LttTracefile{
356 gboolean cpu_online; //is the cpu online ?
357 GQuark long_name; //tracefile complete filename
358 GQuark name; //tracefile name
359 guint cpu_num; //cpu number of the tracefile
360 LttTrace * trace; //trace containing the tracefile
361 int fd; //file descriptor
362 off_t file_size; //file size
363 //unsigned block_size; //block_size
364 guint num_blocks; //number of blocks in the file
365 gboolean reverse_bo; //must we reverse byte order ?
366 gboolean float_word_order; //what is the byte order of floats ?
367 size_t has_alignment; //alignment of events in the tracefile.
368 // 0 or the architecture size in bytes.
369
370 size_t buffer_header_size;
371
372 /* Current event */
373 LttEvent event; //Event currently accessible in the trace
374
375 /* Current block */
376 LttBuffer buffer; //current buffer
377 guint32 buf_size; /* The size of blocks */
378
379 /* Time flow */
380 //unsigned int count; //the number of overflow of cycle count
381 //double nsec_per_cycle; //Nsec per cycle
382 //TimeHeartbeat * last_heartbeat; //last heartbeat
383
384 //LttCycleCount cycles_per_nsec_reciprocal; // Optimisation for speed
385 //void * last_event_pos;
386
387 //LttTime prev_block_end_time; //the end time of previous block
388 //LttTime prev_event_time; //the time of the previous event
389 //LttCycleCount pre_cycle_count; //previous cycle count of the event
390};
391
392struct _LttTrace{
393 GQuark pathname; //the pathname of the trace
394 //LttSystemDescription * system_description;//system description
395
396 GArray *facilities_by_num; /* fac_id as index in array */
397 GData *facilities_by_name; /* fac name (GQuark) as index */
398 /* Points to array of fac_id of all the
399 * facilities that has this name. */
400 guint num_cpu;
401
402 guint32 arch_type;
403 guint32 arch_variant;
404 guint8 arch_size;
405 guint8 ltt_major_version;
406 guint8 ltt_minor_version;
407 guint8 flight_recorder;
408 guint8 has_heartbeat;
409 guint8 has_tsc;
410 uint64_t start_freq;
411 uint64_t start_tsc;
412 uint64_t start_monotonic;
413 LttTime start_time;
414 LttTime start_time_from_tsc;
415
416 GData *tracefiles; //tracefiles groups
417};
418
419/* The characteristics of the system on which the trace was obtained
420 is described in a LttSystemDescription structure. */
421
422struct _LttSystemDescription {
423 gchar *description;
424 gchar *node_name;
425 gchar *domain_name;
426 unsigned nb_cpu;
427 LttArchSize size;
428 LttArchEndian endian;
429 gchar *kernel_name;
430 gchar *kernel_release;
431 gchar *kernel_version;
432 gchar *machine;
433 gchar *processor;
434 gchar *hardware_platform;
435 gchar *operating_system;
436 LttTime trace_start;
437 LttTime trace_end;
438};
439
440/*****************************************************************************
441 macro for size of some data types
442 *****************************************************************************/
443// alignment -> dynamic!
444
445//#define TIMESTAMP_SIZE sizeof(guint32)
446//#define EVENT_ID_SIZE sizeof(guint16)
447//#define EVENT_HEADER_SIZE (TIMESTAMP_SIZE + EVENT_ID_SIZE)
448
449
450/* Calculate the offset needed to align the type.
451 * If has_alignment is 0, alignment is disactivated.
452 * else, the function returns the offset needed to
453 * align align_drift on the has_alignment value (should be
454 * the size of the architecture). */
455static inline unsigned int ltt_align(size_t align_drift,
456 size_t size_of_type,
457 size_t has_alignment)
458{
459 size_t alignment = min(has_alignment, size_of_type);
460
461 if(!has_alignment) return 0;
462
463 return ((alignment - align_drift) & (alignment-1));
464}
465
466
467#endif /* LTT_PRIVATE_H */
This page took 0.023103 seconds and 4 git commands to generate.