449cb9d7 |
1 | /* This file is part of the Linux Trace Toolkit viewer |
2 | * Copyright (C) 2003-2004 Xiangxiu Yang |
1b44b0b5 |
3 | * 2006 Mathieu Desnoyers |
449cb9d7 |
4 | * |
1b44b0b5 |
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. |
449cb9d7 |
8 | * |
1b44b0b5 |
9 | * This library is distributed in the hope that it will be useful, |
449cb9d7 |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1b44b0b5 |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Lesser General Public License for more details. |
449cb9d7 |
13 | * |
1b44b0b5 |
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. |
449cb9d7 |
18 | */ |
19 | |
fcdf0ec2 |
20 | #ifndef LTT_PRIVATE_H |
21 | #define LTT_PRIVATE_H |
22 | |
858bd80a |
23 | #include <glib.h> |
cbd41522 |
24 | #include <sys/types.h> |
fcdf0ec2 |
25 | #include <ltt/ltt.h> |
3b10b765 |
26 | #include <endian.h> |
29af7cfd |
27 | #include <ltt/event.h> |
bb38a290 |
28 | #include <ltt/marker.h> |
29af7cfd |
29 | #include <ltt/trace.h> |
e3247aa5 |
30 | |
eed2ef37 |
31 | #ifndef max |
32 | #define max(a,b) ((a)>(b)?(a):(b)) |
33 | #endif |
34 | |
2312de30 |
35 | #ifndef min |
36 | #define min(a,b) ((a)<(b)?(a):(b)) |
37 | #endif |
38 | |
39 | |
eed2ef37 |
40 | |
3aee1200 |
41 | #define LTT_MAGIC_NUMBER 0x00D6B7ED |
42 | #define LTT_REV_MAGIC_NUMBER 0xEDB7D600 |
43 | |
44 | #define NSEC_PER_USEC 1000 |
45 | |
cbd41522 |
46 | #define LTT_PACKED_STRUCT __attribute__ ((packed)) |
47 | |
3aee1200 |
48 | /* Hardcoded facilities */ |
49 | #define LTT_FACILITY_CORE 0 |
3b10b765 |
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 | |
f104d082 |
58 | #define SEQUENCE_AVG_ELEMENTS 1000 |
59 | |
3aee1200 |
60 | /* Hardcoded core events */ |
61 | enum ltt_core_events { |
62 | LTT_EVENT_FACILITY_LOAD, |
63 | LTT_EVENT_FACILITY_UNLOAD, |
b77d1b57 |
64 | LTT_EVENT_HEARTBEAT, |
d1bb700c |
65 | LTT_EVENT_HEARTBEAT_FULL, |
b77d1b57 |
66 | LTT_EVENT_STATE_DUMP_FACILITY_LOAD |
3aee1200 |
67 | }; |
68 | |
69 | |
70 | #if 0 |
e3247aa5 |
71 | /* enumeration definition */ |
72 | |
73 | typedef enum _BuildinEvent{ |
74 | TRACE_FACILITY_LOAD = 0, |
75 | TRACE_BLOCK_START = 17, |
76 | TRACE_BLOCK_END = 18, |
0d7aac52 |
77 | TRACE_TIME_HEARTBEAT= 19 |
e3247aa5 |
78 | } BuildinEvent; |
fcdf0ec2 |
79 | |
7c6b3cd7 |
80 | |
81 | /* structure definition */ |
82 | |
e3247aa5 |
83 | typedef struct _FacilityLoad{ |
45e14832 |
84 | gchar * name; |
e3247aa5 |
85 | LttChecksum checksum; |
cbd41522 |
86 | guint32 base_code; |
e3247aa5 |
87 | } LTT_PACKED_STRUCT FacilityLoad; |
88 | |
89 | typedef struct _BlockStart { |
3aee1200 |
90 | LttTime time; //Time stamp of this block |
e3247aa5 |
91 | LttCycleCount cycle_count; //cycle count of the event |
cbd41522 |
92 | guint32 block_id; //block id |
e3247aa5 |
93 | } LTT_PACKED_STRUCT BlockStart; |
94 | |
95 | typedef struct _BlockEnd { |
3aee1200 |
96 | LttTime time; //Time stamp of this block |
e3247aa5 |
97 | LttCycleCount cycle_count; //cycle count of the event |
cbd41522 |
98 | guint32 block_id; //block id |
e3247aa5 |
99 | } LTT_PACKED_STRUCT BlockEnd; |
3aee1200 |
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 | |
3aee1200 |
108 | struct ltt_event_header_hb { |
109 | uint32_t timestamp; |
3c165eaf |
110 | uint16_t event_id; |
3aee1200 |
111 | uint16_t event_size; |
16fcbb80 |
112 | } LTT_PACKED_STRUCT; |
3aee1200 |
113 | |
114 | struct ltt_event_header_nohb { |
115 | uint64_t timestamp; |
3c165eaf |
116 | uint16_t event_id; |
3aee1200 |
117 | uint16_t event_size; |
16fcbb80 |
118 | } LTT_PACKED_STRUCT; |
3aee1200 |
119 | |
b7576a11 |
120 | |
121 | /* Block and trace headers */ |
122 | |
123 | struct ltt_trace_header_any { |
124 | uint32_t magic_number; |
125 | uint32_t arch_type; |
126 | uint32_t arch_variant; |
127 | uint32_t float_word_order; |
128 | uint8_t arch_size; |
129 | uint8_t major_version; |
130 | uint8_t minor_version; |
131 | uint8_t flight_recorder; |
132 | uint8_t has_heartbeat; |
256a5b3a |
133 | uint8_t alignment; /* Event header alignment */ |
c88ddec5 |
134 | uint32_t freq_scale; |
b7576a11 |
135 | } LTT_PACKED_STRUCT; |
136 | |
3c165eaf |
137 | struct ltt_trace_header_1_0 { |
d1bb700c |
138 | uint32_t magic_number; |
139 | uint32_t arch_type; |
140 | uint32_t arch_variant; |
141 | uint32_t float_word_order; |
142 | uint8_t arch_size; |
143 | uint8_t major_version; |
144 | uint8_t minor_version; |
145 | uint8_t flight_recorder; |
146 | uint8_t has_heartbeat; |
256a5b3a |
147 | uint8_t alignment; /* Event header alignment */ |
d1bb700c |
148 | uint8_t tsc_lsb_truncate; |
149 | uint8_t tscbits; |
08a986f1 |
150 | uint8_t compact_data_shift; |
d1bb700c |
151 | uint32_t freq_scale; |
152 | uint64_t start_freq; |
153 | uint64_t start_tsc; |
154 | uint64_t start_monotonic; |
155 | uint64_t start_time_sec; |
156 | uint64_t start_time_usec; |
157 | } LTT_PACKED_STRUCT; |
158 | |
e939e5b2 |
159 | |
3aee1200 |
160 | struct ltt_block_start_header { |
161 | struct { |
3aee1200 |
162 | uint64_t cycle_count; |
986e2a7c |
163 | uint64_t freq; |
3aee1200 |
164 | } begin; |
165 | struct { |
3aee1200 |
166 | uint64_t cycle_count; |
986e2a7c |
167 | uint64_t freq; |
3aee1200 |
168 | } end; |
169 | uint32_t lost_size; /* Size unused at the end of the buffer */ |
170 | uint32_t buf_size; /* The size of this sub-buffer */ |
51551c6f |
171 | struct ltt_trace_header_any trace[0]; |
16fcbb80 |
172 | } LTT_PACKED_STRUCT; |
3aee1200 |
173 | |
e3247aa5 |
174 | |
14b1ac27 |
175 | #if 0 |
e3247aa5 |
176 | struct _LttType{ |
f104d082 |
177 | // LTTV does not care about type names. Everything is a field. |
178 | // GQuark type_name; //type name if it is a named type |
45e14832 |
179 | gchar * fmt; |
f104d082 |
180 | guint size; |
e3247aa5 |
181 | LttTypeEnum type_class; //which type |
2312de30 |
182 | GHashTable *enum_map; //maps enum labels to numbers. |
880fded3 |
183 | gint32 highest_value; //For enum |
184 | gint32 lowest_value; //For enum |
f104d082 |
185 | GArray *fields; // Array of LttFields, for array, sequence, union, struct. |
186 | GData *fields_by_name; |
c88ddec5 |
187 | guint network; // Is the type in network byte order ? |
e8548639 |
188 | //part added by gaby for fmt: |
189 | char *header; |
190 | char *separator; |
191 | char *footer; |
7c6b3cd7 |
192 | }; |
14b1ac27 |
193 | #endif //0 |
7c6b3cd7 |
194 | |
d7913a10 |
195 | #if 0 |
e3247aa5 |
196 | struct _LttEventType{ |
3aee1200 |
197 | GQuark name; |
45e14832 |
198 | gchar * description; |
f104d082 |
199 | guint index; //id of the event type within the facility |
3c165eaf |
200 | struct marker_info *info; |
f104d082 |
201 | GArray * fields; //event's fields (LttField) |
202 | GData *fields_by_name; |
dd3a6d39 |
203 | int has_compact_data; //event header contains compact data (first field) |
7c6b3cd7 |
204 | }; |
d7913a10 |
205 | #endif //0 |
7c6b3cd7 |
206 | |
3aee1200 |
207 | enum field_status { FIELD_UNKNOWN, FIELD_VARIABLE, FIELD_FIXED }; |
208 | |
14b1ac27 |
209 | #if 0 |
e3247aa5 |
210 | struct _LttField{ |
f104d082 |
211 | GQuark name; |
212 | gchar *description; |
213 | LttType field_type; //field type |
214 | |
215 | off_t offset_root; //offset from the root |
216 | enum field_status fixed_root; //offset fixed according to the root |
217 | |
218 | guint field_size; // size of the field |
219 | // Only if field type size is set to 0 |
220 | // (it's variable), then the field_size should be |
221 | // dynamically calculated while reading the trace |
222 | // and put here. Otherwise, the field_size always |
d1bb700c |
223 | // equals the type size. |
f104d082 |
224 | off_t array_offset; // offset of the beginning of the array (for array |
225 | // and sequences) |
226 | GArray * dynamic_offsets; // array of offsets calculated dynamically at |
227 | // each event for sequences and arrays that |
228 | // contain variable length fields. |
7c6b3cd7 |
229 | }; |
14b1ac27 |
230 | #endif //0 |
3c165eaf |
231 | #if 0 |
e3247aa5 |
232 | struct _LttFacility{ |
3aee1200 |
233 | LttTrace *trace; |
3aee1200 |
234 | GQuark name; |
235 | guint32 checksum; //checksum of the facility |
236 | guint32 id; //id of the facility |
237 | |
f104d082 |
238 | guint32 int_size; |
cb03932a |
239 | guint32 long_size; |
f104d082 |
240 | guint32 pointer_size; |
3aee1200 |
241 | guint32 size_t_size; |
242 | guint32 alignment; |
243 | |
3aee1200 |
244 | GArray *events; |
245 | GData *events_by_name; |
f104d082 |
246 | // not necessary in LTTV GData *named_types; |
3aee1200 |
247 | |
248 | unsigned char exists; /* 0 does not exist, 1 exists */ |
7c6b3cd7 |
249 | }; |
3c165eaf |
250 | #endif //0 |
7c6b3cd7 |
251 | |
3aee1200 |
252 | typedef struct _LttBuffer { |
253 | void * head; |
254 | unsigned int index; |
255 | |
256 | struct { |
257 | LttTime timestamp; |
258 | uint64_t cycle_count; |
986e2a7c |
259 | uint64_t freq; /* Frequency in khz */ |
3aee1200 |
260 | } begin; |
261 | struct { |
262 | LttTime timestamp; |
263 | uint64_t cycle_count; |
986e2a7c |
264 | uint64_t freq; /* Frequency in khz */ |
3aee1200 |
265 | } end; |
266 | uint32_t lost_size; /* Size unused at the end of the buffer */ |
267 | |
268 | /* Timekeeping */ |
269 | uint64_t tsc; /* Current timestamp counter */ |
986e2a7c |
270 | uint64_t freq; /* Frequency in khz */ |
791dffa6 |
271 | //double nsecs_per_cycle; /* Precalculated from freq */ |
272 | guint32 cyc2ns_scale; |
3aee1200 |
273 | } LttBuffer; |
274 | |
29af7cfd |
275 | struct LttTracefile { |
3aee1200 |
276 | gboolean cpu_online; //is the cpu online ? |
d3d34f49 |
277 | GQuark long_name; //tracefile complete filename |
3aee1200 |
278 | GQuark name; //tracefile name |
279 | guint cpu_num; //cpu number of the tracefile |
c88ddec5 |
280 | guint tid; //Usertrace tid, else 0 |
281 | guint pgid; //Usertrace pgid, else 0 |
282 | guint64 creation; //Usertrace creation, else 0 |
e3247aa5 |
283 | LttTrace * trace; //trace containing the tracefile |
284 | int fd; //file descriptor |
285 | off_t file_size; //file size |
f628823c |
286 | //unsigned block_size; //block_size |
f104d082 |
287 | guint num_blocks; //number of blocks in the file |
3aee1200 |
288 | gboolean reverse_bo; //must we reverse byte order ? |
3b10b765 |
289 | gboolean float_word_order; //what is the byte order of floats ? |
256a5b3a |
290 | size_t alignment; //alignment of events in the tracefile. |
c88ddec5 |
291 | // 0 or the architecture size in bytes. |
3aee1200 |
292 | |
90440c06 |
293 | guint8 has_heartbeat; |
823820eb |
294 | size_t buffer_header_size; |
d1bb700c |
295 | int compact; //compact tracefile ? |
296 | uint8_t tsc_lsb_truncate; |
297 | uint8_t tscbits; |
298 | uint8_t tsc_msb_cutoff; |
08a986f1 |
299 | uint8_t compact_event_bits; |
d1bb700c |
300 | uint64_t tsc_mask; |
301 | uint64_t tsc_mask_next_bit; //next MSB after the mask |
823820eb |
302 | |
c88ddec5 |
303 | /* Current event */ |
3aee1200 |
304 | LttEvent event; //Event currently accessible in the trace |
305 | |
c88ddec5 |
306 | /* Current block */ |
3aee1200 |
307 | LttBuffer buffer; //current buffer |
308 | guint32 buf_size; /* The size of blocks */ |
309 | |
c88ddec5 |
310 | /* Time flow */ |
3aee1200 |
311 | //unsigned int count; //the number of overflow of cycle count |
312 | //double nsec_per_cycle; //Nsec per cycle |
313 | //TimeHeartbeat * last_heartbeat; //last heartbeat |
314 | |
887208b7 |
315 | //LttCycleCount cycles_per_nsec_reciprocal; // Optimisation for speed |
3aee1200 |
316 | //void * last_event_pos; |
7c6b3cd7 |
317 | |
3aee1200 |
318 | //LttTime prev_block_end_time; //the end time of previous block |
319 | //LttTime prev_event_time; //the time of the previous event |
320 | //LttCycleCount pre_cycle_count; //previous cycle count of the event |
e3247aa5 |
321 | }; |
7c6b3cd7 |
322 | |
a5dcde2f |
323 | /* The characteristics of the system on which the trace was obtained |
324 | is described in a LttSystemDescription structure. */ |
325 | |
29af7cfd |
326 | struct LttSystemDescription { |
45e14832 |
327 | gchar *description; |
328 | gchar *node_name; |
329 | gchar *domain_name; |
a5dcde2f |
330 | unsigned nb_cpu; |
331 | LttArchSize size; |
332 | LttArchEndian endian; |
45e14832 |
333 | gchar *kernel_name; |
334 | gchar *kernel_release; |
335 | gchar *kernel_version; |
336 | gchar *machine; |
337 | gchar *processor; |
338 | gchar *hardware_platform; |
339 | gchar *operating_system; |
a5dcde2f |
340 | LttTime trace_start; |
341 | LttTime trace_end; |
342 | }; |
343 | |
7c6b3cd7 |
344 | /***************************************************************************** |
345 | macro for size of some data types |
346 | *****************************************************************************/ |
3aee1200 |
347 | // alignment -> dynamic! |
348 | |
349 | //#define TIMESTAMP_SIZE sizeof(guint32) |
350 | //#define EVENT_ID_SIZE sizeof(guint16) |
351 | //#define EVENT_HEADER_SIZE (TIMESTAMP_SIZE + EVENT_ID_SIZE) |
352 | |
7c6b3cd7 |
353 | |
29af7cfd |
354 | //off_t get_alignment(LttField *field); |
83e160f2 |
355 | |
f104d082 |
356 | /* Calculate the offset needed to align the type. |
256a5b3a |
357 | * If alignment is 0, alignment is disactivated. |
f104d082 |
358 | * else, the function returns the offset needed to |
256a5b3a |
359 | * align align_drift on the alignment value (should be |
f104d082 |
360 | * the size of the architecture). */ |
361 | static inline unsigned int ltt_align(size_t align_drift, |
83e160f2 |
362 | size_t size_of_type, |
256a5b3a |
363 | size_t alignment) |
f104d082 |
364 | { |
256a5b3a |
365 | size_t align_offset = min(alignment, size_of_type); |
c88ddec5 |
366 | |
256a5b3a |
367 | if(!alignment) |
368 | return 0; |
c88ddec5 |
369 | |
370 | g_assert(size_of_type != 0); |
256a5b3a |
371 | return ((align_offset - align_drift) & (align_offset-1)); |
f104d082 |
372 | } |
373 | |
f104d082 |
374 | |
fcdf0ec2 |
375 | #endif /* LTT_PRIVATE_H */ |