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