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