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