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