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