some compile fix
[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 #include <ltt/event.h>
28 #include <ltt/markers.h>
29 #include <ltt/trace.h>
30
31 #ifndef max
32 #define max(a,b) ((a)>(b)?(a):(b))
33 #endif
34
35 #ifndef min
36 #define min(a,b) ((a)<(b)?(a):(b))
37 #endif
38
39
40
41 #define LTT_MAGIC_NUMBER 0x00D6B7ED
42 #define LTT_REV_MAGIC_NUMBER 0xEDB7D600
43
44 #define NSEC_PER_USEC 1000
45
46 #define LTT_PACKED_STRUCT __attribute__ ((packed))
47
48 /* Hardcoded facilities */
49 #define LTT_FACILITY_CORE 0
50
51 /* Byte ordering */
52 #define LTT_GET_BO(t) ((t)->reverse_bo)
53
54 #define LTT_HAS_FLOAT(t) ((t)->float_word_order!=0)
55 #define LTT_GET_FLOAT_BO(t) \
56 (((t)->float_word_order==__BYTE_ORDER)?0:1)
57
58 #define SEQUENCE_AVG_ELEMENTS 1000
59
60 /* Hardcoded core events */
61 enum ltt_core_events {
62 LTT_EVENT_FACILITY_LOAD,
63 LTT_EVENT_FACILITY_UNLOAD,
64 LTT_EVENT_HEARTBEAT,
65 LTT_EVENT_HEARTBEAT_FULL,
66 LTT_EVENT_STATE_DUMP_FACILITY_LOAD
67 };
68
69
70 #if 0
71 /* enumeration definition */
72
73 typedef enum _BuildinEvent{
74 TRACE_FACILITY_LOAD = 0,
75 TRACE_BLOCK_START = 17,
76 TRACE_BLOCK_END = 18,
77 TRACE_TIME_HEARTBEAT= 19
78 } BuildinEvent;
79
80
81 /* structure definition */
82
83 typedef struct _FacilityLoad{
84 gchar * name;
85 LttChecksum checksum;
86 guint32 base_code;
87 } LTT_PACKED_STRUCT FacilityLoad;
88
89 typedef struct _BlockStart {
90 LttTime time; //Time stamp of this block
91 LttCycleCount cycle_count; //cycle count of the event
92 guint32 block_id; //block id
93 } LTT_PACKED_STRUCT BlockStart;
94
95 typedef struct _BlockEnd {
96 LttTime time; //Time stamp of this block
97 LttCycleCount cycle_count; //cycle count of the event
98 guint32 block_id; //block id
99 } LTT_PACKED_STRUCT BlockEnd;
100 #endif //0
101
102
103 typedef guint8 uint8_t;
104 typedef guint16 uint16_t;
105 typedef guint32 uint32_t;
106 typedef guint64 uint64_t;
107
108 /* Hardcoded facility load event : this plus an preceding "name" string */
109 struct LttFacilityLoad {
110 guint32 checksum;
111 guint32 id;
112 guint32 int_size;
113 guint32 long_size;
114 guint32 pointer_size;
115 guint32 size_t_size;
116 guint32 has_alignment;
117 } LTT_PACKED_STRUCT;
118
119 struct LttFacilityUnload {
120 guint32 id;
121 } LTT_PACKED_STRUCT;
122
123 struct LttStateDumpFacilityLoad {
124 guint32 checksum;
125 guint32 id;
126 guint32 int_size;
127 guint32 long_size;
128 guint32 pointer_size;
129 guint32 size_t_size;
130 guint32 has_alignment;
131 } LTT_PACKED_STRUCT;
132
133 /* Empty event */
134 typedef struct _TimeHeartbeat {
135 } LTT_PACKED_STRUCT TimeHeartbeat;
136
137 typedef struct _TimeHeartbeatFull {
138 guint64 tsc;
139 } LTT_PACKED_STRUCT TimeHeartbeatFull;
140
141 struct ltt_event_header_hb {
142 uint32_t timestamp;
143 uint16_t event_id;
144 uint16_t event_size;
145 } LTT_PACKED_STRUCT;
146
147 struct ltt_event_header_nohb {
148 uint64_t timestamp;
149 uint16_t event_id;
150 uint16_t event_size;
151 } LTT_PACKED_STRUCT;
152
153
154 /* Block and trace headers */
155
156 struct ltt_trace_header_any {
157 uint32_t magic_number;
158 uint32_t arch_type;
159 uint32_t arch_variant;
160 uint32_t float_word_order;
161 uint8_t arch_size;
162 uint8_t major_version;
163 uint8_t minor_version;
164 uint8_t flight_recorder;
165 uint8_t has_heartbeat;
166 uint8_t has_alignment; /* Event header alignment */
167 uint32_t freq_scale;
168 } LTT_PACKED_STRUCT;
169
170 struct ltt_trace_header_1_0 {
171 uint32_t magic_number;
172 uint32_t arch_type;
173 uint32_t arch_variant;
174 uint32_t float_word_order;
175 uint8_t arch_size;
176 uint8_t major_version;
177 uint8_t minor_version;
178 uint8_t flight_recorder;
179 uint8_t has_heartbeat;
180 uint8_t has_alignment; /* Event header alignment */
181 uint8_t tsc_lsb_truncate;
182 uint8_t tscbits;
183 uint32_t freq_scale;
184 uint64_t start_freq;
185 uint64_t start_tsc;
186 uint64_t start_monotonic;
187 uint64_t start_time_sec;
188 uint64_t start_time_usec;
189 } LTT_PACKED_STRUCT;
190
191
192 struct ltt_block_start_header {
193 struct {
194 uint64_t cycle_count;
195 uint64_t freq;
196 } begin;
197 struct {
198 uint64_t cycle_count;
199 uint64_t freq;
200 } end;
201 uint32_t lost_size; /* Size unused at the end of the buffer */
202 uint32_t buf_size; /* The size of this sub-buffer */
203 struct ltt_trace_header_any trace[0];
204 } LTT_PACKED_STRUCT;
205
206
207 #if 0
208 struct _LttType{
209 // LTTV does not care about type names. Everything is a field.
210 // GQuark type_name; //type name if it is a named type
211 gchar * fmt;
212 guint size;
213 LttTypeEnum type_class; //which type
214 GHashTable *enum_map; //maps enum labels to numbers.
215 gint32 highest_value; //For enum
216 gint32 lowest_value; //For enum
217 GArray *fields; // Array of LttFields, for array, sequence, union, struct.
218 GData *fields_by_name;
219 guint network; // Is the type in network byte order ?
220 //part added by gaby for fmt:
221 char *header;
222 char *separator;
223 char *footer;
224 };
225 #endif //0
226
227 #if 0
228 struct _LttEventType{
229 GQuark name;
230 gchar * description;
231 guint index; //id of the event type within the facility
232 struct marker_info *info;
233 GArray * fields; //event's fields (LttField)
234 GData *fields_by_name;
235 int has_compact_data; //event header contains compact data (first field)
236 };
237 #endif //0
238
239 enum field_status { FIELD_UNKNOWN, FIELD_VARIABLE, FIELD_FIXED };
240
241 #if 0
242 struct _LttField{
243 GQuark name;
244 gchar *description;
245 LttType field_type; //field type
246
247 off_t offset_root; //offset from the root
248 enum field_status fixed_root; //offset fixed according to the root
249
250 guint field_size; // size of the field
251 // Only if field type size is set to 0
252 // (it's variable), then the field_size should be
253 // dynamically calculated while reading the trace
254 // and put here. Otherwise, the field_size always
255 // equals the type size.
256 off_t array_offset; // offset of the beginning of the array (for array
257 // and sequences)
258 GArray * dynamic_offsets; // array of offsets calculated dynamically at
259 // each event for sequences and arrays that
260 // contain variable length fields.
261 };
262 #endif //0
263 #if 0
264 struct _LttFacility{
265 LttTrace *trace;
266 GQuark name;
267 guint32 checksum; //checksum of the facility
268 guint32 id; //id of the facility
269
270 guint32 int_size;
271 guint32 long_size;
272 guint32 pointer_size;
273 guint32 size_t_size;
274 guint32 alignment;
275
276 GArray *events;
277 GData *events_by_name;
278 // not necessary in LTTV GData *named_types;
279
280 unsigned char exists; /* 0 does not exist, 1 exists */
281 };
282 #endif //0
283
284 typedef struct _LttBuffer {
285 void * head;
286 unsigned int index;
287
288 struct {
289 LttTime timestamp;
290 uint64_t cycle_count;
291 uint64_t freq; /* Frequency in khz */
292 } begin;
293 struct {
294 LttTime timestamp;
295 uint64_t cycle_count;
296 uint64_t freq; /* Frequency in khz */
297 } end;
298 uint32_t lost_size; /* Size unused at the end of the buffer */
299
300 /* Timekeeping */
301 uint64_t tsc; /* Current timestamp counter */
302 uint64_t freq; /* Frequency in khz */
303 //double nsecs_per_cycle; /* Precalculated from freq */
304 guint32 cyc2ns_scale;
305 } LttBuffer;
306
307 struct LttTracefile {
308 gboolean cpu_online; //is the cpu online ?
309 GQuark long_name; //tracefile complete filename
310 GQuark name; //tracefile name
311 guint cpu_num; //cpu number of the tracefile
312 guint tid; //Usertrace tid, else 0
313 guint pgid; //Usertrace pgid, else 0
314 guint64 creation; //Usertrace creation, else 0
315 LttTrace * trace; //trace containing the tracefile
316 int fd; //file descriptor
317 off_t file_size; //file size
318 //unsigned block_size; //block_size
319 guint num_blocks; //number of blocks in the file
320 gboolean reverse_bo; //must we reverse byte order ?
321 gboolean float_word_order; //what is the byte order of floats ?
322 size_t has_alignment; //alignment of events in the tracefile.
323 // 0 or the architecture size in bytes.
324
325 guint8 has_heartbeat;
326 size_t buffer_header_size;
327 int compact; //compact tracefile ?
328 uint8_t tsc_lsb_truncate;
329 uint8_t tscbits;
330 uint8_t tsc_msb_cutoff;
331 uint64_t tsc_mask;
332 uint64_t tsc_mask_next_bit; //next MSB after the mask
333
334 /* Current event */
335 LttEvent event; //Event currently accessible in the trace
336
337 /* Current block */
338 LttBuffer buffer; //current buffer
339 guint32 buf_size; /* The size of blocks */
340
341 /* Time flow */
342 //unsigned int count; //the number of overflow of cycle count
343 //double nsec_per_cycle; //Nsec per cycle
344 //TimeHeartbeat * last_heartbeat; //last heartbeat
345
346 //LttCycleCount cycles_per_nsec_reciprocal; // Optimisation for speed
347 //void * last_event_pos;
348
349 //LttTime prev_block_end_time; //the end time of previous block
350 //LttTime prev_event_time; //the time of the previous event
351 //LttCycleCount pre_cycle_count; //previous cycle count of the event
352 };
353
354 /* The characteristics of the system on which the trace was obtained
355 is described in a LttSystemDescription structure. */
356
357 struct LttSystemDescription {
358 gchar *description;
359 gchar *node_name;
360 gchar *domain_name;
361 unsigned nb_cpu;
362 LttArchSize size;
363 LttArchEndian endian;
364 gchar *kernel_name;
365 gchar *kernel_release;
366 gchar *kernel_version;
367 gchar *machine;
368 gchar *processor;
369 gchar *hardware_platform;
370 gchar *operating_system;
371 LttTime trace_start;
372 LttTime trace_end;
373 };
374
375 /*****************************************************************************
376 macro for size of some data types
377 *****************************************************************************/
378 // alignment -> dynamic!
379
380 //#define TIMESTAMP_SIZE sizeof(guint32)
381 //#define EVENT_ID_SIZE sizeof(guint16)
382 //#define EVENT_HEADER_SIZE (TIMESTAMP_SIZE + EVENT_ID_SIZE)
383
384
385 //off_t get_alignment(LttField *field);
386
387 /* Calculate the offset needed to align the type.
388 * If has_alignment is 0, alignment is disactivated.
389 * else, the function returns the offset needed to
390 * align align_drift on the has_alignment value (should be
391 * the size of the architecture). */
392 static inline unsigned int ltt_align(size_t align_drift,
393 size_t size_of_type,
394 size_t has_alignment)
395 {
396 size_t alignment = min(has_alignment, size_of_type);
397
398 if(!has_alignment) return 0;
399
400 g_assert(size_of_type != 0);
401 return ((alignment - align_drift) & (alignment-1));
402 }
403
404
405 #endif /* LTT_PRIVATE_H */
This page took 0.037495 seconds and 5 git commands to generate.