change find_field
[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 *
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
19#ifndef LTT_PRIVATE_H
20#define LTT_PRIVATE_H
21
22#include <glib.h>
23#include <sys/types.h>
24#include <ltt/ltt.h>
25#include <endian.h>
26
27
28#ifndef max
29#define max(a,b) ((a)>(b)?(a):(b))
30#endif
31
32
33#define LTT_MAGIC_NUMBER 0x00D6B7ED
34#define LTT_REV_MAGIC_NUMBER 0xEDB7D600
35
36#define NSEC_PER_USEC 1000
37
38#define LTT_PACKED_STRUCT __attribute__ ((packed))
39
40/* Hardcoded facilities */
41#define LTT_FACILITY_CORE 0
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
50#define SEQUENCE_AVG_ELEMENTS 1000
51
52/* Hardcoded core events */
53enum ltt_core_events {
54 LTT_EVENT_FACILITY_LOAD,
55 LTT_EVENT_FACILITY_UNLOAD,
56 LTT_EVENT_HEARTBEAT,
57 LTT_EVENT_STATE_DUMP_FACILITY_LOAD
58};
59
60
61#if 0
62/* enumeration definition */
63
64typedef enum _BuildinEvent{
65 TRACE_FACILITY_LOAD = 0,
66 TRACE_BLOCK_START = 17,
67 TRACE_BLOCK_END = 18,
68 TRACE_TIME_HEARTBEAT= 19
69} BuildinEvent;
70
71
72/* structure definition */
73
74typedef struct _FacilityLoad{
75 gchar * name;
76 LttChecksum checksum;
77 guint32 base_code;
78} LTT_PACKED_STRUCT FacilityLoad;
79
80typedef struct _BlockStart {
81 LttTime time; //Time stamp of this block
82 LttCycleCount cycle_count; //cycle count of the event
83 guint32 block_id; //block id
84} LTT_PACKED_STRUCT BlockStart;
85
86typedef struct _BlockEnd {
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 BlockEnd;
91#endif //0
92
93
94typedef guint8 uint8_t;
95typedef guint16 uint16_t;
96typedef guint32 uint32_t;
97typedef guint64 uint64_t;
98
99/* Hardcoded facility load event : this plus an preceding "name" string */
100struct LttFacilityLoad {
101 guint32 checksum;
102 guint32 id;
103 guint32 int_size;
104 guint32 long_size;
105 guint32 pointer_size;
106 guint32 size_t_size;
107 guint32 has_alignment;
108} LTT_PACKED_STRUCT;
109
110struct LttFacilityUnload {
111 guint32 id;
112} LTT_PACKED_STRUCT;
113
114struct LttStateDumpFacilityLoad {
115 guint32 checksum;
116 guint32 id;
117 guint32 int_size;
118 guint32 long_size;
119 guint32 pointer_size;
120 guint32 size_t_size;
121 guint32 has_alignment;
122} LTT_PACKED_STRUCT;
123
124typedef struct _TimeHeartbeat {
125 LttTime time; //Time stamp of this block
126 uint64_t cycle_count; //cycle count of the event
127} LTT_PACKED_STRUCT TimeHeartbeat;
128
129struct ltt_event_header_hb {
130 uint32_t timestamp;
131 unsigned char facility_id;
132 unsigned char event_id;
133 uint16_t event_size;
134} LTT_PACKED_STRUCT;
135
136struct ltt_event_header_nohb {
137 uint64_t timestamp;
138 unsigned char facility_id;
139 unsigned char event_id;
140 uint16_t event_size;
141} LTT_PACKED_STRUCT;
142
143
144/* Block and trace headers */
145
146struct 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
163struct ltt_trace_header_0_3 {
164 uint32_t magic_number;
165 uint32_t arch_type;
166 uint32_t arch_variant;
167 uint32_t float_word_order;
168 uint8_t arch_size;
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;
175} LTT_PACKED_STRUCT;
176
177/* For version 0.4 */
178
179struct 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;
191 uint64_t start_freq;
192 uint64_t start_tsc;
193 uint64_t start_monotonic;
194 struct timeval start_time;
195} LTT_PACKED_STRUCT;
196
197
198struct ltt_block_start_header {
199 struct {
200 struct timeval timestamp;
201 uint64_t cycle_count;
202 uint64_t freq;
203 } begin;
204 struct {
205 struct timeval timestamp;
206 uint64_t cycle_count;
207 uint64_t freq;
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 */
211 struct ltt_trace_header_any trace[0];
212} LTT_PACKED_STRUCT;
213
214
215struct _LttType{
216// LTTV does not care about type names. Everything is a field.
217// GQuark type_name; //type name if it is a named type
218 gchar * fmt;
219 guint size;
220 LttTypeEnum type_class; //which type
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;
224};
225
226struct _LttEventType{
227 GQuark name;
228 gchar * description;
229 guint index; //id of the event type within the facility
230 LttFacility * facility; //the facility that contains the event type
231 GArray * fields; //event's fields (LttField)
232 GData *fields_by_name;
233};
234
235/* Structure LttEvent and LttEventPosition must begin with the _exact_ same
236 * fields in the exact same order. LttEventPosition is a parent of LttEvent. */
237struct _LttEvent{
238
239 /* Begin of LttEventPosition fields */
240 LttTracefile *tracefile;
241 unsigned int block;
242 unsigned int offset;
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
257 LttTime event_time;
258
259 void * data; //event data
260 guint data_size;
261 guint event_size; //event_size field of the header :
262 //used to verify data_size from facility.
263
264 int count; //the number of overflow of cycle count
265 gint64 overflow_nsec; //precalculated nsec for overflows
266};
267
268struct _LttEventPosition{
269 LttTracefile *tracefile;
270 unsigned int block;
271 unsigned int offset;
272
273 /* Timekeeping */
274 uint64_t tsc; /* Current timestamp counter */
275};
276
277
278enum field_status { FIELD_UNKNOWN, FIELD_VARIABLE, FIELD_FIXED };
279
280struct _LttField{
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.
299};
300
301struct _LttFacility{
302 LttTrace *trace;
303 GQuark name;
304 guint32 checksum; //checksum of the facility
305 guint32 id; //id of the facility
306
307 guint32 int_size;
308 guint32 long_size;
309 guint32 pointer_size;
310 guint32 size_t_size;
311 guint32 alignment;
312
313 GArray *events;
314 GData *events_by_name;
315 // not necessary in LTTV GData *named_types;
316
317 unsigned char exists; /* 0 does not exist, 1 exists */
318};
319
320typedef struct _LttBuffer {
321 void * head;
322 unsigned int index;
323
324 struct {
325 LttTime timestamp;
326 uint64_t cycle_count;
327 uint64_t freq; /* Frequency in khz */
328 } begin;
329 struct {
330 LttTime timestamp;
331 uint64_t cycle_count;
332 uint64_t freq; /* Frequency in khz */
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 */
338 uint64_t freq; /* Frequency in khz */
339 //double nsecs_per_cycle; /* Precalculated from freq */
340 guint32 cyc2ns_scale;
341} LttBuffer;
342
343struct _LttTracefile{
344 gboolean cpu_online; //is the cpu online ?
345 GQuark long_name; //tracefile complete filename
346 GQuark name; //tracefile name
347 guint cpu_num; //cpu number of the tracefile
348 LttTrace * trace; //trace containing the tracefile
349 int fd; //file descriptor
350 off_t file_size; //file size
351 //unsigned block_size; //block_size
352 guint num_blocks; //number of blocks in the file
353 gboolean reverse_bo; //must we reverse byte order ?
354 gboolean float_word_order; //what is the byte order of floats ?
355 size_t has_alignment; //alignment of events in the tracefile.
356 // 0 or the architecture size in bytes.
357
358 size_t buffer_header_size;
359
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
372 //LttCycleCount cycles_per_nsec_reciprocal; // Optimisation for speed
373 //void * last_event_pos;
374
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
378};
379
380struct _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
387 * facilities that has this name. */
388 guint num_cpu;
389
390 guint32 arch_type;
391 guint32 arch_variant;
392 guint8 arch_size;
393 guint8 ltt_major_version;
394 guint8 ltt_minor_version;
395 guint8 flight_recorder;
396 guint8 has_heartbeat;
397 guint8 has_tsc;
398 uint64_t start_freq;
399 uint64_t start_tsc;
400 uint64_t start_monotonic;
401 LttTime start_time;
402 LttTime start_time_from_tsc;
403
404 GData *tracefiles; //tracefiles groups
405};
406
407/* The characteristics of the system on which the trace was obtained
408 is described in a LttSystemDescription structure. */
409
410struct _LttSystemDescription {
411 gchar *description;
412 gchar *node_name;
413 gchar *domain_name;
414 unsigned nb_cpu;
415 LttArchSize size;
416 LttArchEndian endian;
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;
424 LttTime trace_start;
425 LttTime trace_end;
426};
427
428/*****************************************************************************
429 macro for size of some data types
430 *****************************************************************************/
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
437
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). */
443static 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
452off_t field_align(LttTracefile *tf, LttField *field, off_t offset);
453
454
455#endif /* LTT_PRIVATE_H */
This page took 0.023249 seconds and 4 git commands to generate.