lttctl fix
[lttv.git] / ltt / branches / poly / ltt / ltt-private.h
CommitLineData
449cb9d7 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
fcdf0ec2 19#ifndef LTT_PRIVATE_H
20#define LTT_PRIVATE_H
21
858bd80a 22#include <glib.h>
cbd41522 23#include <sys/types.h>
fcdf0ec2 24#include <ltt/ltt.h>
3b10b765 25#include <endian.h>
e3247aa5 26
eed2ef37 27
28#ifndef max
29#define max(a,b) ((a)>(b)?(a):(b))
30#endif
31
32
3aee1200 33#define LTT_MAGIC_NUMBER 0x00D6B7ED
34#define LTT_REV_MAGIC_NUMBER 0xEDB7D600
35
36#define NSEC_PER_USEC 1000
37
cbd41522 38#define LTT_PACKED_STRUCT __attribute__ ((packed))
39
3aee1200 40/* Hardcoded facilities */
41#define LTT_FACILITY_CORE 0
3b10b765 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
3aee1200 50/* Hardcoded core events */
51enum ltt_core_events {
52 LTT_EVENT_FACILITY_LOAD,
53 LTT_EVENT_FACILITY_UNLOAD,
b77d1b57 54 LTT_EVENT_HEARTBEAT,
55 LTT_EVENT_STATE_DUMP_FACILITY_LOAD
3aee1200 56};
57
58
59#if 0
e3247aa5 60/* enumeration definition */
61
62typedef enum _BuildinEvent{
63 TRACE_FACILITY_LOAD = 0,
64 TRACE_BLOCK_START = 17,
65 TRACE_BLOCK_END = 18,
0d7aac52 66 TRACE_TIME_HEARTBEAT= 19
e3247aa5 67} BuildinEvent;
fcdf0ec2 68
7c6b3cd7 69
70/* structure definition */
71
e3247aa5 72typedef struct _FacilityLoad{
45e14832 73 gchar * name;
e3247aa5 74 LttChecksum checksum;
cbd41522 75 guint32 base_code;
e3247aa5 76} LTT_PACKED_STRUCT FacilityLoad;
77
78typedef struct _BlockStart {
3aee1200 79 LttTime time; //Time stamp of this block
e3247aa5 80 LttCycleCount cycle_count; //cycle count of the event
cbd41522 81 guint32 block_id; //block id
e3247aa5 82} LTT_PACKED_STRUCT BlockStart;
83
84typedef struct _BlockEnd {
3aee1200 85 LttTime time; //Time stamp of this block
e3247aa5 86 LttCycleCount cycle_count; //cycle count of the event
cbd41522 87 guint32 block_id; //block id
e3247aa5 88} LTT_PACKED_STRUCT BlockEnd;
3aee1200 89#endif //0
90
91
92typedef guint8 uint8_t;
93typedef guint16 uint16_t;
94typedef guint32 uint32_t;
95typedef guint64 uint64_t;
96
16fcbb80 97/* Hardcoded facility load event : this plus an preceding "name" string */
3aee1200 98struct LttFacilityLoad {
99 guint32 checksum;
100 guint32 id;
101 guint32 long_size;
102 guint32 pointer_size;
103 guint32 size_t_size;
104 guint32 alignment;
16fcbb80 105} LTT_PACKED_STRUCT;
3aee1200 106
107struct LttFacilityUnload {
108 guint32 id;
16fcbb80 109} LTT_PACKED_STRUCT;
3aee1200 110
111struct LttStateDumpFacilityLoad {
112 guint32 checksum;
113 guint32 id;
114 guint32 long_size;
115 guint32 pointer_size;
116 guint32 size_t_size;
117 guint32 alignment;
16fcbb80 118} LTT_PACKED_STRUCT;
e3247aa5 119
120typedef struct _TimeHeartbeat {
3aee1200 121 LttTime time; //Time stamp of this block
122 uint64_t cycle_count; //cycle count of the event
e3247aa5 123} LTT_PACKED_STRUCT TimeHeartbeat;
124
3aee1200 125struct ltt_event_header_hb {
126 uint32_t timestamp;
127 unsigned char facility_id;
128 unsigned char event_id;
129 uint16_t event_size;
16fcbb80 130} LTT_PACKED_STRUCT;
3aee1200 131
132struct ltt_event_header_nohb {
133 uint64_t timestamp;
134 unsigned char facility_id;
135 unsigned char event_id;
136 uint16_t event_size;
16fcbb80 137} LTT_PACKED_STRUCT;
3aee1200 138
b7576a11 139
140/* Block and trace headers */
141
142struct ltt_trace_header_any {
143 uint32_t magic_number;
144 uint32_t arch_type;
145 uint32_t arch_variant;
146 uint32_t float_word_order;
147 uint8_t arch_size;
148 uint8_t major_version;
149 uint8_t minor_version;
150 uint8_t flight_recorder;
151 uint8_t has_heartbeat;
152 uint8_t has_alignment; /* Event header alignment */
153 uint8_t has_tsc;
154} LTT_PACKED_STRUCT;
155
156
157/* For version 0.3 */
158
159struct ltt_trace_header_0_3 {
3aee1200 160 uint32_t magic_number;
161 uint32_t arch_type;
162 uint32_t arch_variant;
79257ba5 163 uint32_t float_word_order;
3aee1200 164 uint8_t arch_size;
b7576a11 165 uint8_t major_version;
166 uint8_t minor_version;
167 uint8_t flight_recorder;
168 uint8_t has_heartbeat;
169 uint8_t has_alignment; /* Event header alignment */
170 uint8_t has_tsc;
16fcbb80 171} LTT_PACKED_STRUCT;
3aee1200 172
173
b7576a11 174
3aee1200 175struct ltt_block_start_header {
176 struct {
177 struct timeval timestamp;
178 uint64_t cycle_count;
179 } begin;
180 struct {
181 struct timeval timestamp;
182 uint64_t cycle_count;
183 } end;
184 uint32_t lost_size; /* Size unused at the end of the buffer */
185 uint32_t buf_size; /* The size of this sub-buffer */
51551c6f 186 struct ltt_trace_header_any trace[0];
16fcbb80 187} LTT_PACKED_STRUCT;
3aee1200 188
e3247aa5 189
190struct _LttType{
3aee1200 191 GQuark type_name; //type name if it is a named type
192 GQuark element_name; //elements name of the struct
45e14832 193 gchar * fmt;
8d1e6362 194 unsigned int size;
e3247aa5 195 LttTypeEnum type_class; //which type
3aee1200 196 GQuark * enum_strings; //for enum labels
e3247aa5 197 struct _LttType ** element_type; //for array, sequence and struct
198 unsigned element_number; //the number of elements
199 //for enum, array, sequence and structure
7c6b3cd7 200};
201
e3247aa5 202struct _LttEventType{
3aee1200 203 GQuark name;
45e14832 204 gchar * description;
3aee1200 205 guint index; //id of the event type within the facility
e3247aa5 206 LttFacility * facility; //the facility that contains the event type
207 LttField * root_field; //root field
7c6b3cd7 208};
209
3aee1200 210/* Structure LttEvent and LttEventPosition must begin with the _exact_ same
211 * fields in the exact same order. LttEventPosition is a parent of LttEvent. */
c02ea99f 212struct _LttEvent{
3aee1200 213
214 /* Begin of LttEventPosition fields */
215 LttTracefile *tracefile;
216 unsigned int block;
eed2ef37 217 unsigned int offset;
3aee1200 218
219 /* Timekeeping */
220 uint64_t tsc; /* Current timestamp counter */
221
222 /* End of LttEventPosition fields */
223
224 union { /* choice by trace has_tsc */
225 guint32 timestamp; /* truncated timestamp */
226 LttTime delta;
227 } time;
228
229 unsigned char facility_id; /* facility ID are never reused. */
230 unsigned char event_id;
231
c02ea99f 232 LttTime event_time;
3aee1200 233
c02ea99f 234 void * data; //event data
77175651 235 guint data_size;
b77d1b57 236 guint event_size; //event_size field of the header :
237 //used to verify data_size from facility.
3aee1200 238
c02ea99f 239 int count; //the number of overflow of cycle count
2dee981d 240 gint64 overflow_nsec; //precalculated nsec for overflows
3aee1200 241};
dfb73233 242
3aee1200 243struct _LttEventPosition{
244 LttTracefile *tracefile;
245 unsigned int block;
eed2ef37 246 unsigned int offset;
3aee1200 247
248 /* Timekeeping */
249 uint64_t tsc; /* Current timestamp counter */
c02ea99f 250};
251
252
3aee1200 253enum field_status { FIELD_UNKNOWN, FIELD_VARIABLE, FIELD_FIXED };
254
e3247aa5 255struct _LttField{
3aee1200 256 //guint field_pos; //field position within its parent
e3247aa5 257 LttType * field_type; //field type, if it is root field
7c6b3cd7 258 //then it must be struct type
259
260 off_t offset_root; //offset from the root, -1:uninitialized
3aee1200 261 enum field_status fixed_root; //offset fixed according to the root
7c6b3cd7 262 //-1:uninitialized, 0:unfixed, 1:fixed
263 off_t offset_parent; //offset from the parent,-1:uninitialized
3aee1200 264 enum field_status fixed_parent; //offset fixed according to its parent
7c6b3cd7 265 //-1:uninitialized, 0:unfixed, 1:fixed
266 // void * base_address; //base address of the field ????
267
3aee1200 268 guint field_size; // //>0: size of the field,
269 // //0 : uncertain
270 // //-1: uninitialize
271 enum field_status fixed_size;
272
273 /* for sequence */
274 gint sequ_number_size; //the size of unsigned used to save the
0d7aac52 275 //number of elements in the sequence
276
3aee1200 277 gint element_size; //the element size of the sequence
278 //int field_fixed; //0: field has string or sequence
7c6b3cd7 279 //1: field has no string or sequenc
280 //-1: uninitialize
281
e3247aa5 282 struct _LttField * parent;
3aee1200 283 struct _LttField ** child; //for array, sequence, struct and union:
7c6b3cd7 284 //list of fields, it may have only one
3aee1200 285 //field if the element is not a struct or
286 //union
7c6b3cd7 287 unsigned current_element; //which element is currently processed
3aee1200 288 // Used for sequences and arrays.
7c6b3cd7 289};
290
7c6b3cd7 291
e3247aa5 292struct _LttFacility{
3aee1200 293 LttTrace *trace;
294 //gchar * name; //facility name
295 GQuark name;
296 guint32 checksum; //checksum of the facility
297 guint32 id; //id of the facility
298
299 guint32 pointer_size;
cb03932a 300 guint32 long_size;
3aee1200 301 guint32 size_t_size;
302 guint32 alignment;
303
304
305 //LttEventType ** events; //array of event types
306 //unsigned int event_number; //number of events in the facility
307 //LttType ** named_types;
308 //unsigned int named_types_number;
309
310 GArray *events;
311 GData *events_by_name;
312 // GArray *named_types;
313 //GData *named_types_by_name;
314 GData *named_types;
315
316 unsigned char exists; /* 0 does not exist, 1 exists */
7c6b3cd7 317};
318
3aee1200 319typedef struct _LttBuffer {
320 void * head;
321 unsigned int index;
322
323 struct {
324 LttTime timestamp;
325 uint64_t cycle_count;
326 } begin;
327 struct {
328 LttTime timestamp;
329 uint64_t cycle_count;
330 } end;
331 uint32_t lost_size; /* Size unused at the end of the buffer */
332
333 /* Timekeeping */
334 uint64_t tsc; /* Current timestamp counter */
335 double nsecs_per_cycle;
336} LttBuffer;
337
e3247aa5 338struct _LttTracefile{
3aee1200 339 gboolean cpu_online; //is the cpu online ?
d3d34f49 340 GQuark long_name; //tracefile complete filename
3aee1200 341 GQuark name; //tracefile name
342 guint cpu_num; //cpu number of the tracefile
e3247aa5 343 LttTrace * trace; //trace containing the tracefile
344 int fd; //file descriptor
345 off_t file_size; //file size
f628823c 346 //unsigned block_size; //block_size
3aee1200 347 unsigned int num_blocks; //number of blocks in the file
348 gboolean reverse_bo; //must we reverse byte order ?
3b10b765 349 gboolean float_word_order; //what is the byte order of floats ?
3aee1200 350
823820eb 351 size_t buffer_header_size;
352
3aee1200 353 /* Current event */
354 LttEvent event; //Event currently accessible in the trace
355
356 /* Current block */
357 LttBuffer buffer; //current buffer
358 guint32 buf_size; /* The size of blocks */
359
360 /* Time flow */
361 //unsigned int count; //the number of overflow of cycle count
362 //double nsec_per_cycle; //Nsec per cycle
363 //TimeHeartbeat * last_heartbeat; //last heartbeat
364
887208b7 365 //LttCycleCount cycles_per_nsec_reciprocal; // Optimisation for speed
3aee1200 366 //void * last_event_pos;
7c6b3cd7 367
3aee1200 368 //LttTime prev_block_end_time; //the end time of previous block
369 //LttTime prev_event_time; //the time of the previous event
370 //LttCycleCount pre_cycle_count; //previous cycle count of the event
e3247aa5 371};
7c6b3cd7 372
3aee1200 373struct _LttTrace{
374 GQuark pathname; //the pathname of the trace
375 //LttSystemDescription * system_description;//system description
376
377 GArray *facilities_by_num; /* fac_id as index in array */
378 GData *facilities_by_name; /* fac name (GQuark) as index */
379 /* Points to array of fac_id of all the
b56dcdf2 380 * facilities that has this name. */
381 guint num_cpu;
3aee1200 382
16fcbb80 383 guint32 arch_type;
384 guint32 arch_variant;
385 guint8 arch_size;
3aee1200 386 guint8 ltt_major_version;
387 guint8 ltt_minor_version;
388 guint8 flight_recorder;
389 guint8 has_heartbeat;
16fcbb80 390 guint8 has_alignment;
3aee1200 391 guint8 has_tsc;
392
393 GData *tracefiles; //tracefiles groups
80da81ad 394};
7c6b3cd7 395
a5dcde2f 396/* The characteristics of the system on which the trace was obtained
397 is described in a LttSystemDescription structure. */
398
399struct _LttSystemDescription {
45e14832 400 gchar *description;
401 gchar *node_name;
402 gchar *domain_name;
a5dcde2f 403 unsigned nb_cpu;
404 LttArchSize size;
405 LttArchEndian endian;
45e14832 406 gchar *kernel_name;
407 gchar *kernel_release;
408 gchar *kernel_version;
409 gchar *machine;
410 gchar *processor;
411 gchar *hardware_platform;
412 gchar *operating_system;
a5dcde2f 413 LttTime trace_start;
414 LttTime trace_end;
415};
416
7c6b3cd7 417/*****************************************************************************
418 macro for size of some data types
419 *****************************************************************************/
3aee1200 420// alignment -> dynamic!
421
422//#define TIMESTAMP_SIZE sizeof(guint32)
423//#define EVENT_ID_SIZE sizeof(guint16)
424//#define EVENT_HEADER_SIZE (TIMESTAMP_SIZE + EVENT_ID_SIZE)
425
7c6b3cd7 426
fcdf0ec2 427#endif /* LTT_PRIVATE_H */
This page took 0.05804 seconds and 4 git commands to generate.