449cb9d7 |
1 | /* This file is part of the Linux Trace Toolkit viewer |
3aee1200 |
2 | * Copyright (C) 2005 Mathieu Desnoyers |
449cb9d7 |
3 | * |
3aee1200 |
4 | * Complete rewrite from the original version made by XangXiu Yang. |
5 | * |
1b44b0b5 |
6 | * This library is free software; you can redistribute it and/or |
7 | * modify it under the terms of the GNU Lesser General Public |
8 | * License Version 2.1 as published by the Free Software Foundation. |
449cb9d7 |
9 | * |
1b44b0b5 |
10 | * This library is distributed in the hope that it will be useful, |
449cb9d7 |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1b44b0b5 |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | * Lesser General Public License for more details. |
449cb9d7 |
14 | * |
1b44b0b5 |
15 | * You should have received a copy of the GNU Lesser General Public |
16 | * License along with this library; if not, write to the |
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | * Boston, MA 02111-1307, USA. |
449cb9d7 |
19 | */ |
20 | |
4e4d11b3 |
21 | #ifdef HAVE_CONFIG_H |
22 | #include <config.h> |
23 | #endif |
24 | |
6cd62ccf |
25 | #include <stdio.h> |
26 | #include <fcntl.h> |
8d1e6362 |
27 | #include <string.h> |
28 | #include <dirent.h> |
6cd62ccf |
29 | #include <sys/stat.h> |
30 | #include <sys/types.h> |
8d1e6362 |
31 | #include <errno.h> |
32 | #include <unistd.h> |
42db9bf1 |
33 | #include <math.h> |
cdf90f40 |
34 | #include <glib.h> |
3aee1200 |
35 | #include <malloc.h> |
36 | #include <sys/mman.h> |
dd3a6d39 |
37 | #include <string.h> |
6cd62ccf |
38 | |
ef35d837 |
39 | // For realpath |
40 | #include <limits.h> |
41 | #include <stdlib.h> |
42 | |
43 | |
6cd62ccf |
44 | #include "parser.h" |
a5dcde2f |
45 | #include <ltt/ltt.h> |
46 | #include "ltt-private.h" |
963b5f2d |
47 | #include <ltt/trace.h> |
a5dcde2f |
48 | #include <ltt/facility.h> |
c02ea99f |
49 | #include <ltt/event.h> |
8d1e6362 |
50 | #include <ltt/type.h> |
1a2ceb63 |
51 | #include <ltt/ltt-types.h> |
6cd62ccf |
52 | |
3aee1200 |
53 | |
54 | /* Facility names used in this file */ |
55 | |
56 | GQuark LTT_FACILITY_NAME_HEARTBEAT, |
d1bb700c |
57 | LTT_EVENT_NAME_HEARTBEAT, |
58 | LTT_EVENT_NAME_HEARTBEAT_FULL; |
3aee1200 |
59 | GQuark LTT_TRACEFILE_NAME_FACILITIES; |
60 | |
86005ded |
61 | #ifndef g_open |
62 | #define g_open open |
63 | #endif |
64 | |
65 | |
51b5991e |
66 | #define __UNUSED__ __attribute__((__unused__)) |
6cd62ccf |
67 | |
a1062ddd |
68 | #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format) |
3aee1200 |
69 | |
70 | #ifndef g_debug |
a1062ddd |
71 | #define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format) |
3aee1200 |
72 | #endif |
a1062ddd |
73 | |
45e14832 |
74 | #define g_close close |
8959a0c8 |
75 | |
b77d1b57 |
76 | /* Those macros must be called from within a function where page_size is a known |
77 | * variable */ |
78 | #define PAGE_MASK (~(page_size-1)) |
79 | #define PAGE_ALIGN(addr) (((addr)+page_size-1)&PAGE_MASK) |
80 | |
6cd62ccf |
81 | /* set the offset of the fields belonging to the event, |
82 | need the information of the archecture */ |
f104d082 |
83 | //void set_fields_offsets(LttTracefile *tf, LttEventType *event_type); |
eed2ef37 |
84 | //size_t get_fields_offsets(LttTracefile *tf, LttEventType *event_type, void *data); |
6cd62ccf |
85 | |
3aee1200 |
86 | /* get the size of the field type according to |
87 | * The facility size information. */ |
f104d082 |
88 | #if 0 |
3aee1200 |
89 | static inline void preset_field_type_size(LttTracefile *tf, |
90 | LttEventType *event_type, |
91 | off_t offset_root, off_t offset_parent, |
92 | enum field_status *fixed_root, enum field_status *fixed_parent, |
93 | LttField *field); |
f104d082 |
94 | #endif //0 |
6cd62ccf |
95 | |
3aee1200 |
96 | /* map a fixed size or a block information from the file (fd) */ |
97 | static gint map_block(LttTracefile * tf, guint block_num); |
98 | |
99 | /* calculate nsec per cycles for current block */ |
791dffa6 |
100 | #if 0 |
101 | static guint32 calc_nsecs_per_cycle(LttTracefile * t); |
102 | static guint64 cycles_2_ns(LttTracefile *tf, guint64 cycles); |
103 | #endif //0 |
6cd62ccf |
104 | |
3aee1200 |
105 | /* go to the next event */ |
106 | static int ltt_seek_next_event(LttTracefile *tf); |
6cd62ccf |
107 | |
eed2ef37 |
108 | void ltt_update_event_size(LttTracefile *tf); |
109 | |
2312de30 |
110 | |
743e50fd |
111 | void precompute_offsets(LttFacility *fac, LttEventType *event); |
2312de30 |
112 | |
3aee1200 |
113 | #if 0 |
43da6a59 |
114 | /* Functions to parse system.xml file (using glib xml parser) */ |
51b5991e |
115 | static void parser_start_element (GMarkupParseContext __UNUSED__ *context, |
43da6a59 |
116 | const gchar *element_name, |
117 | const gchar **attribute_names, |
118 | const gchar **attribute_values, |
119 | gpointer user_data, |
120 | GError **error) |
121 | { |
122 | int i=0; |
123 | LttSystemDescription* des = (LttSystemDescription* )user_data; |
124 | if(strcmp("system", element_name)){ |
2a74fbf4 |
125 | *error = g_error_new(G_MARKUP_ERROR, |
126 | G_LOG_LEVEL_WARNING, |
127 | "This is not system.xml file"); |
128 | return; |
43da6a59 |
129 | } |
130 | |
131 | while(attribute_names[i]){ |
132 | if(strcmp("node_name", attribute_names[i])==0){ |
133 | des->node_name = g_strdup(attribute_values[i]); |
134 | }else if(strcmp("domainname", attribute_names[i])==0){ |
135 | des->domain_name = g_strdup(attribute_values[i]); |
136 | }else if(strcmp("cpu", attribute_names[i])==0){ |
137 | des->nb_cpu = atoi(attribute_values[i]); |
138 | }else if(strcmp("arch_size", attribute_names[i])==0){ |
139 | if(strcmp(attribute_values[i],"LP32") == 0) des->size = LTT_LP32; |
140 | else if(strcmp(attribute_values[i],"ILP32") == 0) des->size = LTT_ILP32; |
141 | else if(strcmp(attribute_values[i],"LP64") == 0) des->size = LTT_LP64; |
142 | else if(strcmp(attribute_values[i],"ILP64") == 0) des->size = LTT_ILP64; |
143 | else if(strcmp(attribute_values[i],"UNKNOWN") == 0) des->size = LTT_UNKNOWN; |
144 | }else if(strcmp("endian", attribute_names[i])==0){ |
145 | if(strcmp(attribute_values[i],"LITTLE_ENDIAN") == 0) |
146 | des->endian = LTT_LITTLE_ENDIAN; |
147 | else if(strcmp(attribute_values[i],"BIG_ENDIAN") == 0) |
148 | des->endian = LTT_BIG_ENDIAN; |
149 | }else if(strcmp("kernel_name", attribute_names[i])==0){ |
150 | des->kernel_name = g_strdup(attribute_values[i]); |
151 | }else if(strcmp("kernel_release", attribute_names[i])==0){ |
152 | des->kernel_release = g_strdup(attribute_values[i]); |
153 | }else if(strcmp("kernel_version", attribute_names[i])==0){ |
154 | des->kernel_version = g_strdup(attribute_values[i]); |
155 | }else if(strcmp("machine", attribute_names[i])==0){ |
156 | des->machine = g_strdup(attribute_values[i]); |
157 | }else if(strcmp("processor", attribute_names[i])==0){ |
158 | des->processor = g_strdup(attribute_values[i]); |
159 | }else if(strcmp("hardware_platform", attribute_names[i])==0){ |
160 | des->hardware_platform = g_strdup(attribute_values[i]); |
161 | }else if(strcmp("operating_system", attribute_names[i])==0){ |
162 | des->operating_system = g_strdup(attribute_values[i]); |
163 | }else if(strcmp("ltt_major_version", attribute_names[i])==0){ |
164 | des->ltt_major_version = atoi(attribute_values[i]); |
165 | }else if(strcmp("ltt_minor_version", attribute_names[i])==0){ |
166 | des->ltt_minor_version = atoi(attribute_values[i]); |
167 | }else if(strcmp("ltt_block_size", attribute_names[i])==0){ |
168 | des->ltt_block_size = atoi(attribute_values[i]); |
169 | }else{ |
2a74fbf4 |
170 | *error = g_error_new(G_MARKUP_ERROR, |
171 | G_LOG_LEVEL_WARNING, |
172 | "Not a valid attribute"); |
173 | return; |
43da6a59 |
174 | } |
175 | i++; |
176 | } |
177 | } |
178 | |
51b5991e |
179 | static void parser_characters (GMarkupParseContext __UNUSED__ *context, |
43da6a59 |
180 | const gchar *text, |
51b5991e |
181 | gsize __UNUSED__ text_len, |
43da6a59 |
182 | gpointer user_data, |
51b5991e |
183 | GError __UNUSED__ **error) |
43da6a59 |
184 | { |
185 | LttSystemDescription* des = (LttSystemDescription* )user_data; |
186 | des->description = g_strdup(text); |
187 | } |
3aee1200 |
188 | #endif //0 |
f104d082 |
189 | |
190 | |
77175651 |
191 | LttFacility *ltt_trace_get_facility_by_num(LttTrace *t, |
3aee1200 |
192 | guint num) |
193 | { |
194 | g_assert(num < t->facilities_by_num->len); |
195 | |
196 | return &g_array_index(t->facilities_by_num, LttFacility, num); |
197 | |
198 | } |
43da6a59 |
199 | |
b56dcdf2 |
200 | guint ltt_trace_get_num_cpu(LttTrace *t) |
201 | { |
202 | return t->num_cpu; |
203 | } |
204 | |
43da6a59 |
205 | |
b7576a11 |
206 | /* trace can be NULL |
207 | * |
208 | * Return value : 0 success, 1 bad tracefile |
209 | */ |
210 | int parse_trace_header(void *header, LttTracefile *tf, LttTrace *t) |
211 | { |
212 | guint32 *magic_number = (guint32*)header; |
213 | struct ltt_trace_header_any *any = (struct ltt_trace_header_any *)header; |
214 | |
215 | if(*magic_number == LTT_MAGIC_NUMBER) |
216 | tf->reverse_bo = 0; |
217 | else if(*magic_number == LTT_REV_MAGIC_NUMBER) |
218 | tf->reverse_bo = 1; |
219 | else /* invalid magic number, bad tracefile ! */ |
220 | return 1; |
221 | |
222 | /* Get float byte order : might be different from int byte order |
223 | * (or is set to 0 if the trace has no float (kernel trace)) */ |
224 | tf->float_word_order = any->float_word_order; |
f104d082 |
225 | tf->has_alignment = any->has_alignment; |
90440c06 |
226 | tf->has_heartbeat = any->has_heartbeat; |
b7576a11 |
227 | |
228 | if(t) { |
229 | t->arch_type = ltt_get_uint32(LTT_GET_BO(tf), |
230 | &any->arch_type); |
231 | t->arch_variant = ltt_get_uint32(LTT_GET_BO(tf), |
232 | &any->arch_variant); |
233 | t->arch_size = any->arch_size; |
234 | t->ltt_major_version = any->major_version; |
235 | t->ltt_minor_version = any->minor_version; |
236 | t->flight_recorder = any->flight_recorder; |
d1bb700c |
237 | t->compact_facilities = NULL; |
b7576a11 |
238 | } |
239 | |
240 | |
241 | switch(any->major_version) { |
242 | |
243 | case 0: |
244 | switch(any->minor_version) { |
245 | case 3: |
246 | { |
823820eb |
247 | tf->buffer_header_size = |
248 | sizeof(struct ltt_block_start_header) |
249 | + sizeof(struct ltt_trace_header_0_3); |
986e2a7c |
250 | g_warning("Unsupported trace version : %hhu.%hhu", |
251 | any->major_version, any->minor_version); |
252 | return 1; |
253 | } |
254 | break; |
cb310b57 |
255 | case 7: |
e939e5b2 |
256 | { |
cb310b57 |
257 | struct ltt_trace_header_0_7 *vheader = |
258 | (struct ltt_trace_header_0_7 *)header; |
e939e5b2 |
259 | tf->buffer_header_size = |
260 | sizeof(struct ltt_block_start_header) |
cb310b57 |
261 | + sizeof(struct ltt_trace_header_0_7); |
d1bb700c |
262 | tf->tsc_lsb_truncate = 0; |
263 | tf->tscbits = 32; |
264 | tf->tsc_msb_cutoff = 32 - tf->tsc_lsb_truncate - tf->tscbits; |
265 | tf->tsc_mask = (1ULL<<32)-1; |
266 | tf->tsc_mask_next_bit = (1ULL<<32); |
267 | if(t) { |
268 | t->start_freq = ltt_get_uint64(LTT_GET_BO(tf), |
269 | &vheader->start_freq); |
270 | t->freq_scale = ltt_get_uint32(LTT_GET_BO(tf), |
271 | &vheader->freq_scale); |
272 | t->start_tsc = ltt_get_uint64(LTT_GET_BO(tf), |
273 | &vheader->start_tsc); |
274 | t->start_monotonic = ltt_get_uint64(LTT_GET_BO(tf), |
275 | &vheader->start_monotonic); |
276 | t->start_time.tv_sec = ltt_get_uint64(LTT_GET_BO(tf), |
277 | &vheader->start_time_sec); |
278 | t->start_time.tv_nsec = ltt_get_uint64(LTT_GET_BO(tf), |
279 | &vheader->start_time_usec); |
280 | t->start_time.tv_nsec *= 1000; /* microsec to nanosec */ |
281 | |
282 | t->start_time_from_tsc = ltt_time_from_uint64( |
283 | (double)t->start_tsc |
284 | * (1000000000.0 / tf->trace->freq_scale) |
285 | / (double)t->start_freq); |
dd3a6d39 |
286 | t->compact_event_bits = 0; |
d1bb700c |
287 | } |
288 | } |
289 | break; |
290 | case 8: |
291 | { |
292 | struct ltt_trace_header_0_8 *vheader = |
293 | (struct ltt_trace_header_0_8 *)header; |
294 | tf->buffer_header_size = |
295 | sizeof(struct ltt_block_start_header) |
296 | + sizeof(struct ltt_trace_header_0_8); |
297 | tf->tsc_lsb_truncate = vheader->tsc_lsb_truncate; |
298 | tf->tscbits = vheader->tscbits; |
299 | tf->tsc_msb_cutoff = 32 - tf->tsc_lsb_truncate - tf->tscbits; |
dd3a6d39 |
300 | tf->tsc_mask = ((1ULL << (tf->tscbits))-1); |
301 | tf->tsc_mask = tf->tsc_mask << tf->tsc_lsb_truncate; |
d1bb700c |
302 | tf->tsc_mask_next_bit = (1ULL<<(tf->tscbits)); |
303 | tf->tsc_mask_next_bit = tf->tsc_mask_next_bit << tf->tsc_lsb_truncate; |
e939e5b2 |
304 | if(t) { |
305 | t->start_freq = ltt_get_uint64(LTT_GET_BO(tf), |
306 | &vheader->start_freq); |
a3999b49 |
307 | t->freq_scale = ltt_get_uint32(LTT_GET_BO(tf), |
308 | &vheader->freq_scale); |
e939e5b2 |
309 | t->start_tsc = ltt_get_uint64(LTT_GET_BO(tf), |
310 | &vheader->start_tsc); |
311 | t->start_monotonic = ltt_get_uint64(LTT_GET_BO(tf), |
312 | &vheader->start_monotonic); |
313 | t->start_time.tv_sec = ltt_get_uint64(LTT_GET_BO(tf), |
314 | &vheader->start_time_sec); |
315 | t->start_time.tv_nsec = ltt_get_uint64(LTT_GET_BO(tf), |
316 | &vheader->start_time_usec); |
317 | t->start_time.tv_nsec *= 1000; /* microsec to nanosec */ |
318 | |
319 | t->start_time_from_tsc = ltt_time_from_uint64( |
c7f86478 |
320 | (double)t->start_tsc |
321 | * (1000000000.0 / tf->trace->freq_scale) |
322 | / (double)t->start_freq); |
dd3a6d39 |
323 | t->compact_event_bits = 0; |
e939e5b2 |
324 | } |
325 | } |
326 | break; |
b7576a11 |
327 | default: |
986e2a7c |
328 | g_warning("Unsupported trace version : %hhu.%hhu", |
b7576a11 |
329 | any->major_version, any->minor_version); |
330 | return 1; |
331 | } |
332 | break; |
333 | |
334 | default: |
335 | g_warning("Unsupported trace version : %hhu.%hhu", |
336 | any->major_version, any->minor_version); |
337 | return 1; |
338 | } |
339 | |
340 | |
341 | return 0; |
342 | } |
343 | |
344 | |
345 | |
6cd62ccf |
346 | /***************************************************************************** |
347 | *Function name |
963b5f2d |
348 | * ltt_tracefile_open : open a trace file, construct a LttTracefile |
6cd62ccf |
349 | *Input params |
963b5f2d |
350 | * t : the trace containing the tracefile |
351 | * fileName : path name of the trace file |
3aee1200 |
352 | * tf : the tracefile structure |
6cd62ccf |
353 | *Return value |
3aee1200 |
354 | * : 0 for success, -1 otherwise. |
6cd62ccf |
355 | ****************************************************************************/ |
356 | |
3aee1200 |
357 | gint ltt_tracefile_open(LttTrace *t, gchar * fileName, LttTracefile *tf) |
6cd62ccf |
358 | { |
963b5f2d |
359 | struct stat lTDFStat; /* Trace data file status */ |
3aee1200 |
360 | struct ltt_block_start_header *header; |
b77d1b57 |
361 | int page_size = getpagesize(); |
6cd62ccf |
362 | |
363 | //open the file |
d3d34f49 |
364 | tf->long_name = g_quark_from_string(fileName); |
963b5f2d |
365 | tf->trace = t; |
3865ea09 |
366 | tf->fd = open(fileName, O_RDONLY); |
6cd62ccf |
367 | if(tf->fd < 0){ |
2a74fbf4 |
368 | g_warning("Unable to open input data file %s\n", fileName); |
3aee1200 |
369 | goto end; |
6cd62ccf |
370 | } |
371 | |
372 | // Get the file's status |
373 | if(fstat(tf->fd, &lTDFStat) < 0){ |
2a74fbf4 |
374 | g_warning("Unable to get the status of the input data file %s\n", fileName); |
3aee1200 |
375 | goto close_file; |
6cd62ccf |
376 | } |
377 | |
378 | // Is the file large enough to contain a trace |
823820eb |
379 | if(lTDFStat.st_size < |
9ea7b94b |
380 | (off_t)(sizeof(struct ltt_block_start_header) |
381 | + sizeof(struct ltt_trace_header_any))){ |
8710c6c7 |
382 | g_print("The input data file %s does not contain a trace\n", fileName); |
3aee1200 |
383 | goto close_file; |
384 | } |
385 | |
386 | /* Temporarily map the buffer start header to get trace information */ |
387 | /* Multiple of pages aligned head */ |
b77d1b57 |
388 | tf->buffer.head = mmap(0, |
9ea7b94b |
389 | PAGE_ALIGN(sizeof(struct ltt_block_start_header) |
390 | + sizeof(struct ltt_trace_header_any)), PROT_READ, |
3aee1200 |
391 | MAP_PRIVATE, tf->fd, 0); |
3865ea09 |
392 | if(tf->buffer.head == MAP_FAILED) { |
3aee1200 |
393 | perror("Error in allocating memory for buffer of tracefile"); |
394 | goto close_file; |
6cd62ccf |
395 | } |
3865ea09 |
396 | g_assert( ( (guint)tf->buffer.head&(8-1) ) == 0); // make sure it's aligned. |
3aee1200 |
397 | |
398 | header = (struct ltt_block_start_header*)tf->buffer.head; |
6cd62ccf |
399 | |
51551c6f |
400 | if(parse_trace_header(header->trace, tf, NULL)) { |
401 | g_warning("parse_trace_header error"); |
402 | goto unmap_file; |
403 | } |
3aee1200 |
404 | |
6cd62ccf |
405 | //store the size of the file |
406 | tf->file_size = lTDFStat.st_size; |
f628823c |
407 | tf->buf_size = ltt_get_uint32(LTT_GET_BO(tf), &header->buf_size); |
408 | tf->num_blocks = tf->file_size / tf->buf_size; |
409 | |
410 | if(munmap(tf->buffer.head, |
9ea7b94b |
411 | PAGE_ALIGN(sizeof(struct ltt_block_start_header) |
412 | + sizeof(struct ltt_trace_header_any)))) { |
f628823c |
413 | g_warning("unmap size : %u\n", |
9ea7b94b |
414 | PAGE_ALIGN(sizeof(struct ltt_block_start_header) |
415 | + sizeof(struct ltt_trace_header_any))); |
f628823c |
416 | perror("munmap error"); |
417 | g_assert(0); |
418 | } |
3aee1200 |
419 | tf->buffer.head = NULL; |
6cd62ccf |
420 | |
963b5f2d |
421 | //read the first block |
3aee1200 |
422 | if(map_block(tf,0)) { |
423 | perror("Cannot map block for tracefile"); |
424 | goto close_file; |
425 | } |
426 | |
427 | return 0; |
6cd62ccf |
428 | |
3aee1200 |
429 | /* Error */ |
430 | unmap_file: |
f628823c |
431 | if(munmap(tf->buffer.head, |
9ea7b94b |
432 | PAGE_ALIGN(sizeof(struct ltt_block_start_header) |
433 | + sizeof(struct ltt_trace_header_any)))) { |
f628823c |
434 | g_warning("unmap size : %u\n", |
9ea7b94b |
435 | PAGE_ALIGN(sizeof(struct ltt_block_start_header) |
436 | + sizeof(struct ltt_trace_header_any))); |
f628823c |
437 | perror("munmap error"); |
438 | g_assert(0); |
439 | } |
3aee1200 |
440 | close_file: |
3865ea09 |
441 | close(tf->fd); |
3aee1200 |
442 | end: |
443 | return -1; |
6cd62ccf |
444 | } |
445 | |
d3d34f49 |
446 | LttTrace *ltt_tracefile_get_trace(LttTracefile *tf) |
447 | { |
448 | return tf->trace; |
449 | } |
450 | |
3aee1200 |
451 | #if 0 |
6cd62ccf |
452 | /***************************************************************************** |
963b5f2d |
453 | *Open control and per cpu tracefiles |
6cd62ccf |
454 | ****************************************************************************/ |
455 | |
45e14832 |
456 | void ltt_tracefile_open_cpu(LttTrace *t, gchar * tracefile_name) |
6cd62ccf |
457 | { |
963b5f2d |
458 | LttTracefile * tf; |
459 | tf = ltt_tracefile_open(t,tracefile_name); |
4a6c8e36 |
460 | if(!tf) return; |
963b5f2d |
461 | t->per_cpu_tracefile_number++; |
462 | g_ptr_array_add(t->per_cpu_tracefiles, tf); |
6cd62ccf |
463 | } |
464 | |
45e14832 |
465 | gint ltt_tracefile_open_control(LttTrace *t, gchar * control_name) |
6cd62ccf |
466 | { |
963b5f2d |
467 | LttTracefile * tf; |
c02ea99f |
468 | LttEvent ev; |
963b5f2d |
469 | LttFacility * f; |
963b5f2d |
470 | void * pos; |
471 | FacilityLoad fLoad; |
8d1e6362 |
472 | unsigned int i; |
963b5f2d |
473 | |
474 | tf = ltt_tracefile_open(t,control_name); |
2a74fbf4 |
475 | if(!tf) { |
476 | g_warning("ltt_tracefile_open_control : bad file descriptor"); |
477 | return -1; |
478 | } |
963b5f2d |
479 | t->control_tracefile_number++; |
480 | g_ptr_array_add(t->control_tracefiles,tf); |
481 | |
482 | //parse facilities tracefile to get base_id |
542ceddd |
483 | if(strcmp(&control_name[strlen(control_name)-10],"facilities") ==0){ |
963b5f2d |
484 | while(1){ |
c02ea99f |
485 | if(!ltt_tracefile_read(tf,&ev)) return 0; // end of file |
40331ba8 |
486 | |
c02ea99f |
487 | if(ev.event_id == TRACE_FACILITY_LOAD){ |
488 | pos = ev.data; |
45e14832 |
489 | fLoad.name = (gchar*)pos; |
47a166fc |
490 | fLoad.checksum = *(LttChecksum*)(pos + strlen(fLoad.name)); |
cbd41522 |
491 | fLoad.base_code = *(guint32 *)(pos + strlen(fLoad.name) + sizeof(LttChecksum)); |
963b5f2d |
492 | |
493 | for(i=0;i<t->facility_number;i++){ |
494 | f = (LttFacility*)g_ptr_array_index(t->facilities,i); |
495 | if(strcmp(f->name,fLoad.name)==0 && fLoad.checksum==f->checksum){ |
496 | f->base_id = fLoad.base_code; |
497 | break; |
498 | } |
499 | } |
2a74fbf4 |
500 | if(i==t->facility_number) { |
8d1e6362 |
501 | g_warning("Facility: %s, checksum: %u is not found", |
502 | fLoad.name,(unsigned int)fLoad.checksum); |
2a74fbf4 |
503 | return -1; |
504 | } |
c02ea99f |
505 | }else if(ev.event_id == TRACE_BLOCK_START){ |
40331ba8 |
506 | continue; |
c02ea99f |
507 | }else if(ev.event_id == TRACE_BLOCK_END){ |
40331ba8 |
508 | break; |
2a74fbf4 |
509 | }else { |
8d1e6362 |
510 | g_warning("Not valid facilities trace file"); |
2a74fbf4 |
511 | return -1; |
512 | } |
963b5f2d |
513 | } |
514 | } |
2a74fbf4 |
515 | return 0; |
6cd62ccf |
516 | } |
3aee1200 |
517 | #endif //0 |
6cd62ccf |
518 | |
519 | /***************************************************************************** |
520 | *Function name |
963b5f2d |
521 | * ltt_tracefile_close: close a trace file, |
6cd62ccf |
522 | *Input params |
963b5f2d |
523 | * t : tracefile which will be closed |
6cd62ccf |
524 | ****************************************************************************/ |
525 | |
963b5f2d |
526 | void ltt_tracefile_close(LttTracefile *t) |
6cd62ccf |
527 | { |
f628823c |
528 | int page_size = getpagesize(); |
529 | |
3aee1200 |
530 | if(t->buffer.head != NULL) |
f628823c |
531 | if(munmap(t->buffer.head, PAGE_ALIGN(t->buf_size))) { |
532 | g_warning("unmap size : %u\n", |
533 | PAGE_ALIGN(t->buf_size)); |
534 | perror("munmap error"); |
535 | g_assert(0); |
536 | } |
537 | |
3865ea09 |
538 | close(t->fd); |
963b5f2d |
539 | } |
6cd62ccf |
540 | |
6cd62ccf |
541 | |
963b5f2d |
542 | /***************************************************************************** |
543 | *Get system information |
544 | ****************************************************************************/ |
3aee1200 |
545 | #if 0 |
45e14832 |
546 | gint getSystemInfo(LttSystemDescription* des, gchar * pathname) |
963b5f2d |
547 | { |
45e14832 |
548 | int fd; |
549 | GIOChannel *iochan; |
550 | gchar *buf = NULL; |
551 | gsize length; |
43da6a59 |
552 | |
553 | GMarkupParseContext * context; |
2a74fbf4 |
554 | GError * error = NULL; |
43da6a59 |
555 | GMarkupParser markup_parser = |
556 | { |
557 | parser_start_element, |
8d1e6362 |
558 | NULL, |
43da6a59 |
559 | parser_characters, |
560 | NULL, /* passthrough */ |
561 | NULL /* error */ |
562 | }; |
963b5f2d |
563 | |
45e14832 |
564 | fd = g_open(pathname, O_RDONLY, 0); |
565 | if(fd == -1){ |
2a74fbf4 |
566 | g_warning("Can not open file : %s\n", pathname); |
567 | return -1; |
6cd62ccf |
568 | } |
963b5f2d |
569 | |
45e14832 |
570 | iochan = g_io_channel_unix_new(fd); |
571 | |
43da6a59 |
572 | context = g_markup_parse_context_new(&markup_parser, 0, des,NULL); |
6cd62ccf |
573 | |
45e14832 |
574 | //while(fgets(buf,DIR_NAME_SIZE, fp) != NULL){ |
575 | while(g_io_channel_read_line(iochan, &buf, &length, NULL, &error) |
576 | != G_IO_STATUS_EOF) { |
577 | |
578 | if(error != NULL) { |
579 | g_warning("Can not read xml file: \n%s\n", error->message); |
580 | g_error_free(error); |
581 | } |
582 | if(!g_markup_parse_context_parse(context, buf, length, &error)){ |
2a74fbf4 |
583 | if(error != NULL) { |
584 | g_warning("Can not parse xml file: \n%s\n", error->message); |
585 | g_error_free(error); |
586 | } |
587 | g_markup_parse_context_free(context); |
45e14832 |
588 | |
589 | g_io_channel_shutdown(iochan, FALSE, &error); /* No flush */ |
590 | if(error != NULL) { |
591 | g_warning("Can not close file: \n%s\n", error->message); |
592 | g_error_free(error); |
593 | } |
594 | |
595 | close(fd); |
2a74fbf4 |
596 | return -1; |
43da6a59 |
597 | } |
963b5f2d |
598 | } |
2a74fbf4 |
599 | g_markup_parse_context_free(context); |
45e14832 |
600 | |
601 | g_io_channel_shutdown(iochan, FALSE, &error); /* No flush */ |
602 | if(error != NULL) { |
603 | g_warning("Can not close file: \n%s\n", error->message); |
604 | g_error_free(error); |
605 | } |
606 | |
607 | g_close(fd); |
608 | |
609 | g_free(buf); |
2a74fbf4 |
610 | return 0; |
6cd62ccf |
611 | } |
3aee1200 |
612 | #endif //0 |
6cd62ccf |
613 | |
614 | /***************************************************************************** |
963b5f2d |
615 | *The following functions get facility/tracefile information |
6cd62ccf |
616 | ****************************************************************************/ |
3aee1200 |
617 | #if 0 |
45e14832 |
618 | gint getFacilityInfo(LttTrace *t, gchar* eventdefs) |
6cd62ccf |
619 | { |
45e14832 |
620 | GDir * dir; |
621 | const gchar * name; |
8d1e6362 |
622 | unsigned int i,j; |
963b5f2d |
623 | LttFacility * f; |
624 | LttEventType * et; |
45e14832 |
625 | gchar fullname[DIR_NAME_SIZE]; |
626 | GError * error = NULL; |
627 | |
628 | dir = g_dir_open(eventdefs, 0, &error); |
963b5f2d |
629 | |
45e14832 |
630 | if(error != NULL) { |
631 | g_warning("Can not open directory: %s, %s\n", eventdefs, error->message); |
632 | g_error_free(error); |
2a74fbf4 |
633 | return -1; |
634 | } |
963b5f2d |
635 | |
45e14832 |
636 | while((name = g_dir_read_name(dir)) != NULL){ |
637 | if(!g_pattern_match_simple("*.xml", name)) continue; |
638 | strcpy(fullname,eventdefs); |
639 | strcat(fullname,name); |
640 | ltt_facility_open(t,fullname); |
641 | } |
642 | g_dir_close(dir); |
963b5f2d |
643 | |
963b5f2d |
644 | for(j=0;j<t->facility_number;j++){ |
8710c6c7 |
645 | f = (LttFacility*)g_ptr_array_index(t->facilities, j); |
963b5f2d |
646 | for(i=0; i<f->event_number; i++){ |
647 | et = f->events[i]; |
40331ba8 |
648 | setFieldsOffset(NULL, et, NULL, t); |
963b5f2d |
649 | } |
650 | } |
2a74fbf4 |
651 | return 0; |
963b5f2d |
652 | } |
3aee1200 |
653 | #endif //0 |
6cd62ccf |
654 | |
963b5f2d |
655 | /***************************************************************************** |
656 | *A trace is specified as a pathname to the directory containing all the |
657 | *associated data (control tracefiles, per cpu tracefiles, event |
658 | *descriptions...). |
659 | * |
660 | *When a trace is closed, all the associated facilities, types and fields |
661 | *are released as well. |
8d1e6362 |
662 | */ |
663 | |
664 | |
665 | /**************************************************************************** |
666 | * get_absolute_pathname |
803229fa |
667 | * |
8d1e6362 |
668 | * return the unique pathname in the system |
669 | * |
ef35d837 |
670 | * MD : Fixed this function so it uses realpath, dealing well with |
671 | * forgotten cases (.. were not used correctly before). |
803229fa |
672 | * |
963b5f2d |
673 | ****************************************************************************/ |
45e14832 |
674 | void get_absolute_pathname(const gchar *pathname, gchar * abs_pathname) |
9f797243 |
675 | { |
9f797243 |
676 | abs_pathname[0] = '\0'; |
803229fa |
677 | |
ef35d837 |
678 | if ( realpath (pathname, abs_pathname) != NULL) |
679 | return; |
680 | else |
681 | { |
8d1e6362 |
682 | /* error, return the original path unmodified */ |
ef35d837 |
683 | strcpy(abs_pathname, pathname); |
9f797243 |
684 | return; |
685 | } |
ef35d837 |
686 | return; |
9f797243 |
687 | } |
688 | |
3aee1200 |
689 | /* Search for something like : .*_.* |
690 | * |
691 | * The left side is the name, the right side is the number. |
692 | */ |
693 | |
ae3d0f50 |
694 | int get_tracefile_name_number(gchar *raw_name, |
3aee1200 |
695 | GQuark *name, |
ae3d0f50 |
696 | guint *num, |
697 | guint *tid, |
698 | guint *pgid, |
699 | guint64 *creation) |
6cd62ccf |
700 | { |
3aee1200 |
701 | guint raw_name_len = strlen(raw_name); |
702 | gchar char_name[PATH_MAX]; |
3aee1200 |
703 | int i; |
704 | int underscore_pos; |
705 | long int cpu_num; |
706 | gchar *endptr; |
ae3d0f50 |
707 | gchar *tmpptr; |
3aee1200 |
708 | |
709 | for(i=raw_name_len-1;i>=0;i--) { |
710 | if(raw_name[i] == '_') break; |
711 | } |
ae3d0f50 |
712 | if(i==-1) { /* Either not found or name length is 0 */ |
713 | /* This is a userspace tracefile */ |
714 | strncpy(char_name, raw_name, raw_name_len); |
61a02d96 |
715 | char_name[raw_name_len] = '\0'; |
ae3d0f50 |
716 | *name = g_quark_from_string(char_name); |
717 | *num = 0; /* unknown cpu */ |
718 | for(i=0;i<raw_name_len;i++) { |
719 | if(raw_name[i] == '/') { |
720 | break; |
721 | } |
722 | } |
723 | i++; |
724 | for(;i<raw_name_len;i++) { |
725 | if(raw_name[i] == '/') { |
726 | break; |
727 | } |
728 | } |
729 | i++; |
730 | for(;i<raw_name_len;i++) { |
731 | if(raw_name[i] == '-') { |
732 | break; |
733 | } |
734 | } |
735 | if(i == raw_name_len) return -1; |
736 | i++; |
737 | tmpptr = &raw_name[i]; |
738 | for(;i<raw_name_len;i++) { |
739 | if(raw_name[i] == '.') { |
740 | raw_name[i] = ' '; |
741 | break; |
742 | } |
743 | } |
744 | *tid = strtoul(tmpptr, &endptr, 10); |
745 | if(endptr == tmpptr) |
746 | return -1; /* No digit */ |
747 | if(*tid == ULONG_MAX) |
748 | return -1; /* underflow / overflow */ |
749 | i++; |
750 | tmpptr = &raw_name[i]; |
751 | for(;i<raw_name_len;i++) { |
752 | if(raw_name[i] == '.') { |
753 | raw_name[i] = ' '; |
754 | break; |
755 | } |
756 | } |
757 | *pgid = strtoul(tmpptr, &endptr, 10); |
758 | if(endptr == tmpptr) |
759 | return -1; /* No digit */ |
760 | if(*pgid == ULONG_MAX) |
761 | return -1; /* underflow / overflow */ |
762 | i++; |
763 | tmpptr = &raw_name[i]; |
764 | *creation = strtoull(tmpptr, &endptr, 10); |
765 | if(endptr == tmpptr) |
766 | return -1; /* No digit */ |
767 | if(*creation == G_MAXUINT64) |
768 | return -1; /* underflow / overflow */ |
769 | } else { |
770 | underscore_pos = i; |
963b5f2d |
771 | |
ae3d0f50 |
772 | cpu_num = strtol(raw_name+underscore_pos+1, &endptr, 10); |
3aee1200 |
773 | |
ae3d0f50 |
774 | if(endptr == raw_name+underscore_pos+1) |
775 | return -1; /* No digit */ |
776 | if(cpu_num == LONG_MIN || cpu_num == LONG_MAX) |
777 | return -1; /* underflow / overflow */ |
778 | |
779 | strncpy(char_name, raw_name, underscore_pos); |
780 | char_name[underscore_pos] = '\0'; |
781 | |
782 | *name = g_quark_from_string(char_name); |
783 | *num = cpu_num; |
784 | } |
69bd59ed |
785 | |
b333a76b |
786 | |
3aee1200 |
787 | return 0; |
788 | } |
963b5f2d |
789 | |
3aee1200 |
790 | |
3865ea09 |
791 | GData **ltt_trace_get_tracefiles_groups(LttTrace *trace) |
77175651 |
792 | { |
3865ea09 |
793 | return &trace->tracefiles; |
77175651 |
794 | } |
795 | |
796 | |
3865ea09 |
797 | void compute_tracefile_group(GQuark key_id, |
798 | GArray *group, |
799 | struct compute_tracefile_group_args *args) |
77175651 |
800 | { |
801 | int i; |
802 | LttTracefile *tf; |
803 | |
804 | for(i=0; i<group->len; i++) { |
805 | tf = &g_array_index (group, LttTracefile, i); |
806 | if(tf->cpu_online) |
3865ea09 |
807 | args->func(tf, args->func_args); |
77175651 |
808 | } |
809 | } |
810 | |
811 | |
3aee1200 |
812 | void ltt_tracefile_group_destroy(gpointer data) |
813 | { |
814 | GArray *group = (GArray *)data; |
815 | int i; |
816 | LttTracefile *tf; |
817 | |
818 | for(i=0; i<group->len; i++) { |
819 | tf = &g_array_index (group, LttTracefile, i); |
820 | if(tf->cpu_online) |
821 | ltt_tracefile_close(tf); |
822 | } |
823 | g_array_free(group, TRUE); |
6cd62ccf |
824 | } |
825 | |
3aee1200 |
826 | gboolean ltt_tracefile_group_has_cpu_online(gpointer data) |
49bf71b5 |
827 | { |
3aee1200 |
828 | GArray *group = (GArray *)data; |
829 | int i; |
830 | LttTracefile *tf; |
831 | |
832 | for(i=0; i<group->len; i++) { |
833 | tf = &g_array_index (group, LttTracefile, i); |
834 | if(tf->cpu_online) return 1; |
835 | } |
836 | return 0; |
49bf71b5 |
837 | } |
838 | |
839 | |
3aee1200 |
840 | /* Open each tracefile under a specific directory. Put them in a |
841 | * GData : permits to access them using their tracefile group pathname. |
842 | * i.e. access control/modules tracefile group by index : |
843 | * "control/module". |
3865ea09 |
844 | * |
845 | * relative path is the path relative to the trace root |
846 | * root path is the full path |
3aee1200 |
847 | * |
848 | * A tracefile group is simply an array where all the per cpu tracefiles sits. |
849 | */ |
850 | |
69bd59ed |
851 | static int open_tracefiles(LttTrace *trace, gchar *root_path, |
852 | gchar *relative_path) |
f7afe191 |
853 | { |
3aee1200 |
854 | DIR *dir = opendir(root_path); |
855 | struct dirent *entry; |
856 | struct stat stat_buf; |
857 | int ret; |
3865ea09 |
858 | |
69bd59ed |
859 | gchar path[PATH_MAX]; |
3aee1200 |
860 | int path_len; |
69bd59ed |
861 | gchar *path_ptr; |
3aee1200 |
862 | |
3865ea09 |
863 | int rel_path_len; |
69bd59ed |
864 | gchar rel_path[PATH_MAX]; |
865 | gchar *rel_path_ptr; |
cb03932a |
866 | LttTracefile tmp_tf; |
3865ea09 |
867 | |
3aee1200 |
868 | if(dir == NULL) { |
869 | perror(root_path); |
870 | return ENOENT; |
871 | } |
872 | |
873 | strncpy(path, root_path, PATH_MAX-1); |
874 | path_len = strlen(path); |
875 | path[path_len] = '/'; |
876 | path_len++; |
877 | path_ptr = path + path_len; |
878 | |
3865ea09 |
879 | strncpy(rel_path, relative_path, PATH_MAX-1); |
880 | rel_path_len = strlen(rel_path); |
881 | rel_path[rel_path_len] = '/'; |
882 | rel_path_len++; |
883 | rel_path_ptr = rel_path + rel_path_len; |
884 | |
3aee1200 |
885 | while((entry = readdir(dir)) != NULL) { |
886 | |
887 | if(entry->d_name[0] == '.') continue; |
888 | |
889 | strncpy(path_ptr, entry->d_name, PATH_MAX - path_len); |
3865ea09 |
890 | strncpy(rel_path_ptr, entry->d_name, PATH_MAX - rel_path_len); |
3aee1200 |
891 | |
892 | ret = stat(path, &stat_buf); |
893 | if(ret == -1) { |
894 | perror(path); |
895 | continue; |
896 | } |
897 | |
898 | g_debug("Tracefile file or directory : %s\n", path); |
899 | |
74a588bb |
900 | if(strcmp(rel_path, "/eventdefs") == 0) continue; |
901 | |
3aee1200 |
902 | if(S_ISDIR(stat_buf.st_mode)) { |
903 | |
904 | g_debug("Entering subdirectory...\n"); |
3865ea09 |
905 | ret = open_tracefiles(trace, path, rel_path); |
3aee1200 |
906 | if(ret < 0) continue; |
907 | } else if(S_ISREG(stat_buf.st_mode)) { |
3aee1200 |
908 | GQuark name; |
ae3d0f50 |
909 | guint num, tid, pgid; |
910 | guint64 creation; |
3aee1200 |
911 | GArray *group; |
ae3d0f50 |
912 | num = tid = pgid = 0; |
913 | creation = 0; |
914 | if(get_tracefile_name_number(rel_path, &name, &num, &tid, &pgid, &creation)) |
3aee1200 |
915 | continue; /* invalid name */ |
3865ea09 |
916 | |
cb03932a |
917 | g_debug("Opening file.\n"); |
918 | if(ltt_tracefile_open(trace, path, &tmp_tf)) { |
919 | g_info("Error opening tracefile %s", path); |
920 | |
921 | continue; /* error opening the tracefile : bad magic number ? */ |
922 | } |
923 | |
3865ea09 |
924 | g_debug("Tracefile name is %s and number is %u", |
925 | g_quark_to_string(name), num); |
926 | |
cb03932a |
927 | tmp_tf.cpu_online = 1; |
928 | tmp_tf.cpu_num = num; |
d3d34f49 |
929 | tmp_tf.name = name; |
ae3d0f50 |
930 | tmp_tf.tid = tid; |
931 | tmp_tf.pgid = pgid; |
932 | tmp_tf.creation = creation; |
d1bb700c |
933 | if(tmp_tf.name == g_quark_from_string("/compact") |
934 | || tmp_tf.name == g_quark_from_string("/flight-compact")) |
935 | tmp_tf.compact = 1; |
936 | else |
937 | tmp_tf.compact = 0; |
3865ea09 |
938 | group = g_datalist_id_get_data(&trace->tracefiles, name); |
3aee1200 |
939 | if(group == NULL) { |
940 | /* Elements are automatically cleared when the array is allocated. |
941 | * It makes the cpu_online variable set to 0 : cpu offline, by default. |
942 | */ |
943 | group = g_array_sized_new (FALSE, TRUE, sizeof(LttTracefile), 10); |
3865ea09 |
944 | g_datalist_id_set_data_full(&trace->tracefiles, name, |
3aee1200 |
945 | group, ltt_tracefile_group_destroy); |
946 | } |
cb03932a |
947 | |
3aee1200 |
948 | /* Add the per cpu tracefile to the named group */ |
949 | unsigned int old_len = group->len; |
950 | if(num+1 > old_len) |
951 | group = g_array_set_size(group, num+1); |
cb03932a |
952 | g_array_index (group, LttTracefile, num) = tmp_tf; |
3aee1200 |
953 | |
3aee1200 |
954 | } |
955 | } |
956 | |
957 | closedir(dir); |
958 | |
959 | return 0; |
f7afe191 |
960 | } |
961 | |
3aee1200 |
962 | /* ltt_get_facility_description |
963 | * |
29e7c5b3 |
964 | * Opens the file corresponding to the requested facility (identified by fac_id |
3aee1200 |
965 | * and checksum). |
966 | * |
967 | * The name searched is : %trace root%/eventdefs/facname_checksum.xml |
968 | * |
969 | * Returns 0 on success, or 1 on failure. |
970 | */ |
971 | |
972 | static int ltt_get_facility_description(LttFacility *f, |
973 | LttTrace *t, |
974 | LttTracefile *fac_tf) |
6cd62ccf |
975 | { |
3aee1200 |
976 | char desc_file_name[PATH_MAX]; |
977 | const gchar *text; |
978 | guint textlen; |
979 | gint err; |
f5d7967f |
980 | gint arch_spec; |
981 | gint fac_name_len; |
3aee1200 |
982 | |
983 | text = g_quark_to_string(t->pathname); |
984 | textlen = strlen(text); |
985 | |
986 | if(textlen >= PATH_MAX) goto name_error; |
987 | strcpy(desc_file_name, text); |
988 | |
989 | text = "/eventdefs/"; |
990 | textlen+=strlen(text); |
991 | if(textlen >= PATH_MAX) goto name_error; |
992 | strcat(desc_file_name, text); |
993 | |
994 | text = g_quark_to_string(f->name); |
f5d7967f |
995 | fac_name_len = strlen(text); |
996 | textlen+=fac_name_len; |
3aee1200 |
997 | if(textlen >= PATH_MAX) goto name_error; |
998 | strcat(desc_file_name, text); |
f5d7967f |
999 | |
1000 | /* arch specific facilities are named like this : name_arch */ |
1001 | if(fac_name_len+1 < sizeof("_arch")) |
1002 | arch_spec = 0; |
1003 | else { |
1004 | if(!strcmp(&text[fac_name_len+1-sizeof("_arch")], "_arch")) |
1005 | arch_spec = 1; |
1006 | else |
1007 | arch_spec = 0; |
1008 | } |
1009 | |
29e7c5b3 |
1010 | #if 0 |
3aee1200 |
1011 | text = "_"; |
1012 | textlen+=strlen(text); |
1013 | if(textlen >= PATH_MAX) goto name_error; |
1014 | strcat(desc_file_name, text); |
963b5f2d |
1015 | |
3aee1200 |
1016 | err = snprintf(desc_file_name+textlen, PATH_MAX-textlen-1, |
1017 | "%u", f->checksum); |
d2083cab |
1018 | if(err < 0) goto name_error; |
3aee1200 |
1019 | |
1020 | textlen=strlen(desc_file_name); |
1021 | |
29e7c5b3 |
1022 | #endif //0 |
f5d7967f |
1023 | |
1024 | if(arch_spec) { |
1025 | switch(t->arch_type) { |
1026 | case LTT_ARCH_TYPE_I386: |
1027 | text = "_i386"; |
1028 | break; |
1029 | case LTT_ARCH_TYPE_PPC: |
1030 | text = "_ppc"; |
1031 | break; |
1032 | case LTT_ARCH_TYPE_SH: |
1033 | text = "_sh"; |
1034 | break; |
1035 | case LTT_ARCH_TYPE_S390: |
1036 | text = "_s390"; |
1037 | break; |
1038 | case LTT_ARCH_TYPE_MIPS: |
1039 | text = "_mips"; |
1040 | break; |
1041 | case LTT_ARCH_TYPE_ARM: |
1042 | text = "_arm"; |
b6fd32e3 |
1043 | break; |
f5d7967f |
1044 | case LTT_ARCH_TYPE_PPC64: |
1045 | text = "_ppc64"; |
b6fd32e3 |
1046 | break; |
f5d7967f |
1047 | case LTT_ARCH_TYPE_X86_64: |
1048 | text = "_x86_64"; |
1049 | break; |
285468d4 |
1050 | case LTT_ARCH_TYPE_C2: |
1051 | text = "_c2"; |
1052 | break; |
83e160f2 |
1053 | case LTT_ARCH_TYPE_POWERPC: |
1054 | text = "_powerpc"; |
1055 | break; |
f5d7967f |
1056 | default: |
1057 | g_error("Trace from unsupported architecture."); |
1058 | } |
1059 | textlen+=strlen(text); |
1060 | if(textlen >= PATH_MAX) goto name_error; |
1061 | strcat(desc_file_name, text); |
1062 | } |
1063 | |
3aee1200 |
1064 | text = ".xml"; |
1065 | textlen+=strlen(text); |
1066 | if(textlen >= PATH_MAX) goto name_error; |
1067 | strcat(desc_file_name, text); |
29e7c5b3 |
1068 | |
3aee1200 |
1069 | err = ltt_facility_open(f, t, desc_file_name); |
1070 | if(err) goto facility_error; |
3aee1200 |
1071 | |
1072 | return 0; |
1073 | |
1074 | facility_error: |
1075 | name_error: |
1076 | return 1; |
1077 | } |
1078 | |
1079 | static void ltt_fac_ids_destroy(gpointer data) |
1080 | { |
1081 | GArray *fac_ids = (GArray *)data; |
963b5f2d |
1082 | |
3aee1200 |
1083 | g_array_free(fac_ids, TRUE); |
1084 | } |
1085 | |
1086 | |
1087 | /* Presumes the tracefile is already seeked at the beginning. It makes sense, |
1088 | * because it must be done just after the opening */ |
1089 | static int ltt_process_facility_tracefile(LttTracefile *tf) |
1090 | { |
1091 | int err; |
1092 | LttFacility *fac; |
1093 | GArray *fac_ids; |
cb03932a |
1094 | guint i; |
1095 | LttEventType *et; |
3aee1200 |
1096 | |
1097 | while(1) { |
1098 | err = ltt_tracefile_read_seek(tf); |
1099 | if(err == EPERM) goto seek_error; |
1100 | else if(err == ERANGE) break; /* End of tracefile */ |
1101 | |
1102 | err = ltt_tracefile_read_update_event(tf); |
1103 | if(err) goto update_error; |
1104 | |
1105 | /* We are on a facility load/or facility unload/ or heartbeat event */ |
1106 | /* The rules are : |
1107 | * * facility 0 is hardcoded : this is the core facility. It will be shown |
1108 | * in the facility array though, and is shown as "loaded builtin" in the |
1109 | * trace. |
1110 | * It contains event : |
1111 | * 0 : facility load |
1112 | * 1 : facility unload |
1113 | * 2 : state dump facility load |
d2083cab |
1114 | * 3 : heartbeat |
3aee1200 |
1115 | */ |
d2083cab |
1116 | if(tf->event.facility_id != LTT_FACILITY_CORE) { |
1117 | /* Should only contain core facility */ |
3aee1200 |
1118 | g_warning("Error in processing facility file %s, " |
1119 | "should not contain facility id %u.", g_quark_to_string(tf->name), |
1120 | tf->event.facility_id); |
1121 | err = EPERM; |
1122 | goto fac_id_error; |
d2083cab |
1123 | } else { |
3aee1200 |
1124 | |
1125 | struct LttFacilityLoad *fac_load_data; |
b77d1b57 |
1126 | struct LttStateDumpFacilityLoad *fac_state_dump_load_data; |
3aee1200 |
1127 | char *fac_name; |
743e50fd |
1128 | void *pos; |
3aee1200 |
1129 | |
1130 | // FIXME align |
1131 | switch((enum ltt_core_events)tf->event.event_id) { |
1132 | case LTT_EVENT_FACILITY_LOAD: |
b77d1b57 |
1133 | fac_name = (char*)(tf->event.data); |
d2083cab |
1134 | g_debug("Doing LTT_EVENT_FACILITY_LOAD of facility %s", |
1135 | fac_name); |
743e50fd |
1136 | pos = (tf->event.data + strlen(fac_name) + 1); |
7cbcdb89 |
1137 | pos += ltt_align((size_t)pos, tf->trace->arch_size, tf->has_alignment); |
743e50fd |
1138 | fac_load_data = (struct LttFacilityLoad *)pos; |
1139 | |
3aee1200 |
1140 | fac = &g_array_index (tf->trace->facilities_by_num, LttFacility, |
1141 | ltt_get_uint32(LTT_GET_BO(tf), &fac_load_data->id)); |
950683f4 |
1142 | /* facility may already exist if trace is paused/unpaused */ |
1143 | if(fac->exists) continue; |
3aee1200 |
1144 | fac->name = g_quark_from_string(fac_name); |
1145 | fac->checksum = ltt_get_uint32(LTT_GET_BO(tf), |
1146 | &fac_load_data->checksum); |
1147 | fac->id = ltt_get_uint32(LTT_GET_BO(tf), &fac_load_data->id); |
1148 | fac->pointer_size = ltt_get_uint32(LTT_GET_BO(tf), |
1149 | &fac_load_data->pointer_size); |
83e160f2 |
1150 | fac->int_size = ltt_get_uint32(LTT_GET_BO(tf), |
1151 | &fac_load_data->int_size); |
cb03932a |
1152 | fac->long_size = ltt_get_uint32(LTT_GET_BO(tf), |
1153 | &fac_load_data->long_size); |
eed2ef37 |
1154 | fac->size_t_size = ltt_get_uint32(LTT_GET_BO(tf), |
3aee1200 |
1155 | &fac_load_data->size_t_size); |
1156 | fac->alignment = ltt_get_uint32(LTT_GET_BO(tf), |
2312de30 |
1157 | &fac_load_data->has_alignment); |
3aee1200 |
1158 | |
1159 | if(ltt_get_facility_description(fac, tf->trace, tf)) |
cb03932a |
1160 | continue; /* error opening description */ |
3aee1200 |
1161 | |
1162 | fac->trace = tf->trace; |
cb03932a |
1163 | |
1164 | /* Preset the field offsets */ |
1165 | for(i=0; i<fac->events->len; i++){ |
1166 | et = &g_array_index(fac->events, LttEventType, i); |
743e50fd |
1167 | precompute_offsets(fac, et); |
cb03932a |
1168 | } |
1169 | |
3aee1200 |
1170 | fac->exists = 1; |
1171 | |
77175651 |
1172 | fac_ids = g_datalist_id_get_data(&tf->trace->facilities_by_name, |
1173 | fac->name); |
3aee1200 |
1174 | if(fac_ids == NULL) { |
1175 | fac_ids = g_array_sized_new (FALSE, TRUE, sizeof(guint), 1); |
1176 | g_datalist_id_set_data_full(&tf->trace->facilities_by_name, |
1177 | fac->name, |
1178 | fac_ids, ltt_fac_ids_destroy); |
1179 | } |
1180 | g_array_append_val(fac_ids, fac->id); |
1181 | |
1182 | break; |
1183 | case LTT_EVENT_FACILITY_UNLOAD: |
d2083cab |
1184 | g_debug("Doing LTT_EVENT_FACILITY_UNLOAD"); |
3aee1200 |
1185 | /* We don't care about unload : facilities ID are valid for the whole |
1186 | * trace. They simply won't be used after the unload. */ |
1187 | break; |
1188 | case LTT_EVENT_STATE_DUMP_FACILITY_LOAD: |
b77d1b57 |
1189 | fac_name = (char*)(tf->event.data); |
d2083cab |
1190 | g_debug("Doing LTT_EVENT_STATE_DUMP_FACILITY_LOAD of facility %s", |
1191 | fac_name); |
743e50fd |
1192 | pos = (tf->event.data + strlen(fac_name) + 1); |
7cbcdb89 |
1193 | pos += ltt_align((size_t)pos, tf->trace->arch_size, tf->has_alignment); |
743e50fd |
1194 | fac_state_dump_load_data = (struct LttStateDumpFacilityLoad *)pos; |
1195 | |
3aee1200 |
1196 | fac = &g_array_index (tf->trace->facilities_by_num, LttFacility, |
b77d1b57 |
1197 | ltt_get_uint32(LTT_GET_BO(tf), &fac_state_dump_load_data->id)); |
950683f4 |
1198 | /* facility may already exist if trace is paused/unpaused */ |
1199 | if(fac->exists) continue; |
3aee1200 |
1200 | fac->name = g_quark_from_string(fac_name); |
1201 | fac->checksum = ltt_get_uint32(LTT_GET_BO(tf), |
d2083cab |
1202 | &fac_state_dump_load_data->checksum); |
ad34d116 |
1203 | fac->id = ltt_get_uint32(LTT_GET_BO(tf), |
1204 | &fac_state_dump_load_data->id); |
3aee1200 |
1205 | fac->pointer_size = ltt_get_uint32(LTT_GET_BO(tf), |
d2083cab |
1206 | &fac_state_dump_load_data->pointer_size); |
83e160f2 |
1207 | fac->int_size = ltt_get_uint32(LTT_GET_BO(tf), |
1208 | &fac_state_dump_load_data->int_size); |
cb03932a |
1209 | fac->long_size = ltt_get_uint32(LTT_GET_BO(tf), |
1210 | &fac_state_dump_load_data->long_size); |
eed2ef37 |
1211 | fac->size_t_size = ltt_get_uint32(LTT_GET_BO(tf), |
d2083cab |
1212 | &fac_state_dump_load_data->size_t_size); |
3aee1200 |
1213 | fac->alignment = ltt_get_uint32(LTT_GET_BO(tf), |
2312de30 |
1214 | &fac_state_dump_load_data->has_alignment); |
3aee1200 |
1215 | if(ltt_get_facility_description(fac, tf->trace, tf)) |
cb03932a |
1216 | continue; /* error opening description */ |
3aee1200 |
1217 | |
1218 | fac->trace = tf->trace; |
1219 | |
cb03932a |
1220 | /* Preset the field offsets */ |
1221 | for(i=0; i<fac->events->len; i++){ |
1222 | et = &g_array_index(fac->events, LttEventType, i); |
743e50fd |
1223 | precompute_offsets(fac, et); |
cb03932a |
1224 | } |
1225 | |
3aee1200 |
1226 | fac->exists = 1; |
1227 | |
1228 | fac_ids = g_datalist_id_get_data(&tf->trace->facilities_by_name, |
1229 | fac->name); |
1230 | if(fac_ids == NULL) { |
1231 | fac_ids = g_array_sized_new (FALSE, TRUE, sizeof(guint), 1); |
1232 | g_datalist_id_set_data_full(&tf->trace->facilities_by_name, |
1233 | fac->name, |
1234 | fac_ids, ltt_fac_ids_destroy); |
1235 | } |
1236 | g_array_append_val(fac_ids, fac->id); |
d1bb700c |
1237 | g_debug("fac id : %u", fac->id); |
3aee1200 |
1238 | |
1239 | break; |
1240 | case LTT_EVENT_HEARTBEAT: |
1241 | break; |
d1bb700c |
1242 | case LTT_EVENT_HEARTBEAT_FULL: |
1243 | break; |
3aee1200 |
1244 | default: |
1245 | g_warning("Error in processing facility file %s, " |
1246 | "unknown event id %hhu in core facility.", |
1247 | g_quark_to_string(tf->name), |
1248 | tf->event.event_id); |
1249 | err = EPERM; |
1250 | goto event_id_error; |
1251 | } |
1252 | } |
963b5f2d |
1253 | } |
3aee1200 |
1254 | return 0; |
963b5f2d |
1255 | |
3aee1200 |
1256 | /* Error handling */ |
3aee1200 |
1257 | event_id_error: |
1258 | fac_id_error: |
1259 | update_error: |
1260 | seek_error: |
d2083cab |
1261 | g_warning("An error occured in facility tracefile parsing"); |
3aee1200 |
1262 | return err; |
6cd62ccf |
1263 | } |
1264 | |
963b5f2d |
1265 | |
3aee1200 |
1266 | LttTrace *ltt_trace_open(const gchar *pathname) |
1267 | { |
1268 | gchar abs_path[PATH_MAX]; |
1269 | LttTrace * t; |
1270 | LttTracefile *tf; |
1271 | GArray *group; |
b56dcdf2 |
1272 | int i, ret; |
16fcbb80 |
1273 | struct ltt_block_start_header *header; |
b56dcdf2 |
1274 | DIR *dir; |
1275 | struct dirent *entry; |
1276 | guint control_found = 0; |
1277 | guint eventdefs_found = 0; |
1278 | struct stat stat_buf; |
1279 | gchar path[PATH_MAX]; |
3aee1200 |
1280 | |
1281 | t = g_new(LttTrace, 1); |
1282 | if(!t) goto alloc_error; |
1283 | |
1284 | get_absolute_pathname(pathname, abs_path); |
1285 | t->pathname = g_quark_from_string(abs_path); |
1286 | |
3aee1200 |
1287 | g_datalist_init(&t->tracefiles); |
b56dcdf2 |
1288 | |
1289 | /* Test to see if it looks like a trace */ |
1290 | dir = opendir(abs_path); |
1291 | if(dir == NULL) { |
1292 | perror(abs_path); |
1293 | goto open_error; |
1294 | } |
1295 | while((entry = readdir(dir)) != NULL) { |
1296 | strcpy(path, abs_path); |
1297 | strcat(path, "/"); |
1298 | strcat(path, entry->d_name); |
1299 | ret = stat(path, &stat_buf); |
1300 | if(ret == -1) { |
1301 | perror(path); |
1302 | continue; |
1303 | } |
1304 | if(S_ISDIR(stat_buf.st_mode)) { |
1305 | if(strcmp(entry->d_name, "control") == 0) { |
1306 | control_found = 1; |
1307 | } |
1308 | if(strcmp(entry->d_name, "eventdefs") == 0) { |
1309 | eventdefs_found = 1; |
1310 | } |
1311 | } |
1312 | } |
1313 | closedir(dir); |
1314 | |
1315 | if(!control_found || !eventdefs_found) goto find_error; |
1316 | |
1317 | /* Open all the tracefiles */ |
e45551ac |
1318 | if(open_tracefiles(t, abs_path, "")) { |
1319 | g_warning("Error opening tracefile %s", abs_path); |
b56dcdf2 |
1320 | goto find_error; |
e45551ac |
1321 | } |
3aee1200 |
1322 | |
1323 | /* Prepare the facilities containers : array and mapping */ |
1324 | /* Array is zeroed : the "exists" field is set to false by default */ |
1325 | t->facilities_by_num = g_array_sized_new (FALSE, |
1326 | TRUE, sizeof(LttFacility), |
1327 | NUM_FACILITIES); |
1328 | t->facilities_by_num = g_array_set_size(t->facilities_by_num, NUM_FACILITIES); |
1329 | |
1330 | g_datalist_init(&t->facilities_by_name); |
1331 | |
1332 | /* Parse each trace control/facilitiesN files : get runtime fac. info */ |
1333 | group = g_datalist_id_get_data(&t->tracefiles, LTT_TRACEFILE_NAME_FACILITIES); |
1334 | if(group == NULL) { |
1335 | g_error("Trace %s has no facility tracefile", abs_path); |
3865ea09 |
1336 | g_assert(0); |
3aee1200 |
1337 | goto facilities_error; |
1338 | } |
1339 | |
16fcbb80 |
1340 | /* Get the trace information for the control/facility 0 tracefile */ |
1341 | g_assert(group->len > 0); |
1342 | tf = &g_array_index (group, LttTracefile, 0); |
1343 | header = (struct ltt_block_start_header*)tf->buffer.head; |
51551c6f |
1344 | g_assert(parse_trace_header(header->trace, |
1345 | tf, t) == 0); |
b56dcdf2 |
1346 | |
1347 | t->num_cpu = group->len; |
16fcbb80 |
1348 | |
3aee1200 |
1349 | for(i=0; i<group->len; i++) { |
1350 | tf = &g_array_index (group, LttTracefile, i); |
1351 | if(ltt_process_facility_tracefile(tf)) |
1352 | goto facilities_error; |
1353 | } |
d1bb700c |
1354 | t->compact_facilities = ltt_trace_facility_get_by_name(t, |
1355 | g_quark_from_string("compact")); |
1356 | if(!t->compact_facilities) |
1357 | t->compact_facilities = ltt_trace_facility_get_by_name(t, |
1358 | g_quark_from_string("flight-compact")); |
8e30f324 |
1359 | if (t->compact_facilities) { |
1360 | /* FIXME : currently does not support unload/load of compact |
1361 | * facility during tracing. Should check for the currently loaded |
1362 | * version of the facility. */ |
1363 | g_assert(t->compact_facilities->len == 1); |
1364 | g_assert(t->compact_facilities); |
1365 | { |
1366 | guint facility_id = g_array_index(t->compact_facilities, guint, 0); |
1367 | LttFacility *fac = ltt_trace_facility_by_id(t, facility_id); |
1368 | unsigned int num = ltt_facility_eventtype_number(fac); |
1369 | /* Could be done much quicker, but not on much used code path */ |
1370 | if(num) { |
1371 | t->compact_event_bits = 1; |
1372 | while(num >>= 1) |
1373 | t->compact_event_bits++; |
1374 | } else |
1375 | t->compact_event_bits = 0; |
1376 | } |
dd3a6d39 |
1377 | } |
1378 | |
3aee1200 |
1379 | return t; |
1380 | |
1381 | /* Error handling */ |
1382 | facilities_error: |
1383 | g_datalist_clear(&t->facilities_by_name); |
1384 | g_array_free(t->facilities_by_num, TRUE); |
b56dcdf2 |
1385 | find_error: |
3aee1200 |
1386 | g_datalist_clear(&t->tracefiles); |
b56dcdf2 |
1387 | open_error: |
3aee1200 |
1388 | g_free(t); |
1389 | alloc_error: |
1390 | return NULL; |
1391 | |
1392 | } |
6cd62ccf |
1393 | |
826f1ab2 |
1394 | GQuark ltt_trace_name(const LttTrace *t) |
6cd62ccf |
1395 | { |
3aee1200 |
1396 | return t->pathname; |
6cd62ccf |
1397 | } |
1398 | |
6cd62ccf |
1399 | |
3aee1200 |
1400 | /****************************************************************************** |
1401 | * When we copy a trace, we want all the opening actions to happen again : |
1402 | * the trace will be reopened and totally independant from the original. |
1403 | * That's why we call ltt_trace_open. |
1404 | *****************************************************************************/ |
1405 | LttTrace *ltt_trace_copy(LttTrace *self) |
963b5f2d |
1406 | { |
3aee1200 |
1407 | return ltt_trace_open(g_quark_to_string(self->pathname)); |
963b5f2d |
1408 | } |
1409 | |
3aee1200 |
1410 | void ltt_trace_close(LttTrace *t) |
6cd62ccf |
1411 | { |
cb03932a |
1412 | guint i; |
1413 | LttFacility *fac; |
1414 | |
1415 | for(i=0; i<t->facilities_by_num->len; i++) { |
1416 | fac = &g_array_index (t->facilities_by_num, LttFacility, i); |
1417 | if(fac->exists) |
1418 | ltt_facility_close(fac); |
1419 | } |
1420 | |
3aee1200 |
1421 | g_datalist_clear(&t->facilities_by_name); |
1422 | g_array_free(t->facilities_by_num, TRUE); |
1423 | g_datalist_clear(&t->tracefiles); |
1424 | g_free(t); |
6cd62ccf |
1425 | } |
1426 | |
3aee1200 |
1427 | |
6cd62ccf |
1428 | /***************************************************************************** |
3aee1200 |
1429 | *Get the system description of the trace |
6cd62ccf |
1430 | ****************************************************************************/ |
1431 | |
3aee1200 |
1432 | LttFacility *ltt_trace_facility_by_id(LttTrace *t, guint8 id) |
6cd62ccf |
1433 | { |
3aee1200 |
1434 | g_assert(id < t->facilities_by_num->len); |
1435 | return &g_array_index(t->facilities_by_num, LttFacility, id); |
1436 | } |
1437 | |
1438 | /* ltt_trace_facility_get_by_name |
1439 | * |
1440 | * Returns the GArray of facility indexes. All the fac_ids that matches the |
1441 | * requested facility name. |
1442 | * |
1443 | * If name is not found, returns NULL. |
1444 | */ |
1445 | GArray *ltt_trace_facility_get_by_name(LttTrace *t, GQuark name) |
1446 | { |
1447 | return g_datalist_id_get_data(&t->facilities_by_name, name); |
6cd62ccf |
1448 | } |
1449 | |
1450 | /***************************************************************************** |
963b5f2d |
1451 | * Functions to discover all the event types in the trace |
6cd62ccf |
1452 | ****************************************************************************/ |
1453 | |
3aee1200 |
1454 | #if 0 |
963b5f2d |
1455 | unsigned ltt_trace_eventtype_number(LttTrace *t) |
6cd62ccf |
1456 | { |
8d1e6362 |
1457 | unsigned int i; |
963b5f2d |
1458 | unsigned count = 0; |
dc1cad90 |
1459 | unsigned int num = t->facility_number; |
963b5f2d |
1460 | LttFacility * f; |
dc1cad90 |
1461 | |
1462 | for(i=0;i<num;i++){ |
963b5f2d |
1463 | f = (LttFacility*)g_ptr_array_index(t->facilities, i); |
1464 | count += f->event_number; |
1465 | } |
1466 | return count; |
6cd62ccf |
1467 | } |
3aee1200 |
1468 | #endif //0 |
6cd62ccf |
1469 | |
3aee1200 |
1470 | #if 0 |
1471 | //use an iteration on all the trace facilities, and inside iteration on all the |
1472 | //event types in each facilities instead. |
963b5f2d |
1473 | LttEventType *ltt_trace_eventtype_get(LttTrace *t, unsigned evId) |
6cd62ccf |
1474 | { |
6e8c19d4 |
1475 | LttEventType *event_type; |
1476 | |
963b5f2d |
1477 | LttFacility * f; |
1478 | f = ltt_trace_facility_by_id(t,evId); |
6e8c19d4 |
1479 | |
1480 | if(unlikely(!f)) event_type = NULL; |
1481 | else event_type = f->events[evId - f->base_id]; |
1482 | |
1483 | return event_type; |
6cd62ccf |
1484 | } |
3aee1200 |
1485 | #endif //0 |
6cd62ccf |
1486 | |
3aee1200 |
1487 | #if 0 |
6cd62ccf |
1488 | /***************************************************************************** |
3aee1200 |
1489 | * ltt_trace_find_tracefile |
1490 | * |
1491 | * Find a tracefile by name and index in the group. |
1492 | * |
1493 | * Returns a pointer to the tracefiles, else NULL. |
6cd62ccf |
1494 | ****************************************************************************/ |
6cd62ccf |
1495 | |
3aee1200 |
1496 | LttTracefile *ltt_trace_find_tracefile(LttTrace *t, const gchar *name) |
6cd62ccf |
1497 | { |
6cd62ccf |
1498 | } |
3aee1200 |
1499 | #endif //0 |
6cd62ccf |
1500 | |
1501 | /***************************************************************************** |
3aee1200 |
1502 | * Get the start time and end time of the trace |
6cd62ccf |
1503 | ****************************************************************************/ |
1504 | |
3aee1200 |
1505 | static void ltt_tracefile_time_span_get(LttTracefile *tf, |
1506 | LttTime *start, LttTime *end) |
6cd62ccf |
1507 | { |
3aee1200 |
1508 | int err; |
6cd62ccf |
1509 | |
3aee1200 |
1510 | err = map_block(tf, 0); |
1511 | if(unlikely(err)) { |
1512 | g_error("Can not map block"); |
1513 | *start = ltt_time_infinite; |
1514 | } else |
1515 | *start = tf->buffer.begin.timestamp; |
1516 | |
1517 | err = map_block(tf, tf->num_blocks - 1); /* Last block */ |
1518 | if(unlikely(err)) { |
1519 | g_error("Can not map block"); |
1520 | *end = ltt_time_zero; |
1521 | } else |
1522 | *end = tf->buffer.end.timestamp; |
6cd62ccf |
1523 | } |
1524 | |
3aee1200 |
1525 | struct tracefile_time_span_get_args { |
1526 | LttTrace *t; |
1527 | LttTime *start; |
1528 | LttTime *end; |
1529 | }; |
963b5f2d |
1530 | |
3aee1200 |
1531 | static void group_time_span_get(GQuark name, gpointer data, gpointer user_data) |
963b5f2d |
1532 | { |
3aee1200 |
1533 | struct tracefile_time_span_get_args *args = |
1534 | (struct tracefile_time_span_get_args*)user_data; |
1535 | |
1536 | GArray *group = (GArray *)data; |
1537 | int i; |
1538 | LttTracefile *tf; |
1539 | LttTime tmp_start; |
1540 | LttTime tmp_end; |
1541 | |
1542 | for(i=0; i<group->len; i++) { |
1543 | tf = &g_array_index (group, LttTracefile, i); |
1544 | if(tf->cpu_online) { |
1545 | ltt_tracefile_time_span_get(tf, &tmp_start, &tmp_end); |
1546 | if(ltt_time_compare(*args->start, tmp_start)>0) *args->start = tmp_start; |
1547 | if(ltt_time_compare(*args->end, tmp_end)<0) *args->end = tmp_end; |
1548 | } |
1549 | } |
6cd62ccf |
1550 | } |
1551 | |
487ad181 |
1552 | void ltt_trace_time_span_get(LttTrace *t, LttTime *start, LttTime *end) |
1553 | { |
3aee1200 |
1554 | LttTime min_start = ltt_time_infinite; |
1555 | LttTime max_end = ltt_time_zero; |
1556 | struct tracefile_time_span_get_args args = { t, &min_start, &max_end }; |
487ad181 |
1557 | |
3aee1200 |
1558 | g_datalist_foreach(&t->tracefiles, &group_time_span_get, &args); |
1559 | |
1560 | if(start != NULL) *start = min_start; |
1561 | if(end != NULL) *end = max_end; |
1562 | |
487ad181 |
1563 | } |
1564 | |
1565 | |
6cd62ccf |
1566 | /***************************************************************************** |
963b5f2d |
1567 | *Get the name of a tracefile |
6cd62ccf |
1568 | ****************************************************************************/ |
1569 | |
348c6ba8 |
1570 | GQuark ltt_tracefile_name(const LttTracefile *tf) |
6cd62ccf |
1571 | { |
963b5f2d |
1572 | return tf->name; |
6cd62ccf |
1573 | } |
1574 | |
348c6ba8 |
1575 | GQuark ltt_tracefile_long_name(const LttTracefile *tf) |
1576 | { |
1577 | return tf->long_name; |
1578 | } |
1579 | |
1580 | |
d3d34f49 |
1581 | |
ae3d0f50 |
1582 | guint ltt_tracefile_cpu(LttTracefile *tf) |
d3d34f49 |
1583 | { |
1584 | return tf->cpu_num; |
1585 | } |
1586 | |
ae3d0f50 |
1587 | guint ltt_tracefile_tid(LttTracefile *tf) |
1588 | { |
1589 | return tf->tid; |
1590 | } |
1591 | |
1592 | guint ltt_tracefile_pgid(LttTracefile *tf) |
1593 | { |
1594 | return tf->pgid; |
1595 | } |
1596 | |
1597 | guint64 ltt_tracefile_creation(LttTracefile *tf) |
1598 | { |
1599 | return tf->creation; |
1600 | } |
80da81ad |
1601 | /***************************************************************************** |
1602 | * Get the number of blocks in the tracefile |
1603 | ****************************************************************************/ |
1604 | |
3aee1200 |
1605 | guint ltt_tracefile_block_number(LttTracefile *tf) |
80da81ad |
1606 | { |
3aee1200 |
1607 | return tf->num_blocks; |
80da81ad |
1608 | } |
1609 | |
caf7a67a |
1610 | |
3aee1200 |
1611 | /* Seek to the first event in a tracefile that has a time equal or greater than |
1612 | * the time passed in parameter. |
1613 | * |
1614 | * If the time parameter is outside the tracefile time span, seek to the first |
27304273 |
1615 | * event or if after, return ERANGE. |
3aee1200 |
1616 | * |
1617 | * If the time parameter is before the first event, we have to seek specially to |
1618 | * there. |
1619 | * |
27304273 |
1620 | * If the time is after the end of the trace, return ERANGE. |
3aee1200 |
1621 | * |
1622 | * Do a binary search to find the right block, then a sequential search in the |
1623 | * block to find the event. |
1624 | * |
1625 | * In the special case where the time requested fits inside a block that has no |
1626 | * event corresponding to the requested time, the first event of the next block |
1627 | * will be seeked. |
1628 | * |
1629 | * IMPORTANT NOTE : // FIXME everywhere... |
1630 | * |
1631 | * You MUST NOT do a ltt_tracefile_read right after a ltt_tracefile_seek_time : |
1632 | * you will jump over an event if you do. |
1633 | * |
1634 | * Return value : 0 : no error, the tf->event can be used |
27304273 |
1635 | * ERANGE : time if after the last event of the trace |
3aee1200 |
1636 | * otherwise : this is an error. |
1637 | * |
1638 | * */ |
1639 | |
1640 | int ltt_tracefile_seek_time(LttTracefile *tf, LttTime time) |
1641 | { |
1642 | int ret = 0; |
1643 | int err; |
1644 | unsigned int block_num, high, low; |
1645 | |
1646 | /* seek at the beginning of trace */ |
1647 | err = map_block(tf, 0); /* First block */ |
1648 | if(unlikely(err)) { |
1649 | g_error("Can not map block"); |
1650 | goto fail; |
caf7a67a |
1651 | } |
1652 | |
3aee1200 |
1653 | /* If the time is lower or equal the beginning of the trace, |
1654 | * go to the first event. */ |
1655 | if(ltt_time_compare(time, tf->buffer.begin.timestamp) <= 0) { |
1656 | ret = ltt_tracefile_read(tf); |
27304273 |
1657 | if(ret == ERANGE) goto range; |
1658 | else if (ret) goto fail; |
3aee1200 |
1659 | goto found; /* There is either no event in the trace or the event points |
1660 | to the first event in the trace */ |
1661 | } |
caf7a67a |
1662 | |
3aee1200 |
1663 | err = map_block(tf, tf->num_blocks - 1); /* Last block */ |
1664 | if(unlikely(err)) { |
1665 | g_error("Can not map block"); |
1666 | goto fail; |
caf7a67a |
1667 | } |
6cd62ccf |
1668 | |
27304273 |
1669 | /* If the time is after the end of the trace, return ERANGE. */ |
1670 | if(ltt_time_compare(time, tf->buffer.end.timestamp) > 0) { |
1671 | goto range; |
3aee1200 |
1672 | } |
62e55dd6 |
1673 | |
3aee1200 |
1674 | /* Binary search the block */ |
1675 | high = tf->num_blocks - 1; |
1676 | low = 0; |
1677 | |
1678 | while(1) { |
1679 | block_num = ((high-low) / 2) + low; |
1680 | |
1681 | err = map_block(tf, block_num); |
1682 | if(unlikely(err)) { |
1683 | g_error("Can not map block"); |
1684 | goto fail; |
db55eaae |
1685 | } |
3aee1200 |
1686 | if(high == low) { |
1687 | /* We cannot divide anymore : this is what would happen if the time |
1688 | * requested was exactly between two consecutive buffers'end and start |
1689 | * timestamps. This is also what would happend if we didn't deal with out |
1690 | * of span cases prior in this function. */ |
1691 | /* The event is right in the buffer! |
1692 | * (or in the next buffer first event) */ |
1693 | while(1) { |
1694 | ret = ltt_tracefile_read(tf); |
27304273 |
1695 | if(ret == ERANGE) goto range; /* ERANGE or EPERM */ |
3aee1200 |
1696 | else if(ret) goto fail; |
1697 | |
d9e13a0f |
1698 | if(ltt_time_compare(time, tf->event.event_time) <= 0) |
e45551ac |
1699 | goto found; |
3aee1200 |
1700 | } |
1701 | |
27304273 |
1702 | } else if(ltt_time_compare(time, tf->buffer.begin.timestamp) < 0) { |
3aee1200 |
1703 | /* go to lower part */ |
b1369bef |
1704 | high = block_num - 1; |
3aee1200 |
1705 | } else if(ltt_time_compare(time, tf->buffer.end.timestamp) > 0) { |
1706 | /* go to higher part */ |
b1369bef |
1707 | low = block_num + 1; |
3aee1200 |
1708 | } else {/* The event is right in the buffer! |
1709 | (or in the next buffer first event) */ |
1710 | while(1) { |
27304273 |
1711 | ret = ltt_tracefile_read(tf); |
1712 | if(ret == ERANGE) goto range; /* ERANGE or EPERM */ |
3aee1200 |
1713 | else if(ret) goto fail; |
1714 | |
d9e13a0f |
1715 | if(ltt_time_compare(time, tf->event.event_time) <= 0) |
3aee1200 |
1716 | break; |
6cd62ccf |
1717 | } |
3aee1200 |
1718 | goto found; |
6cd62ccf |
1719 | } |
6cd62ccf |
1720 | } |
3aee1200 |
1721 | |
1722 | found: |
1723 | return 0; |
27304273 |
1724 | range: |
1725 | return ERANGE; |
3aee1200 |
1726 | |
1727 | /* Error handling */ |
1728 | fail: |
1729 | g_error("ltt_tracefile_seek_time failed on tracefile %s", |
1730 | g_quark_to_string(tf->name)); |
1731 | return EPERM; |
6cd62ccf |
1732 | } |
1733 | |
80da81ad |
1734 | |
3aee1200 |
1735 | int ltt_tracefile_seek_position(LttTracefile *tf, const LttEventPosition *ep) { |
80da81ad |
1736 | |
3aee1200 |
1737 | int err; |
1738 | |
1739 | if(ep->tracefile != tf) { |
1740 | goto fail; |
80da81ad |
1741 | } |
1742 | |
3aee1200 |
1743 | err = map_block(tf, ep->block); |
1744 | if(unlikely(err)) { |
1745 | g_error("Can not map block"); |
1746 | goto fail; |
1747 | } |
1748 | |
1749 | tf->event.offset = ep->offset; |
18206708 |
1750 | |
78f79181 |
1751 | /* Put back the event real tsc */ |
1752 | tf->event.tsc = ep->tsc; |
1753 | tf->buffer.tsc = ep->tsc; |
1754 | |
3aee1200 |
1755 | err = ltt_tracefile_read_update_event(tf); |
1756 | if(err) goto fail; |
1757 | err = ltt_tracefile_read_op(tf); |
1758 | if(err) goto fail; |
80da81ad |
1759 | |
a0c1f622 |
1760 | return 0; |
3aee1200 |
1761 | |
1762 | fail: |
1763 | g_error("ltt_tracefile_seek_time failed on tracefile %s", |
1764 | g_quark_to_string(tf->name)); |
a0c1f622 |
1765 | return 1; |
3aee1200 |
1766 | } |
1767 | |
ae3d0f50 |
1768 | LttTime ltt_interpolate_time_from_tsc(LttTracefile *tf, guint64 tsc) |
3aee1200 |
1769 | { |
1770 | LttTime time; |
ae3d0f50 |
1771 | |
1772 | if(tsc > tf->trace->start_tsc) { |
1773 | time = ltt_time_from_uint64( |
1774 | (double)(tsc - tf->trace->start_tsc) |
1775 | * (1000000000.0 / tf->trace->freq_scale) |
1776 | / (double)tf->trace->start_freq); |
1777 | time = ltt_time_add(tf->trace->start_time_from_tsc, time); |
1778 | } else { |
1779 | time = ltt_time_from_uint64( |
1780 | (double)(tf->trace->start_tsc - tsc) |
1781 | * (1000000000.0 / tf->trace->freq_scale) |
1782 | / (double)tf->trace->start_freq); |
1783 | time = ltt_time_sub(tf->trace->start_time_from_tsc, time); |
1784 | } |
3aee1200 |
1785 | return time; |
80da81ad |
1786 | } |
1787 | |
ae3d0f50 |
1788 | /* Calculate the real event time based on the buffer boundaries */ |
1789 | LttTime ltt_interpolate_time(LttTracefile *tf, LttEvent *event) |
1790 | { |
1791 | return ltt_interpolate_time_from_tsc(tf, tf->buffer.tsc); |
1792 | } |
1793 | |
eed2ef37 |
1794 | |
1795 | /* Get the current event of the tracefile : valid until the next read */ |
1796 | LttEvent *ltt_tracefile_get_event(LttTracefile *tf) |
1797 | { |
1798 | return &tf->event; |
1799 | } |
1800 | |
1801 | |
1802 | |
6cd62ccf |
1803 | /***************************************************************************** |
1804 | *Function name |
3aee1200 |
1805 | * ltt_tracefile_read : Read the next event in the tracefile |
6cd62ccf |
1806 | *Input params |
1807 | * t : tracefile |
1808 | *Return value |
3aee1200 |
1809 | * |
1810 | * Returns 0 if an event can be used in tf->event. |
d822520b |
1811 | * Returns ERANGE on end of trace. The event in tf->event still can be used |
1812 | * (if the last block was not empty). |
3aee1200 |
1813 | * Returns EPERM on error. |
1814 | * |
1815 | * This function does make the tracefile event structure point to the event |
1816 | * currently pointed to by the tf->event. |
1817 | * |
1818 | * Note : you must call a ltt_tracefile_seek to the beginning of the trace to |
1819 | * reinitialize it after an error if you want results to be coherent. |
1820 | * It would be the case if a end of trace last buffer has no event : the end |
1821 | * of trace wouldn't be returned, but an error. |
1822 | * We make the assumption there is at least one event per buffer. |
6cd62ccf |
1823 | ****************************************************************************/ |
1824 | |
3aee1200 |
1825 | int ltt_tracefile_read(LttTracefile *tf) |
6cd62ccf |
1826 | { |
963b5f2d |
1827 | int err; |
6cd62ccf |
1828 | |
3aee1200 |
1829 | err = ltt_tracefile_read_seek(tf); |
1830 | if(err) return err; |
1831 | err = ltt_tracefile_read_update_event(tf); |
1832 | if(err) return err; |
1833 | err = ltt_tracefile_read_op(tf); |
1834 | if(err) return err; |
1835 | |
1836 | return 0; |
1837 | } |
1838 | |
1839 | int ltt_tracefile_read_seek(LttTracefile *tf) |
1840 | { |
1841 | int err; |
1842 | |
1843 | /* Get next buffer until we finally have an event, or end of trace */ |
1844 | while(1) { |
1845 | err = ltt_seek_next_event(tf); |
1846 | if(unlikely(err == ENOPROTOOPT)) { |
1847 | return EPERM; |
bdc36259 |
1848 | } |
bdc36259 |
1849 | |
3aee1200 |
1850 | /* Are we at the end of the buffer ? */ |
1851 | if(err == ERANGE) { |
1852 | if(unlikely(tf->buffer.index == tf->num_blocks-1)){ /* end of trace ? */ |
1853 | return ERANGE; |
1854 | } else { |
1855 | /* get next block */ |
1856 | err = map_block(tf, tf->buffer.index + 1); |
1857 | if(unlikely(err)) { |
1858 | g_error("Can not map block"); |
1859 | return EPERM; |
1860 | } |
1861 | } |
1862 | } else break; /* We found an event ! */ |
1863 | } |
2dee981d |
1864 | |
3aee1200 |
1865 | return 0; |
1866 | } |
18206708 |
1867 | |
1868 | |
3aee1200 |
1869 | /* do specific operation on events */ |
1870 | int ltt_tracefile_read_op(LttTracefile *tf) |
1871 | { |
3aee1200 |
1872 | LttEvent *event; |
1873 | |
1874 | event = &tf->event; |
18206708 |
1875 | |
3aee1200 |
1876 | /* do event specific operation */ |
40331ba8 |
1877 | |
3aee1200 |
1878 | /* do something if its an heartbeat event : increment the heartbeat count */ |
1879 | //if(event->facility_id == LTT_FACILITY_CORE) |
1880 | // if(event->event_id == LTT_EVENT_HEARTBEAT) |
1881 | // tf->cur_heart_beat_number++; |
1882 | |
1883 | return 0; |
6cd62ccf |
1884 | } |
1885 | |
6cd62ccf |
1886 | |
3aee1200 |
1887 | /* same as ltt_tracefile_read, but does not seek to the next event nor call |
1888 | * event specific operation. */ |
1889 | int ltt_tracefile_read_update_event(LttTracefile *tf) |
6cd62ccf |
1890 | { |
3aee1200 |
1891 | void * pos; |
1892 | LttEvent *event; |
1893 | |
1894 | event = &tf->event; |
eed2ef37 |
1895 | pos = tf->buffer.head + event->offset; |
3aee1200 |
1896 | |
1897 | /* Read event header */ |
1898 | |
f104d082 |
1899 | /* Align the head */ |
d1bb700c |
1900 | if(!tf->compact) |
1901 | pos += ltt_align((size_t)pos, tf->trace->arch_size, tf->has_alignment); |
1902 | else { |
90440c06 |
1903 | g_assert(tf->has_heartbeat); |
d1bb700c |
1904 | pos += ltt_align((size_t)pos, sizeof(uint32_t), tf->has_alignment); |
1905 | } |
3aee1200 |
1906 | |
90440c06 |
1907 | if(tf->has_heartbeat) { |
cb310b57 |
1908 | event->timestamp = ltt_get_uint32(LTT_GET_BO(tf), |
1909 | pos); |
d1bb700c |
1910 | if(!tf->compact) { |
1911 | /* 32 bits -> 64 bits tsc */ |
1912 | /* note : still works for seek and non seek cases. */ |
1913 | if(event->timestamp < (0xFFFFFFFFULL&tf->buffer.tsc)) { |
1914 | tf->buffer.tsc = ((tf->buffer.tsc&0xFFFFFFFF00000000ULL) |
1915 | + 0x100000000ULL) |
1916 | | (guint64)event->timestamp; |
1917 | event->tsc = tf->buffer.tsc; |
1918 | } else { |
1919 | /* no overflow */ |
1920 | tf->buffer.tsc = (tf->buffer.tsc&0xFFFFFFFF00000000ULL) |
1921 | | (guint64)event->timestamp; |
1922 | event->tsc = tf->buffer.tsc; |
dd3a6d39 |
1923 | event->compact_data = 0; |
d1bb700c |
1924 | } |
1925 | } else { |
1926 | /* Compact header */ |
1927 | /* We keep the LSB of the previous timestamp, to make sure |
1928 | * we never go back */ |
1929 | event->event_id = event->timestamp >> tf->tscbits; |
dd3a6d39 |
1930 | event->event_id = event->event_id & ((1 << tf->trace->compact_event_bits) - 1); |
1931 | event->compact_data = event->timestamp >> |
1932 | (tf->trace->compact_event_bits + tf->tscbits); |
1933 | //printf("tsc bits %u, ev bits %u init data %u\n", |
1934 | // tf->tscbits, tf->trace->compact_event_bits, event->compact_data); |
1935 | /* Put the compact data back in original endianness */ |
1936 | event->compact_data = ltt_get_uint32(LTT_GET_BO(tf), &event->compact_data); |
d1bb700c |
1937 | event->event_size = 0xFFFF; |
dd3a6d39 |
1938 | //printf("Found compact event %d\n", event->event_id); |
1939 | //printf("Compact data %d\n", event->compact_data); |
d1bb700c |
1940 | event->timestamp = event->timestamp << tf->tsc_lsb_truncate; |
1941 | event->timestamp = event->timestamp & tf->tsc_mask; |
dd3a6d39 |
1942 | //printf("timestamp 0x%lX\n", event->timestamp); |
1943 | //printf("mask 0x%llX\n", tf->tsc_mask); |
1944 | //printf("mask_next 0x%llX\n", tf->tsc_mask_next_bit); |
1945 | //printf("previous tsc 0x%llX\n", tf->buffer.tsc); |
1946 | //printf("previous tsc&mask 0x%llX\n", tf->tsc_mask&tf->buffer.tsc); |
1947 | //printf("previous tsc&(~mask) 0x%llX\n", tf->buffer.tsc&(~tf->tsc_mask)); |
d1bb700c |
1948 | if(event->timestamp < (tf->tsc_mask&tf->buffer.tsc)) { |
dd3a6d39 |
1949 | //printf("wrap\n"); |
d1bb700c |
1950 | tf->buffer.tsc = ((tf->buffer.tsc&(~tf->tsc_mask)) |
1951 | + tf->tsc_mask_next_bit) |
1952 | | (guint64)event->timestamp; |
1953 | event->tsc = tf->buffer.tsc; |
1954 | } else { |
dd3a6d39 |
1955 | //printf("no wrap\n"); |
d1bb700c |
1956 | /* no overflow */ |
1957 | tf->buffer.tsc = (tf->buffer.tsc&(~tf->tsc_mask)) |
1958 | | (guint64)event->timestamp; |
1959 | event->tsc = tf->buffer.tsc; |
1960 | } |
dd3a6d39 |
1961 | //printf("current tsc 0x%llX\n", tf->buffer.tsc); |
d1bb700c |
1962 | event->facility_id = g_array_index(tf->trace->compact_facilities, guint, 0); |
1963 | } |
cb310b57 |
1964 | pos += sizeof(guint32); |
1965 | } else { |
1966 | event->tsc = ltt_get_uint64(LTT_GET_BO(tf), pos); |
1967 | tf->buffer.tsc = event->tsc; |
dd3a6d39 |
1968 | event->compact_data = 0; |
cb310b57 |
1969 | pos += sizeof(guint64); |
1970 | } |
cb310b57 |
1971 | event->event_time = ltt_interpolate_time(tf, event); |
3aee1200 |
1972 | |
d1bb700c |
1973 | if(!tf->compact) { |
1974 | event->facility_id = *(guint8*)pos; |
1975 | pos += sizeof(guint8); |
3aee1200 |
1976 | |
d1bb700c |
1977 | event->event_id = *(guint8*)pos; |
1978 | pos += sizeof(guint8); |
1979 | |
1980 | event->event_size = ltt_get_uint16(LTT_GET_BO(tf), pos); |
1981 | pos += sizeof(guint16); |
1982 | } else { |
1983 | /* Compact event */ |
1984 | } |
f104d082 |
1985 | /* Align the head */ |
d1bb700c |
1986 | if(!tf->compact) |
1987 | pos += ltt_align((size_t)pos, tf->trace->arch_size, tf->has_alignment); |
f104d082 |
1988 | |
3aee1200 |
1989 | event->data = pos; |
1990 | |
77175651 |
1991 | /* get the data size and update the event fields with the current |
d1bb700c |
1992 | * information. Also update the time if a heartbeat_full event is found. */ |
eed2ef37 |
1993 | ltt_update_event_size(tf); |
77175651 |
1994 | |
3aee1200 |
1995 | return 0; |
6cd62ccf |
1996 | } |
1997 | |
507915ee |
1998 | |
6cd62ccf |
1999 | /**************************************************************************** |
2000 | *Function name |
3aee1200 |
2001 | * map_block : map a block from the file |
6cd62ccf |
2002 | *Input Params |
2003 | * lttdes : ltt trace file |
2004 | * whichBlock : the block which will be read |
2005 | *return value |
2006 | * 0 : success |
2007 | * EINVAL : lseek fail |
2008 | * EIO : can not read from the file |
2009 | ****************************************************************************/ |
2010 | |
3aee1200 |
2011 | static gint map_block(LttTracefile * tf, guint block_num) |
6cd62ccf |
2012 | { |
b77d1b57 |
2013 | int page_size = getpagesize(); |
3aee1200 |
2014 | struct ltt_block_start_header *header; |
2015 | |
2016 | g_assert(block_num < tf->num_blocks); |
6cd62ccf |
2017 | |
f628823c |
2018 | if(tf->buffer.head != NULL) { |
2019 | if(munmap(tf->buffer.head, PAGE_ALIGN(tf->buf_size))) { |
2020 | g_warning("unmap size : %u\n", |
2021 | PAGE_ALIGN(tf->buf_size)); |
2022 | perror("munmap error"); |
2023 | g_assert(0); |
2024 | } |
2025 | } |
2026 | |
ac849774 |
2027 | |
3aee1200 |
2028 | /* Multiple of pages aligned head */ |
b77d1b57 |
2029 | tf->buffer.head = mmap(0, |
f628823c |
2030 | PAGE_ALIGN(tf->buf_size), |
b77d1b57 |
2031 | PROT_READ, MAP_PRIVATE, tf->fd, |
f628823c |
2032 | PAGE_ALIGN((off_t)tf->buf_size * (off_t)block_num)); |
3aee1200 |
2033 | |
3865ea09 |
2034 | if(tf->buffer.head == MAP_FAILED) { |
3aee1200 |
2035 | perror("Error in allocating memory for buffer of tracefile"); |
3865ea09 |
2036 | g_assert(0); |
3aee1200 |
2037 | goto map_error; |
6cd62ccf |
2038 | } |
3865ea09 |
2039 | g_assert( ( (guint)tf->buffer.head&(8-1) ) == 0); // make sure it's aligned. |
3aee1200 |
2040 | |
6cd62ccf |
2041 | |
3aee1200 |
2042 | tf->buffer.index = block_num; |
2043 | |
2044 | header = (struct ltt_block_start_header*)tf->buffer.head; |
2045 | |
791dffa6 |
2046 | #if 0 |
986e2a7c |
2047 | tf->buffer.begin.timestamp = ltt_time_add( |
2048 | ltt_time_from_uint64( |
2049 | ltt_get_uint64(LTT_GET_BO(tf), |
2050 | &header->begin.timestamp) |
2051 | - tf->trace->start_monotonic), |
2052 | tf->trace->start_time); |
791dffa6 |
2053 | #endif //0 |
348c6ba8 |
2054 | //g_debug("block %u begin : %lu.%lu", block_num, |
2055 | // tf->buffer.begin.timestamp.tv_sec, tf->buffer.begin.timestamp.tv_nsec); |
3aee1200 |
2056 | tf->buffer.begin.cycle_count = ltt_get_uint64(LTT_GET_BO(tf), |
2057 | &header->begin.cycle_count); |
986e2a7c |
2058 | tf->buffer.begin.freq = ltt_get_uint64(LTT_GET_BO(tf), |
2059 | &header->begin.freq); |
ae3d0f50 |
2060 | if(tf->buffer.begin.freq == 0) |
2061 | tf->buffer.begin.freq = tf->trace->start_freq; |
2062 | |
2063 | tf->buffer.begin.timestamp = ltt_interpolate_time_from_tsc(tf, |
2064 | tf->buffer.begin.cycle_count); |
2065 | #if 0 |
2066 | ltt_time_add( |
791dffa6 |
2067 | ltt_time_from_uint64( |
88612d17 |
2068 | (double)(tf->buffer.begin.cycle_count |
2069 | - tf->trace->start_tsc) * 1000000.0 |
791dffa6 |
2070 | / (double)tf->trace->start_freq), |
ae3d0f50 |
2071 | tf->trace->start_time_from_tsc); |
2072 | #endif //0 |
791dffa6 |
2073 | #if 0 |
2074 | |
986e2a7c |
2075 | tf->buffer.end.timestamp = ltt_time_add( |
2076 | ltt_time_from_uint64( |
2077 | ltt_get_uint64(LTT_GET_BO(tf), |
2078 | &header->end.timestamp) |
2079 | - tf->trace->start_monotonic), |
2080 | tf->trace->start_time); |
791dffa6 |
2081 | #endif //0 |
348c6ba8 |
2082 | //g_debug("block %u end : %lu.%lu", block_num, |
2083 | // tf->buffer.end.timestamp.tv_sec, tf->buffer.end.timestamp.tv_nsec); |
3aee1200 |
2084 | tf->buffer.end.cycle_count = ltt_get_uint64(LTT_GET_BO(tf), |
2085 | &header->end.cycle_count); |
986e2a7c |
2086 | tf->buffer.end.freq = ltt_get_uint64(LTT_GET_BO(tf), |
2087 | &header->end.freq); |
ae3d0f50 |
2088 | if(tf->buffer.end.freq == 0) |
2089 | tf->buffer.end.freq = tf->trace->start_freq; |
2090 | |
3aee1200 |
2091 | tf->buffer.lost_size = ltt_get_uint32(LTT_GET_BO(tf), |
986e2a7c |
2092 | &header->lost_size); |
ae3d0f50 |
2093 | tf->buffer.end.timestamp = ltt_interpolate_time_from_tsc(tf, |
2094 | tf->buffer.end.cycle_count); |
2095 | #if 0 |
2096 | ltt_time_add( |
791dffa6 |
2097 | ltt_time_from_uint64( |
88612d17 |
2098 | (double)(tf->buffer.end.cycle_count |
2099 | - tf->trace->start_tsc) * 1000000.0 |
791dffa6 |
2100 | / (double)tf->trace->start_freq), |
88612d17 |
2101 | tf->trace->start_time_from_tsc); |
ae3d0f50 |
2102 | #endif //0 |
3aee1200 |
2103 | tf->buffer.tsc = tf->buffer.begin.cycle_count; |
2104 | tf->event.tsc = tf->buffer.tsc; |
986e2a7c |
2105 | tf->buffer.freq = tf->buffer.begin.freq; |
3aee1200 |
2106 | |
2107 | /* FIXME |
2108 | * eventually support variable buffer size : will need a partial pre-read of |
2109 | * the headers to create an index when we open the trace... eventually. */ |
f628823c |
2110 | g_assert(tf->buf_size == ltt_get_uint32(LTT_GET_BO(tf), |
3aee1200 |
2111 | &header->buf_size)); |
507915ee |
2112 | |
3aee1200 |
2113 | /* Now that the buffer is mapped, calculate the time interpolation for the |
2114 | * block. */ |
2115 | |
791dffa6 |
2116 | // tf->buffer.nsecs_per_cycle = calc_nsecs_per_cycle(tf); |
2117 | //tf->buffer.cyc2ns_scale = calc_nsecs_per_cycle(tf); |
3aee1200 |
2118 | |
2119 | /* Make the current event point to the beginning of the buffer : |
2120 | * it means that the event read must get the first event. */ |
2121 | tf->event.tracefile = tf; |
2122 | tf->event.block = block_num; |
eed2ef37 |
2123 | tf->event.offset = 0; |
3aee1200 |
2124 | |
2125 | return 0; |
6cd62ccf |
2126 | |
3aee1200 |
2127 | map_error: |
2128 | return -errno; |
40331ba8 |
2129 | |
6cd62ccf |
2130 | } |
2131 | |
77175651 |
2132 | /* It will update the fields offsets too */ |
2133 | void ltt_update_event_size(LttTracefile *tf) |
6cd62ccf |
2134 | { |
2312de30 |
2135 | off_t size = 0; |
77175651 |
2136 | LttFacility *f = ltt_trace_get_facility_by_num(tf->trace, |
2137 | tf->event.facility_id); |
d1bb700c |
2138 | char *tscdata; |
44f317b7 |
2139 | |
2140 | if(!f->exists) { |
2141 | /* Specific handling of core events : necessary to read the facility control |
2142 | * tracefile. */ |
2143 | |
2144 | if(likely(tf->event.facility_id == LTT_FACILITY_CORE)) { |
2145 | switch((enum ltt_core_events)tf->event.event_id) { |
2146 | case LTT_EVENT_FACILITY_LOAD: |
2147 | size = strlen((char*)tf->event.data) + 1; |
2148 | //g_debug("Update Event facility load of facility %s", (char*)tf->event.data); |
2149 | size += ltt_align(size, sizeof(guint32), tf->has_alignment); |
2150 | size += sizeof(struct LttFacilityLoad); |
2151 | break; |
2152 | case LTT_EVENT_FACILITY_UNLOAD: |
2153 | //g_debug("Update Event facility unload"); |
2154 | size = sizeof(struct LttFacilityUnload); |
2155 | break; |
2156 | case LTT_EVENT_STATE_DUMP_FACILITY_LOAD: |
2157 | size = strlen((char*)tf->event.data) + 1; |
2158 | size += ltt_align(size, sizeof(guint32), tf->has_alignment); |
2159 | //g_debug("Update Event facility load state dump of facility %s", |
2160 | // (char*)tf->event.data); |
2161 | size += sizeof(struct LttStateDumpFacilityLoad); |
2162 | break; |
2163 | case LTT_EVENT_HEARTBEAT: |
2164 | //g_debug("Update Event heartbeat"); |
2165 | size = sizeof(TimeHeartbeat); |
2166 | break; |
d1bb700c |
2167 | case LTT_EVENT_HEARTBEAT_FULL: |
2168 | //g_debug("Update Event heartbeat full"); |
2169 | tscdata = (char*)(tf->event.data); |
2170 | tf->event.tsc = ltt_get_uint64(LTT_GET_BO(tf), tscdata); |
2171 | tf->buffer.tsc = tf->event.tsc; |
2172 | tf->event.event_time = ltt_interpolate_time(tf, &tf->event); |
2173 | size = sizeof(TimeHeartbeatFull); |
2174 | size += ltt_align(size, sizeof(guint64), tf->has_alignment); |
2175 | break; |
44f317b7 |
2176 | default: |
2177 | g_warning("Error in getting event size : tracefile %s, " |
2178 | "unknown event id %hhu in core facility.", |
2179 | g_quark_to_string(tf->name), |
2180 | tf->event.event_id); |
2181 | goto event_id_error; |
2182 | |
2183 | } |
7cbcdb89 |
2184 | goto no_offset; /* Skip the field computation */ |
44f317b7 |
2185 | } else { |
9d7e0c25 |
2186 | g_warning("Unknown facility %hhu (0x%hhx) in tracefile %s", |
c4afd5d8 |
2187 | tf->event.facility_id, |
2188 | tf->event.facility_id, |
2189 | g_quark_to_string(tf->name)); |
2190 | goto facility_error; |
2191 | } |
44f317b7 |
2192 | } |
c4afd5d8 |
2193 | |
44f317b7 |
2194 | LttEventType *event_type = |
2195 | ltt_facility_eventtype_get(f, tf->event.event_id); |
c4afd5d8 |
2196 | |
44f317b7 |
2197 | if(!event_type) { |
2198 | g_warning("Unknown event id %hhu in facility %s in tracefile %s", |
2199 | tf->event.event_id, |
2200 | g_quark_to_string(f->name), |
2201 | g_quark_to_string(tf->name)); |
2202 | goto event_type_error; |
3aee1200 |
2203 | } |
3aee1200 |
2204 | |
44f317b7 |
2205 | /* Compute the dynamic offsets */ |
2206 | compute_offsets(tf, f, event_type, &size, tf->event.data); |
2207 | |
2208 | //g_debug("Event root field : f.e %hhu.%hhu size %zd", |
2209 | // tf->event.facility_id, |
2210 | // tf->event.event_id, size); |
7cbcdb89 |
2211 | |
2212 | no_offset: |
77175651 |
2213 | tf->event.data_size = size; |
eed2ef37 |
2214 | |
b77d1b57 |
2215 | /* Check consistency between kernel and LTTV structure sizes */ |
055d359a |
2216 | if(tf->event.event_size == 0xFFFF) { |
2217 | /* Event size too big to fit in the event size field */ |
2218 | tf->event.event_size = tf->event.data_size; |
2219 | } |
f63ebe51 |
2220 | if (tf->event.data_size != tf->event.event_size) { |
2221 | g_error("Kernel/LTTV event size differs for event %s.%s: kernel %u, LTTV %u", |
2222 | g_quark_to_string(f->name), g_quark_to_string(event_type->name), |
2223 | tf->event.event_size, tf->event.data_size); |
2224 | exit(-1); |
2225 | } |
2226 | //g_assert(tf->event.data_size == tf->event.event_size); |
9eb6aa7a |
2227 | |
eed2ef37 |
2228 | return; |
2229 | |
c4afd5d8 |
2230 | facility_error: |
2231 | event_type_error: |
3aee1200 |
2232 | event_id_error: |
9d7e0c25 |
2233 | if(tf->event.event_size == 0xFFFF) { |
2234 | g_error("Cannot jump over an unknown event bigger than 0xFFFE bytes"); |
2235 | } |
2236 | /* The facility is unknown : use the kernel information about this event |
2237 | * to jump over it. */ |
2238 | tf->event.data_size = tf->event.event_size; |
6cd62ccf |
2239 | } |
2240 | |
6cd62ccf |
2241 | |
3aee1200 |
2242 | /* Take the tf current event offset and use the event facility id and event id |
2243 | * to figure out where is the next event offset. |
2244 | * |
2245 | * This is an internal function not aiming at being used elsewhere : it will |
2246 | * not jump over the current block limits. Please consider using |
2247 | * ltt_tracefile_read to do this. |
2248 | * |
2249 | * Returns 0 on success |
2250 | * ERANGE if we are at the end of the buffer. |
2251 | * ENOPROTOOPT if an error occured when getting the current event size. |
2252 | */ |
2253 | static int ltt_seek_next_event(LttTracefile *tf) |
6cd62ccf |
2254 | { |
3aee1200 |
2255 | int ret = 0; |
2256 | void *pos; |
3aee1200 |
2257 | |
2258 | /* seek over the buffer header if we are at the buffer start */ |
eed2ef37 |
2259 | if(tf->event.offset == 0) { |
51551c6f |
2260 | tf->event.offset += tf->buffer_header_size; |
b77d1b57 |
2261 | |
f628823c |
2262 | if(tf->event.offset == tf->buf_size - tf->buffer.lost_size) { |
b77d1b57 |
2263 | ret = ERANGE; |
2264 | } |
3aee1200 |
2265 | goto found; |
2266 | } |
6cd62ccf |
2267 | |
6cd62ccf |
2268 | |
3aee1200 |
2269 | pos = tf->event.data; |
2270 | |
77175651 |
2271 | if(tf->event.data_size < 0) goto error; |
3aee1200 |
2272 | |
77175651 |
2273 | pos += (size_t)tf->event.data_size; |
3aee1200 |
2274 | |
eed2ef37 |
2275 | tf->event.offset = pos - tf->buffer.head; |
cb03932a |
2276 | |
f628823c |
2277 | if(tf->event.offset == tf->buf_size - tf->buffer.lost_size) { |
cb03932a |
2278 | ret = ERANGE; |
2279 | goto found; |
2280 | } |
36d36c9f |
2281 | g_assert(tf->event.offset < tf->buf_size - tf->buffer.lost_size); |
3aee1200 |
2282 | |
2283 | found: |
2284 | return ret; |
2285 | |
2286 | error: |
2287 | g_error("Error in ltt_seek_next_event for tracefile %s", |
2288 | g_quark_to_string(tf->name)); |
2289 | return ENOPROTOOPT; |
6cd62ccf |
2290 | } |
2291 | |
791dffa6 |
2292 | #if 0 |
6cd62ccf |
2293 | /***************************************************************************** |
2294 | *Function name |
3aee1200 |
2295 | * calc_nsecs_per_cycle : calculate nsecs per cycle for current block |
986e2a7c |
2296 | * |
2297 | * 1.0 / (freq(khz) *1000) * 1000000000 |
6cd62ccf |
2298 | *Input Params |
2299 | * t : tracefile |
2300 | ****************************************************************************/ |
986e2a7c |
2301 | /* from timer_tsc.c */ |
2302 | #define CYC2NS_SCALE_FACTOR 10 |
791dffa6 |
2303 | static guint32 calc_nsecs_per_cycle(LttTracefile * tf) |
6cd62ccf |
2304 | { |
986e2a7c |
2305 | //return 1e6 / (double)tf->buffer.freq; |
791dffa6 |
2306 | guint32 cpu_mhz = tf->buffer.freq / 1000; |
2307 | guint32 cyc2ns_scale = (1000 << CYC2NS_SCALE_FACTOR)/cpu_mhz; |
6cd62ccf |
2308 | |
791dffa6 |
2309 | return cyc2ns_scale; |
986e2a7c |
2310 | // return 1e6 / (double)tf->buffer.freq; |
3aee1200 |
2311 | } |
791dffa6 |
2312 | |
2313 | static guint64 cycles_2_ns(LttTracefile *tf, guint64 cycles) |
2314 | { |
2315 | return (cycles * tf->buffer.cyc2ns_scale) >> CYC2NS_SCALE_FACTOR; |
2316 | } |
2317 | #endif //0 |
2318 | |
3aee1200 |
2319 | #if 0 |
2320 | void setFieldsOffset(LttTracefile *tf, LttEventType *evT,void *evD) |
2321 | { |
2322 | LttField * rootFld = evT->root_field; |
2323 | // rootFld->base_address = evD; |
2dee981d |
2324 | |
3aee1200 |
2325 | if(likely(rootFld)) |
2326 | rootFld->field_size = getFieldtypeSize(tf, evT->facility, |
2327 | evT, 0,0,rootFld, evD); |
6cd62ccf |
2328 | } |
3aee1200 |
2329 | #endif //0 |
f104d082 |
2330 | #if 0 |
3aee1200 |
2331 | /***************************************************************************** |
6cd62ccf |
2332 | *Function name |
3aee1200 |
2333 | * set_fields_offsets : set the precomputable offset of the fields |
6cd62ccf |
2334 | *Input params |
3aee1200 |
2335 | * tracefile : opened trace file |
2336 | * event_type : the event type |
6cd62ccf |
2337 | ****************************************************************************/ |
2338 | |
3aee1200 |
2339 | void set_fields_offsets(LttTracefile *tf, LttEventType *event_type) |
6cd62ccf |
2340 | { |
3aee1200 |
2341 | LttField *field = event_type->root_field; |
2342 | enum field_status fixed_root = FIELD_FIXED, fixed_parent = FIELD_FIXED; |
2343 | |
2344 | if(likely(field)) |
2345 | preset_field_type_size(tf, event_type, 0, 0, |
2346 | &fixed_root, &fixed_parent, |
2347 | field); |
2348 | |
2349 | } |
f104d082 |
2350 | #endif //0 |
2351 | |
2352 | |
2353 | /***************************************************************************** |
2354 | *Function name |
2355 | * get_alignment : Get the alignment needed for a field. |
2356 | *Input params |
f104d082 |
2357 | * field : field |
2358 | * |
2359 | * returns : The size on which it must be aligned. |
2360 | * |
2361 | ****************************************************************************/ |
743e50fd |
2362 | off_t get_alignment(LttField *field) |
f104d082 |
2363 | { |
2312de30 |
2364 | LttType *type = &field->field_type; |
f104d082 |
2365 | |
2366 | switch(type->type_class) { |
2367 | case LTT_INT_FIXED: |
2368 | case LTT_UINT_FIXED: |
2369 | case LTT_POINTER: |
2370 | case LTT_CHAR: |
2371 | case LTT_UCHAR: |
2372 | case LTT_SHORT: |
2373 | case LTT_USHORT: |
2374 | case LTT_INT: |
2375 | case LTT_UINT: |
2376 | case LTT_LONG: |
2377 | case LTT_ULONG: |
2378 | case LTT_SIZE_T: |
2379 | case LTT_SSIZE_T: |
2380 | case LTT_OFF_T: |
2381 | case LTT_FLOAT: |
2382 | case LTT_ENUM: |
2383 | /* Align offset on type size */ |
83e160f2 |
2384 | g_assert(field->field_size != 0); |
f104d082 |
2385 | return field->field_size; |
2386 | break; |
2387 | case LTT_STRING: |
83e160f2 |
2388 | return 1; |
f104d082 |
2389 | break; |
2390 | case LTT_ARRAY: |
2391 | g_assert(type->fields->len == 1); |
2392 | { |
2393 | LttField *child = &g_array_index(type->fields, LttField, 0); |
743e50fd |
2394 | return get_alignment(child); |
f104d082 |
2395 | } |
2396 | break; |
2397 | case LTT_SEQUENCE: |
2398 | g_assert(type->fields->len == 2); |
2399 | { |
83e160f2 |
2400 | off_t localign = 1; |
f104d082 |
2401 | LttField *child = &g_array_index(type->fields, LttField, 0); |
2402 | |
743e50fd |
2403 | localign = max(localign, get_alignment(child)); |
f104d082 |
2404 | |
2405 | child = &g_array_index(type->fields, LttField, 1); |
743e50fd |
2406 | localign = max(localign, get_alignment(child)); |
f104d082 |
2407 | |
2408 | return localign; |
2409 | } |
2410 | break; |
2411 | case LTT_STRUCT: |
2412 | case LTT_UNION: |
2413 | { |
2414 | guint i; |
83e160f2 |
2415 | off_t localign = 1; |
f104d082 |
2416 | |
2417 | for(i=0; i<type->fields->len; i++) { |
2418 | LttField *child = &g_array_index(type->fields, LttField, i); |
743e50fd |
2419 | localign = max(localign, get_alignment(child)); |
f104d082 |
2420 | } |
2421 | return localign; |
2422 | } |
2423 | break; |
2424 | case LTT_NONE: |
2425 | default: |
2426 | g_error("get_alignment : unknown type"); |
83e160f2 |
2427 | return -1; |
f104d082 |
2428 | } |
f104d082 |
2429 | } |
2430 | |
2431 | /***************************************************************************** |
2432 | *Function name |
2433 | * field_compute_static_size : Determine the size of fields known by their |
2434 | * sole definition. Unions, arrays and struct sizes might be known, but |
2435 | * the parser does not give that information. |
2436 | *Input params |
2437 | * tf : tracefile |
2438 | * field : field |
2439 | * |
2440 | ****************************************************************************/ |
2441 | |
743e50fd |
2442 | void field_compute_static_size(LttFacility *fac, LttField *field) |
f104d082 |
2443 | { |
2312de30 |
2444 | LttType *type = &field->field_type; |
f104d082 |
2445 | |
2446 | switch(type->type_class) { |
2447 | case LTT_INT_FIXED: |
2448 | case LTT_UINT_FIXED: |
2449 | case LTT_POINTER: |
2450 | case LTT_CHAR: |
2451 | case LTT_UCHAR: |
2452 | case LTT_SHORT: |
2453 | case LTT_USHORT: |
2454 | case LTT_INT: |
2455 | case LTT_UINT: |
2456 | case LTT_LONG: |
2457 | case LTT_ULONG: |
2458 | case LTT_SIZE_T: |
2459 | case LTT_SSIZE_T: |
2460 | case LTT_OFF_T: |
2461 | case LTT_FLOAT: |
2462 | case LTT_ENUM: |
2463 | case LTT_STRING: |
2464 | /* nothing to do */ |
2465 | break; |
2466 | case LTT_ARRAY: |
2467 | /* note this : array type size is the number of elements in the array, |
2468 | * while array field size of the length of the array in bytes */ |
2469 | g_assert(type->fields->len == 1); |
2470 | { |
2471 | LttField *child = &g_array_index(type->fields, LttField, 0); |
743e50fd |
2472 | field_compute_static_size(fac, child); |
f104d082 |
2473 | |
2474 | if(child->field_size != 0) { |
2475 | field->field_size = type->size * child->field_size; |
2476 | field->dynamic_offsets = g_array_sized_new(FALSE, TRUE, |
2477 | sizeof(off_t), type->size); |
2478 | } else { |
2479 | field->field_size = 0; |
2480 | } |
2481 | } |
2482 | break; |
2483 | case LTT_SEQUENCE: |
2484 | g_assert(type->fields->len == 2); |
2485 | { |
2312de30 |
2486 | off_t local_offset = 0; |
f104d082 |
2487 | LttField *child = &g_array_index(type->fields, LttField, 1); |
743e50fd |
2488 | field_compute_static_size(fac, child); |
f104d082 |
2489 | field->field_size = 0; |
2490 | type->size = 0; |
2491 | if(child->field_size != 0) { |
2492 | field->dynamic_offsets = g_array_sized_new(FALSE, TRUE, |
2493 | sizeof(off_t), SEQUENCE_AVG_ELEMENTS); |
2494 | } |
2495 | } |
2496 | break; |
2497 | case LTT_STRUCT: |
2498 | case LTT_UNION: |
2499 | { |
2500 | guint i; |
2501 | for(i=0;i<type->fields->len;i++) { |
2502 | LttField *child = &g_array_index(type->fields, LttField, i); |
743e50fd |
2503 | field_compute_static_size(fac, child); |
f104d082 |
2504 | if(child->field_size != 0) { |
743e50fd |
2505 | type->size += ltt_align(type->size, get_alignment(child), |
2506 | fac->alignment); |
f104d082 |
2507 | type->size += child->field_size; |
2508 | } else { |
2509 | /* As soon as we find a child with variable size, we have |
2510 | * a variable size */ |
2511 | type->size = 0; |
2512 | break; |
2513 | } |
2514 | } |
2515 | field->field_size = type->size; |
2516 | } |
2517 | break; |
2518 | default: |
2519 | g_error("field_static_size : unknown type"); |
2312de30 |
2520 | } |
f104d082 |
2521 | |
2522 | } |
2523 | |
2524 | |
2525 | |
2526 | /***************************************************************************** |
2527 | *Function name |
2528 | * precompute_fields_offsets : set the precomputable offset of the fields |
2529 | *Input params |
743e50fd |
2530 | * fac : facility |
f104d082 |
2531 | * field : the field |
2532 | * offset : pointer to the current offset, must be incremented |
2533 | * |
2534 | * return : 1 : found a variable length field, stop the processing. |
2535 | * 0 otherwise. |
2536 | ****************************************************************************/ |
2537 | |
2538 | |
dd3a6d39 |
2539 | gint precompute_fields_offsets(LttFacility *fac, LttField *field, off_t *offset, gint is_compact) |
f104d082 |
2540 | { |
2312de30 |
2541 | LttType *type = &field->field_type; |
dd3a6d39 |
2542 | |
2543 | if(unlikely(is_compact)) { |
2544 | g_assert(field->field_size != 0); |
2545 | /* FIXME THIS IS A HUUUUUGE hack : |
2546 | * offset is between the compact_data field in struct LttEvent |
2547 | * and the address of the field root in the memory map. |
2548 | * ark. Both will stay at the same addresses while the event |
2549 | * is readable, so it's ok. |
2550 | */ |
2551 | field->offset_root = 0; |
2552 | field->fixed_root = FIELD_FIXED; |
2553 | return 0; |
2554 | } |
f104d082 |
2555 | |
2556 | switch(type->type_class) { |
2557 | case LTT_INT_FIXED: |
2558 | case LTT_UINT_FIXED: |
2559 | case LTT_POINTER: |
2560 | case LTT_CHAR: |
2561 | case LTT_UCHAR: |
2562 | case LTT_SHORT: |
2563 | case LTT_USHORT: |
2564 | case LTT_INT: |
2565 | case LTT_UINT: |
2566 | case LTT_LONG: |
2567 | case LTT_ULONG: |
2568 | case LTT_SIZE_T: |
2569 | case LTT_SSIZE_T: |
2570 | case LTT_OFF_T: |
2571 | case LTT_FLOAT: |
2572 | case LTT_ENUM: |
743e50fd |
2573 | g_assert(field->field_size != 0); |
f104d082 |
2574 | /* Align offset on type size */ |
743e50fd |
2575 | *offset += ltt_align(*offset, get_alignment(field), |
2576 | fac->alignment); |
f104d082 |
2577 | /* remember offset */ |
2578 | field->offset_root = *offset; |
2579 | field->fixed_root = FIELD_FIXED; |
2580 | /* Increment offset */ |
2581 | *offset += field->field_size; |
2582 | return 0; |
2583 | break; |
2584 | case LTT_STRING: |
2585 | field->offset_root = *offset; |
2586 | field->fixed_root = FIELD_FIXED; |
2587 | return 1; |
2588 | break; |
2589 | case LTT_ARRAY: |
2590 | g_assert(type->fields->len == 1); |
2591 | { |
2592 | LttField *child = &g_array_index(type->fields, LttField, 0); |
2593 | |
743e50fd |
2594 | *offset += ltt_align(*offset, get_alignment(field), |
2595 | fac->alignment); |
f104d082 |
2596 | |
2597 | /* remember offset */ |
2598 | field->offset_root = *offset; |
2599 | field->array_offset = *offset; |
2600 | field->fixed_root = FIELD_FIXED; |
2601 | |
2602 | /* Let the child be variable */ |
2603 | //precompute_fields_offsets(tf, child, offset); |
2604 | |
2605 | if(field->field_size != 0) { |
2606 | /* Increment offset */ |
2607 | /* field_size is the array size in bytes */ |
2608 | *offset += field->field_size; |
2609 | return 0; |
2610 | } else { |
2611 | return 1; |
2612 | } |
2613 | } |
2614 | break; |
2615 | case LTT_SEQUENCE: |
2616 | g_assert(type->fields->len == 2); |
2617 | { |
2618 | LttField *child; |
2619 | guint ret; |
2620 | |
743e50fd |
2621 | *offset += ltt_align(*offset, get_alignment(field), |
2622 | fac->alignment); |
f104d082 |
2623 | |
2624 | /* remember offset */ |
2625 | field->offset_root = *offset; |
2626 | field->fixed_root = FIELD_FIXED; |
2627 | |
2628 | child = &g_array_index(type->fields, LttField, 0); |
dd3a6d39 |
2629 | ret = precompute_fields_offsets(fac, child, offset, is_compact); |
f104d082 |
2630 | g_assert(ret == 0); /* Seq len cannot have variable len */ |
2631 | |
2632 | child = &g_array_index(type->fields, LttField, 1); |
743e50fd |
2633 | *offset += ltt_align(*offset, get_alignment(child), |
2634 | fac->alignment); |
f104d082 |
2635 | field->array_offset = *offset; |
743e50fd |
2636 | /* Let the child be variable. */ |
2637 | //ret = precompute_fields_offsets(fac, child, offset); |
f104d082 |
2638 | |
2639 | /* Cannot precompute fields offsets of sequence members, and has |
2640 | * variable length. */ |
2641 | return 1; |
2642 | } |
2643 | break; |
2644 | case LTT_STRUCT: |
2645 | { |
2646 | LttField *child; |
2647 | guint i; |
2648 | gint ret=0; |
2649 | |
743e50fd |
2650 | *offset += ltt_align(*offset, get_alignment(field), |
2651 | fac->alignment); |
f104d082 |
2652 | /* remember offset */ |
2653 | field->offset_root = *offset; |
2654 | field->fixed_root = FIELD_FIXED; |
2655 | |
2656 | for(i=0; i< type->fields->len; i++) { |
2657 | child = &g_array_index(type->fields, LttField, i); |
dd3a6d39 |
2658 | ret = precompute_fields_offsets(fac, child, offset, is_compact); |
f104d082 |
2659 | |
2660 | if(ret) break; |
2661 | } |
2662 | return ret; |
2663 | } |
2664 | break; |
2665 | case LTT_UNION: |
2666 | { |
2667 | LttField *child; |
2668 | guint i; |
2669 | gint ret=0; |
2670 | |
743e50fd |
2671 | *offset += ltt_align(*offset, get_alignment(field), |
2672 | fac->alignment); |
f104d082 |
2673 | /* remember offset */ |
2674 | field->offset_root = *offset; |
2675 | field->fixed_root = FIELD_FIXED; |
2676 | |
2677 | for(i=0; i< type->fields->len; i++) { |
2678 | *offset = field->offset_root; |
2679 | child = &g_array_index(type->fields, LttField, i); |
dd3a6d39 |
2680 | ret = precompute_fields_offsets(fac, child, offset, is_compact); |
f104d082 |
2681 | |
2682 | if(ret) break; |
2683 | } |
2684 | *offset = field->offset_root + field->field_size; |
2685 | return ret; |
2686 | } |
2687 | |
2688 | break; |
2689 | case LTT_NONE: |
2690 | default: |
2691 | g_error("precompute_fields_offsets : unknown type"); |
2692 | return 1; |
2693 | } |
2694 | |
2695 | } |
2696 | |
2697 | |
2698 | /***************************************************************************** |
2699 | *Function name |
2700 | * precompute_offsets : set the precomputable offset of an event type |
2701 | *Input params |
2702 | * tf : tracefile |
2703 | * event : event type |
2704 | * |
2705 | ****************************************************************************/ |
743e50fd |
2706 | void precompute_offsets(LttFacility *fac, LttEventType *event) |
f104d082 |
2707 | { |
2708 | guint i; |
2709 | off_t offset = 0; |
2710 | gint ret; |
2711 | |
2712 | /* First, compute the size of fixed size fields. Will determine size for |
2713 | * arrays, struct and unions, which is not done by the parser */ |
2714 | for(i=0; i<event->fields->len; i++) { |
2715 | LttField *field = &g_array_index(event->fields, LttField, i); |
743e50fd |
2716 | field_compute_static_size(fac, field); |
f104d082 |
2717 | } |
2718 | |
2719 | /* Precompute all known offsets */ |
2720 | for(i=0; i<event->fields->len; i++) { |
2721 | LttField *field = &g_array_index(event->fields, LttField, i); |
dd3a6d39 |
2722 | if(event->has_compact_data && i == 0) |
2723 | ret = precompute_fields_offsets(fac, field, &offset, 1); |
2724 | else |
2725 | ret = precompute_fields_offsets(fac, field, &offset, 0); |
f104d082 |
2726 | if(ret) break; |
2727 | } |
2728 | } |
2729 | |
2730 | |
e4eced0f |
2731 | |
bbf28e50 |
2732 | |
3aee1200 |
2733 | /***************************************************************************** |
2734 | *Function name |
2735 | * preset_field_type_size : set the fixed sizes of the field type |
2736 | *Input params |
2737 | * tf : tracefile |
2738 | * event_type : event type |
2739 | * offset_root : offset from the root |
2740 | * offset_parent : offset from the parent |
2741 | * fixed_root : Do we know a fixed offset to the root ? |
2742 | * fixed_parent : Do we know a fixed offset to the parent ? |
2743 | * field : field |
2744 | ****************************************************************************/ |
f104d082 |
2745 | |
2746 | |
2747 | |
2748 | // preset the fixed size offsets. Calculate them just like genevent-new : an |
2749 | // increment of a *to value that represents the offset from the start of the |
2750 | // event data. |
2751 | // The preset information is : offsets up to (and including) the first element |
2752 | // of variable size. All subsequent fields must be flagged "VARIABLE OFFSET". |
2753 | #if 0 |
3aee1200 |
2754 | void preset_field_type_size(LttTracefile *tf, LttEventType *event_type, |
2755 | off_t offset_root, off_t offset_parent, |
2756 | enum field_status *fixed_root, enum field_status *fixed_parent, |
2757 | LttField *field) |
2758 | { |
2759 | enum field_status local_fixed_root, local_fixed_parent; |
2760 | guint i; |
2761 | LttType *type; |
dfb73233 |
2762 | |
3aee1200 |
2763 | g_assert(field->fixed_root == FIELD_UNKNOWN); |
2764 | g_assert(field->fixed_parent == FIELD_UNKNOWN); |
2765 | g_assert(field->fixed_size == FIELD_UNKNOWN); |
dfb73233 |
2766 | |
3aee1200 |
2767 | type = field->field_type; |
2768 | |
2769 | field->fixed_root = *fixed_root; |
2770 | if(field->fixed_root == FIELD_FIXED) |
2771 | field->offset_root = offset_root; |
2772 | else |
2773 | field->offset_root = 0; |
2774 | |
2775 | field->fixed_parent = *fixed_parent; |
2776 | if(field->fixed_parent == FIELD_FIXED) |
2777 | field->offset_parent = offset_parent; |
2778 | else |
2779 | field->offset_parent = 0; |
2780 | |
2781 | size_t current_root_offset; |
2782 | size_t current_offset; |
2783 | enum field_status current_child_status, final_child_status; |
2784 | size_t max_size; |
2785 | |
2786 | switch(type->type_class) { |
83e160f2 |
2787 | case LTT_INT_FIXED: |
2788 | case LTT_UINT_FIXED: |
2789 | case LTT_CHAR: |
2790 | case LTT_UCHAR: |
2791 | case LTT_SHORT: |
2792 | case LTT_USHORT: |
3aee1200 |
2793 | case LTT_INT: |
2794 | case LTT_UINT: |
2795 | case LTT_FLOAT: |
2796 | case LTT_ENUM: |
2797 | field->field_size = ltt_type_size(tf->trace, type); |
2798 | field->fixed_size = FIELD_FIXED; |
2799 | break; |
2800 | case LTT_POINTER: |
2801 | field->field_size = (off_t)event_type->facility->pointer_size; |
2802 | field->fixed_size = FIELD_FIXED; |
2803 | break; |
2804 | case LTT_LONG: |
2805 | case LTT_ULONG: |
cb03932a |
2806 | field->field_size = (off_t)event_type->facility->long_size; |
3aee1200 |
2807 | field->fixed_size = FIELD_FIXED; |
2808 | break; |
2809 | case LTT_SIZE_T: |
2810 | case LTT_SSIZE_T: |
2811 | case LTT_OFF_T: |
2812 | field->field_size = (off_t)event_type->facility->size_t_size; |
2813 | field->fixed_size = FIELD_FIXED; |
2814 | break; |
2815 | case LTT_SEQUENCE: |
2816 | local_fixed_root = FIELD_VARIABLE; |
2817 | local_fixed_parent = FIELD_VARIABLE; |
2818 | preset_field_type_size(tf, event_type, |
2819 | 0, 0, |
2820 | &local_fixed_root, &local_fixed_parent, |
2821 | field->child[0]); |
2822 | field->fixed_size = FIELD_VARIABLE; |
2823 | field->field_size = 0; |
27304273 |
2824 | *fixed_root = FIELD_VARIABLE; |
2825 | *fixed_parent = FIELD_VARIABLE; |
3aee1200 |
2826 | break; |
2827 | case LTT_STRING: |
2828 | field->fixed_size = FIELD_VARIABLE; |
2829 | field->field_size = 0; |
27304273 |
2830 | *fixed_root = FIELD_VARIABLE; |
2831 | *fixed_parent = FIELD_VARIABLE; |
3aee1200 |
2832 | break; |
2833 | case LTT_ARRAY: |
2834 | local_fixed_root = FIELD_VARIABLE; |
2835 | local_fixed_parent = FIELD_VARIABLE; |
2836 | preset_field_type_size(tf, event_type, |
2837 | 0, 0, |
2838 | &local_fixed_root, &local_fixed_parent, |
2839 | field->child[0]); |
2840 | field->fixed_size = field->child[0]->fixed_size; |
27304273 |
2841 | if(field->fixed_size == FIELD_FIXED) { |
3aee1200 |
2842 | field->field_size = type->element_number * field->child[0]->field_size; |
27304273 |
2843 | } else { |
3aee1200 |
2844 | field->field_size = 0; |
27304273 |
2845 | *fixed_root = FIELD_VARIABLE; |
2846 | *fixed_parent = FIELD_VARIABLE; |
2847 | } |
3aee1200 |
2848 | break; |
2849 | case LTT_STRUCT: |
2850 | current_root_offset = field->offset_root; |
2851 | current_offset = 0; |
2852 | current_child_status = FIELD_FIXED; |
2853 | for(i=0;i<type->element_number;i++) { |
2854 | preset_field_type_size(tf, event_type, |
2855 | current_root_offset, current_offset, |
2856 | fixed_root, ¤t_child_status, |
2857 | field->child[i]); |
2858 | if(current_child_status == FIELD_FIXED) { |
2859 | current_root_offset += field->child[i]->field_size; |
2860 | current_offset += field->child[i]->field_size; |
2861 | } else { |
2862 | current_root_offset = 0; |
2863 | current_offset = 0; |
2864 | } |
2865 | } |
2866 | if(current_child_status != FIELD_FIXED) { |
2867 | *fixed_parent = current_child_status; |
2868 | field->field_size = 0; |
2869 | field->fixed_size = current_child_status; |
2870 | } else { |
2871 | field->field_size = current_offset; |
2872 | field->fixed_size = FIELD_FIXED; |
2873 | } |
2874 | break; |
2875 | case LTT_UNION: |
2876 | current_root_offset = field->offset_root; |
2877 | current_offset = 0; |
2878 | max_size = 0; |
2879 | final_child_status = FIELD_FIXED; |
2880 | for(i=0;i<type->element_number;i++) { |
2881 | enum field_status current_root_child_status = FIELD_FIXED; |
2882 | enum field_status current_child_status = FIELD_FIXED; |
2883 | preset_field_type_size(tf, event_type, |
2884 | current_root_offset, current_offset, |
2885 | ¤t_root_child_status, ¤t_child_status, |
2886 | field->child[i]); |
2887 | if(current_child_status != FIELD_FIXED) |
2888 | final_child_status = current_child_status; |
2889 | else |
2890 | max_size = max(max_size, field->child[i]->field_size); |
2891 | } |
2892 | if(final_child_status != FIELD_FIXED) { |
e2542235 |
2893 | g_error("LTTV does not support variable size fields in unions."); |
2894 | /* This will stop the application. */ |
3aee1200 |
2895 | *fixed_root = final_child_status; |
2896 | *fixed_parent = final_child_status; |
2897 | field->field_size = 0; |
2898 | field->fixed_size = current_child_status; |
2899 | } else { |
2900 | field->field_size = max_size; |
2901 | field->fixed_size = FIELD_FIXED; |
2902 | } |
2903 | break; |
83e160f2 |
2904 | case LTT_NONE: |
2905 | g_error("unexpected type NONE"); |
2906 | break; |
dfb73233 |
2907 | } |
2908 | |
6cd62ccf |
2909 | } |
f104d082 |
2910 | #endif //0 |
3aee1200 |
2911 | |
77175651 |
2912 | /***************************************************************************** |
2913 | *Function name |
2914 | * check_fields_compatibility : Check for compatibility between two fields : |
2915 | * do they use the same inner structure ? |
2916 | *Input params |
2917 | * event_type1 : event type |
2918 | * event_type2 : event type |
2919 | * field1 : field |
2920 | * field2 : field |
2921 | *Returns : 0 if identical |
2922 | * 1 if not. |
2923 | ****************************************************************************/ |
f104d082 |
2924 | // this function checks for equality of field types. Therefore, it does not use |
2925 | // per se offsets. For instance, an aligned version of a structure is |
2926 | // compatible with an unaligned version of the same structure. |
2927 | gint check_fields_compatibility(LttEventType *event_type1, |
2928 | LttEventType *event_type2, |
2929 | LttField *field1, LttField *field2) |
2930 | { |
2931 | guint different = 0; |
2312de30 |
2932 | LttType *type1; |
2933 | LttType *type2; |
f104d082 |
2934 | |
2935 | if(field1 == NULL) { |
2936 | if(field2 == NULL) goto end; |
2937 | else { |
2938 | different = 1; |
2939 | goto end; |
2940 | } |
2941 | } else if(field2 == NULL) { |
2942 | different = 1; |
2943 | goto end; |
2944 | } |
2945 | |
2312de30 |
2946 | type1 = &field1->field_type; |
2947 | type2 = &field2->field_type; |
f104d082 |
2948 | |
2949 | if(type1->type_class != type2->type_class) { |
2950 | different = 1; |
2951 | goto end; |
2952 | } |
f0b795e0 |
2953 | if(type1->network != type2->network) { |
2954 | different = 1; |
2955 | goto end; |
2956 | } |
f104d082 |
2957 | |
2958 | switch(type1->type_class) { |
2959 | case LTT_INT_FIXED: |
2960 | case LTT_UINT_FIXED: |
2961 | case LTT_POINTER: |
2962 | case LTT_CHAR: |
2963 | case LTT_UCHAR: |
2964 | case LTT_SHORT: |
2965 | case LTT_USHORT: |
2966 | case LTT_INT: |
2967 | case LTT_UINT: |
2968 | case LTT_LONG: |
2969 | case LTT_ULONG: |
2970 | case LTT_SIZE_T: |
2971 | case LTT_SSIZE_T: |
2972 | case LTT_OFF_T: |
2973 | case LTT_FLOAT: |
2974 | case LTT_ENUM: |
2975 | if(field1->field_size != field2->field_size) |
2976 | different = 1; |
2977 | break; |
2978 | case LTT_STRING: |
2979 | break; |
2980 | case LTT_ARRAY: |
2981 | { |
2982 | LttField *child1 = &g_array_index(type1->fields, LttField, 0); |
2983 | LttField *child2 = &g_array_index(type2->fields, LttField, 0); |
2984 | |
2985 | if(type1->size != type2->size) |
2986 | different = 1; |
2987 | if(check_fields_compatibility(event_type1, event_type2, child1, child2)) |
2988 | different = 1; |
2989 | } |
2990 | break; |
2991 | case LTT_SEQUENCE: |
2992 | { |
2993 | LttField *child1 = &g_array_index(type1->fields, LttField, 1); |
2994 | LttField *child2 = &g_array_index(type2->fields, LttField, 1); |
2995 | |
2996 | if(check_fields_compatibility(event_type1, event_type2, child1, child2)) |
2997 | different = 1; |
2998 | } |
2999 | break; |
3000 | case LTT_STRUCT: |
3001 | case LTT_UNION: |
3002 | { |
3003 | LttField *child; |
3004 | guint i; |
3005 | |
3006 | if(type1->fields->len != type2->fields->len) { |
3007 | different = 1; |
3008 | goto end; |
3009 | } |
3010 | |
3011 | for(i=0; i< type1->fields->len; i++) { |
2312de30 |
3012 | LttField *child1; |
3013 | LttField *child2; |
f104d082 |
3014 | child1 = &g_array_index(type1->fields, LttField, i); |
3015 | child2 = &g_array_index(type2->fields, LttField, i); |
3016 | different = check_fields_compatibility(event_type1, |
3017 | event_type2, child1, child2); |
3018 | |
3019 | if(different) break; |
3020 | } |
3021 | } |
3022 | break; |
3023 | case LTT_NONE: |
3024 | default: |
dd3a6d39 |
3025 | g_error("check_fields_compatibility : unknown type"); |
f104d082 |
3026 | } |
3027 | |
3028 | end: |
3029 | return different; |
3030 | } |
3031 | |
3032 | |
3033 | #if 0 |
77175651 |
3034 | gint check_fields_compatibility(LttEventType *event_type1, |
3035 | LttEventType *event_type2, |
3036 | LttField *field1, LttField *field2) |
3037 | { |
3038 | guint different = 0; |
77175651 |
3039 | guint i; |
3040 | LttType *type1; |
3041 | LttType *type2; |
3042 | |
3043 | if(field1 == NULL) { |
3044 | if(field2 == NULL) goto end; |
3045 | else { |
3046 | different = 1; |
3047 | goto end; |
3048 | } |
3049 | } else if(field2 == NULL) { |
3050 | different = 1; |
3051 | goto end; |
3052 | } |
3053 | |
3054 | g_assert(field1->fixed_root != FIELD_UNKNOWN); |
3055 | g_assert(field2->fixed_root != FIELD_UNKNOWN); |
3056 | g_assert(field1->fixed_parent != FIELD_UNKNOWN); |
3057 | g_assert(field2->fixed_parent != FIELD_UNKNOWN); |
3058 | g_assert(field1->fixed_size != FIELD_UNKNOWN); |
3059 | g_assert(field2->fixed_size != FIELD_UNKNOWN); |
3060 | |
3061 | type1 = field1->field_type; |
3062 | type2 = field2->field_type; |
3063 | |
77175651 |
3064 | if(type1->type_class != type2->type_class) { |
3065 | different = 1; |
3066 | goto end; |
3067 | } |
3068 | if(type1->element_name != type2->element_name) { |
3069 | different = 1; |
3070 | goto end; |
3071 | } |
3072 | |
3073 | switch(type1->type_class) { |
83e160f2 |
3074 | case LTT_INT_FIXED: |
3075 | case LTT_UINT_FIXED: |
3076 | case LTT_POINTER: |
3077 | case LTT_CHAR: |
3078 | case LTT_UCHAR: |
3079 | case LTT_SHORT: |
3080 | case LTT_USHORT: |
77175651 |
3081 | case LTT_INT: |
3082 | case LTT_UINT: |
3083 | case LTT_FLOAT: |
3084 | case LTT_POINTER: |
3085 | case LTT_LONG: |
3086 | case LTT_ULONG: |
3087 | case LTT_SIZE_T: |
3088 | case LTT_SSIZE_T: |
3089 | case LTT_OFF_T: |
3090 | if(field1->field_size != field2->field_size) { |
3091 | different = 1; |
3092 | goto end; |
3093 | } |
3094 | break; |
3095 | case LTT_ENUM: |
3096 | if(type1->element_number != type2->element_number) { |
3097 | different = 1; |
3098 | goto end; |
3099 | } |
3100 | for(i=0;i<type1->element_number;i++) { |
3101 | if(type1->enum_strings[i] != type2->enum_strings[i]) { |
3102 | different = 1; |
3103 | goto end; |
3104 | } |
3105 | } |
3106 | break; |
3107 | case LTT_SEQUENCE: |
3108 | /* Two elements : size and child */ |
3109 | g_assert(type1->element_number != type2->element_number); |
3110 | for(i=0;i<type1->element_number;i++) { |
3111 | if(check_fields_compatibility(event_type1, event_type2, |
3112 | field1->child[0], field2->child[0])) { |
3113 | different = 1; |
3114 | goto end; |
3115 | } |
3116 | } |
3117 | break; |
3118 | case LTT_STRING: |
3119 | break; |
3120 | case LTT_ARRAY: |
3121 | if(field1->field_size != field2->field_size) { |
3122 | different = 1; |
3123 | goto end; |
3124 | } |
3125 | /* Two elements : size and child */ |
3126 | g_assert(type1->element_number != type2->element_number); |
3127 | for(i=0;i<type1->element_number;i++) { |
3128 | if(check_fields_compatibility(event_type1, event_type2, |
3129 | field1->child[0], field2->child[0])) { |
3130 | different = 1; |
3131 | goto end; |
3132 | } |
3133 | } |
3134 | break; |
3135 | case LTT_STRUCT: |
3136 | case LTT_UNION: |
3137 | if(type1->element_number != type2->element_number) { |
3138 | different = 1; |
3139 | break; |
3140 | } |
3141 | for(i=0;i<type1->element_number;i++) { |
3142 | if(check_fields_compatibility(event_type1, event_type2, |
3143 | field1->child[0], field2->child[0])) { |
3144 | different = 1; |
3145 | goto end; |
3146 | } |
3147 | } |
3148 | break; |
3149 | } |
3150 | end: |
3151 | return different; |
3152 | } |
3aee1200 |
3153 | #endif //0 |
6cd62ccf |
3154 | |
f104d082 |
3155 | |
6cd62ccf |
3156 | /***************************************************************************** |
3157 | *Function name |
eed2ef37 |
3158 | * ltt_get_int : get an integer number |
6cd62ccf |
3159 | *Input params |
3aee1200 |
3160 | * reverse_byte_order: must we reverse the byte order ? |
6cd62ccf |
3161 | * size : the size of the integer |
3aee1200 |
3162 | * ptr : the data pointer |
6cd62ccf |
3163 | *Return value |
cf74a6f1 |
3164 | * gint64 : a 64 bits integer |
6cd62ccf |
3165 | ****************************************************************************/ |
3166 | |
eed2ef37 |
3167 | gint64 ltt_get_int(gboolean reverse_byte_order, gint size, void *data) |
6cd62ccf |
3168 | { |
3aee1200 |
3169 | gint64 val; |
cf74a6f1 |
3170 | |
3171 | switch(size) { |
3aee1200 |
3172 | case 1: val = *((gint8*)data); break; |
3173 | case 2: val = ltt_get_int16(reverse_byte_order, data); break; |
3174 | case 4: val = ltt_get_int32(reverse_byte_order, data); break; |
3175 | case 8: val = ltt_get_int64(reverse_byte_order, data); break; |
3176 | default: val = ltt_get_int64(reverse_byte_order, data); |
3177 | g_critical("get_int : integer size %d unknown", size); |
cf74a6f1 |
3178 | break; |
3179 | } |
3180 | |
3aee1200 |
3181 | return val; |
6cd62ccf |
3182 | } |
3aee1200 |
3183 | |
6cd62ccf |
3184 | /***************************************************************************** |
3185 | *Function name |
eed2ef37 |
3186 | * ltt_get_uint : get an unsigned integer number |
6cd62ccf |
3187 | *Input params |
3aee1200 |
3188 | * reverse_byte_order: must we reverse the byte order ? |
3189 | * size : the size of the integer |
3190 | * ptr : the data pointer |
3191 | *Return value |
3192 | * guint64 : a 64 bits unsigned integer |
6cd62ccf |
3193 | ****************************************************************************/ |
3194 | |
eed2ef37 |
3195 | guint64 ltt_get_uint(gboolean reverse_byte_order, gint size, void *data) |
6cd62ccf |
3196 | { |
3aee1200 |
3197 | guint64 val; |
3198 | |
3199 | switch(size) { |
3200 | case 1: val = *((gint8*)data); break; |
3201 | case 2: val = ltt_get_uint16(reverse_byte_order, data); break; |
3202 | case 4: val = ltt_get_uint32(reverse_byte_order, data); break; |
3203 | case 8: val = ltt_get_uint64(reverse_byte_order, data); break; |
3204 | default: val = ltt_get_uint64(reverse_byte_order, data); |
3205 | g_critical("get_uint : unsigned integer size %d unknown", |
3206 | size); |
3207 | break; |
3208 | } |
3209 | |
3210 | return val; |
6cd62ccf |
3211 | } |
3aee1200 |
3212 | |
3213 | |
a5dcde2f |
3214 | /* get the node name of the system */ |
3215 | |
3216 | char * ltt_trace_system_description_node_name (LttSystemDescription * s) |
3217 | { |
3218 | return s->node_name; |
3219 | } |
3220 | |
3221 | |
3222 | /* get the domain name of the system */ |
3223 | |
3224 | char * ltt_trace_system_description_domain_name (LttSystemDescription * s) |
3225 | { |
3226 | return s->domain_name; |
3227 | } |
3228 | |
3229 | |
3230 | /* get the description of the system */ |
3231 | |
3232 | char * ltt_trace_system_description_description (LttSystemDescription * s) |
3233 | { |
3234 | return s->description; |
3235 | } |
3236 | |
3237 | |
bf33dd50 |
3238 | /* get the NTP corrected start time of the trace */ |
7bd563ec |
3239 | LttTime ltt_trace_start_time(LttTrace *t) |
a5dcde2f |
3240 | { |
7bd563ec |
3241 | return t->start_time; |
a5dcde2f |
3242 | } |
3243 | |
bf33dd50 |
3244 | /* get the monotonic start time of the trace */ |
3245 | LttTime ltt_trace_start_time_monotonic(LttTrace *t) |
3246 | { |
3247 | return t->start_time_from_tsc; |
3248 | } |
3249 | |
18206708 |
3250 | LttTracefile *ltt_tracefile_new() |
3251 | { |
3252 | return g_new(LttTracefile, 1); |
3253 | } |
3254 | |
3255 | void ltt_tracefile_destroy(LttTracefile *tf) |
3256 | { |
3257 | g_free(tf); |
3258 | } |
3259 | |
3260 | void ltt_tracefile_copy(LttTracefile *dest, const LttTracefile *src) |
3261 | { |
3262 | *dest = *src; |
3263 | } |
3264 | |
3aee1200 |
3265 | /* Before library loading... */ |
3266 | |
3267 | static void __attribute__((constructor)) init(void) |
3268 | { |
3269 | LTT_FACILITY_NAME_HEARTBEAT = g_quark_from_string("heartbeat"); |
3270 | LTT_EVENT_NAME_HEARTBEAT = g_quark_from_string("heartbeat"); |
d1bb700c |
3271 | LTT_EVENT_NAME_HEARTBEAT_FULL = g_quark_from_string("heartbeat_full"); |
3aee1200 |
3272 | |
3865ea09 |
3273 | LTT_TRACEFILE_NAME_FACILITIES = g_quark_from_string("/control/facilities"); |
3aee1200 |
3274 | } |
3275 | |