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