fix event reading cycle count
[lttv.git] / ltt / branches / poly / ltt / tracefile.c
CommitLineData
449cb9d7 1/* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Xiangxiu Yang
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
16 * MA 02111-1307, USA.
17 */
18
6cd62ccf 19#include <stdio.h>
20#include <fcntl.h>
8d1e6362 21#include <string.h>
22#include <dirent.h>
6cd62ccf 23#include <sys/stat.h>
24#include <sys/types.h>
8d1e6362 25#include <errno.h>
26#include <unistd.h>
6cd62ccf 27
ef35d837 28// For realpath
29#include <limits.h>
30#include <stdlib.h>
31
32
6cd62ccf 33#include "parser.h"
a5dcde2f 34#include <ltt/ltt.h>
35#include "ltt-private.h"
963b5f2d 36#include <ltt/trace.h>
a5dcde2f 37#include <ltt/facility.h>
c02ea99f 38#include <ltt/event.h>
8d1e6362 39#include <ltt/type.h>
6cd62ccf 40
963b5f2d 41#define DIR_NAME_SIZE 256
51b5991e 42#define __UNUSED__ __attribute__((__unused__))
6cd62ccf 43
a1062ddd 44#define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
45#define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format)
46
8959a0c8 47
48/* obtain the time of an event */
49
50static inline LttTime getEventTime(LttTracefile * tf);
51
52
6cd62ccf 53/* set the offset of the fields belonging to the event,
54 need the information of the archecture */
40331ba8 55void setFieldsOffset(LttTracefile *tf,LttEventType *evT,void *evD,LttTrace *t);
6cd62ccf 56
57/* get the size of the field type according to the archtecture's
58 size and endian type(info of the archecture) */
40331ba8 59int getFieldtypeSize(LttTracefile * tf, LttEventType * evT, int offsetRoot,
60 int offsetParent, LttField *fld, void *evD, LttTrace* t);
6cd62ccf 61
62/* read a fixed size or a block information from the file (fd) */
63int readFile(int fd, void * buf, size_t size, char * mesg);
963b5f2d 64int readBlock(LttTracefile * tf, int whichBlock);
6cd62ccf 65
66/* calculate cycles per nsec for current block */
963b5f2d 67void getCyclePerNsec(LttTracefile * t);
6cd62ccf 68
69/* reinitialize the info of the block which is already in the buffer */
963b5f2d 70void updateTracefile(LttTracefile * tf);
6cd62ccf 71
72/* go to the next event */
963b5f2d 73int skipEvent(LttTracefile * t);
6cd62ccf 74
6cd62ccf 75
43da6a59 76/* Functions to parse system.xml file (using glib xml parser) */
51b5991e 77static void parser_start_element (GMarkupParseContext __UNUSED__ *context,
43da6a59 78 const gchar *element_name,
79 const gchar **attribute_names,
80 const gchar **attribute_values,
81 gpointer user_data,
82 GError **error)
83{
84 int i=0;
85 LttSystemDescription* des = (LttSystemDescription* )user_data;
86 if(strcmp("system", element_name)){
2a74fbf4 87 *error = g_error_new(G_MARKUP_ERROR,
88 G_LOG_LEVEL_WARNING,
89 "This is not system.xml file");
90 return;
43da6a59 91 }
92
93 while(attribute_names[i]){
94 if(strcmp("node_name", attribute_names[i])==0){
95 des->node_name = g_strdup(attribute_values[i]);
96 }else if(strcmp("domainname", attribute_names[i])==0){
97 des->domain_name = g_strdup(attribute_values[i]);
98 }else if(strcmp("cpu", attribute_names[i])==0){
99 des->nb_cpu = atoi(attribute_values[i]);
100 }else if(strcmp("arch_size", attribute_names[i])==0){
101 if(strcmp(attribute_values[i],"LP32") == 0) des->size = LTT_LP32;
102 else if(strcmp(attribute_values[i],"ILP32") == 0) des->size = LTT_ILP32;
103 else if(strcmp(attribute_values[i],"LP64") == 0) des->size = LTT_LP64;
104 else if(strcmp(attribute_values[i],"ILP64") == 0) des->size = LTT_ILP64;
105 else if(strcmp(attribute_values[i],"UNKNOWN") == 0) des->size = LTT_UNKNOWN;
106 }else if(strcmp("endian", attribute_names[i])==0){
107 if(strcmp(attribute_values[i],"LITTLE_ENDIAN") == 0)
108 des->endian = LTT_LITTLE_ENDIAN;
109 else if(strcmp(attribute_values[i],"BIG_ENDIAN") == 0)
110 des->endian = LTT_BIG_ENDIAN;
111 }else if(strcmp("kernel_name", attribute_names[i])==0){
112 des->kernel_name = g_strdup(attribute_values[i]);
113 }else if(strcmp("kernel_release", attribute_names[i])==0){
114 des->kernel_release = g_strdup(attribute_values[i]);
115 }else if(strcmp("kernel_version", attribute_names[i])==0){
116 des->kernel_version = g_strdup(attribute_values[i]);
117 }else if(strcmp("machine", attribute_names[i])==0){
118 des->machine = g_strdup(attribute_values[i]);
119 }else if(strcmp("processor", attribute_names[i])==0){
120 des->processor = g_strdup(attribute_values[i]);
121 }else if(strcmp("hardware_platform", attribute_names[i])==0){
122 des->hardware_platform = g_strdup(attribute_values[i]);
123 }else if(strcmp("operating_system", attribute_names[i])==0){
124 des->operating_system = g_strdup(attribute_values[i]);
125 }else if(strcmp("ltt_major_version", attribute_names[i])==0){
126 des->ltt_major_version = atoi(attribute_values[i]);
127 }else if(strcmp("ltt_minor_version", attribute_names[i])==0){
128 des->ltt_minor_version = atoi(attribute_values[i]);
129 }else if(strcmp("ltt_block_size", attribute_names[i])==0){
130 des->ltt_block_size = atoi(attribute_values[i]);
131 }else{
2a74fbf4 132 *error = g_error_new(G_MARKUP_ERROR,
133 G_LOG_LEVEL_WARNING,
134 "Not a valid attribute");
135 return;
43da6a59 136 }
137 i++;
138 }
139}
140
51b5991e 141static void parser_characters (GMarkupParseContext __UNUSED__ *context,
43da6a59 142 const gchar *text,
51b5991e 143 gsize __UNUSED__ text_len,
43da6a59 144 gpointer user_data,
51b5991e 145 GError __UNUSED__ **error)
43da6a59 146{
147 LttSystemDescription* des = (LttSystemDescription* )user_data;
148 des->description = g_strdup(text);
149}
150
151
6cd62ccf 152/*****************************************************************************
153 *Function name
963b5f2d 154 * ltt_tracefile_open : open a trace file, construct a LttTracefile
6cd62ccf 155 *Input params
963b5f2d 156 * t : the trace containing the tracefile
157 * fileName : path name of the trace file
6cd62ccf 158 *Return value
963b5f2d 159 * : a pointer to a tracefile
6cd62ccf 160 ****************************************************************************/
161
963b5f2d 162LttTracefile* ltt_tracefile_open(LttTrace * t, char * fileName)
6cd62ccf 163{
963b5f2d 164 LttTracefile * tf;
165 struct stat lTDFStat; /* Trace data file status */
6cd62ccf 166
963b5f2d 167 tf = g_new(LttTracefile, 1);
6cd62ccf 168
169 //open the file
963b5f2d 170 tf->name = g_strdup(fileName);
171 tf->trace = t;
6cd62ccf 172 tf->fd = open(fileName, O_RDONLY, 0);
173 if(tf->fd < 0){
2a74fbf4 174 g_warning("Unable to open input data file %s\n", fileName);
175 g_free(tf->name);
176 g_free(tf);
177 return NULL;
6cd62ccf 178 }
179
180 // Get the file's status
181 if(fstat(tf->fd, &lTDFStat) < 0){
2a74fbf4 182 g_warning("Unable to get the status of the input data file %s\n", fileName);
183 g_free(tf->name);
184 close(tf->fd);
185 g_free(tf);
186 return NULL;
6cd62ccf 187 }
188
189 // Is the file large enough to contain a trace
8d1e6362 190 if(lTDFStat.st_size < (off_t)(sizeof(BlockStart) + EVENT_HEADER_SIZE)){
8710c6c7 191 g_print("The input data file %s does not contain a trace\n", fileName);
663bd9ff 192 g_free(tf->name);
193 close(tf->fd);
194 g_free(tf);
8710c6c7 195 return NULL;
6cd62ccf 196 }
197
198 //store the size of the file
199 tf->file_size = lTDFStat.st_size;
963b5f2d 200 tf->block_size = t->system_description->ltt_block_size;
201 tf->block_number = tf->file_size / tf->block_size;
202 tf->which_block = 0;
6cd62ccf 203
204 //allocate memory to contain the info of a block
963b5f2d 205 tf->buffer = (void *) g_new(char, t->system_description->ltt_block_size);
6cd62ccf 206
963b5f2d 207 //read the first block
208 if(readBlock(tf,1)) exit(1);
6cd62ccf 209
210 return tf;
211}
212
6cd62ccf 213
214/*****************************************************************************
963b5f2d 215 *Open control and per cpu tracefiles
6cd62ccf 216 ****************************************************************************/
217
963b5f2d 218void ltt_tracefile_open_cpu(LttTrace *t, char * tracefile_name)
6cd62ccf 219{
963b5f2d 220 LttTracefile * tf;
221 tf = ltt_tracefile_open(t,tracefile_name);
4a6c8e36 222 if(!tf) return;
963b5f2d 223 t->per_cpu_tracefile_number++;
224 g_ptr_array_add(t->per_cpu_tracefiles, tf);
6cd62ccf 225}
226
2a74fbf4 227gint ltt_tracefile_open_control(LttTrace *t, char * control_name)
6cd62ccf 228{
963b5f2d 229 LttTracefile * tf;
c02ea99f 230 LttEvent ev;
963b5f2d 231 LttFacility * f;
963b5f2d 232 void * pos;
233 FacilityLoad fLoad;
8d1e6362 234 unsigned int i;
963b5f2d 235
236 tf = ltt_tracefile_open(t,control_name);
2a74fbf4 237 if(!tf) {
238 g_warning("ltt_tracefile_open_control : bad file descriptor");
239 return -1;
240 }
963b5f2d 241 t->control_tracefile_number++;
242 g_ptr_array_add(t->control_tracefiles,tf);
243
244 //parse facilities tracefile to get base_id
542ceddd 245 if(strcmp(&control_name[strlen(control_name)-10],"facilities") ==0){
963b5f2d 246 while(1){
c02ea99f 247 if(!ltt_tracefile_read(tf,&ev)) return 0; // end of file
40331ba8 248
c02ea99f 249 if(ev.event_id == TRACE_FACILITY_LOAD){
250 pos = ev.data;
963b5f2d 251 fLoad.name = (char*)pos;
47a166fc 252 fLoad.checksum = *(LttChecksum*)(pos + strlen(fLoad.name));
cbd41522 253 fLoad.base_code = *(guint32 *)(pos + strlen(fLoad.name) + sizeof(LttChecksum));
963b5f2d 254
255 for(i=0;i<t->facility_number;i++){
256 f = (LttFacility*)g_ptr_array_index(t->facilities,i);
257 if(strcmp(f->name,fLoad.name)==0 && fLoad.checksum==f->checksum){
258 f->base_id = fLoad.base_code;
259 break;
260 }
261 }
2a74fbf4 262 if(i==t->facility_number) {
8d1e6362 263 g_warning("Facility: %s, checksum: %u is not found",
264 fLoad.name,(unsigned int)fLoad.checksum);
2a74fbf4 265 return -1;
266 }
c02ea99f 267 }else if(ev.event_id == TRACE_BLOCK_START){
40331ba8 268 continue;
c02ea99f 269 }else if(ev.event_id == TRACE_BLOCK_END){
40331ba8 270 break;
2a74fbf4 271 }else {
8d1e6362 272 g_warning("Not valid facilities trace file");
2a74fbf4 273 return -1;
274 }
963b5f2d 275 }
276 }
2a74fbf4 277 return 0;
6cd62ccf 278}
279
280/*****************************************************************************
281 *Function name
963b5f2d 282 * ltt_tracefile_close: close a trace file,
6cd62ccf 283 *Input params
963b5f2d 284 * t : tracefile which will be closed
6cd62ccf 285 ****************************************************************************/
286
963b5f2d 287void ltt_tracefile_close(LttTracefile *t)
6cd62ccf 288{
963b5f2d 289 g_free(t->name);
290 g_free(t->buffer);
663bd9ff 291 close(t->fd);
963b5f2d 292 g_free(t);
293}
6cd62ccf 294
6cd62ccf 295
963b5f2d 296/*****************************************************************************
297 *Get system information
298 ****************************************************************************/
2a74fbf4 299gint getSystemInfo(LttSystemDescription* des, char * pathname)
963b5f2d 300{
301 FILE * fp;
963b5f2d 302 char buf[DIR_NAME_SIZE];
43da6a59 303
304 GMarkupParseContext * context;
2a74fbf4 305 GError * error = NULL;
43da6a59 306 GMarkupParser markup_parser =
307 {
308 parser_start_element,
8d1e6362 309 NULL,
43da6a59 310 parser_characters,
311 NULL, /* passthrough */
312 NULL /* error */
313 };
963b5f2d 314
315 fp = fopen(pathname,"r");
316 if(!fp){
2a74fbf4 317 g_warning("Can not open file : %s\n", pathname);
318 return -1;
6cd62ccf 319 }
963b5f2d 320
43da6a59 321 context = g_markup_parse_context_new(&markup_parser, 0, des,NULL);
6cd62ccf 322
43da6a59 323 while(fgets(buf,DIR_NAME_SIZE, fp) != NULL){
324 if(!g_markup_parse_context_parse(context, buf, DIR_NAME_SIZE, &error)){
2a74fbf4 325 if(error != NULL) {
326 g_warning("Can not parse xml file: \n%s\n", error->message);
327 g_error_free(error);
328 }
329 g_markup_parse_context_free(context);
330 fclose(fp);
331 return -1;
43da6a59 332 }
963b5f2d 333 }
2a74fbf4 334 g_markup_parse_context_free(context);
963b5f2d 335 fclose(fp);
2a74fbf4 336 return 0;
6cd62ccf 337}
338
339/*****************************************************************************
963b5f2d 340 *The following functions get facility/tracefile information
6cd62ccf 341 ****************************************************************************/
342
2a74fbf4 343gint getFacilityInfo(LttTrace *t, char* eventdefs)
6cd62ccf 344{
963b5f2d 345 DIR * dir;
346 struct dirent *entry;
347 char * ptr;
8d1e6362 348 unsigned int i,j;
963b5f2d 349 LttFacility * f;
350 LttEventType * et;
e8bb1a73 351 char name[DIR_NAME_SIZE];
963b5f2d 352
353 dir = opendir(eventdefs);
2a74fbf4 354 if(!dir) {
355 g_warning("Can not open directory: %s\n", eventdefs);
356 return -1;
357 }
963b5f2d 358
359 while((entry = readdir(dir)) != NULL){
360 ptr = &entry->d_name[strlen(entry->d_name)-4];
361 if(strcmp(ptr,".xml") != 0) continue;
e8bb1a73 362 strcpy(name,eventdefs);
363 strcat(name,entry->d_name);
364 ltt_facility_open(t,name);
963b5f2d 365 }
366 closedir(dir);
367
963b5f2d 368 for(j=0;j<t->facility_number;j++){
8710c6c7 369 f = (LttFacility*)g_ptr_array_index(t->facilities, j);
963b5f2d 370 for(i=0; i<f->event_number; i++){
371 et = f->events[i];
40331ba8 372 setFieldsOffset(NULL, et, NULL, t);
963b5f2d 373 }
374 }
2a74fbf4 375 return 0;
963b5f2d 376}
6cd62ccf 377
2a74fbf4 378gint getControlFileInfo(LttTrace *t, char* control)
6cd62ccf 379{
963b5f2d 380 DIR * dir;
381 struct dirent *entry;
e8bb1a73 382 char name[DIR_NAME_SIZE];
963b5f2d 383
384 dir = opendir(control);
2a74fbf4 385 if(!dir) {
386 g_warning("Can not open directory: %s\n", control);
387 return -1;
388 }
963b5f2d 389
390 while((entry = readdir(dir)) != NULL){
8710c6c7 391 if(strcmp(entry->d_name,"facilities") != 0 &&
392 strcmp(entry->d_name,"interrupts") != 0 &&
963b5f2d 393 strcmp(entry->d_name,"processes") != 0) continue;
394
e8bb1a73 395 strcpy(name,control);
396 strcat(name,entry->d_name);
2a74fbf4 397 if(ltt_tracefile_open_control(t,name))
398 return -1;
963b5f2d 399 }
400 closedir(dir);
2a74fbf4 401 return 0;
6cd62ccf 402}
403
2a74fbf4 404gint getCpuFileInfo(LttTrace *t, char* cpu)
6cd62ccf 405{
963b5f2d 406 DIR * dir;
407 struct dirent *entry;
e8bb1a73 408 char name[DIR_NAME_SIZE];
963b5f2d 409
410 dir = opendir(cpu);
2a74fbf4 411 if(!dir) {
412 g_warning("Can not open directory: %s\n", cpu);
413 return -1;
414 }
963b5f2d 415
416 while((entry = readdir(dir)) != NULL){
8710c6c7 417 if(strcmp(entry->d_name,".") != 0 &&
a614481a 418 strcmp(entry->d_name,"..") != 0 &&
419 strcmp(entry->d_name,".svn") != 0){
e8bb1a73 420 strcpy(name,cpu);
421 strcat(name,entry->d_name);
422 ltt_tracefile_open_cpu(t,name);
963b5f2d 423 }else continue;
424 }
425 closedir(dir);
2a74fbf4 426 return 0;
6cd62ccf 427}
428
963b5f2d 429/*****************************************************************************
430 *A trace is specified as a pathname to the directory containing all the
431 *associated data (control tracefiles, per cpu tracefiles, event
432 *descriptions...).
433 *
434 *When a trace is closed, all the associated facilities, types and fields
435 *are released as well.
8d1e6362 436 */
437
438
439/****************************************************************************
440 * get_absolute_pathname
803229fa 441 *
8d1e6362 442 * return the unique pathname in the system
443 *
ef35d837 444 * MD : Fixed this function so it uses realpath, dealing well with
445 * forgotten cases (.. were not used correctly before).
803229fa 446 *
963b5f2d 447 ****************************************************************************/
9f797243 448void get_absolute_pathname(const char *pathname, char * abs_pathname)
449{
9f797243 450 abs_pathname[0] = '\0';
803229fa 451
ef35d837 452 if ( realpath (pathname, abs_pathname) != NULL)
453 return;
454 else
455 {
8d1e6362 456 /* error, return the original path unmodified */
ef35d837 457 strcpy(abs_pathname, pathname);
9f797243 458 return;
459 }
ef35d837 460 return;
9f797243 461}
462
f7afe191 463LttTrace *ltt_trace_open(const char *pathname)
6cd62ccf 464{
963b5f2d 465 LttTrace * t;
466 LttSystemDescription * sys_description;
467 char eventdefs[DIR_NAME_SIZE];
468 char info[DIR_NAME_SIZE];
469 char control[DIR_NAME_SIZE];
470 char cpu[DIR_NAME_SIZE];
471 char tmp[DIR_NAME_SIZE];
9f797243 472 char abs_path[DIR_NAME_SIZE];
963b5f2d 473 gboolean has_slash = FALSE;
474
9f797243 475 get_absolute_pathname(pathname, abs_path);
963b5f2d 476 //establish the pathname to different directories
9f797243 477 if(abs_path[strlen(abs_path)-1] == '/')has_slash = TRUE;
478 strcpy(eventdefs,abs_path);
963b5f2d 479 if(!has_slash)strcat(eventdefs,"/");
480 strcat(eventdefs,"eventdefs/");
481
9f797243 482 strcpy(info,abs_path);
963b5f2d 483 if(!has_slash)strcat(info,"/");
484 strcat(info,"info/");
485
9f797243 486 strcpy(control,abs_path);
963b5f2d 487 if(!has_slash)strcat(control,"/");
488 strcat(control,"control/");
489
9f797243 490 strcpy(cpu,abs_path);
963b5f2d 491 if(!has_slash)strcat(cpu,"/");
492 strcat(cpu,"cpu/");
493
494 //new trace
963b5f2d 495 sys_description = g_new(LttSystemDescription, 1);
2a74fbf4 496 t = g_new(LttTrace, 1);
9f797243 497 t->pathname = g_strdup(abs_path);
963b5f2d 498 t->facility_number = 0;
499 t->control_tracefile_number = 0;
500 t->per_cpu_tracefile_number = 0;
501 t->system_description = sys_description;
502 t->control_tracefiles = g_ptr_array_new();
503 t->per_cpu_tracefiles = g_ptr_array_new();
504 t->facilities = g_ptr_array_new();
505 getDataEndianType(&(t->my_arch_size), &(t->my_arch_endian));
506
507 //get system description
508 strcpy(tmp,info);
509 strcat(tmp,"system.xml");
2a74fbf4 510 if(getSystemInfo(sys_description, tmp)) {
511 g_ptr_array_free(t->facilities, TRUE);
512 g_ptr_array_free(t->per_cpu_tracefiles, TRUE);
513 g_ptr_array_free(t->control_tracefiles, TRUE);
514 g_free(sys_description);
515 g_free(t->pathname);
516 g_free(t);
517 return NULL;
518 }
519
520
963b5f2d 521
b333a76b 522 //get facilities info
2a74fbf4 523 if(getFacilityInfo(t,eventdefs)) {
524 g_ptr_array_free(t->facilities, TRUE);
525 g_ptr_array_free(t->per_cpu_tracefiles, TRUE);
526 g_ptr_array_free(t->control_tracefiles, TRUE);
527 g_free(sys_description);
528 g_free(t->pathname);
529 g_free(t);
530 return NULL;
531 }
b333a76b 532
963b5f2d 533 //get control tracefile info
a00149f6 534 getControlFileInfo(t,control);
535 /*
2a74fbf4 536 if(getControlFileInfo(t,control)) {
537 g_ptr_array_free(t->facilities, TRUE);
538 g_ptr_array_free(t->per_cpu_tracefiles, TRUE);
539 g_ptr_array_free(t->control_tracefiles, TRUE);
540 g_free(sys_description);
541 g_free(t->pathname);
542 g_free(t);
543 return NULL;
a00149f6 544 }*/ // With fatal error
963b5f2d 545
546 //get cpu tracefile info
2a74fbf4 547 if(getCpuFileInfo(t,cpu)) {
548 g_ptr_array_free(t->facilities, TRUE);
549 g_ptr_array_free(t->per_cpu_tracefiles, TRUE);
550 g_ptr_array_free(t->control_tracefiles, TRUE);
551 g_free(sys_description);
552 g_free(t->pathname);
553 g_free(t);
554 return NULL;
555 }
963b5f2d 556
963b5f2d 557 return t;
6cd62ccf 558}
559
49bf71b5 560char * ltt_trace_name(LttTrace *t)
561{
562 return t->pathname;
563}
564
565
f7afe191 566/******************************************************************************
567 * When we copy a trace, we want all the opening actions to happen again :
568 * the trace will be reopened and totally independant from the original.
569 * That's why we call ltt_trace_open.
570 *****************************************************************************/
571LttTrace *ltt_trace_copy(LttTrace *self)
572{
573 return ltt_trace_open(self->pathname);
574}
575
963b5f2d 576void ltt_trace_close(LttTrace *t)
6cd62ccf 577{
8d1e6362 578 unsigned int i;
963b5f2d 579 LttTracefile * tf;
580 LttFacility * f;
581
582 g_free(t->pathname);
583
584 //free system_description
585 g_free(t->system_description->description);
586 g_free(t->system_description->node_name);
587 g_free(t->system_description->domain_name);
588 g_free(t->system_description->kernel_name);
589 g_free(t->system_description->kernel_release);
590 g_free(t->system_description->kernel_version);
591 g_free(t->system_description->machine);
592 g_free(t->system_description->processor);
593 g_free(t->system_description->hardware_platform);
594 g_free(t->system_description->operating_system);
595 g_free(t->system_description);
596
597 //free control_tracefiles
598 for(i=0;i<t->control_tracefile_number;i++){
599 tf = (LttTracefile*)g_ptr_array_index(t->control_tracefiles,i);
600 ltt_tracefile_close(tf);
601 }
09ad4797 602 g_ptr_array_free(t->control_tracefiles, TRUE);
963b5f2d 603
604 //free per_cpu_tracefiles
605 for(i=0;i<t->per_cpu_tracefile_number;i++){
606 tf = (LttTracefile*)g_ptr_array_index(t->per_cpu_tracefiles,i);
607 ltt_tracefile_close(tf);
608 }
09ad4797 609 g_ptr_array_free(t->per_cpu_tracefiles, TRUE);
963b5f2d 610
611 //free facilities
612 for(i=0;i<t->facility_number;i++){
613 f = (LttFacility*)g_ptr_array_index(t->facilities,i);
614 ltt_facility_close(f);
615 }
09ad4797 616 g_ptr_array_free(t->facilities, TRUE);
963b5f2d 617
618 g_free(t);
09ad4797 619
620 g_blow_chunks();
6cd62ccf 621}
622
963b5f2d 623
6cd62ccf 624/*****************************************************************************
963b5f2d 625 *Get the system description of the trace
6cd62ccf 626 ****************************************************************************/
627
963b5f2d 628LttSystemDescription *ltt_trace_system_description(LttTrace *t)
6cd62ccf 629{
963b5f2d 630 return t->system_description;
6cd62ccf 631}
632
633/*****************************************************************************
963b5f2d 634 * The following functions discover the facilities of the trace
6cd62ccf 635 ****************************************************************************/
636
963b5f2d 637unsigned ltt_trace_facility_number(LttTrace *t)
638{
639 return (unsigned)(t->facility_number);
640}
641
642LttFacility *ltt_trace_facility_get(LttTrace *t, unsigned i)
6cd62ccf 643{
963b5f2d 644 return (LttFacility*)g_ptr_array_index(t->facilities, i);
6cd62ccf 645}
646
647/*****************************************************************************
648 *Function name
963b5f2d 649 * ltt_trace_facility_find : find facilities in the trace
6cd62ccf 650 *Input params
963b5f2d 651 * t : the trace
652 * name : facility name
653 *Output params
654 * position : position of the facility in the trace
6cd62ccf 655 *Return value
963b5f2d 656 * : the number of facilities
6cd62ccf 657 ****************************************************************************/
658
963b5f2d 659unsigned ltt_trace_facility_find(LttTrace *t, char *name, unsigned *position)
6cd62ccf 660{
8d1e6362 661 unsigned int i, count=0;
963b5f2d 662 LttFacility * f;
8a3005f3 663 for(i=0;i<t->facility_number;i++){
963b5f2d 664 f = (LttFacility*)g_ptr_array_index(t->facilities, i);
665 if(strcmp(f->name,name)==0){
666 count++;
667 if(count==1) *position = i;
668 }else{
669 if(count) break;
670 }
671 }
672 return count;
6cd62ccf 673}
674
675/*****************************************************************************
963b5f2d 676 * Functions to discover all the event types in the trace
6cd62ccf 677 ****************************************************************************/
678
963b5f2d 679unsigned ltt_trace_eventtype_number(LttTrace *t)
6cd62ccf 680{
8d1e6362 681 unsigned int i;
963b5f2d 682 unsigned count = 0;
683 LttFacility * f;
b445142a 684 for(i=0;i<t->facility_number;i++){
963b5f2d 685 f = (LttFacility*)g_ptr_array_index(t->facilities, i);
686 count += f->event_number;
687 }
688 return count;
6cd62ccf 689}
690
155a7b0a 691/* FIXME : performances could be improved with a better design for this
692 * function */
963b5f2d 693LttFacility * ltt_trace_facility_by_id(LttTrace * trace, unsigned id)
6cd62ccf 694{
cf74a6f1 695 LttFacility * facility = NULL;
8d1e6362 696 unsigned int i;
cf74a6f1 697
963b5f2d 698 for(i=0;i<trace->facility_number;i++){
cf74a6f1 699 LttFacility *iter_facility =
700 (LttFacility*) g_ptr_array_index(trace->facilities,i);
155a7b0a 701 if(unlikely(id >= iter_facility->base_id &&
702 id < iter_facility->base_id + iter_facility->event_number)) {
cf74a6f1 703 facility = iter_facility;
963b5f2d 704 break;
cf74a6f1 705 }
963b5f2d 706 }
cf74a6f1 707
708 return facility;
6cd62ccf 709}
710
963b5f2d 711LttEventType *ltt_trace_eventtype_get(LttTrace *t, unsigned evId)
6cd62ccf 712{
963b5f2d 713 LttFacility * f;
714 f = ltt_trace_facility_by_id(t,evId);
715 if(!f) return NULL;
716 return f->events[evId - f->base_id];
6cd62ccf 717}
718
719/*****************************************************************************
963b5f2d 720 *There is one "per cpu" tracefile for each CPU, numbered from 0 to
721 *the maximum number of CPU in the system. When the number of CPU installed
722 *is less than the maximum, some positions are unused. There are also a
723 *number of "control" tracefiles (facilities, interrupts...).
6cd62ccf 724 ****************************************************************************/
963b5f2d 725unsigned ltt_trace_control_tracefile_number(LttTrace *t)
6cd62ccf 726{
963b5f2d 727 return t->control_tracefile_number;
6cd62ccf 728}
729
963b5f2d 730unsigned ltt_trace_per_cpu_tracefile_number(LttTrace *t)
6cd62ccf 731{
963b5f2d 732 return t->per_cpu_tracefile_number;
6cd62ccf 733}
734
735/*****************************************************************************
963b5f2d 736 *It is possible to search for the tracefiles by name or by CPU position.
737 *The index within the tracefiles of the same type is returned if found
738 *and a negative value otherwise.
6cd62ccf 739 ****************************************************************************/
740
8d1e6362 741int ltt_trace_control_tracefile_find(LttTrace *t, const gchar *name)
6cd62ccf 742{
963b5f2d 743 LttTracefile * tracefile;
8d1e6362 744 unsigned int i;
963b5f2d 745 for(i=0;i<t->control_tracefile_number;i++){
746 tracefile = (LttTracefile*)g_ptr_array_index(t->control_tracefiles, i);
747 if(strcmp(tracefile->name, name)==0)break;
748 }
749 if(i == t->control_tracefile_number) return -1;
750 return i;
6cd62ccf 751}
752
8d1e6362 753/* not really useful. We just have to know that cpu tracefiles
754 * comes before control tracefiles.
755 */
756int ltt_trace_per_cpu_tracefile_find(LttTrace *t, const gchar *name)
6cd62ccf 757{
963b5f2d 758 LttTracefile * tracefile;
8d1e6362 759 unsigned int i;
760 for(i=0;i<t->per_cpu_tracefile_number;i++){
761 tracefile = (LttTracefile*)g_ptr_array_index(t->per_cpu_tracefiles, i);
762 if(strcmp(tracefile->name, name)==0)break;
963b5f2d 763 }
8d1e6362 764 if(i == t->per_cpu_tracefile_number) return -1;
765 return i;
6cd62ccf 766}
767
768/*****************************************************************************
963b5f2d 769 *Get a specific tracefile
6cd62ccf 770 ****************************************************************************/
771
963b5f2d 772LttTracefile *ltt_trace_control_tracefile_get(LttTrace *t, unsigned i)
6cd62ccf 773{
5598cfe3 774 return (LttTracefile*)g_ptr_array_index(t->control_tracefiles, i);
963b5f2d 775}
776
777LttTracefile *ltt_trace_per_cpu_tracefile_get(LttTrace *t, unsigned i)
778{
779 return (LttTracefile*)g_ptr_array_index(t->per_cpu_tracefiles, i);
6cd62ccf 780}
781
487ad181 782/*****************************************************************************
783 * Get the start time and end time of the trace
784 ****************************************************************************/
785
786void ltt_trace_time_span_get(LttTrace *t, LttTime *start, LttTime *end)
787{
788 LttTime startSmall, startTmp, endBig, endTmp;
8d1e6362 789 unsigned int i, j=0;
487ad181 790 LttTracefile * tf;
791
792 for(i=0;i<t->control_tracefile_number;i++){
793 tf = g_ptr_array_index(t->control_tracefiles, i);
794 readBlock(tf,1);
795 startTmp = tf->a_block_start->time;
796 readBlock(tf,tf->block_number);
797 endTmp = tf->a_block_end->time;
798 if(i==0){
799 startSmall = startTmp;
800 endBig = endTmp;
801 j = 1;
802 continue;
803 }
308711e5 804 if(ltt_time_compare(startSmall,startTmp) > 0) startSmall = startTmp;
805 if(ltt_time_compare(endBig,endTmp) < 0) endBig = endTmp;
487ad181 806 }
807
808 for(i=0;i<t->per_cpu_tracefile_number;i++){
809 tf = g_ptr_array_index(t->per_cpu_tracefiles, i);
810 readBlock(tf,1);
811 startTmp = tf->a_block_start->time;
812 readBlock(tf,tf->block_number);
813 endTmp = tf->a_block_end->time;
814 if(j == 0 && i==0){
815 startSmall = startTmp;
816 endBig = endTmp;
817 continue;
818 }
308711e5 819 if(ltt_time_compare(startSmall,startTmp) > 0) startSmall = startTmp;
820 if(ltt_time_compare(endBig,endTmp) < 0) endBig = endTmp;
487ad181 821 }
822
c02ea99f 823 if(start != NULL) *start = startSmall;
824 if(end != NULL) *end = endBig;
487ad181 825}
826
827
6cd62ccf 828/*****************************************************************************
963b5f2d 829 *Get the name of a tracefile
6cd62ccf 830 ****************************************************************************/
831
963b5f2d 832char *ltt_tracefile_name(LttTracefile *tf)
6cd62ccf 833{
963b5f2d 834 return tf->name;
6cd62ccf 835}
836
80da81ad 837/*****************************************************************************
838 * Get the number of blocks in the tracefile
839 ****************************************************************************/
840
841unsigned ltt_tracefile_block_number(LttTracefile *tf)
842{
843 return tf->block_number;
844}
845
6cd62ccf 846/*****************************************************************************
847 *Function name
848 * ltt_tracefile_seek_time: seek to the first event of the trace with time
849 * larger or equal to time
850 *Input params
851 * t : tracefile
852 * time : criteria of the time
6cd62ccf 853 ****************************************************************************/
caf7a67a 854void ltt_tracefile_find_time_block(LttTracefile *t, LttTime time,
855 int start_block, int end_block)
856{
857 int err, tmp_block, s, e;
858 int headTime;
859 int tailTime;
860
861 err=readBlock(t,start_block);
862 if(err) g_error("Can not read tracefile: %s\n", t->name);
863 if(start_block == end_block)return;
864
865 tailTime = ltt_time_compare(t->a_block_end->time, time);
866 if(tailTime >= 0) return;
867
868 err=readBlock(t,end_block);
869 if(err) g_error("Can not read tracefile: %s\n", t->name);
870 if(start_block+1 == end_block)return;
871
872 headTime = ltt_time_compare(t->a_block_start->time, time);
873 if(headTime <= 0 ) return;
874
875 tmp_block = (end_block + start_block)/2;
876 err=readBlock(t,tmp_block);
877 if(err) g_error("Can not read tracefile: %s\n", t->name);
878
879 headTime = ltt_time_compare(t->a_block_start->time, time);
880 tailTime = ltt_time_compare(t->a_block_end->time, time);
881 if(headTime <= 0 && tailTime >= 0) return;
882
883 if(headTime > 0){
884 s = start_block + 1;
885 e = tmp_block - 1;
886 if(s <= e)
887 ltt_tracefile_find_time_block(t, time, s, e);
888 else return;
889 }
890
891 if(tailTime < 0){
892 s = tmp_block + 1;
893 e = end_block - 1;
894 if(s <= e)
895 ltt_tracefile_find_time_block(t, time, s, e);
896 else return;
897 }
898}
899
900void ltt_tracefile_backward_find_time_block(LttTracefile *t, LttTime time)
901{
902 int t_time, h_time, err;
903 err=readBlock(t,t->which_block-1);
904 if(err) g_error("Can not read tracefile: %s\n", t->name);
905 h_time = ltt_time_compare(t->a_block_start->time, time);
906 t_time = ltt_time_compare(t->a_block_end->time, time);
907 if(h_time == 0){
908 int tmp;
909 if(t->which_block == 1) return;
910 err=readBlock(t,t->which_block-1);
911 if(err) g_error("Can not read tracefile: %s\n", t->name);
912 tmp = ltt_time_compare(t->a_block_end->time, time);
913 if(tmp == 0) return ltt_tracefile_seek_time(t, time);
914 err=readBlock(t,t->which_block+1);
915 if(err) g_error("Can not read tracefile: %s\n", t->name);
916 }else if(h_time > 0){
917 ltt_tracefile_find_time_block(t, time, 1, t->which_block);
918 return ltt_tracefile_seek_time(t, time) ;
919 }else{
920 if(t_time >= 0) return ltt_tracefile_seek_time(t, time);
921 err=readBlock(t,t->which_block+1);
922 if(err) g_error("Can not read tracefile: %s\n", t->name);
923 }
924}
6cd62ccf 925
963b5f2d 926void ltt_tracefile_seek_time(LttTracefile *t, LttTime time)
6cd62ccf 927{
928 int err;
963b5f2d 929 LttTime lttTime;
308711e5 930 int headTime = ltt_time_compare(t->a_block_start->time, time);
931 int tailTime = ltt_time_compare(t->a_block_end->time, time);
c02ea99f 932 LttEvent ev;
62e55dd6 933
6cd62ccf 934 if(headTime < 0 && tailTime > 0){
308711e5 935 if(ltt_time_compare(t->a_block_end->time, t->current_event_time) !=0) {
db55eaae 936 lttTime = getEventTime(t);
308711e5 937 err = ltt_time_compare(lttTime, time);
db55eaae 938 if(err > 0){
8d1e6362 939 if(t->which_event==2 || ltt_time_compare(t->prev_event_time,time)<0){
1a3b8cbd 940 return;
db55eaae 941 }else{
942 updateTracefile(t);
943 return ltt_tracefile_seek_time(t, time);
1a3b8cbd 944 }
db55eaae 945 }else if(err < 0){
946 while(1){
c02ea99f 947 if(ltt_tracefile_read(t,&ev) == NULL) {
db55eaae 948 g_print("End of file\n");
949 return;
950 }
951 lttTime = getEventTime(t);
308711e5 952 err = ltt_time_compare(lttTime, time);
db55eaae 953 if(err >= 0)return;
954 }
955 }else return;
956 }else{//we are at the end of the block
957 updateTracefile(t);
958 return ltt_tracefile_seek_time(t, time);
959 }
e37c1372 960 }else if(headTime >= 0){
6cd62ccf 961 if(t->which_block == 1){
962 updateTracefile(t);
963 }else{
1ee6a9af 964 if(ltt_time_compare(t->prev_block_end_time, time) >= 0 ||
965 (t->prev_block_end_time.tv_sec == 0 &&
966 t->prev_block_end_time.tv_nsec == 0 )){
caf7a67a 967 ltt_tracefile_backward_find_time_block(t, time);
6cd62ccf 968 }else{
969 updateTracefile(t);
970 }
971 }
40331ba8 972 }else if(tailTime < 0){
6cd62ccf 973 if(t->which_block != t->block_number){
caf7a67a 974 ltt_tracefile_find_time_block(t, time, t->which_block+1, t->block_number);
975 return ltt_tracefile_seek_time(t, time);
963b5f2d 976 }else {
a8c0f09d 977 t->cur_event_pos = t->buffer + t->block_size;
978 g_print("End of file\n");
963b5f2d 979 return;
980 }
40331ba8 981 }else if(tailTime == 0){
e37c1372 982 t->cur_event_pos = t->last_event_pos;
62e55dd6 983 t->current_event_time = time;
984 t->cur_heart_beat_number = 0;
985 t->prev_event_time.tv_sec = 0;
986 t->prev_event_time.tv_nsec = 0;
40331ba8 987 return;
6cd62ccf 988 }
6cd62ccf 989}
990
80da81ad 991/*****************************************************************************
992 * Seek to the first event with position equal or larger to ep
18206708 993 *
994 * Modified by Mathieu Desnoyers to used faster offset position instead of
995 * re-reading the whole buffer.
80da81ad 996 ****************************************************************************/
997
04b44e05 998void ltt_tracefile_seek_position(LttTracefile *t, const LttEventPosition *ep)
80da81ad 999{
1000 //if we are at the right place, just return
155a7b0a 1001 if(likely(t->which_block == ep->block_num && t->which_event == ep->event_num))
80da81ad 1002 return;
1003
155a7b0a 1004 if(likely(t->which_block == ep->block_num)) updateTracefile(t);
80da81ad 1005 else readBlock(t,ep->block_num);
18206708 1006 //event offset is available
155a7b0a 1007 if(likely(ep->old_position)){
18206708 1008 int err;
1009
1010 t->which_event = ep->event_num;
80da81ad 1011 t->cur_event_pos = t->buffer + ep->event_offset;
18206708 1012 t->prev_event_time = ep->event_time;
1013 t->current_event_time = ep->event_time;
1014 t->cur_heart_beat_number = ep->heart_beat_number;
1015 t->cur_cycle_count = ep->event_cycle_count;
1016
1017 /* This is a workaround for fast position seek */
1018 t->last_event_pos = ep->last_event_pos;
1019 t->prev_block_end_time = ep->prev_block_end_time;
1020 t->prev_event_time = ep->prev_event_time;
1021 t->pre_cycle_count = ep->pre_cycle_count;
1022 t->count = ep->count;
1023 /* end of workaround */
1024
1025 //update the fields of the current event and go to the next event
1026 err = skipEvent(t);
155a7b0a 1027 if(unlikely(err == ERANGE)) g_error("event id is out of range\n");
18206708 1028
80da81ad 1029 return;
1030 }
1031
18206708 1032 //only block number and event index are available
1033 //MD: warning : this is slow!
1034 g_warning("using slow O(n) tracefile seek position");
1035
c02ea99f 1036 LttEvent event;
155a7b0a 1037 while(likely(t->which_event < ep->event_num)) ltt_tracefile_read(t, &event);
80da81ad 1038
1039 return;
1040}
1041
6cd62ccf 1042/*****************************************************************************
1043 *Function name
40331ba8 1044 * ltt_tracefile_read : read the current event, set the pointer to the next
6cd62ccf 1045 *Input params
1046 * t : tracefile
1047 *Return value
963b5f2d 1048 * LttEvent * : an event to be processed
6cd62ccf 1049 ****************************************************************************/
1050
c02ea99f 1051LttEvent *ltt_tracefile_read(LttTracefile *t, LttEvent *event)
6cd62ccf 1052{
963b5f2d 1053 int err;
6cd62ccf 1054
155a7b0a 1055 if(unlikely(t->cur_event_pos == t->buffer + t->block_size)){
1056 if(unlikely(t->which_block == t->block_number)){
bdc36259 1057 return NULL;
1058 }
1059 err = readBlock(t, t->which_block + 1);
155a7b0a 1060 if(unlikely(err))g_error("Can not read tracefile");
bdc36259 1061 }
1062
c02ea99f 1063 event->event_id = (int)(*(guint16 *)(t->cur_event_pos));
155a7b0a 1064 if(unlikely(event->event_id == TRACE_TIME_HEARTBEAT))
963b5f2d 1065 t->cur_heart_beat_number++;
6cd62ccf 1066
40331ba8 1067 t->prev_event_time = t->current_event_time;
62e55dd6 1068 // t->current_event_time = getEventTime(t);
6cd62ccf 1069
c02ea99f 1070 event->time_delta = *(guint32 *)(t->cur_event_pos + EVENT_ID_SIZE);
1071 event->event_time = t->current_event_time;
1072 event->event_cycle_count = t->cur_cycle_count;
963b5f2d 1073
c02ea99f 1074 event->tracefile = t;
1075 event->data = t->cur_event_pos + EVENT_HEADER_SIZE;
1076 event->which_block = t->which_block;
1077 event->which_event = t->which_event;
6cd62ccf 1078
18206708 1079 /* This is a workaround for fast position seek */
c02ea99f 1080 event->last_event_pos = t->last_event_pos;
1081 event->prev_block_end_time = t->prev_block_end_time;
1082 event->prev_event_time = t->prev_event_time;
1083 event->pre_cycle_count = t->pre_cycle_count;
1084 event->count = t->count;
18206708 1085 /* end of workaround */
1086
1087
1088
40331ba8 1089 //update the fields of the current event and go to the next event
1090 err = skipEvent(t);
155a7b0a 1091 if(unlikely(err == ERANGE)) g_error("event id is out of range\n");
40331ba8 1092
c02ea99f 1093 return event;
6cd62ccf 1094}
1095
1096/****************************************************************************
1097 *Function name
1098 * readFile : wrap function to read from a file
1099 *Input Params
1100 * fd : file descriptor
1101 * buf : buf to contain the content
1102 * size : number of bytes to be read
1103 * mesg : message to be printed if some thing goes wrong
1104 *return value
1105 * 0 : success
1106 * EIO : can not read from the file
1107 ****************************************************************************/
1108
1109int readFile(int fd, void * buf, size_t size, char * mesg)
1110{
8d1e6362 1111 ssize_t nbBytes = read(fd, buf, size);
1112
1113 if((size_t)nbBytes != size) {
1114 if(nbBytes < 0) {
1115 perror("Error in readFile : ");
1116 } else {
1117 g_warning("%s",mesg);
1118 }
6cd62ccf 1119 return EIO;
1120 }
1121 return 0;
1122}
1123
507915ee 1124/*****************************************************************************
1125 *Function name
1126 * skipEvent_pre_read_cycles : go to the next event,
1127 * update the necessary fields of the current event
1128 * increment the cycle counter, save it at the end.
1129 *Input params
1130 * t : tracefile
1131 *return value
1132 * 0 : success
1133 * ERANGE : event id is out of range
1134 ****************************************************************************/
1135
1136int skipEvent_pre_read_cycles(LttTracefile * t)
1137{
1138 int evId;
1139 void * evData;
1140 LttEventType * evT;
1141 LttField * rootFld;
1142
1143 evId = (int)(*(guint16 *)(t->cur_event_pos));
1144 evData = t->cur_event_pos + EVENT_HEADER_SIZE;
1145
1146 evT = ltt_trace_eventtype_get(t->trace,(unsigned)evId);
1147
1148 if(likely(evT)) rootFld = evT->root_field;
1149 else return ERANGE;
1150
1151 if(likely(rootFld)){
1152 //event has string/sequence or the last event is not the same event
1153 if(likely((evT->latest_block!=t->which_block || evT->latest_event!=t->which_event)
1154 && rootFld->field_fixed == 0)){
1155 setFieldsOffset(t, evT, evData, t->trace);
1156 }
1157 t->cur_event_pos += EVENT_HEADER_SIZE + rootFld->field_size;
1158 }else t->cur_event_pos += EVENT_HEADER_SIZE;
1159
1160 //evT->latest_block = t->which_block;
1161 //evT->latest_event = t->which_event;
1162
1163 //the next event is in the next block
1164 //if(unlikely(evId == TRACE_BLOCK_END)){
1165 // Specify end of buffer reached.
1166 // t->cur_event_pos = t->buffer + t->block_size;
1167 //}else{
1168 //g_critical("COUNT : %lu", t->cur_cycle_count);
1169 //t->which_event++;
1170 // t->current_event_time = getEventTime(t);
1171 //}
1172
1173 return 0;
1174}
1175
1176
1177
1178
1179/*****************************************************************************
1180 *Function name
1181 * ltt_tracefile_pre_read_cycles :
1182 * read the current event, increment the cycle counter
1183 *Input params
1184 * t : tracefile
1185 *Return value
1186 * False : end of bloc reached
1187 ****************************************************************************/
1188
1189gboolean ltt_tracefile_pre_read_cycles(LttTracefile *tf)
1190{
1191 int err;
1192 //LttEvent event;
1193
1194 // if(unlikely(t->cur_event_pos == t->buffer + t->block_size)){
1195 //if(unlikely(t->which_block == t->block_number)){
1196 // return FALSE;
1197 //}
1198 // return FALSE; // end of bloc reached
1199 //err = readBlock(t, t->which_block + 1);
1200 //if(unlikely(err))g_error("Can not read tracefile");
1201 //}
1202
1203 //event.event_id = (int)(*(guint16 *)(t->cur_event_pos));
1204 //if(unlikely(event.event_id == TRACE_TIME_HEARTBEAT))
1205 // t->cur_heart_beat_number++;
1206
1207 //t->prev_event_time = t->current_event_time;
1208 // t->current_event_time = getEventTime(t);
1209
1210 //event.time_delta = *(guint32 *)(t->cur_event_pos + EVENT_ID_SIZE);
1211 //event.event_time = t->current_event_time;
1212 //event.event_cycle_count = t->cur_cycle_count;
1213
1214 //event.tracefile = t;
1215 //event.data = t->cur_event_pos + EVENT_HEADER_SIZE;
1216 //event.which_block = t->which_block;
1217 //event.which_event = t->which_event;
1218
1219 /* This is a workaround for fast position seek */
1220 //event.last_event_pos = t->last_event_pos;
1221 //event.prev_block_end_time = t->prev_block_end_time;
1222 //event.prev_event_time = t->prev_event_time;
1223 //event.pre_cycle_count = t->pre_cycle_count;
1224 //event.count = t->count;
1225 /* end of workaround */
1226
1227
1228 /* Increment the cycle counter for the bloc */
1229 LttTime time;
1230 LttCycleCount cycle_count; // cycle count for the current event
1231 LttCycleCount lEventTotalCycle; // Total cycles from start for event
1232 LttCycleCount lEventNSec; // Total nsecs from start for event
1233 LttTime lTimeOffset; // Time offset in struct LttTime
1234 guint16 evId;
1235
1236 evId = *(guint16 *)tf->cur_event_pos;
1237
1238 // Calculate total time in cycles from start of buffer for this event
1239 cycle_count = (LttCycleCount)*(guint32 *)(tf->cur_event_pos + EVENT_ID_SIZE);
1240 //g_debug("event cycle count %llu", cycle_count);
a1062ddd 1241 gint64 delta_count = (gint64)(cycle_count - tf->pre_cycle_count);
1242 LttCycleCount res_delta_count;
507915ee 1243 tf->pre_cycle_count = cycle_count;
a1062ddd 1244
1245 //if(unlikely(cycle_count < tf->pre_cycle_count)) tf->count++;
1246 if(unlikely(delta_count < 0)) {
1247 // tf->count++; //increment wrap count
1248 // keep in mind that delta_count is negative here.
1249 res_delta_count = delta_count + 0x100000000ULL ;
1250 } else
1251 res_delta_count = (LttCycleCount)delta_count;
1252
1253 //cycle_count += (LttCycleCount)tf->count << 32;
507915ee 1254
1255 //FIXME (MD)
1256 // if(tf->cur_heart_beat_number > tf->count)
1257 // cycle_count += (tf->cur_heart_beat_number - tf->count) << 32;
1258
a1062ddd 1259 tf->cur_cycle_count = tf->cur_cycle_count + res_delta_count;
1260 g_debug("cur cycle count %llu", tf->cur_cycle_count);
507915ee 1261
1262
1263
1264
1265 if(unlikely(evId == TRACE_BLOCK_START)){
a1062ddd 1266 g_debug("BLOCK START");
507915ee 1267 }else if(unlikely(evId == TRACE_BLOCK_END)){
a1062ddd 1268 g_debug("BLOCK END");
507915ee 1269
1270 /* The goal of all this pre reading */
1271 tf->a_block_end->cycle_count = tf->cur_cycle_count;
a1062ddd 1272 g_debug("end of block cycle count : %llu", tf->cur_cycle_count);
507915ee 1273 return FALSE;
1274 }
1275
1276 //update the fields of the current event and go to the next event
1277 err = skipEvent_pre_read_cycles(tf);
1278 if(unlikely(err == ERANGE)) g_error("event id is out of range\n");
1279
1280
1281 return TRUE;
1282}
1283
6cd62ccf 1284/****************************************************************************
1285 *Function name
1286 * readBlock : read a block from the file
1287 *Input Params
1288 * lttdes : ltt trace file
1289 * whichBlock : the block which will be read
1290 *return value
1291 * 0 : success
1292 * EINVAL : lseek fail
1293 * EIO : can not read from the file
1294 ****************************************************************************/
1295
963b5f2d 1296int readBlock(LttTracefile * tf, int whichBlock)
6cd62ccf 1297{
1298 off_t nbBytes;
cbd41522 1299 guint32 lostSize;
6cd62ccf 1300
155a7b0a 1301 if(likely(whichBlock - tf->which_block == 1 && tf->which_block != 0)){
963b5f2d 1302 tf->prev_block_end_time = tf->a_block_end->time;
40331ba8 1303 tf->prev_event_time = tf->a_block_end->time;
6cd62ccf 1304 }else{
1305 tf->prev_block_end_time.tv_sec = 0;
1306 tf->prev_block_end_time.tv_nsec = 0;
40331ba8 1307 tf->prev_event_time.tv_sec = 0;
1308 tf->prev_event_time.tv_nsec = 0;
6cd62ccf 1309 }
6cd62ccf 1310
963b5f2d 1311 nbBytes=lseek(tf->fd,(off_t)((whichBlock-1)*tf->block_size), SEEK_SET);
155a7b0a 1312 if(unlikely(nbBytes == -1)) return EINVAL;
6cd62ccf 1313
155a7b0a 1314 if(unlikely(readFile(tf->fd,tf->buffer,tf->block_size,"Unable to read a block")))
963b5f2d 1315 return EIO;
6cd62ccf 1316
963b5f2d 1317 tf->a_block_start=(BlockStart *) (tf->buffer + EVENT_HEADER_SIZE);
cbd41522 1318 lostSize = *(guint32 *)(tf->buffer + tf->block_size - sizeof(guint32));
963b5f2d 1319 tf->a_block_end=(BlockEnd *)(tf->buffer + tf->block_size -
1320 lostSize + EVENT_HEADER_SIZE);
e37c1372 1321 tf->last_event_pos = tf->buffer + tf->block_size - lostSize;
6cd62ccf 1322
6cd62ccf 1323 tf->which_block = whichBlock;
963b5f2d 1324 tf->which_event = 1;
40331ba8 1325 tf->cur_event_pos = tf->buffer;//the beginning of the block, block start ev
6cd62ccf 1326 tf->cur_heart_beat_number = 0;
507915ee 1327
1328 /* read the whole block to precalculate total of cycles in it */
1329 tf->count = 0;
1330 tf->pre_cycle_count = 0;
1331 tf->cur_cycle_count = tf->a_block_start->cycle_count;
1332 while(likely(ltt_tracefile_pre_read_cycles(tf)));
1333
1334 /* put back pointer at the beginning */
1335 tf->which_event = 1;
1336 tf->cur_event_pos = tf->buffer;//the beginning of the block, block start ev
1337 tf->cur_heart_beat_number = 0;
963b5f2d 1338
6cd62ccf 1339 getCyclePerNsec(tf);
1340
62e55dd6 1341 tf->current_event_time = getEventTime(tf);
40331ba8 1342
6cd62ccf 1343 return 0;
1344}
1345
1346/*****************************************************************************
1347 *Function name
1348 * updateTracefile : reinitialize the info of the block which is already
1349 * in the buffer
1350 *Input params
1351 * tf : tracefile
1352 ****************************************************************************/
1353
963b5f2d 1354void updateTracefile(LttTracefile * tf)
6cd62ccf 1355{
963b5f2d 1356 tf->which_event = 1;
40331ba8 1357 tf->cur_event_pos = tf->buffer;
62e55dd6 1358 tf->current_event_time = getEventTime(tf);
6cd62ccf 1359 tf->cur_heart_beat_number = 0;
1360
1361 tf->prev_event_time.tv_sec = 0;
1362 tf->prev_event_time.tv_nsec = 0;
1363}
1364
1365/*****************************************************************************
1366 *Function name
1367 * skipEvent : go to the next event, update the fields of the current event
1368 *Input params
1369 * t : tracefile
1370 *return value
1371 * 0 : success
6cd62ccf 1372 * ERANGE : event id is out of range
1373 ****************************************************************************/
1374
963b5f2d 1375int skipEvent(LttTracefile * t)
6cd62ccf 1376{
8d1e6362 1377 int evId;
6cd62ccf 1378 void * evData;
963b5f2d 1379 LttEventType * evT;
1380 LttField * rootFld;
6cd62ccf 1381
cbd41522 1382 evId = (int)(*(guint16 *)(t->cur_event_pos));
6cd62ccf 1383 evData = t->cur_event_pos + EVENT_HEADER_SIZE;
6cd62ccf 1384
908f42fa 1385 evT = ltt_trace_eventtype_get(t->trace,(unsigned)evId);
47a166fc 1386
1d1df11d 1387 if(likely(evT)) rootFld = evT->root_field;
908f42fa 1388 else return ERANGE;
6cd62ccf 1389
1d1df11d 1390 if(likely(rootFld)){
908f42fa 1391 //event has string/sequence or the last event is not the same event
1d1df11d 1392 if(likely((evT->latest_block!=t->which_block || evT->latest_event!=t->which_event)
1393 && rootFld->field_fixed == 0)){
908f42fa 1394 setFieldsOffset(t, evT, evData, t->trace);
47a166fc 1395 }
908f42fa 1396 t->cur_event_pos += EVENT_HEADER_SIZE + rootFld->field_size;
1397 }else t->cur_event_pos += EVENT_HEADER_SIZE;
1398
1399 evT->latest_block = t->which_block;
1400 evT->latest_event = t->which_event;
1401
6cd62ccf 1402 //the next event is in the next block
1d1df11d 1403 if(unlikely(evId == TRACE_BLOCK_END)){
bdc36259 1404 t->cur_event_pos = t->buffer + t->block_size;
6cd62ccf 1405 }else{
1406 t->which_event++;
62e55dd6 1407 t->current_event_time = getEventTime(t);
6cd62ccf 1408 }
1409
1410 return 0;
1411}
1412
18206708 1413
6cd62ccf 1414/*****************************************************************************
1415 *Function name
1416 * getCyclePerNsec : calculate cycles per nsec for current block
507915ee 1417 * MD: should have tracefile_read the whole block, so we know the
1418 * total of cycles in it before being called.
6cd62ccf 1419 *Input Params
1420 * t : tracefile
1421 ****************************************************************************/
1422
963b5f2d 1423void getCyclePerNsec(LttTracefile * t)
6cd62ccf 1424{
963b5f2d 1425 LttTime lBufTotalTime; /* Total time for this buffer */
887208b7 1426 double lBufTotalNSec; /* Total time for this buffer in nsecs */
1427 double lBufTotalCycle;/* Total cycles for this buffer */
6cd62ccf 1428
1429 /* Calculate the total time for this buffer */
308711e5 1430 lBufTotalTime = ltt_time_sub(t->a_block_end->time, t->a_block_start->time);
6cd62ccf 1431
1432 /* Calculate the total cycles for this bufffer */
e4eced0f 1433 lBufTotalCycle = t->a_block_end->cycle_count;
1434 lBufTotalCycle -= t->a_block_start->cycle_count;
6cd62ccf 1435
1436 /* Convert the total time to nsecs */
887208b7 1437 lBufTotalNSec = ltt_time_to_double(lBufTotalTime);
6cd62ccf 1438
887208b7 1439 t->nsec_per_cycle = (double)lBufTotalNSec / (double)lBufTotalCycle;
1440 /* See : http://www.azillionmonkeys.com/qed/adiv.html */
1441 // precalculate the reciprocal, so divisions will be really fast.
1442 // 2^32-1 == 0xFFFFFFFFULL
1443 //{
1444 // double int_res = lBufTotalCycle/lBufTotalNSec;
1445 // t->cycles_per_nsec_reciprocal =
1446 // ((0xFFFF+int_res)/int_res);
1447 //}
1448
6cd62ccf 1449}
1450
1451/****************************************************************************
1452 *Function name
1453 * getEventTime : obtain the time of an event
887208b7 1454 * NOTE : this function _really_ is on critical path.
6cd62ccf 1455 *Input params
1456 * tf : tracefile
1457 *Return value
963b5f2d 1458 * LttTime : the time of the event
6cd62ccf 1459 ****************************************************************************/
1460
8959a0c8 1461static inline LttTime getEventTime(LttTracefile * tf)
6cd62ccf 1462{
963b5f2d 1463 LttTime time;
1464 LttCycleCount cycle_count; // cycle count for the current event
1465 LttCycleCount lEventTotalCycle; // Total cycles from start for event
887208b7 1466 LttCycleCount lEventNSec; // Total nsecs from start for event
963b5f2d 1467 LttTime lTimeOffset; // Time offset in struct LttTime
cbd41522 1468 guint16 evId;
e4eced0f 1469
cbd41522 1470 evId = *(guint16 *)tf->cur_event_pos;
7d65dfad 1471 //if(unlikely(evId == TRACE_BLOCK_START)){
1472 // tf->count = 0;
1473 // tf->pre_cycle_count = 0;
1474 // tf->cur_cycle_count = tf->a_block_start->cycle_count;
1475 // return tf->a_block_start->time;
1476 //}//else if(unlikely(evId == TRACE_BLOCK_END)){
1477 //tf->count = 0;
1478 //tf->pre_cycle_count = 0;
1479 //tf->cur_cycle_count = tf->a_block_end->cycle_count;
1480 //return tf->a_block_end->time;
1481 //}
1482
1483 // Calculate total time in cycles from start of buffer for this event
1484 cycle_count = (LttCycleCount)*(guint32 *)(tf->cur_event_pos + EVENT_ID_SIZE);
1485 //g_debug("event cycle count %llu", cycle_count);
1486 gint64 delta_count = (gint64)(cycle_count - tf->pre_cycle_count);
1487 LttCycleCount res_delta_count;
1488 tf->pre_cycle_count = cycle_count;
1489
1490 //if(unlikely(cycle_count < tf->pre_cycle_count)) tf->count++;
1491 if(unlikely(delta_count < 0)) {
1492 // tf->count++; //increment wrap count
1493 // keep in mind that delta_count is negative here.
1494 res_delta_count = delta_count + 0x100000000ULL ;
1495 } else
1496 res_delta_count = (LttCycleCount)delta_count;
1497
1498 //cycle_count += (LttCycleCount)tf->count << 32;
40331ba8 1499
7d65dfad 1500 //FIXME (MD)
1501 // if(tf->cur_heart_beat_number > tf->count)
1502 // cycle_count += (tf->cur_heart_beat_number - tf->count) << 32;
1503
1504 tf->cur_cycle_count = tf->cur_cycle_count + res_delta_count;
1505 g_debug("cur cycle count %llu", tf->cur_cycle_count);
1506
1507 lEventTotalCycle = tf->cur_cycle_count;
1508
1509
1510
1511#if 0
e4eced0f 1512 // Calculate total time in cycles from start of buffer for this event
cbd41522 1513 cycle_count = (LttCycleCount)*(guint32 *)(tf->cur_event_pos + EVENT_ID_SIZE);
e4eced0f 1514
1d1df11d 1515 if(unlikely(cycle_count < tf->pre_cycle_count)) tf->count++;
dd691a2e 1516 tf->pre_cycle_count = cycle_count;
8959a0c8 1517 cycle_count += (LttCycleCount)tf->count << 32;
e4eced0f 1518
507915ee 1519 //FIXME (MD)
e9b34357 1520 // if(tf->cur_heart_beat_number > tf->count)
507915ee 1521 // cycle_count += (tf->cur_heart_beat_number - tf->count) << 32;
e4eced0f 1522
1523 tf->cur_cycle_count = cycle_count;
1524
1525 lEventTotalCycle = cycle_count;
1526 lEventTotalCycle -= tf->a_block_start->cycle_count;
7d65dfad 1527#endif //0
963b5f2d 1528 // Convert it to nsecs
887208b7 1529 lEventNSec = (double)lEventTotalCycle * (double)tf->nsec_per_cycle;
1530 //lEventNSec = (tf->cycles_per_nsec_reciprocal * lEventTotalCycle) >> 16;
1531
963b5f2d 1532 // Determine offset in struct LttTime
8959a0c8 1533 lTimeOffset = ltt_time_from_double(lEventNSec);
6cd62ccf 1534
308711e5 1535 time = ltt_time_add(tf->a_block_start->time, lTimeOffset);
e4eced0f 1536
6cd62ccf 1537 return time;
1538}
1539
1540/*****************************************************************************
1541 *Function name
1542 * setFieldsOffset : set offset of the fields
1543 *Input params
1544 * tracefile : opened trace file
1545 * evT : the event type
1546 * evD : event data, it may be NULL
1547 ****************************************************************************/
1548
40331ba8 1549void setFieldsOffset(LttTracefile *tf,LttEventType *evT,void *evD,LttTrace* t)
6cd62ccf 1550{
963b5f2d 1551 LttField * rootFld = evT->root_field;
6cd62ccf 1552 // rootFld->base_address = evD;
1553
1d1df11d 1554 if(likely(rootFld))
8710c6c7 1555 rootFld->field_size = getFieldtypeSize(tf, evT, 0,0,rootFld, evD,t);
6cd62ccf 1556}
1557
1558/*****************************************************************************
1559 *Function name
1560 * getFieldtypeSize: get the size of the field type (primitive type)
1561 *Input params
1562 * tracefile : opened trace file
1563 * evT : event type
1564 * offsetRoot : offset from the root
1565 * offsetParent : offset from the parrent
1566 * fld : field
1567 * evD : event data, it may be NULL
1568 *Return value
1569 * int : size of the field
1570 ****************************************************************************/
1571
963b5f2d 1572int getFieldtypeSize(LttTracefile * t, LttEventType * evT, int offsetRoot,
40331ba8 1573 int offsetParent, LttField * fld, void *evD, LttTrace *trace)
6cd62ccf 1574{
1575 int size, size1, element_number, i, offset1, offset2;
963b5f2d 1576 LttType * type = fld->field_type;
6cd62ccf 1577
1d1df11d 1578 if(likely(t)){
1579 if(unlikely(evT->latest_block==t->which_block && evT->latest_event==t->which_event)){
963b5f2d 1580 return fld->field_size;
1581 }
1582 }
6cd62ccf 1583
1d1df11d 1584 if(likely(fld->field_fixed == 1)){
6cd62ccf 1585 if(fld == evT->root_field) return fld->field_size;
1586 }
1587
cf74a6f1 1588 switch(type->type_class) {
1589 case LTT_ARRAY:
1590 element_number = (int) type->element_number;
1591 if(fld->field_fixed == -1){
1592 size = getFieldtypeSize(t, evT, offsetRoot,
1593 0,fld->child[0], NULL, trace);
1594 if(size == 0){ //has string or sequence
1595 fld->field_fixed = 0;
1596 }else{
1597 fld->field_fixed = 1;
1598 size *= element_number;
1599 }
1600 }else if(fld->field_fixed == 0){// has string or sequence
1601 size = 0;
1602 for(i=0;i<element_number;i++){
1603 size += getFieldtypeSize(t, evT, offsetRoot+size,size,
1604 fld->child[0], evD+size, trace);
1605 }
1606 }else size = fld->field_size;
1607 break;
1608
1609 case LTT_SEQUENCE:
1610 size1 = (int) ltt_type_size(trace, type);
1611 if(fld->field_fixed == -1){
1612 fld->sequ_number_size = size1;
1613 fld->field_fixed = 0;
1614 size = getFieldtypeSize(t, evT, offsetRoot,
1615 0,fld->child[0], NULL, trace);
1616 fld->element_size = size;
1617 }else{//0: sequence
1618 element_number = getIntNumber(size1,evD);
1619 type->element_number = element_number;
1620 if(fld->element_size > 0){
1621 size = element_number * fld->element_size;
1622 }else{//sequence has string or sequence
1623 size = 0;
1624 for(i=0;i<element_number;i++){
1625 size += getFieldtypeSize(t, evT, offsetRoot+size+size1,size+size1,
1626 fld->child[0], evD+size+size1, trace);
1627 }
1628 }
1629 size += size1;
1630 }
1631 break;
1632
1633 case LTT_STRING:
1634 size = 0;
1635 if(fld->field_fixed == -1){
1636 fld->field_fixed = 0;
1637 }else{//0: string
1638 size = strlen((char*)evD) + 1; //include end : '\0'
1639 }
1640 break;
1641
1642 case LTT_STRUCT:
1643 element_number = (int) type->element_number;
1644 size = 0;
1d1df11d 1645 if(fld->field_fixed == -1){
cf74a6f1 1646 offset1 = offsetRoot;
1647 offset2 = 0;
1648 for(i=0;i<element_number;i++){
1649 size1=getFieldtypeSize(t, evT,offset1,offset2,
1650 fld->child[i], NULL, trace);
1651 if(size1 > 0 && size >= 0){
1652 size += size1;
1653 if(offset1 >= 0) offset1 += size1;
1654 offset2 += size1;
1655 }else{
1656 size = -1;
1657 offset1 = -1;
1658 offset2 = -1;
1659 }
1660 }
1661 if(size == -1){
1662 fld->field_fixed = 0;
1663 size = 0;
1664 }else fld->field_fixed = 1;
1665 }else if(fld->field_fixed == 0){
1666 offset1 = offsetRoot;
1667 offset2 = 0;
1668 for(i=0;i<element_number;i++){
1669 size=getFieldtypeSize(t,evT,offset1,offset2,
1670 fld->child[i],evD+offset2, trace);
1671 offset1 += size;
1672 offset2 += size;
1673 }
1674 size = offset2;
1675 }else size = fld->field_size;
1676 break;
1677
1678 default:
1679 if(fld->field_fixed == -1){
1680 size = (int) ltt_type_size(trace, type);
1681 fld->field_fixed = 1;
1682 }else size = fld->field_size;
1683 break;
1684 }
1685
1686
1687
1688#if 0
6cd62ccf 1689 if(type->type_class != LTT_STRUCT && type->type_class != LTT_ARRAY &&
1690 type->type_class != LTT_SEQUENCE && type->type_class != LTT_STRING){
1691 if(fld->field_fixed == -1){
40331ba8 1692 size = (int) ltt_type_size(trace, type);
6cd62ccf 1693 fld->field_fixed = 1;
1694 }else size = fld->field_size;
1695
1696 }else if(type->type_class == LTT_ARRAY){
1697 element_number = (int) type->element_number;
1698 if(fld->field_fixed == -1){
40331ba8 1699 size = getFieldtypeSize(t, evT, offsetRoot,0,fld->child[0], NULL, trace);
6cd62ccf 1700 if(size == 0){ //has string or sequence
1701 fld->field_fixed = 0;
1702 }else{
1703 fld->field_fixed = 1;
1704 size *= element_number;
1705 }
1706 }else if(fld->field_fixed == 0){// has string or sequence
1707 size = 0;
1708 for(i=0;i<element_number;i++){
1709 size += getFieldtypeSize(t, evT, offsetRoot+size,size,
40331ba8 1710 fld->child[0], evD+size, trace);
6cd62ccf 1711 }
1712 }else size = fld->field_size;
1713
1714 }else if(type->type_class == LTT_SEQUENCE){
40331ba8 1715 size1 = (int) ltt_type_size(trace, type);
6cd62ccf 1716 if(fld->field_fixed == -1){
908f42fa 1717 fld->sequ_number_size = size1;
6cd62ccf 1718 fld->field_fixed = 0;
40331ba8 1719 size = getFieldtypeSize(t, evT, offsetRoot,0,fld->child[0], NULL, trace);
6cd62ccf 1720 fld->element_size = size;
1721 }else{//0: sequence
1722 element_number = getIntNumber(size1,evD);
1723 type->element_number = element_number;
1724 if(fld->element_size > 0){
1725 size = element_number * fld->element_size;
1726 }else{//sequence has string or sequence
1727 size = 0;
1728 for(i=0;i<element_number;i++){
1729 size += getFieldtypeSize(t, evT, offsetRoot+size+size1,size+size1,
40331ba8 1730 fld->child[0], evD+size+size1, trace);
6cd62ccf 1731 }
1732 }
1733 size += size1;
1734 }
1735
1736 }else if(type->type_class == LTT_STRING){
1737 size = 0;
1738 if(fld->field_fixed == -1){
1739 fld->field_fixed = 0;
1740 }else{//0: string
47a166fc 1741 size = strlen((char*)evD) + 1; //include end : '\0'
6cd62ccf 1742 }
1743
1744 }else if(type->type_class == LTT_STRUCT){
1745 element_number = (int) type->element_number;
1746 size = 0;
1747 if(fld->field_fixed == -1){
1748 offset1 = offsetRoot;
1749 offset2 = 0;
1750 for(i=0;i<element_number;i++){
40331ba8 1751 size1=getFieldtypeSize(t, evT,offset1,offset2, fld->child[i], NULL, trace);
6cd62ccf 1752 if(size1 > 0 && size >= 0){
1753 size += size1;
1754 if(offset1 >= 0) offset1 += size1;
1755 offset2 += size1;
1756 }else{
1757 size = -1;
1758 offset1 = -1;
1759 offset2 = -1;
1760 }
1761 }
1762 if(size == -1){
1763 fld->field_fixed = 0;
1764 size = 0;
1765 }else fld->field_fixed = 1;
1766 }else if(fld->field_fixed == 0){
1767 offset1 = offsetRoot;
1768 offset2 = 0;
1769 for(i=0;i<element_number;i++){
40331ba8 1770 size=getFieldtypeSize(t,evT,offset1,offset2,fld->child[i],evD+offset2, trace);
6cd62ccf 1771 offset1 += size;
1772 offset2 += size;
1773 }
1774 size = offset2;
1775 }else size = fld->field_size;
1776 }
cf74a6f1 1777#endif //0
6cd62ccf 1778
1779 fld->offset_root = offsetRoot;
1780 fld->offset_parent = offsetParent;
1781 if(!evD){
1782 fld->fixed_root = (offsetRoot==-1) ? 0 : 1;
1783 fld->fixed_parent = (offsetParent==-1) ? 0 : 1;
1784 }
1785 fld->field_size = size;
1786
1787 return size;
1788}
1789
6cd62ccf 1790
1791/*****************************************************************************
1792 *Function name
1793 * getIntNumber : get an integer number
1794 *Input params
1795 * size : the size of the integer
1796 * evD : the event data
1797 *Return value
cf74a6f1 1798 * gint64 : a 64 bits integer
6cd62ccf 1799 ****************************************************************************/
1800
cf74a6f1 1801gint64 getIntNumber(int size, void *evD)
6cd62ccf 1802{
cbd41522 1803 gint64 i;
cf74a6f1 1804
1805 switch(size) {
1806 case 1: i = *(gint8 *)evD; break;
1807 case 2: i = *(gint16 *)evD; break;
1808 case 4: i = *(gint32 *)evD; break;
1809 case 8: i = *(gint64 *)evD; break;
1810 default: i = *(gint64 *)evD;
1811 g_critical("getIntNumber : integer size %d unknown", size);
1812 break;
1813 }
1814
1815#if 0
cbd41522 1816 if(size == 1) i = *(gint8 *)evD;
1817 else if(size == 2) i = *(gint16 *)evD;
1818 else if(size == 4) i = *(gint32 *)evD;
1819 else if(size == 8) i = *(gint64 *)evD;
cf74a6f1 1820#endif //0
1821
1822 return (gint64)i;
6cd62ccf 1823}
1824
1825/*****************************************************************************
1826 *Function name
1827 * getDataEndianType : get the data type size and endian type of the local
1828 * machine
1829 *Input params
1830 * size : size of data type
1831 * endian : endian type, little or big
1832 ****************************************************************************/
1833
963b5f2d 1834void getDataEndianType(LttArchSize * size, LttArchEndian * endian)
6cd62ccf 1835{
1836 int i = 1;
1837 char c = (char) i;
1838 int sizeInt=sizeof(int), sizeLong=sizeof(long), sizePointer=sizeof(void *);
1839
1840 if(c == 1) *endian = LTT_LITTLE_ENDIAN;
1841 else *endian = LTT_BIG_ENDIAN;
1842
1843 if(sizeInt == 2 && sizeLong == 4 && sizePointer == 4)
1844 *size = LTT_LP32;
1845 else if(sizeInt == 4 && sizeLong == 4 && sizePointer == 4)
1846 *size = LTT_ILP32;
1847 else if(sizeInt == 4 && sizeLong == 8 && sizePointer == 8)
1848 *size = LTT_LP64;
1849 else if(sizeInt == 8 && sizeLong == 8 && sizePointer == 8)
1850 *size = LTT_ILP64;
1851 else *size = LTT_UNKNOWN;
1852}
1853
a5dcde2f 1854/* get the node name of the system */
1855
1856char * ltt_trace_system_description_node_name (LttSystemDescription * s)
1857{
1858 return s->node_name;
1859}
1860
1861
1862/* get the domain name of the system */
1863
1864char * ltt_trace_system_description_domain_name (LttSystemDescription * s)
1865{
1866 return s->domain_name;
1867}
1868
1869
1870/* get the description of the system */
1871
1872char * ltt_trace_system_description_description (LttSystemDescription * s)
1873{
1874 return s->description;
1875}
1876
1877
1878/* get the start time of the trace */
1879
1880LttTime ltt_trace_system_description_trace_start_time(LttSystemDescription *s)
1881{
1882 return s->trace_start;
1883}
1884
18206708 1885
1886LttTracefile *ltt_tracefile_new()
1887{
1888 return g_new(LttTracefile, 1);
1889}
1890
1891void ltt_tracefile_destroy(LttTracefile *tf)
1892{
1893 g_free(tf);
1894}
1895
1896void ltt_tracefile_copy(LttTracefile *dest, const LttTracefile *src)
1897{
1898 *dest = *src;
1899}
1900
This page took 0.126725 seconds and 4 git commands to generate.