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