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