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 | * |
449cb9d7 |
6 | * This program is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License Version 2 as |
8 | * published by the Free Software Foundation; |
9 | * |
10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * GNU General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU General Public License |
16 | * along with this program; if not, write to the Free Software |
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
18 | * MA 02111-1307, USA. |
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> |
6cd62ccf |
37 | |
ef35d837 |
38 | // For realpath |
39 | #include <limits.h> |
40 | #include <stdlib.h> |
41 | |
42 | |
6cd62ccf |
43 | #include "parser.h" |
a5dcde2f |
44 | #include <ltt/ltt.h> |
45 | #include "ltt-private.h" |
963b5f2d |
46 | #include <ltt/trace.h> |
a5dcde2f |
47 | #include <ltt/facility.h> |
c02ea99f |
48 | #include <ltt/event.h> |
8d1e6362 |
49 | #include <ltt/type.h> |
1a2ceb63 |
50 | #include <ltt/ltt-types.h> |
6cd62ccf |
51 | |
3aee1200 |
52 | |
53 | /* Facility names used in this file */ |
54 | |
55 | GQuark LTT_FACILITY_NAME_HEARTBEAT, |
56 | LTT_EVENT_NAME_HEARTBEAT; |
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 | |
74 | /* obtain the time of an event */ |
75 | |
76 | static inline LttTime getEventTime(LttTracefile * tf); |
77 | |
78 | |
6cd62ccf |
79 | /* set the offset of the fields belonging to the event, |
80 | need the information of the archecture */ |
3aee1200 |
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. */ |
86 | static inline void preset_field_type_size(LttTracefile *tf, |
87 | LttEventType *event_type, |
88 | off_t offset_root, off_t offset_parent, |
89 | enum field_status *fixed_root, enum field_status *fixed_parent, |
90 | LttField *field); |
6cd62ccf |
91 | |
3aee1200 |
92 | /* map a fixed size or a block information from the file (fd) */ |
93 | static gint map_block(LttTracefile * tf, guint block_num); |
94 | |
95 | /* calculate nsec per cycles for current block */ |
96 | static double calc_nsecs_per_cycle(LttTracefile * t); |
6cd62ccf |
97 | |
3aee1200 |
98 | /* go to the next event */ |
99 | static int ltt_seek_next_event(LttTracefile *tf); |
6cd62ccf |
100 | |
eed2ef37 |
101 | void ltt_update_event_size(LttTracefile *tf); |
102 | |
3aee1200 |
103 | #if 0 |
43da6a59 |
104 | /* Functions to parse system.xml file (using glib xml parser) */ |
51b5991e |
105 | static void parser_start_element (GMarkupParseContext __UNUSED__ *context, |
43da6a59 |
106 | const gchar *element_name, |
107 | const gchar **attribute_names, |
108 | const gchar **attribute_values, |
109 | gpointer user_data, |
110 | GError **error) |
111 | { |
112 | int i=0; |
113 | LttSystemDescription* des = (LttSystemDescription* )user_data; |
114 | if(strcmp("system", element_name)){ |
2a74fbf4 |
115 | *error = g_error_new(G_MARKUP_ERROR, |
116 | G_LOG_LEVEL_WARNING, |
117 | "This is not system.xml file"); |
118 | return; |
43da6a59 |
119 | } |
120 | |
121 | while(attribute_names[i]){ |
122 | if(strcmp("node_name", attribute_names[i])==0){ |
123 | des->node_name = g_strdup(attribute_values[i]); |
124 | }else if(strcmp("domainname", attribute_names[i])==0){ |
125 | des->domain_name = g_strdup(attribute_values[i]); |
126 | }else if(strcmp("cpu", attribute_names[i])==0){ |
127 | des->nb_cpu = atoi(attribute_values[i]); |
128 | }else if(strcmp("arch_size", attribute_names[i])==0){ |
129 | if(strcmp(attribute_values[i],"LP32") == 0) des->size = LTT_LP32; |
130 | else if(strcmp(attribute_values[i],"ILP32") == 0) des->size = LTT_ILP32; |
131 | else if(strcmp(attribute_values[i],"LP64") == 0) des->size = LTT_LP64; |
132 | else if(strcmp(attribute_values[i],"ILP64") == 0) des->size = LTT_ILP64; |
133 | else if(strcmp(attribute_values[i],"UNKNOWN") == 0) des->size = LTT_UNKNOWN; |
134 | }else if(strcmp("endian", attribute_names[i])==0){ |
135 | if(strcmp(attribute_values[i],"LITTLE_ENDIAN") == 0) |
136 | des->endian = LTT_LITTLE_ENDIAN; |
137 | else if(strcmp(attribute_values[i],"BIG_ENDIAN") == 0) |
138 | des->endian = LTT_BIG_ENDIAN; |
139 | }else if(strcmp("kernel_name", attribute_names[i])==0){ |
140 | des->kernel_name = g_strdup(attribute_values[i]); |
141 | }else if(strcmp("kernel_release", attribute_names[i])==0){ |
142 | des->kernel_release = g_strdup(attribute_values[i]); |
143 | }else if(strcmp("kernel_version", attribute_names[i])==0){ |
144 | des->kernel_version = g_strdup(attribute_values[i]); |
145 | }else if(strcmp("machine", attribute_names[i])==0){ |
146 | des->machine = g_strdup(attribute_values[i]); |
147 | }else if(strcmp("processor", attribute_names[i])==0){ |
148 | des->processor = g_strdup(attribute_values[i]); |
149 | }else if(strcmp("hardware_platform", attribute_names[i])==0){ |
150 | des->hardware_platform = g_strdup(attribute_values[i]); |
151 | }else if(strcmp("operating_system", attribute_names[i])==0){ |
152 | des->operating_system = g_strdup(attribute_values[i]); |
153 | }else if(strcmp("ltt_major_version", attribute_names[i])==0){ |
154 | des->ltt_major_version = atoi(attribute_values[i]); |
155 | }else if(strcmp("ltt_minor_version", attribute_names[i])==0){ |
156 | des->ltt_minor_version = atoi(attribute_values[i]); |
157 | }else if(strcmp("ltt_block_size", attribute_names[i])==0){ |
158 | des->ltt_block_size = atoi(attribute_values[i]); |
159 | }else{ |
2a74fbf4 |
160 | *error = g_error_new(G_MARKUP_ERROR, |
161 | G_LOG_LEVEL_WARNING, |
162 | "Not a valid attribute"); |
163 | return; |
43da6a59 |
164 | } |
165 | i++; |
166 | } |
167 | } |
168 | |
51b5991e |
169 | static void parser_characters (GMarkupParseContext __UNUSED__ *context, |
43da6a59 |
170 | const gchar *text, |
51b5991e |
171 | gsize __UNUSED__ text_len, |
43da6a59 |
172 | gpointer user_data, |
51b5991e |
173 | GError __UNUSED__ **error) |
43da6a59 |
174 | { |
175 | LttSystemDescription* des = (LttSystemDescription* )user_data; |
176 | des->description = g_strdup(text); |
177 | } |
3aee1200 |
178 | #endif //0 |
77175651 |
179 | LttFacility *ltt_trace_get_facility_by_num(LttTrace *t, |
3aee1200 |
180 | guint num) |
181 | { |
182 | g_assert(num < t->facilities_by_num->len); |
183 | |
184 | return &g_array_index(t->facilities_by_num, LttFacility, num); |
185 | |
186 | } |
43da6a59 |
187 | |
188 | |
6cd62ccf |
189 | /***************************************************************************** |
190 | *Function name |
963b5f2d |
191 | * ltt_tracefile_open : open a trace file, construct a LttTracefile |
6cd62ccf |
192 | *Input params |
963b5f2d |
193 | * t : the trace containing the tracefile |
194 | * fileName : path name of the trace file |
3aee1200 |
195 | * tf : the tracefile structure |
6cd62ccf |
196 | *Return value |
3aee1200 |
197 | * : 0 for success, -1 otherwise. |
6cd62ccf |
198 | ****************************************************************************/ |
199 | |
3aee1200 |
200 | gint ltt_tracefile_open(LttTrace *t, gchar * fileName, LttTracefile *tf) |
6cd62ccf |
201 | { |
963b5f2d |
202 | struct stat lTDFStat; /* Trace data file status */ |
3aee1200 |
203 | struct ltt_block_start_header *header; |
6cd62ccf |
204 | |
205 | //open the file |
3aee1200 |
206 | tf->name = g_quark_from_string(fileName); |
963b5f2d |
207 | tf->trace = t; |
45e14832 |
208 | tf->fd = g_open(fileName, O_RDONLY, 0); |
6cd62ccf |
209 | if(tf->fd < 0){ |
2a74fbf4 |
210 | g_warning("Unable to open input data file %s\n", fileName); |
3aee1200 |
211 | goto end; |
6cd62ccf |
212 | } |
213 | |
214 | // Get the file's status |
215 | if(fstat(tf->fd, &lTDFStat) < 0){ |
2a74fbf4 |
216 | g_warning("Unable to get the status of the input data file %s\n", fileName); |
3aee1200 |
217 | goto close_file; |
6cd62ccf |
218 | } |
219 | |
220 | // Is the file large enough to contain a trace |
3aee1200 |
221 | if(lTDFStat.st_size < (off_t)(sizeof(struct ltt_block_start_header))){ |
8710c6c7 |
222 | g_print("The input data file %s does not contain a trace\n", fileName); |
3aee1200 |
223 | goto close_file; |
224 | } |
225 | |
226 | /* Temporarily map the buffer start header to get trace information */ |
227 | /* Multiple of pages aligned head */ |
228 | tf->buffer.head = mmap(0, sizeof(struct ltt_block_start_header), PROT_READ, |
229 | MAP_PRIVATE, tf->fd, 0); |
230 | if(tf->buffer.head == NULL) { |
231 | perror("Error in allocating memory for buffer of tracefile"); |
232 | goto close_file; |
6cd62ccf |
233 | } |
3aee1200 |
234 | g_assert(((guint)tf->buffer.head & (8-1)) == 0); // make sure it's aligned. |
235 | |
236 | header = (struct ltt_block_start_header*)tf->buffer.head; |
6cd62ccf |
237 | |
3aee1200 |
238 | if(header->trace.magic_number == LTT_MAGIC_NUMBER) |
239 | tf->reverse_bo = 0; |
240 | else if(header->trace.magic_number == LTT_REV_MAGIC_NUMBER) |
241 | tf->reverse_bo = 1; |
242 | else /* invalid magic number, bad tracefile ! */ |
243 | goto unmap_file; |
244 | |
6cd62ccf |
245 | //store the size of the file |
246 | tf->file_size = lTDFStat.st_size; |
3aee1200 |
247 | tf->block_size = header->buf_size; |
248 | tf->num_blocks = tf->file_size / tf->block_size; |
6cd62ccf |
249 | |
eed2ef37 |
250 | munmap(tf->buffer.head, sizeof(struct ltt_block_start_header)); |
3aee1200 |
251 | tf->buffer.head = NULL; |
6cd62ccf |
252 | |
963b5f2d |
253 | //read the first block |
3aee1200 |
254 | if(map_block(tf,0)) { |
255 | perror("Cannot map block for tracefile"); |
256 | goto close_file; |
257 | } |
258 | |
259 | return 0; |
6cd62ccf |
260 | |
3aee1200 |
261 | /* Error */ |
262 | unmap_file: |
263 | munmap(tf->buffer.head, sizeof(struct ltt_block_start_header)); |
264 | close_file: |
265 | g_close(tf->fd); |
266 | end: |
267 | return -1; |
6cd62ccf |
268 | } |
269 | |
3aee1200 |
270 | #if 0 |
6cd62ccf |
271 | /***************************************************************************** |
963b5f2d |
272 | *Open control and per cpu tracefiles |
6cd62ccf |
273 | ****************************************************************************/ |
274 | |
45e14832 |
275 | void ltt_tracefile_open_cpu(LttTrace *t, gchar * tracefile_name) |
6cd62ccf |
276 | { |
963b5f2d |
277 | LttTracefile * tf; |
278 | tf = ltt_tracefile_open(t,tracefile_name); |
4a6c8e36 |
279 | if(!tf) return; |
963b5f2d |
280 | t->per_cpu_tracefile_number++; |
281 | g_ptr_array_add(t->per_cpu_tracefiles, tf); |
6cd62ccf |
282 | } |
283 | |
45e14832 |
284 | gint ltt_tracefile_open_control(LttTrace *t, gchar * control_name) |
6cd62ccf |
285 | { |
963b5f2d |
286 | LttTracefile * tf; |
c02ea99f |
287 | LttEvent ev; |
963b5f2d |
288 | LttFacility * f; |
963b5f2d |
289 | void * pos; |
290 | FacilityLoad fLoad; |
8d1e6362 |
291 | unsigned int i; |
963b5f2d |
292 | |
293 | tf = ltt_tracefile_open(t,control_name); |
2a74fbf4 |
294 | if(!tf) { |
295 | g_warning("ltt_tracefile_open_control : bad file descriptor"); |
296 | return -1; |
297 | } |
963b5f2d |
298 | t->control_tracefile_number++; |
299 | g_ptr_array_add(t->control_tracefiles,tf); |
300 | |
301 | //parse facilities tracefile to get base_id |
542ceddd |
302 | if(strcmp(&control_name[strlen(control_name)-10],"facilities") ==0){ |
963b5f2d |
303 | while(1){ |
c02ea99f |
304 | if(!ltt_tracefile_read(tf,&ev)) return 0; // end of file |
40331ba8 |
305 | |
c02ea99f |
306 | if(ev.event_id == TRACE_FACILITY_LOAD){ |
307 | pos = ev.data; |
45e14832 |
308 | fLoad.name = (gchar*)pos; |
47a166fc |
309 | fLoad.checksum = *(LttChecksum*)(pos + strlen(fLoad.name)); |
cbd41522 |
310 | fLoad.base_code = *(guint32 *)(pos + strlen(fLoad.name) + sizeof(LttChecksum)); |
963b5f2d |
311 | |
312 | for(i=0;i<t->facility_number;i++){ |
313 | f = (LttFacility*)g_ptr_array_index(t->facilities,i); |
314 | if(strcmp(f->name,fLoad.name)==0 && fLoad.checksum==f->checksum){ |
315 | f->base_id = fLoad.base_code; |
316 | break; |
317 | } |
318 | } |
2a74fbf4 |
319 | if(i==t->facility_number) { |
8d1e6362 |
320 | g_warning("Facility: %s, checksum: %u is not found", |
321 | fLoad.name,(unsigned int)fLoad.checksum); |
2a74fbf4 |
322 | return -1; |
323 | } |
c02ea99f |
324 | }else if(ev.event_id == TRACE_BLOCK_START){ |
40331ba8 |
325 | continue; |
c02ea99f |
326 | }else if(ev.event_id == TRACE_BLOCK_END){ |
40331ba8 |
327 | break; |
2a74fbf4 |
328 | }else { |
8d1e6362 |
329 | g_warning("Not valid facilities trace file"); |
2a74fbf4 |
330 | return -1; |
331 | } |
963b5f2d |
332 | } |
333 | } |
2a74fbf4 |
334 | return 0; |
6cd62ccf |
335 | } |
3aee1200 |
336 | #endif //0 |
6cd62ccf |
337 | |
338 | /***************************************************************************** |
339 | *Function name |
963b5f2d |
340 | * ltt_tracefile_close: close a trace file, |
6cd62ccf |
341 | *Input params |
963b5f2d |
342 | * t : tracefile which will be closed |
6cd62ccf |
343 | ****************************************************************************/ |
344 | |
963b5f2d |
345 | void ltt_tracefile_close(LttTracefile *t) |
6cd62ccf |
346 | { |
3aee1200 |
347 | if(t->buffer.head != NULL) |
348 | munmap(t->buffer.head, t->buf_size); |
349 | g_close(t->fd); |
963b5f2d |
350 | } |
6cd62ccf |
351 | |
6cd62ccf |
352 | |
963b5f2d |
353 | /***************************************************************************** |
354 | *Get system information |
355 | ****************************************************************************/ |
3aee1200 |
356 | #if 0 |
45e14832 |
357 | gint getSystemInfo(LttSystemDescription* des, gchar * pathname) |
963b5f2d |
358 | { |
45e14832 |
359 | int fd; |
360 | GIOChannel *iochan; |
361 | gchar *buf = NULL; |
362 | gsize length; |
43da6a59 |
363 | |
364 | GMarkupParseContext * context; |
2a74fbf4 |
365 | GError * error = NULL; |
43da6a59 |
366 | GMarkupParser markup_parser = |
367 | { |
368 | parser_start_element, |
8d1e6362 |
369 | NULL, |
43da6a59 |
370 | parser_characters, |
371 | NULL, /* passthrough */ |
372 | NULL /* error */ |
373 | }; |
963b5f2d |
374 | |
45e14832 |
375 | fd = g_open(pathname, O_RDONLY, 0); |
376 | if(fd == -1){ |
2a74fbf4 |
377 | g_warning("Can not open file : %s\n", pathname); |
378 | return -1; |
6cd62ccf |
379 | } |
963b5f2d |
380 | |
45e14832 |
381 | iochan = g_io_channel_unix_new(fd); |
382 | |
43da6a59 |
383 | context = g_markup_parse_context_new(&markup_parser, 0, des,NULL); |
6cd62ccf |
384 | |
45e14832 |
385 | //while(fgets(buf,DIR_NAME_SIZE, fp) != NULL){ |
386 | while(g_io_channel_read_line(iochan, &buf, &length, NULL, &error) |
387 | != G_IO_STATUS_EOF) { |
388 | |
389 | if(error != NULL) { |
390 | g_warning("Can not read xml file: \n%s\n", error->message); |
391 | g_error_free(error); |
392 | } |
393 | if(!g_markup_parse_context_parse(context, buf, length, &error)){ |
2a74fbf4 |
394 | if(error != NULL) { |
395 | g_warning("Can not parse xml file: \n%s\n", error->message); |
396 | g_error_free(error); |
397 | } |
398 | g_markup_parse_context_free(context); |
45e14832 |
399 | |
400 | g_io_channel_shutdown(iochan, FALSE, &error); /* No flush */ |
401 | if(error != NULL) { |
402 | g_warning("Can not close file: \n%s\n", error->message); |
403 | g_error_free(error); |
404 | } |
405 | |
406 | close(fd); |
2a74fbf4 |
407 | return -1; |
43da6a59 |
408 | } |
963b5f2d |
409 | } |
2a74fbf4 |
410 | g_markup_parse_context_free(context); |
45e14832 |
411 | |
412 | g_io_channel_shutdown(iochan, FALSE, &error); /* No flush */ |
413 | if(error != NULL) { |
414 | g_warning("Can not close file: \n%s\n", error->message); |
415 | g_error_free(error); |
416 | } |
417 | |
418 | g_close(fd); |
419 | |
420 | g_free(buf); |
2a74fbf4 |
421 | return 0; |
6cd62ccf |
422 | } |
3aee1200 |
423 | #endif //0 |
6cd62ccf |
424 | |
425 | /***************************************************************************** |
963b5f2d |
426 | *The following functions get facility/tracefile information |
6cd62ccf |
427 | ****************************************************************************/ |
3aee1200 |
428 | #if 0 |
45e14832 |
429 | gint getFacilityInfo(LttTrace *t, gchar* eventdefs) |
6cd62ccf |
430 | { |
45e14832 |
431 | GDir * dir; |
432 | const gchar * name; |
8d1e6362 |
433 | unsigned int i,j; |
963b5f2d |
434 | LttFacility * f; |
435 | LttEventType * et; |
45e14832 |
436 | gchar fullname[DIR_NAME_SIZE]; |
437 | GError * error = NULL; |
438 | |
439 | dir = g_dir_open(eventdefs, 0, &error); |
963b5f2d |
440 | |
45e14832 |
441 | if(error != NULL) { |
442 | g_warning("Can not open directory: %s, %s\n", eventdefs, error->message); |
443 | g_error_free(error); |
2a74fbf4 |
444 | return -1; |
445 | } |
963b5f2d |
446 | |
45e14832 |
447 | while((name = g_dir_read_name(dir)) != NULL){ |
448 | if(!g_pattern_match_simple("*.xml", name)) continue; |
449 | strcpy(fullname,eventdefs); |
450 | strcat(fullname,name); |
451 | ltt_facility_open(t,fullname); |
452 | } |
453 | g_dir_close(dir); |
963b5f2d |
454 | |
963b5f2d |
455 | for(j=0;j<t->facility_number;j++){ |
8710c6c7 |
456 | f = (LttFacility*)g_ptr_array_index(t->facilities, j); |
963b5f2d |
457 | for(i=0; i<f->event_number; i++){ |
458 | et = f->events[i]; |
40331ba8 |
459 | setFieldsOffset(NULL, et, NULL, t); |
963b5f2d |
460 | } |
461 | } |
2a74fbf4 |
462 | return 0; |
963b5f2d |
463 | } |
3aee1200 |
464 | #endif //0 |
6cd62ccf |
465 | |
963b5f2d |
466 | /***************************************************************************** |
467 | *A trace is specified as a pathname to the directory containing all the |
468 | *associated data (control tracefiles, per cpu tracefiles, event |
469 | *descriptions...). |
470 | * |
471 | *When a trace is closed, all the associated facilities, types and fields |
472 | *are released as well. |
8d1e6362 |
473 | */ |
474 | |
475 | |
476 | /**************************************************************************** |
477 | * get_absolute_pathname |
803229fa |
478 | * |
8d1e6362 |
479 | * return the unique pathname in the system |
480 | * |
ef35d837 |
481 | * MD : Fixed this function so it uses realpath, dealing well with |
482 | * forgotten cases (.. were not used correctly before). |
803229fa |
483 | * |
963b5f2d |
484 | ****************************************************************************/ |
45e14832 |
485 | void get_absolute_pathname(const gchar *pathname, gchar * abs_pathname) |
9f797243 |
486 | { |
9f797243 |
487 | abs_pathname[0] = '\0'; |
803229fa |
488 | |
ef35d837 |
489 | if ( realpath (pathname, abs_pathname) != NULL) |
490 | return; |
491 | else |
492 | { |
8d1e6362 |
493 | /* error, return the original path unmodified */ |
ef35d837 |
494 | strcpy(abs_pathname, pathname); |
9f797243 |
495 | return; |
496 | } |
ef35d837 |
497 | return; |
9f797243 |
498 | } |
499 | |
3aee1200 |
500 | /* Search for something like : .*_.* |
501 | * |
502 | * The left side is the name, the right side is the number. |
503 | */ |
504 | |
505 | int get_tracefile_name_number(const gchar *raw_name, |
506 | GQuark *name, |
507 | guint *num) |
6cd62ccf |
508 | { |
3aee1200 |
509 | guint raw_name_len = strlen(raw_name); |
510 | gchar char_name[PATH_MAX]; |
511 | gchar *digit_begin; |
512 | int i; |
513 | int underscore_pos; |
514 | long int cpu_num; |
515 | gchar *endptr; |
516 | |
517 | for(i=raw_name_len-1;i>=0;i--) { |
518 | if(raw_name[i] == '_') break; |
519 | } |
520 | if(i==0) /* Either not found or name length is 0 */ |
521 | return -1; |
522 | underscore_pos = i; |
963b5f2d |
523 | |
3aee1200 |
524 | cpu_num = strtol(raw_name+underscore_pos+1, &endptr, 10); |
525 | |
526 | if(endptr == raw_name+underscore_pos+1) |
527 | return -1; /* No digit */ |
528 | if(cpu_num == LONG_MIN || cpu_num == LONG_MAX) |
529 | return -1; /* underflow / overflow */ |
1a2ceb63 |
530 | |
3aee1200 |
531 | strncpy(char_name, raw_name, underscore_pos); |
1a2ceb63 |
532 | |
3aee1200 |
533 | *name = g_quark_from_string(char_name); |
534 | *num = cpu_num; |
b333a76b |
535 | |
3aee1200 |
536 | return 0; |
537 | } |
963b5f2d |
538 | |
3aee1200 |
539 | |
77175651 |
540 | GData *ltt_trace_get_tracefiles_groups(LttTrace *trace) |
541 | { |
542 | return trace->tracefiles; |
543 | } |
544 | |
545 | |
546 | void compute_tracefile_group(GArray *group, |
547 | struct compute_tracefile_group_args args) |
548 | { |
549 | int i; |
550 | LttTracefile *tf; |
551 | |
552 | for(i=0; i<group->len; i++) { |
553 | tf = &g_array_index (group, LttTracefile, i); |
554 | if(tf->cpu_online) |
555 | args.func(tf, args.func_args); |
556 | } |
557 | } |
558 | |
559 | |
3aee1200 |
560 | void ltt_tracefile_group_destroy(gpointer data) |
561 | { |
562 | GArray *group = (GArray *)data; |
563 | int i; |
564 | LttTracefile *tf; |
565 | |
566 | for(i=0; i<group->len; i++) { |
567 | tf = &g_array_index (group, LttTracefile, i); |
568 | if(tf->cpu_online) |
569 | ltt_tracefile_close(tf); |
570 | } |
571 | g_array_free(group, TRUE); |
6cd62ccf |
572 | } |
573 | |
3aee1200 |
574 | gboolean ltt_tracefile_group_has_cpu_online(gpointer data) |
49bf71b5 |
575 | { |
3aee1200 |
576 | GArray *group = (GArray *)data; |
577 | int i; |
578 | LttTracefile *tf; |
579 | |
580 | for(i=0; i<group->len; i++) { |
581 | tf = &g_array_index (group, LttTracefile, i); |
582 | if(tf->cpu_online) return 1; |
583 | } |
584 | return 0; |
49bf71b5 |
585 | } |
586 | |
587 | |
3aee1200 |
588 | /* Open each tracefile under a specific directory. Put them in a |
589 | * GData : permits to access them using their tracefile group pathname. |
590 | * i.e. access control/modules tracefile group by index : |
591 | * "control/module". |
592 | * |
593 | * A tracefile group is simply an array where all the per cpu tracefiles sits. |
594 | */ |
595 | |
596 | static int open_tracefiles(LttTrace *trace, char *root_path, GData *tracefiles) |
f7afe191 |
597 | { |
3aee1200 |
598 | DIR *dir = opendir(root_path); |
599 | struct dirent *entry; |
600 | struct stat stat_buf; |
601 | int ret; |
602 | char path[PATH_MAX]; |
603 | int path_len; |
604 | char *path_ptr; |
605 | |
606 | if(dir == NULL) { |
607 | perror(root_path); |
608 | return ENOENT; |
609 | } |
610 | |
611 | strncpy(path, root_path, PATH_MAX-1); |
612 | path_len = strlen(path); |
613 | path[path_len] = '/'; |
614 | path_len++; |
615 | path_ptr = path + path_len; |
616 | |
617 | while((entry = readdir(dir)) != NULL) { |
618 | |
619 | if(entry->d_name[0] == '.') continue; |
620 | |
621 | strncpy(path_ptr, entry->d_name, PATH_MAX - path_len); |
622 | |
623 | ret = stat(path, &stat_buf); |
624 | if(ret == -1) { |
625 | perror(path); |
626 | continue; |
627 | } |
628 | |
629 | g_debug("Tracefile file or directory : %s\n", path); |
630 | |
631 | if(S_ISDIR(stat_buf.st_mode)) { |
632 | |
633 | g_debug("Entering subdirectory...\n"); |
634 | ret = open_tracefiles(trace, path, tracefiles); |
635 | if(ret < 0) continue; |
636 | } else if(S_ISREG(stat_buf.st_mode)) { |
637 | g_debug("Opening file.\n"); |
638 | |
639 | GQuark name; |
640 | guint num; |
641 | GArray *group; |
642 | LttTracefile *tf; |
643 | guint len; |
644 | |
645 | if(get_tracefile_name_number(path, &name, &num)) |
646 | continue; /* invalid name */ |
647 | |
648 | group = g_datalist_id_get_data(&tracefiles, name); |
649 | if(group == NULL) { |
650 | /* Elements are automatically cleared when the array is allocated. |
651 | * It makes the cpu_online variable set to 0 : cpu offline, by default. |
652 | */ |
653 | group = g_array_sized_new (FALSE, TRUE, sizeof(LttTracefile), 10); |
654 | g_datalist_id_set_data_full(&tracefiles, name, |
655 | group, ltt_tracefile_group_destroy); |
656 | } |
657 | /* Add the per cpu tracefile to the named group */ |
658 | unsigned int old_len = group->len; |
659 | if(num+1 > old_len) |
660 | group = g_array_set_size(group, num+1); |
661 | tf = &g_array_index (group, LttTracefile, num); |
662 | |
663 | if(ltt_tracefile_open(trace, path, tf)) { |
664 | g_info("Error opening tracefile %s", path); |
665 | g_array_set_size(group, old_len); |
666 | |
667 | if(!ltt_tracefile_group_has_cpu_online(group)) |
668 | g_datalist_id_remove_data(&tracefiles, name); |
669 | |
670 | continue; /* error opening the tracefile : bad magic number ? */ |
671 | } |
672 | tf->cpu_online = 1; |
673 | tf->cpu_num = num; |
674 | } |
675 | } |
676 | |
677 | closedir(dir); |
678 | |
679 | return 0; |
f7afe191 |
680 | } |
681 | |
3aee1200 |
682 | /* ltt_get_facility_description |
683 | * |
684 | * Opens the trace corresponding to the requested facility (identified by fac_id |
685 | * and checksum). |
686 | * |
687 | * The name searched is : %trace root%/eventdefs/facname_checksum.xml |
688 | * |
689 | * Returns 0 on success, or 1 on failure. |
690 | */ |
691 | |
692 | static int ltt_get_facility_description(LttFacility *f, |
693 | LttTrace *t, |
694 | LttTracefile *fac_tf) |
6cd62ccf |
695 | { |
3aee1200 |
696 | char desc_file_name[PATH_MAX]; |
697 | const gchar *text; |
698 | guint textlen; |
699 | gint err; |
700 | int i, j; |
701 | LttEventType *et; |
702 | |
703 | text = g_quark_to_string(t->pathname); |
704 | textlen = strlen(text); |
705 | |
706 | if(textlen >= PATH_MAX) goto name_error; |
707 | strcpy(desc_file_name, text); |
708 | |
709 | text = "/eventdefs/"; |
710 | textlen+=strlen(text); |
711 | if(textlen >= PATH_MAX) goto name_error; |
712 | strcat(desc_file_name, text); |
713 | |
714 | text = g_quark_to_string(f->name); |
715 | textlen+=strlen(text); |
716 | if(textlen >= PATH_MAX) goto name_error; |
717 | strcat(desc_file_name, text); |
718 | |
719 | text = "_"; |
720 | textlen+=strlen(text); |
721 | if(textlen >= PATH_MAX) goto name_error; |
722 | strcat(desc_file_name, text); |
963b5f2d |
723 | |
3aee1200 |
724 | err = snprintf(desc_file_name+textlen, PATH_MAX-textlen-1, |
725 | "%u", f->checksum); |
726 | if(err) goto name_error; |
727 | |
728 | textlen=strlen(desc_file_name); |
729 | |
730 | text = ".xml"; |
731 | textlen+=strlen(text); |
732 | if(textlen >= PATH_MAX) goto name_error; |
733 | strcat(desc_file_name, text); |
963b5f2d |
734 | |
3aee1200 |
735 | err = ltt_facility_open(f, t, desc_file_name); |
736 | if(err) goto facility_error; |
737 | |
738 | for(i=0;i<t->facilities_by_num->len;i++){ |
739 | f = &g_array_index(t->facilities_by_num, LttFacility, i); |
740 | if(f->exists) { |
741 | for(j=0; j<f->events->len; j++){ |
742 | et = &g_array_index(f->events, LttEventType, j); |
743 | set_fields_offsets(fac_tf, et); |
744 | } |
745 | } |
963b5f2d |
746 | } |
963b5f2d |
747 | |
3aee1200 |
748 | |
749 | return 0; |
750 | |
751 | facility_error: |
752 | name_error: |
753 | return 1; |
754 | } |
755 | |
756 | static void ltt_fac_ids_destroy(gpointer data) |
757 | { |
758 | GArray *fac_ids = (GArray *)data; |
759 | int i; |
760 | LttFacility *fac; |
761 | |
762 | for(i=0; i<fac_ids->len; i++) { |
763 | fac = &g_array_index (fac_ids, LttFacility, i); |
764 | ltt_facility_close(fac); |
963b5f2d |
765 | } |
963b5f2d |
766 | |
3aee1200 |
767 | g_array_free(fac_ids, TRUE); |
768 | } |
769 | |
770 | |
771 | /* Presumes the tracefile is already seeked at the beginning. It makes sense, |
772 | * because it must be done just after the opening */ |
773 | static int ltt_process_facility_tracefile(LttTracefile *tf) |
774 | { |
775 | int err; |
776 | LttFacility *fac; |
777 | GArray *fac_ids; |
778 | |
779 | while(1) { |
780 | err = ltt_tracefile_read_seek(tf); |
781 | if(err == EPERM) goto seek_error; |
782 | else if(err == ERANGE) break; /* End of tracefile */ |
783 | |
784 | err = ltt_tracefile_read_update_event(tf); |
785 | if(err) goto update_error; |
786 | |
787 | /* We are on a facility load/or facility unload/ or heartbeat event */ |
788 | /* The rules are : |
789 | * * facility 0 is hardcoded : this is the core facility. It will be shown |
790 | * in the facility array though, and is shown as "loaded builtin" in the |
791 | * trace. |
792 | * It contains event : |
793 | * 0 : facility load |
794 | * 1 : facility unload |
795 | * 2 : state dump facility load |
796 | * Facility 1 : (heartbeat) |
797 | * 0 : heartbeat |
798 | */ |
799 | if(tf->event.facility_id > 1) { /* Should only contain core and heartbeat |
800 | facilities */ |
801 | g_warning("Error in processing facility file %s, " |
802 | "should not contain facility id %u.", g_quark_to_string(tf->name), |
803 | tf->event.facility_id); |
804 | err = EPERM; |
805 | goto fac_id_error; |
806 | } else if(tf->event.facility_id == LTT_FACILITY_CORE) { |
807 | |
808 | struct LttFacilityLoad *fac_load_data; |
809 | char *fac_name; |
810 | |
811 | // FIXME align |
812 | switch((enum ltt_core_events)tf->event.event_id) { |
813 | case LTT_EVENT_FACILITY_LOAD: |
814 | fac_load_data = |
815 | (struct LttFacilityLoad *)tf->event.data; |
816 | fac_name = |
817 | (char*)(tf->event.data + sizeof(struct LttFacilityLoad)); |
818 | fac = &g_array_index (tf->trace->facilities_by_num, LttFacility, |
819 | ltt_get_uint32(LTT_GET_BO(tf), &fac_load_data->id)); |
820 | g_assert(fac->exists == 0); |
821 | fac->name = g_quark_from_string(fac_name); |
822 | fac->checksum = ltt_get_uint32(LTT_GET_BO(tf), |
823 | &fac_load_data->checksum); |
824 | fac->id = ltt_get_uint32(LTT_GET_BO(tf), &fac_load_data->id); |
825 | fac->pointer_size = ltt_get_uint32(LTT_GET_BO(tf), |
826 | &fac_load_data->pointer_size); |
eed2ef37 |
827 | fac->size_t_size = ltt_get_uint32(LTT_GET_BO(tf), |
3aee1200 |
828 | &fac_load_data->size_t_size); |
829 | fac->alignment = ltt_get_uint32(LTT_GET_BO(tf), |
830 | &fac_load_data->alignment); |
831 | |
832 | if(ltt_get_facility_description(fac, tf->trace, tf)) |
833 | goto facility_error; |
834 | |
835 | fac->trace = tf->trace; |
836 | fac->exists = 1; |
837 | |
77175651 |
838 | fac_ids = g_datalist_id_get_data(&tf->trace->facilities_by_name, |
839 | fac->name); |
3aee1200 |
840 | if(fac_ids == NULL) { |
841 | fac_ids = g_array_sized_new (FALSE, TRUE, sizeof(guint), 1); |
842 | g_datalist_id_set_data_full(&tf->trace->facilities_by_name, |
843 | fac->name, |
844 | fac_ids, ltt_fac_ids_destroy); |
845 | } |
846 | g_array_append_val(fac_ids, fac->id); |
847 | |
848 | break; |
849 | case LTT_EVENT_FACILITY_UNLOAD: |
850 | /* We don't care about unload : facilities ID are valid for the whole |
851 | * trace. They simply won't be used after the unload. */ |
852 | break; |
853 | case LTT_EVENT_STATE_DUMP_FACILITY_LOAD: |
854 | fac_load_data = |
855 | (struct LttFacilityLoad *)tf->event.data; |
856 | fac_name = |
857 | (char*)(tf->event.data + sizeof(struct LttFacilityLoad)); |
858 | fac = &g_array_index (tf->trace->facilities_by_num, LttFacility, |
859 | ltt_get_uint32(LTT_GET_BO(tf), &fac_load_data->id)); |
860 | g_assert(fac->exists == 0); |
861 | fac->name = g_quark_from_string(fac_name); |
862 | fac->checksum = ltt_get_uint32(LTT_GET_BO(tf), |
863 | &fac_load_data->checksum); |
eed2ef37 |
864 | fac->id = fac_load_data->id; |
3aee1200 |
865 | fac->pointer_size = ltt_get_uint32(LTT_GET_BO(tf), |
866 | &fac_load_data->pointer_size); |
eed2ef37 |
867 | fac->size_t_size = ltt_get_uint32(LTT_GET_BO(tf), |
3aee1200 |
868 | &fac_load_data->size_t_size); |
869 | fac->alignment = ltt_get_uint32(LTT_GET_BO(tf), |
870 | &fac_load_data->alignment); |
871 | if(ltt_get_facility_description(fac, tf->trace, tf)) |
872 | goto facility_error; |
873 | |
874 | fac->trace = tf->trace; |
875 | |
876 | fac->exists = 1; |
877 | |
878 | fac_ids = g_datalist_id_get_data(&tf->trace->facilities_by_name, |
879 | fac->name); |
880 | if(fac_ids == NULL) { |
881 | fac_ids = g_array_sized_new (FALSE, TRUE, sizeof(guint), 1); |
882 | g_datalist_id_set_data_full(&tf->trace->facilities_by_name, |
883 | fac->name, |
884 | fac_ids, ltt_fac_ids_destroy); |
885 | } |
886 | g_array_append_val(fac_ids, fac->id); |
887 | |
888 | break; |
889 | case LTT_EVENT_HEARTBEAT: |
890 | break; |
891 | default: |
892 | g_warning("Error in processing facility file %s, " |
893 | "unknown event id %hhu in core facility.", |
894 | g_quark_to_string(tf->name), |
895 | tf->event.event_id); |
896 | err = EPERM; |
897 | goto event_id_error; |
898 | } |
899 | } |
963b5f2d |
900 | } |
3aee1200 |
901 | return 0; |
963b5f2d |
902 | |
3aee1200 |
903 | /* Error handling */ |
904 | facility_error: |
905 | event_id_error: |
906 | fac_id_error: |
907 | update_error: |
908 | seek_error: |
909 | return err; |
6cd62ccf |
910 | } |
911 | |
963b5f2d |
912 | |
3aee1200 |
913 | LttTrace *ltt_trace_open(const gchar *pathname) |
914 | { |
915 | gchar abs_path[PATH_MAX]; |
916 | LttTrace * t; |
917 | LttTracefile *tf; |
918 | GArray *group; |
919 | int i; |
920 | |
921 | t = g_new(LttTrace, 1); |
922 | if(!t) goto alloc_error; |
923 | |
924 | get_absolute_pathname(pathname, abs_path); |
925 | t->pathname = g_quark_from_string(abs_path); |
926 | |
927 | /* Open all the tracefiles */ |
928 | g_datalist_init(&t->tracefiles); |
929 | if(open_tracefiles(t, abs_path, t->tracefiles)) |
930 | goto open_error; |
931 | |
932 | /* Prepare the facilities containers : array and mapping */ |
933 | /* Array is zeroed : the "exists" field is set to false by default */ |
934 | t->facilities_by_num = g_array_sized_new (FALSE, |
935 | TRUE, sizeof(LttFacility), |
936 | NUM_FACILITIES); |
937 | t->facilities_by_num = g_array_set_size(t->facilities_by_num, NUM_FACILITIES); |
938 | |
939 | g_datalist_init(&t->facilities_by_name); |
940 | |
941 | /* Parse each trace control/facilitiesN files : get runtime fac. info */ |
942 | group = g_datalist_id_get_data(&t->tracefiles, LTT_TRACEFILE_NAME_FACILITIES); |
943 | if(group == NULL) { |
944 | g_error("Trace %s has no facility tracefile", abs_path); |
945 | goto facilities_error; |
946 | } |
947 | |
948 | for(i=0; i<group->len; i++) { |
949 | tf = &g_array_index (group, LttTracefile, i); |
950 | if(ltt_process_facility_tracefile(tf)) |
951 | goto facilities_error; |
952 | } |
953 | |
954 | |
955 | |
956 | return t; |
957 | |
958 | /* Error handling */ |
959 | facilities_error: |
960 | g_datalist_clear(&t->facilities_by_name); |
961 | g_array_free(t->facilities_by_num, TRUE); |
962 | open_error: |
963 | g_datalist_clear(&t->tracefiles); |
964 | g_free(t); |
965 | alloc_error: |
966 | return NULL; |
967 | |
968 | } |
6cd62ccf |
969 | |
3aee1200 |
970 | GQuark ltt_trace_name(LttTrace *t) |
6cd62ccf |
971 | { |
3aee1200 |
972 | return t->pathname; |
6cd62ccf |
973 | } |
974 | |
6cd62ccf |
975 | |
3aee1200 |
976 | /****************************************************************************** |
977 | * When we copy a trace, we want all the opening actions to happen again : |
978 | * the trace will be reopened and totally independant from the original. |
979 | * That's why we call ltt_trace_open. |
980 | *****************************************************************************/ |
981 | LttTrace *ltt_trace_copy(LttTrace *self) |
963b5f2d |
982 | { |
3aee1200 |
983 | return ltt_trace_open(g_quark_to_string(self->pathname)); |
963b5f2d |
984 | } |
985 | |
3aee1200 |
986 | void ltt_trace_close(LttTrace *t) |
6cd62ccf |
987 | { |
3aee1200 |
988 | g_datalist_clear(&t->facilities_by_name); |
989 | g_array_free(t->facilities_by_num, TRUE); |
990 | g_datalist_clear(&t->tracefiles); |
991 | g_free(t); |
6cd62ccf |
992 | } |
993 | |
3aee1200 |
994 | |
6cd62ccf |
995 | /***************************************************************************** |
3aee1200 |
996 | *Get the system description of the trace |
6cd62ccf |
997 | ****************************************************************************/ |
998 | |
3aee1200 |
999 | LttFacility *ltt_trace_facility_by_id(LttTrace *t, guint8 id) |
6cd62ccf |
1000 | { |
3aee1200 |
1001 | g_assert(id < t->facilities_by_num->len); |
1002 | return &g_array_index(t->facilities_by_num, LttFacility, id); |
1003 | } |
1004 | |
1005 | /* ltt_trace_facility_get_by_name |
1006 | * |
1007 | * Returns the GArray of facility indexes. All the fac_ids that matches the |
1008 | * requested facility name. |
1009 | * |
1010 | * If name is not found, returns NULL. |
1011 | */ |
1012 | GArray *ltt_trace_facility_get_by_name(LttTrace *t, GQuark name) |
1013 | { |
1014 | return g_datalist_id_get_data(&t->facilities_by_name, name); |
6cd62ccf |
1015 | } |
1016 | |
1017 | /***************************************************************************** |
963b5f2d |
1018 | * Functions to discover all the event types in the trace |
6cd62ccf |
1019 | ****************************************************************************/ |
1020 | |
3aee1200 |
1021 | #if 0 |
963b5f2d |
1022 | unsigned ltt_trace_eventtype_number(LttTrace *t) |
6cd62ccf |
1023 | { |
8d1e6362 |
1024 | unsigned int i; |
963b5f2d |
1025 | unsigned count = 0; |
dc1cad90 |
1026 | unsigned int num = t->facility_number; |
963b5f2d |
1027 | LttFacility * f; |
dc1cad90 |
1028 | |
1029 | for(i=0;i<num;i++){ |
963b5f2d |
1030 | f = (LttFacility*)g_ptr_array_index(t->facilities, i); |
1031 | count += f->event_number; |
1032 | } |
1033 | return count; |
6cd62ccf |
1034 | } |
3aee1200 |
1035 | #endif //0 |
6cd62ccf |
1036 | |
3aee1200 |
1037 | #if 0 |
1038 | //use an iteration on all the trace facilities, and inside iteration on all the |
1039 | //event types in each facilities instead. |
963b5f2d |
1040 | LttEventType *ltt_trace_eventtype_get(LttTrace *t, unsigned evId) |
6cd62ccf |
1041 | { |
6e8c19d4 |
1042 | LttEventType *event_type; |
1043 | |
963b5f2d |
1044 | LttFacility * f; |
1045 | f = ltt_trace_facility_by_id(t,evId); |
6e8c19d4 |
1046 | |
1047 | if(unlikely(!f)) event_type = NULL; |
1048 | else event_type = f->events[evId - f->base_id]; |
1049 | |
1050 | return event_type; |
6cd62ccf |
1051 | } |
3aee1200 |
1052 | #endif //0 |
6cd62ccf |
1053 | |
3aee1200 |
1054 | #if 0 |
6cd62ccf |
1055 | /***************************************************************************** |
3aee1200 |
1056 | * ltt_trace_find_tracefile |
1057 | * |
1058 | * Find a tracefile by name and index in the group. |
1059 | * |
1060 | * Returns a pointer to the tracefiles, else NULL. |
6cd62ccf |
1061 | ****************************************************************************/ |
6cd62ccf |
1062 | |
3aee1200 |
1063 | LttTracefile *ltt_trace_find_tracefile(LttTrace *t, const gchar *name) |
6cd62ccf |
1064 | { |
6cd62ccf |
1065 | } |
3aee1200 |
1066 | #endif //0 |
6cd62ccf |
1067 | |
1068 | /***************************************************************************** |
3aee1200 |
1069 | * Get the start time and end time of the trace |
6cd62ccf |
1070 | ****************************************************************************/ |
1071 | |
3aee1200 |
1072 | static void ltt_tracefile_time_span_get(LttTracefile *tf, |
1073 | LttTime *start, LttTime *end) |
6cd62ccf |
1074 | { |
3aee1200 |
1075 | struct ltt_block_start_header * header; |
1076 | int err; |
6cd62ccf |
1077 | |
3aee1200 |
1078 | err = map_block(tf, 0); |
1079 | if(unlikely(err)) { |
1080 | g_error("Can not map block"); |
1081 | *start = ltt_time_infinite; |
1082 | } else |
1083 | *start = tf->buffer.begin.timestamp; |
1084 | |
1085 | err = map_block(tf, tf->num_blocks - 1); /* Last block */ |
1086 | if(unlikely(err)) { |
1087 | g_error("Can not map block"); |
1088 | *end = ltt_time_zero; |
1089 | } else |
1090 | *end = tf->buffer.end.timestamp; |
6cd62ccf |
1091 | } |
1092 | |
3aee1200 |
1093 | struct tracefile_time_span_get_args { |
1094 | LttTrace *t; |
1095 | LttTime *start; |
1096 | LttTime *end; |
1097 | }; |
963b5f2d |
1098 | |
3aee1200 |
1099 | static void group_time_span_get(GQuark name, gpointer data, gpointer user_data) |
963b5f2d |
1100 | { |
3aee1200 |
1101 | struct tracefile_time_span_get_args *args = |
1102 | (struct tracefile_time_span_get_args*)user_data; |
1103 | |
1104 | GArray *group = (GArray *)data; |
1105 | int i; |
1106 | LttTracefile *tf; |
1107 | LttTime tmp_start; |
1108 | LttTime tmp_end; |
1109 | |
1110 | for(i=0; i<group->len; i++) { |
1111 | tf = &g_array_index (group, LttTracefile, i); |
1112 | if(tf->cpu_online) { |
1113 | ltt_tracefile_time_span_get(tf, &tmp_start, &tmp_end); |
1114 | if(ltt_time_compare(*args->start, tmp_start)>0) *args->start = tmp_start; |
1115 | if(ltt_time_compare(*args->end, tmp_end)<0) *args->end = tmp_end; |
1116 | } |
1117 | } |
6cd62ccf |
1118 | } |
1119 | |
487ad181 |
1120 | void ltt_trace_time_span_get(LttTrace *t, LttTime *start, LttTime *end) |
1121 | { |
3aee1200 |
1122 | LttTime min_start = ltt_time_infinite; |
1123 | LttTime max_end = ltt_time_zero; |
1124 | struct tracefile_time_span_get_args args = { t, &min_start, &max_end }; |
487ad181 |
1125 | |
3aee1200 |
1126 | g_datalist_foreach(&t->tracefiles, &group_time_span_get, &args); |
1127 | |
1128 | if(start != NULL) *start = min_start; |
1129 | if(end != NULL) *end = max_end; |
1130 | |
487ad181 |
1131 | } |
1132 | |
1133 | |
6cd62ccf |
1134 | /***************************************************************************** |
963b5f2d |
1135 | *Get the name of a tracefile |
6cd62ccf |
1136 | ****************************************************************************/ |
1137 | |
3aee1200 |
1138 | GQuark ltt_tracefile_name(LttTracefile *tf) |
6cd62ccf |
1139 | { |
963b5f2d |
1140 | return tf->name; |
6cd62ccf |
1141 | } |
1142 | |
80da81ad |
1143 | /***************************************************************************** |
1144 | * Get the number of blocks in the tracefile |
1145 | ****************************************************************************/ |
1146 | |
3aee1200 |
1147 | guint ltt_tracefile_block_number(LttTracefile *tf) |
80da81ad |
1148 | { |
3aee1200 |
1149 | return tf->num_blocks; |
80da81ad |
1150 | } |
1151 | |
caf7a67a |
1152 | |
3aee1200 |
1153 | /* Seek to the first event in a tracefile that has a time equal or greater than |
1154 | * the time passed in parameter. |
1155 | * |
1156 | * If the time parameter is outside the tracefile time span, seek to the first |
1157 | * or the last event of the tracefile. |
1158 | * |
1159 | * If the time parameter is before the first event, we have to seek specially to |
1160 | * there. |
1161 | * |
1162 | * If the time is after the end of the trace, get the last event. |
1163 | * |
1164 | * Do a binary search to find the right block, then a sequential search in the |
1165 | * block to find the event. |
1166 | * |
1167 | * In the special case where the time requested fits inside a block that has no |
1168 | * event corresponding to the requested time, the first event of the next block |
1169 | * will be seeked. |
1170 | * |
1171 | * IMPORTANT NOTE : // FIXME everywhere... |
1172 | * |
1173 | * You MUST NOT do a ltt_tracefile_read right after a ltt_tracefile_seek_time : |
1174 | * you will jump over an event if you do. |
1175 | * |
1176 | * Return value : 0 : no error, the tf->event can be used |
1177 | * otherwise : this is an error. |
1178 | * |
1179 | * */ |
1180 | |
1181 | int ltt_tracefile_seek_time(LttTracefile *tf, LttTime time) |
1182 | { |
1183 | int ret = 0; |
1184 | int err; |
1185 | unsigned int block_num, high, low; |
1186 | |
1187 | /* seek at the beginning of trace */ |
1188 | err = map_block(tf, 0); /* First block */ |
1189 | if(unlikely(err)) { |
1190 | g_error("Can not map block"); |
1191 | goto fail; |
caf7a67a |
1192 | } |
1193 | |
3aee1200 |
1194 | /* If the time is lower or equal the beginning of the trace, |
1195 | * go to the first event. */ |
1196 | if(ltt_time_compare(time, tf->buffer.begin.timestamp) <= 0) { |
1197 | ret = ltt_tracefile_read(tf); |
1198 | goto found; /* There is either no event in the trace or the event points |
1199 | to the first event in the trace */ |
1200 | } |
caf7a67a |
1201 | |
3aee1200 |
1202 | err = map_block(tf, tf->num_blocks - 1); /* Last block */ |
1203 | if(unlikely(err)) { |
1204 | g_error("Can not map block"); |
1205 | goto fail; |
caf7a67a |
1206 | } |
6cd62ccf |
1207 | |
3aee1200 |
1208 | /* If the time is after the end of the trace, get the last event. */ |
1209 | if(ltt_time_compare(time, tf->buffer.end.timestamp) >= 0) { |
1210 | /* While the ltt_tracefile_read doesn't return ERANGE or EPERM, |
1211 | * continue reading. |
1212 | */ |
1213 | while(1) { |
1214 | ret = ltt_tracefile_read(tf); |
1215 | if(ret == ERANGE) goto found; /* ERANGE or EPERM */ |
1216 | else if(ret) goto fail; |
1217 | } |
1218 | } |
62e55dd6 |
1219 | |
3aee1200 |
1220 | /* Binary search the block */ |
1221 | high = tf->num_blocks - 1; |
1222 | low = 0; |
1223 | |
1224 | while(1) { |
1225 | block_num = ((high-low) / 2) + low; |
1226 | |
1227 | err = map_block(tf, block_num); |
1228 | if(unlikely(err)) { |
1229 | g_error("Can not map block"); |
1230 | goto fail; |
db55eaae |
1231 | } |
3aee1200 |
1232 | if(high == low) { |
1233 | /* We cannot divide anymore : this is what would happen if the time |
1234 | * requested was exactly between two consecutive buffers'end and start |
1235 | * timestamps. This is also what would happend if we didn't deal with out |
1236 | * of span cases prior in this function. */ |
1237 | /* The event is right in the buffer! |
1238 | * (or in the next buffer first event) */ |
1239 | while(1) { |
1240 | ret = ltt_tracefile_read(tf); |
1241 | if(ret == ERANGE) goto found; /* ERANGE or EPERM */ |
1242 | else if(ret) goto fail; |
1243 | |
1244 | if(ltt_time_compare(time, tf->event.event_time) >= 0) |
1245 | break; |
1246 | } |
1247 | |
1248 | } if(ltt_time_compare(time, tf->buffer.begin.timestamp) < 0) { |
1249 | /* go to lower part */ |
1250 | high = block_num; |
1251 | } else if(ltt_time_compare(time, tf->buffer.end.timestamp) > 0) { |
1252 | /* go to higher part */ |
1253 | low = block_num; |
1254 | } else {/* The event is right in the buffer! |
1255 | (or in the next buffer first event) */ |
1256 | while(1) { |
1257 | ltt_tracefile_read(tf); |
1258 | if(ret == ERANGE) goto found; /* ERANGE or EPERM */ |
1259 | else if(ret) goto fail; |
1260 | |
1261 | if(ltt_time_compare(time, tf->event.event_time) >= 0) |
1262 | break; |
6cd62ccf |
1263 | } |
3aee1200 |
1264 | goto found; |
6cd62ccf |
1265 | } |
6cd62ccf |
1266 | } |
3aee1200 |
1267 | |
1268 | found: |
1269 | return 0; |
1270 | |
1271 | /* Error handling */ |
1272 | fail: |
1273 | g_error("ltt_tracefile_seek_time failed on tracefile %s", |
1274 | g_quark_to_string(tf->name)); |
1275 | return EPERM; |
6cd62ccf |
1276 | } |
1277 | |
80da81ad |
1278 | |
3aee1200 |
1279 | int ltt_tracefile_seek_position(LttTracefile *tf, const LttEventPosition *ep) { |
80da81ad |
1280 | |
3aee1200 |
1281 | int err; |
1282 | |
1283 | if(ep->tracefile != tf) { |
1284 | goto fail; |
80da81ad |
1285 | } |
1286 | |
3aee1200 |
1287 | err = map_block(tf, ep->block); |
1288 | if(unlikely(err)) { |
1289 | g_error("Can not map block"); |
1290 | goto fail; |
1291 | } |
1292 | |
1293 | tf->event.offset = ep->offset; |
18206708 |
1294 | |
3aee1200 |
1295 | err = ltt_tracefile_read_update_event(tf); |
1296 | if(err) goto fail; |
1297 | err = ltt_tracefile_read_op(tf); |
1298 | if(err) goto fail; |
80da81ad |
1299 | |
1300 | return; |
3aee1200 |
1301 | |
1302 | fail: |
1303 | g_error("ltt_tracefile_seek_time failed on tracefile %s", |
1304 | g_quark_to_string(tf->name)); |
1305 | } |
1306 | |
1307 | /* Calculate the real event time based on the buffer boundaries */ |
1308 | LttTime ltt_interpolate_time(LttTracefile *tf, LttEvent *event) |
1309 | { |
1310 | LttTime time; |
1311 | |
1312 | g_assert(tf->trace->has_tsc); |
1313 | |
1314 | time = ltt_time_from_uint64( |
1315 | (guint64)tf->buffer.tsc*tf->buffer.nsecs_per_cycle); |
1316 | time = ltt_time_add(tf->buffer.begin.timestamp, time); |
1317 | |
1318 | return time; |
80da81ad |
1319 | } |
1320 | |
eed2ef37 |
1321 | |
1322 | /* Get the current event of the tracefile : valid until the next read */ |
1323 | LttEvent *ltt_tracefile_get_event(LttTracefile *tf) |
1324 | { |
1325 | return &tf->event; |
1326 | } |
1327 | |
1328 | |
1329 | |
6cd62ccf |
1330 | /***************************************************************************** |
1331 | *Function name |
3aee1200 |
1332 | * ltt_tracefile_read : Read the next event in the tracefile |
6cd62ccf |
1333 | *Input params |
1334 | * t : tracefile |
1335 | *Return value |
3aee1200 |
1336 | * |
1337 | * Returns 0 if an event can be used in tf->event. |
1338 | * Returns ERANGE on end of trace. The event in tf->event still can be used. |
1339 | * Returns EPERM on error. |
1340 | * |
1341 | * This function does make the tracefile event structure point to the event |
1342 | * currently pointed to by the tf->event. |
1343 | * |
1344 | * Note : you must call a ltt_tracefile_seek to the beginning of the trace to |
1345 | * reinitialize it after an error if you want results to be coherent. |
1346 | * It would be the case if a end of trace last buffer has no event : the end |
1347 | * of trace wouldn't be returned, but an error. |
1348 | * We make the assumption there is at least one event per buffer. |
6cd62ccf |
1349 | ****************************************************************************/ |
1350 | |
3aee1200 |
1351 | int ltt_tracefile_read(LttTracefile *tf) |
6cd62ccf |
1352 | { |
963b5f2d |
1353 | int err; |
6cd62ccf |
1354 | |
3aee1200 |
1355 | err = ltt_tracefile_read_seek(tf); |
1356 | if(err) return err; |
1357 | err = ltt_tracefile_read_update_event(tf); |
1358 | if(err) return err; |
1359 | err = ltt_tracefile_read_op(tf); |
1360 | if(err) return err; |
1361 | |
1362 | return 0; |
1363 | } |
1364 | |
1365 | int ltt_tracefile_read_seek(LttTracefile *tf) |
1366 | { |
1367 | int err; |
1368 | |
1369 | /* Get next buffer until we finally have an event, or end of trace */ |
1370 | while(1) { |
1371 | err = ltt_seek_next_event(tf); |
1372 | if(unlikely(err == ENOPROTOOPT)) { |
1373 | return EPERM; |
bdc36259 |
1374 | } |
bdc36259 |
1375 | |
3aee1200 |
1376 | /* Are we at the end of the buffer ? */ |
1377 | if(err == ERANGE) { |
1378 | if(unlikely(tf->buffer.index == tf->num_blocks-1)){ /* end of trace ? */ |
1379 | return ERANGE; |
1380 | } else { |
1381 | /* get next block */ |
1382 | err = map_block(tf, tf->buffer.index + 1); |
1383 | if(unlikely(err)) { |
1384 | g_error("Can not map block"); |
1385 | return EPERM; |
1386 | } |
1387 | } |
1388 | } else break; /* We found an event ! */ |
1389 | } |
2dee981d |
1390 | |
3aee1200 |
1391 | return 0; |
1392 | } |
18206708 |
1393 | |
1394 | |
3aee1200 |
1395 | /* do specific operation on events */ |
1396 | int ltt_tracefile_read_op(LttTracefile *tf) |
1397 | { |
1398 | int err; |
1399 | LttFacility *f; |
1400 | void * pos; |
1401 | LttEvent *event; |
1402 | |
1403 | event = &tf->event; |
18206708 |
1404 | |
3aee1200 |
1405 | /* do event specific operation */ |
40331ba8 |
1406 | |
3aee1200 |
1407 | /* do something if its an heartbeat event : increment the heartbeat count */ |
1408 | //if(event->facility_id == LTT_FACILITY_CORE) |
1409 | // if(event->event_id == LTT_EVENT_HEARTBEAT) |
1410 | // tf->cur_heart_beat_number++; |
1411 | |
1412 | return 0; |
6cd62ccf |
1413 | } |
1414 | |
6cd62ccf |
1415 | |
3aee1200 |
1416 | /* same as ltt_tracefile_read, but does not seek to the next event nor call |
1417 | * event specific operation. */ |
1418 | int ltt_tracefile_read_update_event(LttTracefile *tf) |
6cd62ccf |
1419 | { |
3aee1200 |
1420 | int err; |
1421 | LttFacility *f; |
1422 | void * pos; |
1423 | LttEvent *event; |
1424 | |
1425 | event = &tf->event; |
eed2ef37 |
1426 | pos = tf->buffer.head + event->offset; |
3aee1200 |
1427 | |
1428 | /* Read event header */ |
1429 | |
1430 | //TODO align |
1431 | |
1432 | if(tf->trace->has_tsc) { |
1433 | event->time.timestamp = ltt_get_uint32(LTT_GET_BO(tf), |
1434 | pos); |
1435 | /* 32 bits -> 64 bits tsc */ |
1436 | /* note : still works for seek and non seek cases. */ |
1437 | if(event->time.timestamp < (0xFFFFFFFFULL&tf->buffer.tsc)) { |
1438 | tf->buffer.tsc = ((tf->buffer.tsc&0xFFFFFFFF00000000ULL) |
1439 | + 0x100000000ULL) |
1440 | | (guint64)event->time.timestamp; |
1441 | event->tsc = tf->buffer.tsc; |
1442 | } else { |
1443 | /* no overflow */ |
1444 | tf->buffer.tsc = (tf->buffer.tsc&0xFFFFFFFF00000000ULL) |
1445 | | (guint64)event->time.timestamp; |
1446 | event->tsc = tf->buffer.tsc; |
1447 | } |
1448 | |
1449 | event->event_time = ltt_interpolate_time(tf, event); |
1450 | |
1451 | pos += sizeof(guint32); |
1452 | } else { |
1453 | event->time.delta.tv_sec = 0; |
1454 | event->time.delta.tv_nsec = ltt_get_uint32(LTT_GET_BO(tf), |
1455 | pos) * NSEC_PER_USEC; |
1456 | tf->buffer.tsc = 0; |
1457 | event->tsc = tf->buffer.tsc; |
1458 | |
1459 | event->event_time = ltt_time_add(tf->buffer.begin.timestamp, |
1460 | event->time.delta); |
1461 | pos += sizeof(guint32); |
1462 | } |
1463 | |
eed2ef37 |
1464 | event->facility_id = *(guint8*)pos; |
3aee1200 |
1465 | pos += sizeof(guint8); |
1466 | |
eed2ef37 |
1467 | event->event_id = *(guint8*)pos; |
3aee1200 |
1468 | pos += sizeof(guint8); |
1469 | |
1470 | event->data = pos; |
1471 | |
77175651 |
1472 | /* get the data size and update the event fields with the current |
1473 | * information */ |
eed2ef37 |
1474 | ltt_update_event_size(tf); |
77175651 |
1475 | |
3aee1200 |
1476 | return 0; |
6cd62ccf |
1477 | } |
1478 | |
507915ee |
1479 | |
6cd62ccf |
1480 | /**************************************************************************** |
1481 | *Function name |
3aee1200 |
1482 | * map_block : map a block from the file |
6cd62ccf |
1483 | *Input Params |
1484 | * lttdes : ltt trace file |
1485 | * whichBlock : the block which will be read |
1486 | *return value |
1487 | * 0 : success |
1488 | * EINVAL : lseek fail |
1489 | * EIO : can not read from the file |
1490 | ****************************************************************************/ |
1491 | |
3aee1200 |
1492 | static gint map_block(LttTracefile * tf, guint block_num) |
6cd62ccf |
1493 | { |
3aee1200 |
1494 | struct ltt_block_start_header *header; |
1495 | |
1496 | g_assert(block_num < tf->num_blocks); |
6cd62ccf |
1497 | |
3aee1200 |
1498 | if(tf->buffer.head != NULL) |
1499 | munmap(tf->buffer.head, tf->buf_size); |
ac849774 |
1500 | |
3aee1200 |
1501 | /* Multiple of pages aligned head */ |
1502 | tf->buffer.head = mmap(0, tf->block_size, PROT_READ, tf->fd, MAP_PRIVATE, |
1503 | (off_t)tf->block_size * (off_t)block_num); |
1504 | |
1505 | if(tf->buffer.head == NULL) { |
1506 | perror("Error in allocating memory for buffer of tracefile"); |
1507 | goto map_error; |
6cd62ccf |
1508 | } |
3aee1200 |
1509 | g_assert(((guint)tf->buffer.head) & (8-1) == 0); // make sure it's aligned. |
1510 | |
6cd62ccf |
1511 | |
3aee1200 |
1512 | tf->buffer.index = block_num; |
1513 | |
1514 | header = (struct ltt_block_start_header*)tf->buffer.head; |
1515 | |
1516 | tf->buffer.begin.timestamp = ltt_get_time(LTT_GET_BO(tf), |
1517 | &header->begin.timestamp); |
1518 | tf->buffer.begin.timestamp.tv_nsec *= NSEC_PER_USEC; |
1519 | tf->buffer.begin.cycle_count = ltt_get_uint64(LTT_GET_BO(tf), |
1520 | &header->begin.cycle_count); |
1521 | tf->buffer.end.timestamp = ltt_get_time(LTT_GET_BO(tf), |
1522 | &header->end.timestamp); |
1523 | tf->buffer.end.timestamp.tv_nsec *= NSEC_PER_USEC; |
1524 | tf->buffer.end.cycle_count = ltt_get_uint64(LTT_GET_BO(tf), |
1525 | &header->end.cycle_count); |
1526 | tf->buffer.lost_size = ltt_get_uint32(LTT_GET_BO(tf), |
1527 | &header->lost_size); |
6cd62ccf |
1528 | |
3aee1200 |
1529 | tf->buffer.tsc = tf->buffer.begin.cycle_count; |
1530 | tf->event.tsc = tf->buffer.tsc; |
1531 | |
1532 | /* FIXME |
1533 | * eventually support variable buffer size : will need a partial pre-read of |
1534 | * the headers to create an index when we open the trace... eventually. */ |
1535 | g_assert(tf->block_size == ltt_get_uint32(LTT_GET_BO(tf), |
1536 | &header->buf_size)); |
507915ee |
1537 | |
3aee1200 |
1538 | /* Now that the buffer is mapped, calculate the time interpolation for the |
1539 | * block. */ |
1540 | |
1541 | tf->buffer.nsecs_per_cycle = calc_nsecs_per_cycle(tf); |
1542 | |
1543 | /* Make the current event point to the beginning of the buffer : |
1544 | * it means that the event read must get the first event. */ |
1545 | tf->event.tracefile = tf; |
1546 | tf->event.block = block_num; |
eed2ef37 |
1547 | tf->event.offset = 0; |
3aee1200 |
1548 | |
1549 | return 0; |
6cd62ccf |
1550 | |
3aee1200 |
1551 | map_error: |
1552 | return -errno; |
40331ba8 |
1553 | |
6cd62ccf |
1554 | } |
1555 | |
77175651 |
1556 | /* It will update the fields offsets too */ |
1557 | void ltt_update_event_size(LttTracefile *tf) |
6cd62ccf |
1558 | { |
3aee1200 |
1559 | ssize_t size = 0; |
1560 | |
1561 | /* Specific handling of core events : necessary to read the facility control |
1562 | * tracefile. */ |
77175651 |
1563 | LttFacility *f = ltt_trace_get_facility_by_num(tf->trace, |
1564 | tf->event.facility_id); |
6cd62ccf |
1565 | |
77175651 |
1566 | if(unlikely(f == NULL)) { |
1567 | if(likely(tf->event.facility_id == LTT_FACILITY_CORE)) { |
1568 | switch((enum ltt_core_events)tf->event.event_id) { |
1569 | case LTT_EVENT_FACILITY_LOAD: |
1570 | size = sizeof(struct LttFacilityLoad); |
1571 | break; |
1572 | case LTT_EVENT_FACILITY_UNLOAD: |
1573 | size = sizeof(struct LttFacilityUnload); |
1574 | break; |
1575 | case LTT_EVENT_STATE_DUMP_FACILITY_LOAD: |
1576 | size = sizeof(struct LttStateDumpFacilityLoad); |
1577 | break; |
1578 | case LTT_EVENT_HEARTBEAT: |
1579 | size = sizeof(TimeHeartbeat); |
1580 | break; |
1581 | default: |
1582 | g_warning("Error in getting event size : tracefile %s, " |
1583 | "unknown event id %hhu in core facility.", |
1584 | g_quark_to_string(tf->name), |
1585 | tf->event.event_id); |
1586 | goto event_id_error; |
2dee981d |
1587 | |
77175651 |
1588 | } |
1589 | } |
3aee1200 |
1590 | } else { |
3aee1200 |
1591 | LttEventType *event_type = |
1592 | ltt_facility_eventtype_get(f, tf->event.event_id); |
eed2ef37 |
1593 | size = get_field_type_size(tf, event_type, |
1594 | 0, 0, event_type->root_field, tf->event.data); |
3aee1200 |
1595 | } |
3aee1200 |
1596 | |
77175651 |
1597 | tf->event.data_size = size; |
eed2ef37 |
1598 | |
1599 | return; |
1600 | |
3aee1200 |
1601 | event_id_error: |
eed2ef37 |
1602 | tf->event.data_size = 0; |
6cd62ccf |
1603 | } |
1604 | |
6cd62ccf |
1605 | |
3aee1200 |
1606 | /* Take the tf current event offset and use the event facility id and event id |
1607 | * to figure out where is the next event offset. |
1608 | * |
1609 | * This is an internal function not aiming at being used elsewhere : it will |
1610 | * not jump over the current block limits. Please consider using |
1611 | * ltt_tracefile_read to do this. |
1612 | * |
1613 | * Returns 0 on success |
1614 | * ERANGE if we are at the end of the buffer. |
1615 | * ENOPROTOOPT if an error occured when getting the current event size. |
1616 | */ |
1617 | static int ltt_seek_next_event(LttTracefile *tf) |
6cd62ccf |
1618 | { |
3aee1200 |
1619 | int ret = 0; |
1620 | void *pos; |
1621 | ssize_t event_size; |
1622 | |
1623 | /* seek over the buffer header if we are at the buffer start */ |
eed2ef37 |
1624 | if(tf->event.offset == 0) { |
3aee1200 |
1625 | tf->event.offset += sizeof(struct ltt_block_start_header); |
1626 | goto found; |
1627 | } |
6cd62ccf |
1628 | |
6cd62ccf |
1629 | |
eed2ef37 |
1630 | if(tf->event.offset == tf->buffer.lost_size) { |
3aee1200 |
1631 | ret = ERANGE; |
1632 | goto found; |
6cd62ccf |
1633 | } |
1634 | |
3aee1200 |
1635 | pos = tf->event.data; |
1636 | |
77175651 |
1637 | if(tf->event.data_size < 0) goto error; |
3aee1200 |
1638 | |
77175651 |
1639 | pos += (size_t)tf->event.data_size; |
3aee1200 |
1640 | |
eed2ef37 |
1641 | tf->event.offset = pos - tf->buffer.head; |
3aee1200 |
1642 | |
1643 | found: |
1644 | return ret; |
1645 | |
1646 | error: |
1647 | g_error("Error in ltt_seek_next_event for tracefile %s", |
1648 | g_quark_to_string(tf->name)); |
1649 | return ENOPROTOOPT; |
6cd62ccf |
1650 | } |
1651 | |
18206708 |
1652 | |
6cd62ccf |
1653 | /***************************************************************************** |
1654 | *Function name |
3aee1200 |
1655 | * calc_nsecs_per_cycle : calculate nsecs per cycle for current block |
6cd62ccf |
1656 | *Input Params |
1657 | * t : tracefile |
1658 | ****************************************************************************/ |
1659 | |
3aee1200 |
1660 | static double calc_nsecs_per_cycle(LttTracefile * tf) |
6cd62ccf |
1661 | { |
963b5f2d |
1662 | LttTime lBufTotalTime; /* Total time for this buffer */ |
887208b7 |
1663 | double lBufTotalNSec; /* Total time for this buffer in nsecs */ |
8ee1c3d5 |
1664 | LttCycleCount lBufTotalCycle;/* Total cycles for this buffer */ |
6cd62ccf |
1665 | |
1666 | /* Calculate the total time for this buffer */ |
01bb5763 |
1667 | lBufTotalTime = ltt_time_sub( |
3aee1200 |
1668 | ltt_get_time(LTT_GET_BO(tf), &tf->buffer.end.timestamp), |
1669 | ltt_get_time(LTT_GET_BO(tf), &tf->buffer.begin.timestamp)); |
6cd62ccf |
1670 | |
1671 | /* Calculate the total cycles for this bufffer */ |
3aee1200 |
1672 | lBufTotalCycle = ltt_get_uint64(LTT_GET_BO(tf), &tf->buffer.end.cycle_count); |
1673 | lBufTotalCycle -= ltt_get_uint64(LTT_GET_BO(tf), |
1674 | &tf->buffer.begin.cycle_count); |
6cd62ccf |
1675 | |
8ee1c3d5 |
1676 | /* Convert the total time to double */ |
887208b7 |
1677 | lBufTotalNSec = ltt_time_to_double(lBufTotalTime); |
6cd62ccf |
1678 | |
3aee1200 |
1679 | return lBufTotalNSec / (double)lBufTotalCycle; |
8ee1c3d5 |
1680 | |
3aee1200 |
1681 | } |
1682 | #if 0 |
1683 | void setFieldsOffset(LttTracefile *tf, LttEventType *evT,void *evD) |
1684 | { |
1685 | LttField * rootFld = evT->root_field; |
1686 | // rootFld->base_address = evD; |
2dee981d |
1687 | |
3aee1200 |
1688 | if(likely(rootFld)) |
1689 | rootFld->field_size = getFieldtypeSize(tf, evT->facility, |
1690 | evT, 0,0,rootFld, evD); |
6cd62ccf |
1691 | } |
3aee1200 |
1692 | #endif //0 |
6cd62ccf |
1693 | |
3aee1200 |
1694 | /***************************************************************************** |
6cd62ccf |
1695 | *Function name |
3aee1200 |
1696 | * set_fields_offsets : set the precomputable offset of the fields |
6cd62ccf |
1697 | *Input params |
3aee1200 |
1698 | * tracefile : opened trace file |
1699 | * event_type : the event type |
6cd62ccf |
1700 | ****************************************************************************/ |
1701 | |
3aee1200 |
1702 | void set_fields_offsets(LttTracefile *tf, LttEventType *event_type) |
6cd62ccf |
1703 | { |
3aee1200 |
1704 | LttField *field = event_type->root_field; |
1705 | enum field_status fixed_root = FIELD_FIXED, fixed_parent = FIELD_FIXED; |
1706 | |
1707 | if(likely(field)) |
1708 | preset_field_type_size(tf, event_type, 0, 0, |
1709 | &fixed_root, &fixed_parent, |
1710 | field); |
1711 | |
1712 | } |
e4eced0f |
1713 | |
bbf28e50 |
1714 | |
3aee1200 |
1715 | /***************************************************************************** |
1716 | *Function name |
1717 | * preset_field_type_size : set the fixed sizes of the field type |
1718 | *Input params |
1719 | * tf : tracefile |
1720 | * event_type : event type |
1721 | * offset_root : offset from the root |
1722 | * offset_parent : offset from the parent |
1723 | * fixed_root : Do we know a fixed offset to the root ? |
1724 | * fixed_parent : Do we know a fixed offset to the parent ? |
1725 | * field : field |
1726 | ****************************************************************************/ |
1727 | void preset_field_type_size(LttTracefile *tf, LttEventType *event_type, |
1728 | off_t offset_root, off_t offset_parent, |
1729 | enum field_status *fixed_root, enum field_status *fixed_parent, |
1730 | LttField *field) |
1731 | { |
1732 | enum field_status local_fixed_root, local_fixed_parent; |
1733 | guint i; |
1734 | LttType *type; |
dfb73233 |
1735 | |
3aee1200 |
1736 | g_assert(field->fixed_root == FIELD_UNKNOWN); |
1737 | g_assert(field->fixed_parent == FIELD_UNKNOWN); |
1738 | g_assert(field->fixed_size == FIELD_UNKNOWN); |
dfb73233 |
1739 | |
3aee1200 |
1740 | type = field->field_type; |
1741 | |
1742 | field->fixed_root = *fixed_root; |
1743 | if(field->fixed_root == FIELD_FIXED) |
1744 | field->offset_root = offset_root; |
1745 | else |
1746 | field->offset_root = 0; |
1747 | |
1748 | field->fixed_parent = *fixed_parent; |
1749 | if(field->fixed_parent == FIELD_FIXED) |
1750 | field->offset_parent = offset_parent; |
1751 | else |
1752 | field->offset_parent = 0; |
1753 | |
1754 | size_t current_root_offset; |
1755 | size_t current_offset; |
1756 | enum field_status current_child_status, final_child_status; |
1757 | size_t max_size; |
1758 | |
1759 | switch(type->type_class) { |
1760 | case LTT_INT: |
1761 | case LTT_UINT: |
1762 | case LTT_FLOAT: |
1763 | case LTT_ENUM: |
1764 | field->field_size = ltt_type_size(tf->trace, type); |
1765 | field->fixed_size = FIELD_FIXED; |
1766 | break; |
1767 | case LTT_POINTER: |
1768 | field->field_size = (off_t)event_type->facility->pointer_size; |
1769 | field->fixed_size = FIELD_FIXED; |
1770 | break; |
1771 | case LTT_LONG: |
1772 | case LTT_ULONG: |
1773 | field->field_size = (off_t)event_type->facility->pointer_size; |
1774 | field->fixed_size = FIELD_FIXED; |
1775 | break; |
1776 | case LTT_SIZE_T: |
1777 | case LTT_SSIZE_T: |
1778 | case LTT_OFF_T: |
1779 | field->field_size = (off_t)event_type->facility->size_t_size; |
1780 | field->fixed_size = FIELD_FIXED; |
1781 | break; |
1782 | case LTT_SEQUENCE: |
1783 | local_fixed_root = FIELD_VARIABLE; |
1784 | local_fixed_parent = FIELD_VARIABLE; |
1785 | preset_field_type_size(tf, event_type, |
1786 | 0, 0, |
1787 | &local_fixed_root, &local_fixed_parent, |
1788 | field->child[0]); |
1789 | field->fixed_size = FIELD_VARIABLE; |
1790 | field->field_size = 0; |
1791 | break; |
1792 | case LTT_STRING: |
1793 | field->fixed_size = FIELD_VARIABLE; |
1794 | field->field_size = 0; |
1795 | break; |
1796 | case LTT_ARRAY: |
1797 | local_fixed_root = FIELD_VARIABLE; |
1798 | local_fixed_parent = FIELD_VARIABLE; |
1799 | preset_field_type_size(tf, event_type, |
1800 | 0, 0, |
1801 | &local_fixed_root, &local_fixed_parent, |
1802 | field->child[0]); |
1803 | field->fixed_size = field->child[0]->fixed_size; |
1804 | if(field->fixed_size == FIELD_FIXED) |
1805 | field->field_size = type->element_number * field->child[0]->field_size; |
1806 | else |
1807 | field->field_size = 0; |
1808 | break; |
1809 | case LTT_STRUCT: |
1810 | current_root_offset = field->offset_root; |
1811 | current_offset = 0; |
1812 | current_child_status = FIELD_FIXED; |
1813 | for(i=0;i<type->element_number;i++) { |
1814 | preset_field_type_size(tf, event_type, |
1815 | current_root_offset, current_offset, |
1816 | fixed_root, ¤t_child_status, |
1817 | field->child[i]); |
1818 | if(current_child_status == FIELD_FIXED) { |
1819 | current_root_offset += field->child[i]->field_size; |
1820 | current_offset += field->child[i]->field_size; |
1821 | } else { |
1822 | current_root_offset = 0; |
1823 | current_offset = 0; |
1824 | } |
1825 | } |
1826 | if(current_child_status != FIELD_FIXED) { |
1827 | *fixed_parent = current_child_status; |
1828 | field->field_size = 0; |
1829 | field->fixed_size = current_child_status; |
1830 | } else { |
1831 | field->field_size = current_offset; |
1832 | field->fixed_size = FIELD_FIXED; |
1833 | } |
1834 | break; |
1835 | case LTT_UNION: |
1836 | current_root_offset = field->offset_root; |
1837 | current_offset = 0; |
1838 | max_size = 0; |
1839 | final_child_status = FIELD_FIXED; |
1840 | for(i=0;i<type->element_number;i++) { |
1841 | enum field_status current_root_child_status = FIELD_FIXED; |
1842 | enum field_status current_child_status = FIELD_FIXED; |
1843 | preset_field_type_size(tf, event_type, |
1844 | current_root_offset, current_offset, |
1845 | ¤t_root_child_status, ¤t_child_status, |
1846 | field->child[i]); |
1847 | if(current_child_status != FIELD_FIXED) |
1848 | final_child_status = current_child_status; |
1849 | else |
1850 | max_size = max(max_size, field->child[i]->field_size); |
1851 | } |
1852 | if(final_child_status != FIELD_FIXED) { |
1853 | *fixed_root = final_child_status; |
1854 | *fixed_parent = final_child_status; |
1855 | field->field_size = 0; |
1856 | field->fixed_size = current_child_status; |
1857 | } else { |
1858 | field->field_size = max_size; |
1859 | field->fixed_size = FIELD_FIXED; |
1860 | } |
1861 | break; |
dfb73233 |
1862 | } |
1863 | |
6cd62ccf |
1864 | } |
1865 | |
3aee1200 |
1866 | |
77175651 |
1867 | /***************************************************************************** |
1868 | *Function name |
1869 | * check_fields_compatibility : Check for compatibility between two fields : |
1870 | * do they use the same inner structure ? |
1871 | *Input params |
1872 | * event_type1 : event type |
1873 | * event_type2 : event type |
1874 | * field1 : field |
1875 | * field2 : field |
1876 | *Returns : 0 if identical |
1877 | * 1 if not. |
1878 | ****************************************************************************/ |
1879 | gint check_fields_compatibility(LttEventType *event_type1, |
1880 | LttEventType *event_type2, |
1881 | LttField *field1, LttField *field2) |
1882 | { |
1883 | guint different = 0; |
1884 | enum field_status local_fixed_root, local_fixed_parent; |
1885 | guint i; |
1886 | LttType *type1; |
1887 | LttType *type2; |
1888 | |
1889 | if(field1 == NULL) { |
1890 | if(field2 == NULL) goto end; |
1891 | else { |
1892 | different = 1; |
1893 | goto end; |
1894 | } |
1895 | } else if(field2 == NULL) { |
1896 | different = 1; |
1897 | goto end; |
1898 | } |
1899 | |
1900 | g_assert(field1->fixed_root != FIELD_UNKNOWN); |
1901 | g_assert(field2->fixed_root != FIELD_UNKNOWN); |
1902 | g_assert(field1->fixed_parent != FIELD_UNKNOWN); |
1903 | g_assert(field2->fixed_parent != FIELD_UNKNOWN); |
1904 | g_assert(field1->fixed_size != FIELD_UNKNOWN); |
1905 | g_assert(field2->fixed_size != FIELD_UNKNOWN); |
1906 | |
1907 | type1 = field1->field_type; |
1908 | type2 = field2->field_type; |
1909 | |
1910 | size_t current_root_offset; |
1911 | size_t current_offset; |
1912 | enum field_status current_child_status, final_child_status; |
1913 | size_t max_size; |
1914 | |
1915 | if(type1->type_class != type2->type_class) { |
1916 | different = 1; |
1917 | goto end; |
1918 | } |
1919 | if(type1->element_name != type2->element_name) { |
1920 | different = 1; |
1921 | goto end; |
1922 | } |
1923 | |
1924 | switch(type1->type_class) { |
1925 | case LTT_INT: |
1926 | case LTT_UINT: |
1927 | case LTT_FLOAT: |
1928 | case LTT_POINTER: |
1929 | case LTT_LONG: |
1930 | case LTT_ULONG: |
1931 | case LTT_SIZE_T: |
1932 | case LTT_SSIZE_T: |
1933 | case LTT_OFF_T: |
1934 | if(field1->field_size != field2->field_size) { |
1935 | different = 1; |
1936 | goto end; |
1937 | } |
1938 | break; |
1939 | case LTT_ENUM: |
1940 | if(type1->element_number != type2->element_number) { |
1941 | different = 1; |
1942 | goto end; |
1943 | } |
1944 | for(i=0;i<type1->element_number;i++) { |
1945 | if(type1->enum_strings[i] != type2->enum_strings[i]) { |
1946 | different = 1; |
1947 | goto end; |
1948 | } |
1949 | } |
1950 | break; |
1951 | case LTT_SEQUENCE: |
1952 | /* Two elements : size and child */ |
1953 | g_assert(type1->element_number != type2->element_number); |
1954 | for(i=0;i<type1->element_number;i++) { |
1955 | if(check_fields_compatibility(event_type1, event_type2, |
1956 | field1->child[0], field2->child[0])) { |
1957 | different = 1; |
1958 | goto end; |
1959 | } |
1960 | } |
1961 | break; |
1962 | case LTT_STRING: |
1963 | break; |
1964 | case LTT_ARRAY: |
1965 | if(field1->field_size != field2->field_size) { |
1966 | different = 1; |
1967 | goto end; |
1968 | } |
1969 | /* Two elements : size and child */ |
1970 | g_assert(type1->element_number != type2->element_number); |
1971 | for(i=0;i<type1->element_number;i++) { |
1972 | if(check_fields_compatibility(event_type1, event_type2, |
1973 | field1->child[0], field2->child[0])) { |
1974 | different = 1; |
1975 | goto end; |
1976 | } |
1977 | } |
1978 | break; |
1979 | case LTT_STRUCT: |
1980 | case LTT_UNION: |
1981 | if(type1->element_number != type2->element_number) { |
1982 | different = 1; |
1983 | break; |
1984 | } |
1985 | for(i=0;i<type1->element_number;i++) { |
1986 | if(check_fields_compatibility(event_type1, event_type2, |
1987 | field1->child[0], field2->child[0])) { |
1988 | different = 1; |
1989 | goto end; |
1990 | } |
1991 | } |
1992 | break; |
1993 | } |
1994 | end: |
1995 | return different; |
1996 | } |
1997 | |
1998 | |
1999 | |
3aee1200 |
2000 | |
2001 | #if 0 |
6cd62ccf |
2002 | /***************************************************************************** |
2003 | *Function name |
2004 | * getFieldtypeSize: get the size of the field type (primitive type) |
2005 | *Input params |
6cd62ccf |
2006 | * evT : event type |
2007 | * offsetRoot : offset from the root |
2008 | * offsetParent : offset from the parrent |
2009 | * fld : field |
2010 | * evD : event data, it may be NULL |
2011 | *Return value |
2012 | * int : size of the field |
2013 | ****************************************************************************/ |
2014 | |
3aee1200 |
2015 | static inline gint getFieldtypeSize(LttTracefile *tf, |
21182d4a |
2016 | LttEventType * evT, gint offsetRoot, |
3aee1200 |
2017 | gint offsetParent, LttField * fld, void *evD) |
6cd62ccf |
2018 | { |
21182d4a |
2019 | gint size, size1, element_number, i, offset1, offset2; |
963b5f2d |
2020 | LttType * type = fld->field_type; |
6cd62ccf |
2021 | |
3aee1200 |
2022 | /* This likely has been tested with gcov : half of them.. */ |
2023 | if(unlikely(fld->field_fixed == 1)){ |
2024 | /* tested : none */ |
2025 | if(unlikely(fld == evT->root_field)) { |
2026 | size = fld->field_size; |
2027 | goto end_getFieldtypeSize; |
21182d4a |
2028 | } |
3aee1200 |
2029 | } |
6cd62ccf |
2030 | |
3aee1200 |
2031 | /* From gcov profiling : half string, half struct, can we gain something |
2032 | * from that ? (Mathieu) */ |
2033 | switch(type->type_class) { |
2034 | case LTT_ARRAY: |
2035 | element_number = (int) type->element_number; |
2036 | if(fld->field_fixed == -1){ |
2037 | size = getFieldtypeSize(tf, evT, offsetRoot, |
2038 | 0,fld->child[0], NULL); |
2039 | if(size == 0){ //has string or sequence |
cf74a6f1 |
2040 | fld->field_fixed = 0; |
3aee1200 |
2041 | }else{ |
2042 | fld->field_fixed = 1; |
2043 | size *= element_number; |
a0d63196 |
2044 | } |
3aee1200 |
2045 | }else if(fld->field_fixed == 0){// has string or sequence |
cf74a6f1 |
2046 | size = 0; |
3aee1200 |
2047 | for(i=0;i<element_number;i++){ |
2048 | size += getFieldtypeSize(tf, evT, offsetRoot+size,size, |
2049 | fld->child[0], evD+size); |
cf74a6f1 |
2050 | } |
3aee1200 |
2051 | }else size = fld->field_size; |
2052 | if(unlikely(!evD)){ |
a0d63196 |
2053 | fld->fixed_root = (offsetRoot==-1) ? 0 : 1; |
2054 | fld->fixed_parent = (offsetParent==-1) ? 0 : 1; |
3aee1200 |
2055 | } |
cf74a6f1 |
2056 | |
3aee1200 |
2057 | break; |
2058 | |
2059 | case LTT_SEQUENCE: |
2060 | size1 = (int) ltt_type_size(fac, type); |
2061 | if(fld->field_fixed == -1){ |
2062 | fld->sequ_number_size = size1; |
2063 | fld->field_fixed = 0; |
2064 | size = getFieldtypeSize(evT, offsetRoot, |
2065 | 0,fld->child[0], NULL); |
2066 | fld->element_size = size; |
2067 | }else{//0: sequence |
2068 | element_number = getIntNumber(tf,size1,evD); |
2069 | type->element_number = element_number; |
2070 | if(fld->element_size > 0){ |
2071 | size = element_number * fld->element_size; |
2072 | }else{//sequence has string or sequence |
2073 | size = 0; |
cf74a6f1 |
2074 | for(i=0;i<element_number;i++){ |
3aee1200 |
2075 | size += getFieldtypeSize(tf, evT, |
2076 | offsetRoot+size+size1,size+size1, |
2077 | fld->child[0], evD+size+size1); |
cf74a6f1 |
2078 | } |
3aee1200 |
2079 | } |
2080 | size += size1; |
2081 | } |
2082 | if(unlikely(!evD)){ |
d37b2aaa |
2083 | fld->fixed_root = (offsetRoot==-1) ? 0 : 1; |
2084 | fld->fixed_parent = (offsetParent==-1) ? 0 : 1; |
3aee1200 |
2085 | } |
cf74a6f1 |
2086 | |
3aee1200 |
2087 | break; |
2088 | |
2089 | case LTT_STRING: |
2090 | size = 0; |
2091 | if(fld->field_fixed == -1){ |
2092 | fld->field_fixed = 0; |
2093 | }else{//0: string |
2094 | /* Hope my implementation is faster than strlen (Mathieu) */ |
2095 | char *ptr=(char*)evD; |
2096 | size = 1; |
2097 | /* from gcov : many many strings are empty, make it the common case.*/ |
2098 | while(unlikely(*ptr != '\0')) { size++; ptr++; } |
2099 | //size = ptr - (char*)evD + 1; //include end : '\0' |
2100 | } |
2101 | fld->fixed_root = (offsetRoot==-1) ? 0 : 1; |
2102 | fld->fixed_parent = (offsetParent==-1) ? 0 : 1; |
2103 | |
2104 | break; |
2105 | |
2106 | case LTT_STRUCT: |
2107 | element_number = (int) type->element_number; |
2108 | size = 0; |
2109 | /* tested with gcov */ |
2110 | if(unlikely(fld->field_fixed == -1)){ |
2111 | offset1 = offsetRoot; |
2112 | offset2 = 0; |
2113 | for(i=0;i<element_number;i++){ |
2114 | size1=getFieldtypeSize(tf, evT,offset1,offset2, |
2115 | fld->child[i], NULL); |
2116 | if(likely(size1 > 0 && size >= 0)){ |
2117 | size += size1; |
2118 | if(likely(offset1 >= 0)) offset1 += size1; |
2119 | offset2 += size1; |
2120 | }else{ |
2121 | size = -1; |
2122 | offset1 = -1; |
2123 | offset2 = -1; |
2124 | } |
a0d63196 |
2125 | } |
3aee1200 |
2126 | if(unlikely(size == -1)){ |
2127 | fld->field_fixed = 0; |
2128 | size = 0; |
2129 | }else fld->field_fixed = 1; |
2130 | }else if(likely(fld->field_fixed == 0)){ |
2131 | offset1 = offsetRoot; |
2132 | offset2 = 0; |
2133 | for(i=0;unlikely(i<element_number);i++){ |
2134 | size=getFieldtypeSize(tf, evT, offset1, offset2, |
2135 | fld->child[i], evD+offset2); |
2136 | offset1 += size; |
2137 | offset2 += size; |
2138 | } |
2139 | size = offset2; |
2140 | }else size = fld->field_size; |
2141 | fld->fixed_root = (offsetRoot==-1) ? 0 : 1; |
2142 | fld->fixed_parent = (offsetParent==-1) ? 0 : 1; |
2143 | break; |
2144 | |
2145 | default: |
2146 | if(unlikely(fld->field_fixed == -1)){ |
2147 | size = (int) ltt_type_size(LTT_GET_BO(tf), type); |
2148 | fld->field_fixed = 1; |
2149 | }else size = fld->field_size; |
2150 | if(unlikely(!evD)){ |
2151 | fld->fixed_root = (offsetRoot==-1) ? 0 : 1; |
2152 | fld->fixed_parent = (offsetParent==-1) ? 0 : 1; |
2153 | } |
2154 | break; |
cf74a6f1 |
2155 | } |
2156 | |
6cd62ccf |
2157 | fld->offset_root = offsetRoot; |
2158 | fld->offset_parent = offsetParent; |
6cd62ccf |
2159 | fld->field_size = size; |
2160 | |
21182d4a |
2161 | end_getFieldtypeSize: |
2162 | |
6cd62ccf |
2163 | return size; |
2164 | } |
3aee1200 |
2165 | #endif //0 |
6cd62ccf |
2166 | |
2167 | /***************************************************************************** |
2168 | *Function name |
eed2ef37 |
2169 | * ltt_get_int : get an integer number |
6cd62ccf |
2170 | *Input params |
3aee1200 |
2171 | * reverse_byte_order: must we reverse the byte order ? |
6cd62ccf |
2172 | * size : the size of the integer |
3aee1200 |
2173 | * ptr : the data pointer |
6cd62ccf |
2174 | *Return value |
cf74a6f1 |
2175 | * gint64 : a 64 bits integer |
6cd62ccf |
2176 | ****************************************************************************/ |
2177 | |
eed2ef37 |
2178 | gint64 ltt_get_int(gboolean reverse_byte_order, gint size, void *data) |
6cd62ccf |
2179 | { |
3aee1200 |
2180 | gint64 val; |
cf74a6f1 |
2181 | |
2182 | switch(size) { |
3aee1200 |
2183 | case 1: val = *((gint8*)data); break; |
2184 | case 2: val = ltt_get_int16(reverse_byte_order, data); break; |
2185 | case 4: val = ltt_get_int32(reverse_byte_order, data); break; |
2186 | case 8: val = ltt_get_int64(reverse_byte_order, data); break; |
2187 | default: val = ltt_get_int64(reverse_byte_order, data); |
2188 | g_critical("get_int : integer size %d unknown", size); |
cf74a6f1 |
2189 | break; |
2190 | } |
2191 | |
3aee1200 |
2192 | return val; |
6cd62ccf |
2193 | } |
3aee1200 |
2194 | |
6cd62ccf |
2195 | /***************************************************************************** |
2196 | *Function name |
eed2ef37 |
2197 | * ltt_get_uint : get an unsigned integer number |
6cd62ccf |
2198 | *Input params |
3aee1200 |
2199 | * reverse_byte_order: must we reverse the byte order ? |
2200 | * size : the size of the integer |
2201 | * ptr : the data pointer |
2202 | *Return value |
2203 | * guint64 : a 64 bits unsigned integer |
6cd62ccf |
2204 | ****************************************************************************/ |
2205 | |
eed2ef37 |
2206 | guint64 ltt_get_uint(gboolean reverse_byte_order, gint size, void *data) |
6cd62ccf |
2207 | { |
3aee1200 |
2208 | guint64 val; |
2209 | |
2210 | switch(size) { |
2211 | case 1: val = *((gint8*)data); break; |
2212 | case 2: val = ltt_get_uint16(reverse_byte_order, data); break; |
2213 | case 4: val = ltt_get_uint32(reverse_byte_order, data); break; |
2214 | case 8: val = ltt_get_uint64(reverse_byte_order, data); break; |
2215 | default: val = ltt_get_uint64(reverse_byte_order, data); |
2216 | g_critical("get_uint : unsigned integer size %d unknown", |
2217 | size); |
2218 | break; |
2219 | } |
2220 | |
2221 | return val; |
6cd62ccf |
2222 | } |
3aee1200 |
2223 | |
2224 | |
a5dcde2f |
2225 | /* get the node name of the system */ |
2226 | |
2227 | char * ltt_trace_system_description_node_name (LttSystemDescription * s) |
2228 | { |
2229 | return s->node_name; |
2230 | } |
2231 | |
2232 | |
2233 | /* get the domain name of the system */ |
2234 | |
2235 | char * ltt_trace_system_description_domain_name (LttSystemDescription * s) |
2236 | { |
2237 | return s->domain_name; |
2238 | } |
2239 | |
2240 | |
2241 | /* get the description of the system */ |
2242 | |
2243 | char * ltt_trace_system_description_description (LttSystemDescription * s) |
2244 | { |
2245 | return s->description; |
2246 | } |
2247 | |
2248 | |
2249 | /* get the start time of the trace */ |
2250 | |
2251 | LttTime ltt_trace_system_description_trace_start_time(LttSystemDescription *s) |
2252 | { |
2253 | return s->trace_start; |
2254 | } |
2255 | |
18206708 |
2256 | |
2257 | LttTracefile *ltt_tracefile_new() |
2258 | { |
2259 | return g_new(LttTracefile, 1); |
2260 | } |
2261 | |
2262 | void ltt_tracefile_destroy(LttTracefile *tf) |
2263 | { |
2264 | g_free(tf); |
2265 | } |
2266 | |
2267 | void ltt_tracefile_copy(LttTracefile *dest, const LttTracefile *src) |
2268 | { |
2269 | *dest = *src; |
2270 | } |
2271 | |
3aee1200 |
2272 | /* Before library loading... */ |
2273 | |
2274 | static void __attribute__((constructor)) init(void) |
2275 | { |
2276 | LTT_FACILITY_NAME_HEARTBEAT = g_quark_from_string("heartbeat"); |
2277 | LTT_EVENT_NAME_HEARTBEAT = g_quark_from_string("heartbeat"); |
2278 | |
2279 | LTT_TRACEFILE_NAME_FACILITIES = g_quark_from_string("control/facilities"); |
2280 | } |
2281 | |