git-svn-id: http://ltt.polymtl.ca/svn@132 04897980-b3bd-0310-b5e0-8ef037075253
[lttv.git] / ltt / branches / poly / ltt / tracefile.c
CommitLineData
6cd62ccf 1#include <stdio.h>
2#include <fcntl.h>
3#include <sys/stat.h>
4#include <sys/types.h>
963b5f2d 5#include <dirent.h>
6cd62ccf 6#include <linux/errno.h>
7
fcdf0ec2 8#include <ltt/LTTTypes.h>
6cd62ccf 9#include "parser.h"
963b5f2d 10#include <ltt/trace.h>
6cd62ccf 11
963b5f2d 12#define DIR_NAME_SIZE 256
6cd62ccf 13
14/* set the offset of the fields belonging to the event,
15 need the information of the archecture */
40331ba8 16void setFieldsOffset(LttTracefile *tf,LttEventType *evT,void *evD,LttTrace *t);
6cd62ccf 17
18/* get the size of the field type according to the archtecture's
19 size and endian type(info of the archecture) */
40331ba8 20int getFieldtypeSize(LttTracefile * tf, LttEventType * evT, int offsetRoot,
21 int offsetParent, LttField *fld, void *evD, LttTrace* t);
6cd62ccf 22
23/* read a fixed size or a block information from the file (fd) */
24int readFile(int fd, void * buf, size_t size, char * mesg);
963b5f2d 25int readBlock(LttTracefile * tf, int whichBlock);
6cd62ccf 26
27/* calculate cycles per nsec for current block */
963b5f2d 28void getCyclePerNsec(LttTracefile * t);
6cd62ccf 29
30/* reinitialize the info of the block which is already in the buffer */
963b5f2d 31void updateTracefile(LttTracefile * tf);
6cd62ccf 32
33/* go to the next event */
963b5f2d 34int skipEvent(LttTracefile * t);
6cd62ccf 35
963b5f2d 36/* compare two time (LttTime), 0:t1=t2, -1:t1<t2, 1:t1>t2 */
37int timecmp(LttTime * t1, LttTime * t2);
6cd62ccf 38
39/* get an integer number */
40int getIntNumber(int size1, void *evD);
41
42
963b5f2d 43/* Time operation macros for LttTime (struct timespec) */
6cd62ccf 44/* (T3 = T2 - T1) */
45#define TimeSub(T3, T2, T1) \
46do \
47{\
48 (T3).tv_sec = (T2).tv_sec - (T1).tv_sec; \
49 (T3).tv_nsec = (T2).tv_nsec - (T1).tv_nsec; \
50 if((T3).tv_nsec < 0)\
51 {\
52 (T3).tv_sec--;\
53 (T3).tv_nsec += 1000000000;\
54 }\
55} while(0)
56
57/* (T3 = T2 + T1) */
58#define TimeAdd(T3, T2, T1) \
59do \
60{\
61 (T3).tv_sec = (T2).tv_sec + (T1).tv_sec; \
62 (T3).tv_nsec = (T2).tv_nsec + (T1).tv_nsec; \
63 if((T3).tv_nsec >= 1000000000)\
64 {\
65 (T3).tv_sec += (T3).tv_nsec / 1000000000;\
66 (T3).tv_nsec = (T3).tv_nsec % 1000000000;\
67 }\
68} while(0)
69
70
71
72/*****************************************************************************
73 *Function name
963b5f2d 74 * ltt_tracefile_open : open a trace file, construct a LttTracefile
6cd62ccf 75 *Input params
963b5f2d 76 * t : the trace containing the tracefile
77 * fileName : path name of the trace file
6cd62ccf 78 *Return value
963b5f2d 79 * : a pointer to a tracefile
6cd62ccf 80 ****************************************************************************/
81
963b5f2d 82LttTracefile* ltt_tracefile_open(LttTrace * t, char * fileName)
6cd62ccf 83{
963b5f2d 84 LttTracefile * tf;
85 struct stat lTDFStat; /* Trace data file status */
86 BlockStart a_block_start;
6cd62ccf 87
963b5f2d 88 tf = g_new(LttTracefile, 1);
6cd62ccf 89
90 //open the file
963b5f2d 91 tf->name = g_strdup(fileName);
92 tf->trace = t;
6cd62ccf 93 tf->fd = open(fileName, O_RDONLY, 0);
94 if(tf->fd < 0){
95 g_error("Unable to open input data file %s\n", fileName);
96 }
97
98 // Get the file's status
99 if(fstat(tf->fd, &lTDFStat) < 0){
100 g_error("Unable to get the status of the input data file %s\n", fileName);
101 }
102
103 // Is the file large enough to contain a trace
963b5f2d 104 if(lTDFStat.st_size < sizeof(BlockStart) + EVENT_HEADER_SIZE){
8710c6c7 105 g_print("The input data file %s does not contain a trace\n", fileName);
106 return NULL;
6cd62ccf 107 }
108
109 //store the size of the file
110 tf->file_size = lTDFStat.st_size;
963b5f2d 111 tf->block_size = t->system_description->ltt_block_size;
112 tf->block_number = tf->file_size / tf->block_size;
113 tf->which_block = 0;
6cd62ccf 114
115 //allocate memory to contain the info of a block
963b5f2d 116 tf->buffer = (void *) g_new(char, t->system_description->ltt_block_size);
6cd62ccf 117
963b5f2d 118 //read the first block
119 if(readBlock(tf,1)) exit(1);
6cd62ccf 120
121 return tf;
122}
123
6cd62ccf 124
125/*****************************************************************************
963b5f2d 126 *Open control and per cpu tracefiles
6cd62ccf 127 ****************************************************************************/
128
963b5f2d 129void ltt_tracefile_open_cpu(LttTrace *t, char * tracefile_name)
6cd62ccf 130{
963b5f2d 131 LttTracefile * tf;
132 tf = ltt_tracefile_open(t,tracefile_name);
4a6c8e36 133 if(!tf) return;
963b5f2d 134 t->per_cpu_tracefile_number++;
135 g_ptr_array_add(t->per_cpu_tracefiles, tf);
6cd62ccf 136}
137
963b5f2d 138void ltt_tracefile_open_control(LttTrace *t, char * control_name)
6cd62ccf 139{
963b5f2d 140 LttTracefile * tf;
141 LttEvent * ev;
142 LttFacility * f;
143 uint16_t evId;
144 void * pos;
145 FacilityLoad fLoad;
146 int i;
147
148 tf = ltt_tracefile_open(t,control_name);
8710c6c7 149 if(!tf) return;
963b5f2d 150 t->control_tracefile_number++;
151 g_ptr_array_add(t->control_tracefiles,tf);
152
153 //parse facilities tracefile to get base_id
542ceddd 154 if(strcmp(&control_name[strlen(control_name)-10],"facilities") ==0){
963b5f2d 155 while(1){
40331ba8 156 ev = ltt_tracefile_read(tf);
157 if(!ev)return; // end of file
158
159 if(ev->event_id == TRACE_FACILITY_LOAD){
160 pos = ev->data;
963b5f2d 161 fLoad.name = (char*)pos;
47a166fc 162 fLoad.checksum = *(LttChecksum*)(pos + strlen(fLoad.name));
163 fLoad.base_code = *(uint32_t*)(pos + strlen(fLoad.name) + sizeof(LttChecksum));
963b5f2d 164
165 for(i=0;i<t->facility_number;i++){
166 f = (LttFacility*)g_ptr_array_index(t->facilities,i);
167 if(strcmp(f->name,fLoad.name)==0 && fLoad.checksum==f->checksum){
168 f->base_id = fLoad.base_code;
169 break;
170 }
171 }
172 if(i==t->facility_number)
173 g_error("Facility: %s, checksum: %d is not founded\n",
174 fLoad.name,fLoad.checksum);
40331ba8 175 }else if(ev->event_id == TRACE_BLOCK_START){
176 continue;
177 }else if(ev->event_id == TRACE_BLOCK_END){
178 break;
963b5f2d 179 }else g_error("Not valid facilities trace file\n");
180 }
181 }
6cd62ccf 182}
183
184/*****************************************************************************
185 *Function name
963b5f2d 186 * ltt_tracefile_close: close a trace file,
6cd62ccf 187 *Input params
963b5f2d 188 * t : tracefile which will be closed
6cd62ccf 189 ****************************************************************************/
190
963b5f2d 191void ltt_tracefile_close(LttTracefile *t)
6cd62ccf 192{
963b5f2d 193 g_free(t->name);
194 g_free(t->buffer);
195 g_free(t);
196}
6cd62ccf 197
6cd62ccf 198
963b5f2d 199/*****************************************************************************
200 *Get system information
201 ****************************************************************************/
202void getSystemInfo(LttSystemDescription* des, char * pathname)
203{
204 FILE * fp;
205 int i;
206 int entry_number = 15;
207 char buf[DIR_NAME_SIZE];
208 char description[4*DIR_NAME_SIZE];
209 char * ptr;
210
211 fp = fopen(pathname,"r");
212 if(!fp){
213 g_error("Can not open file : %s\n", pathname);
6cd62ccf 214 }
963b5f2d 215
216 while(fgets(buf,DIR_NAME_SIZE, fp)!= NULL){
217 ptr = buf;
218 while(isspace(*ptr)) ptr++;
219 if(strlen(ptr) == 0) continue;
220 break;
6cd62ccf 221 }
222
963b5f2d 223 if(strlen(ptr) == 0) g_error("Not a valid file: %s\n", pathname);
224 if(strncmp("<system",ptr,7) !=0)g_error("Not a valid file: %s\n", pathname);
225
226 for(i=0;i<entry_number;i++){
227 if(fgets(buf,DIR_NAME_SIZE, fp)== NULL)
228 g_error("Not a valid file: %s\n", pathname);
8710c6c7 229 buf[strlen(buf)-1] = '\0';
963b5f2d 230 ptr = buf;
231 while(isspace(*ptr)) ptr++;
232 switch(i){
233 case 0:
234 if(strncmp("node_name=",ptr,10)!=0)
235 g_error("Not a valid file: %s\n", pathname);
236 des->node_name = g_strdup(ptr+10);
237 break;
238 case 1:
239 if(strncmp("domainname=",ptr,11)!=0)
240 g_error("Not a valid file: %s\n", pathname);
241 des->domain_name = g_strdup(ptr+11);
242 break;
243 case 2:
244 if(strncmp("cpu=",ptr,4)!=0)
245 g_error("Not a valid file: %s\n", pathname);
246 des->nb_cpu = (unsigned)atoi(ptr+4);
247 break;
248 case 3:
249 if(strncmp("arch_size=",ptr,10)!=0)
250 g_error("Not a valid file: %s\n", pathname);
251 if(strcmp(ptr+10,"\"LP32\"") == 0) des->size = LTT_LP32;
252 else if(strcmp(ptr+10,"\"ILP32\"") == 0) des->size = LTT_ILP32;
253 else if(strcmp(ptr+10,"\"LP64\"") == 0) des->size = LTT_LP64;
254 else if(strcmp(ptr+10,"\"ILP64\"") == 0) des->size = LTT_ILP64;
255 else if(strcmp(ptr+10,"\"UNKNOWN\"") == 0) des->size = LTT_UNKNOWN;
256 break;
257 case 4:
258 if(strncmp("endian=",ptr,7)!=0)
259 g_error("Not a valid file: %s\n", pathname);
260 if(strcmp(ptr+7,"\"LITTLE_ENDIAN\"") == 0)
261 des->endian = LTT_LITTLE_ENDIAN;
262 else if(strcmp(ptr+7,"\"BIG_ENDIAN\"") == 0)
263 des->endian = LTT_BIG_ENDIAN;
264 break;
265 case 5:
266 if(strncmp("kernel_name=",ptr,12)!=0)
267 g_error("Not a valid file: %s\n", pathname);
268 des->kernel_name = g_strdup(ptr+12);
269 break;
270 case 6:
271 if(strncmp("kernel_release=",ptr,15)!=0)
272 g_error("Not a valid file: %s\n", pathname);
273 des->kernel_release = g_strdup(ptr+15);
274 break;
275 case 7:
276 if(strncmp("kernel_version=",ptr,15)!=0)
277 g_error("Not a valid file: %s\n", pathname);
278 des->kernel_version = g_strdup(ptr+15);
279 break;
280 case 8:
281 if(strncmp("machine=",ptr,8)!=0)
282 g_error("Not a valid file: %s\n", pathname);
283 des->machine = g_strdup(ptr+8);
284 break;
285 case 9:
286 if(strncmp("processor=",ptr,10)!=0)
287 g_error("Not a valid file: %s\n", pathname);
288 des->processor = g_strdup(ptr+10);
289 break;
290 case 10:
291 if(strncmp("hardware_platform=",ptr,18)!=0)
292 g_error("Not a valid file: %s\n", pathname);
293 des->hardware_platform = g_strdup(ptr+18);
294 break;
295 case 11:
296 if(strncmp("operating_system=",ptr,17)!=0)
297 g_error("Not a valid file: %s\n", pathname);
298 des->operating_system = g_strdup(ptr+17);
299 break;
300 case 12:
301 if(strncmp("ltt_major_version=",ptr,18)!=0)
302 g_error("Not a valid file: %s\n", pathname);
303 ptr += 18;
8710c6c7 304 // ptr++;//skip begining "
305 // ptr[strlen(ptr)-1] = '\0'; //get rid of the ending "
963b5f2d 306 des->ltt_major_version = (unsigned)atoi(ptr);
307 break;
308 case 13:
309 if(strncmp("ltt_minor_version=",ptr,18)!=0)
310 g_error("Not a valid file: %s\n", pathname);
311 ptr += 18;
8710c6c7 312 // ptr++;//skip begining "
313 // ptr[strlen(ptr)-1] = '\0'; //get rid of the ending "
963b5f2d 314 des->ltt_minor_version = (unsigned)atoi(ptr);
315 break;
316 case 14:
317 if(strncmp("ltt_block_size=",ptr,15)!=0)
318 g_error("Not a valid file: %s\n", pathname);
319 ptr += 15;
8710c6c7 320 // ptr++;//skip begining "
321 // ptr[strlen(ptr)-1] = '\0'; //get rid of the ending "
963b5f2d 322 des->ltt_block_size = (unsigned)atoi(ptr);
323 break;
324 default:
325 g_error("Not a valid file: %s\n", pathname);
326 }
6cd62ccf 327 }
328
963b5f2d 329 //get description
330 description[0] = '\0';
331 if(fgets(buf,DIR_NAME_SIZE, fp)== NULL)
332 g_error("Not a valid file: %s\n", pathname);
333 ptr = buf;
334 while(isspace(*ptr)) ptr++;
335 if(*ptr != '>') g_error("Not a valid file: %s\n", pathname);
336 while((ptr=fgets(buf,DIR_NAME_SIZE, fp))!= NULL){
337 ptr = buf;
338 while(isspace(*ptr)) ptr++;
339 if(strncmp("</system>",ptr,9) == 0 )break;
340 strcat(description, buf);
341 }
342 if(!ptr)g_error("Not a valid file: %s\n", pathname);
343 if(description[0] = '\0')des->description = NULL;
344 des->description = g_strdup(description);
6cd62ccf 345
963b5f2d 346 fclose(fp);
6cd62ccf 347}
348
349/*****************************************************************************
963b5f2d 350 *The following functions get facility/tracefile information
6cd62ccf 351 ****************************************************************************/
352
963b5f2d 353void getFacilityInfo(LttTrace *t, char* eventdefs)
6cd62ccf 354{
963b5f2d 355 DIR * dir;
356 struct dirent *entry;
357 char * ptr;
358 int i,j;
359 LttFacility * f;
360 LttEventType * et;
e8bb1a73 361 char name[DIR_NAME_SIZE];
963b5f2d 362
363 dir = opendir(eventdefs);
364 if(!dir) g_error("Can not open directory: %s\n", eventdefs);
365
366 while((entry = readdir(dir)) != NULL){
367 ptr = &entry->d_name[strlen(entry->d_name)-4];
368 if(strcmp(ptr,".xml") != 0) continue;
e8bb1a73 369 strcpy(name,eventdefs);
370 strcat(name,entry->d_name);
371 ltt_facility_open(t,name);
963b5f2d 372 }
373 closedir(dir);
374
963b5f2d 375 for(j=0;j<t->facility_number;j++){
8710c6c7 376 f = (LttFacility*)g_ptr_array_index(t->facilities, j);
963b5f2d 377 for(i=0; i<f->event_number; i++){
378 et = f->events[i];
40331ba8 379 setFieldsOffset(NULL, et, NULL, t);
963b5f2d 380 }
381 }
382}
6cd62ccf 383
963b5f2d 384void getControlFileInfo(LttTrace *t, char* control)
6cd62ccf 385{
963b5f2d 386 DIR * dir;
387 struct dirent *entry;
e8bb1a73 388 char name[DIR_NAME_SIZE];
963b5f2d 389
390 dir = opendir(control);
391 if(!dir) g_error("Can not open directory: %s\n", control);
392
393 while((entry = readdir(dir)) != NULL){
8710c6c7 394 if(strcmp(entry->d_name,"facilities") != 0 &&
395 strcmp(entry->d_name,"interrupts") != 0 &&
963b5f2d 396 strcmp(entry->d_name,"processes") != 0) continue;
397
e8bb1a73 398 strcpy(name,control);
399 strcat(name,entry->d_name);
400 ltt_tracefile_open_control(t,name);
963b5f2d 401 }
402 closedir(dir);
6cd62ccf 403}
404
963b5f2d 405void getCpuFileInfo(LttTrace *t, char* cpu)
6cd62ccf 406{
963b5f2d 407 DIR * dir;
408 struct dirent *entry;
e8bb1a73 409 char name[DIR_NAME_SIZE];
963b5f2d 410
411 dir = opendir(cpu);
412 if(!dir) g_error("Can not open directory: %s\n", cpu);
413
414 while((entry = readdir(dir)) != NULL){
8710c6c7 415 if(strcmp(entry->d_name,".") != 0 &&
963b5f2d 416 strcmp(entry->d_name,"..") != 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);
6cd62ccf 423}
424
963b5f2d 425/*****************************************************************************
426 *A trace is specified as a pathname to the directory containing all the
427 *associated data (control tracefiles, per cpu tracefiles, event
428 *descriptions...).
429 *
430 *When a trace is closed, all the associated facilities, types and fields
431 *are released as well.
432 ****************************************************************************/
6cd62ccf 433
963b5f2d 434LttTrace *ltt_trace_open(char *pathname)
6cd62ccf 435{
963b5f2d 436 LttTrace * t;
437 LttSystemDescription * sys_description;
438 char eventdefs[DIR_NAME_SIZE];
439 char info[DIR_NAME_SIZE];
440 char control[DIR_NAME_SIZE];
441 char cpu[DIR_NAME_SIZE];
442 char tmp[DIR_NAME_SIZE];
443 gboolean has_slash = FALSE;
444
445 //establish the pathname to different directories
446 if(pathname[strlen(pathname)-1] == '/')has_slash = TRUE;
447 strcpy(eventdefs,pathname);
448 if(!has_slash)strcat(eventdefs,"/");
449 strcat(eventdefs,"eventdefs/");
450
451 strcpy(info,pathname);
452 if(!has_slash)strcat(info,"/");
453 strcat(info,"info/");
454
455 strcpy(control,pathname);
456 if(!has_slash)strcat(control,"/");
457 strcat(control,"control/");
458
459 strcpy(cpu,pathname);
460 if(!has_slash)strcat(cpu,"/");
461 strcat(cpu,"cpu/");
462
463 //new trace
464 t = g_new(LttTrace, 1);
465 sys_description = g_new(LttSystemDescription, 1);
466 t->pathname = g_strdup(pathname);
467 t->facility_number = 0;
468 t->control_tracefile_number = 0;
469 t->per_cpu_tracefile_number = 0;
470 t->system_description = sys_description;
471 t->control_tracefiles = g_ptr_array_new();
472 t->per_cpu_tracefiles = g_ptr_array_new();
473 t->facilities = g_ptr_array_new();
474 getDataEndianType(&(t->my_arch_size), &(t->my_arch_endian));
475
476 //get system description
477 strcpy(tmp,info);
478 strcat(tmp,"system.xml");
479 getSystemInfo(sys_description, tmp);
480
b333a76b 481 //get facilities info
482 getFacilityInfo(t,eventdefs);
483
963b5f2d 484 //get control tracefile info
485 getControlFileInfo(t,control);
486
487 //get cpu tracefile info
488 getCpuFileInfo(t,cpu);
489
963b5f2d 490 return t;
6cd62ccf 491}
492
963b5f2d 493void ltt_trace_close(LttTrace *t)
6cd62ccf 494{
963b5f2d 495 int i;
496 LttTracefile * tf;
497 LttFacility * f;
498
499 g_free(t->pathname);
500
501 //free system_description
502 g_free(t->system_description->description);
503 g_free(t->system_description->node_name);
504 g_free(t->system_description->domain_name);
505 g_free(t->system_description->kernel_name);
506 g_free(t->system_description->kernel_release);
507 g_free(t->system_description->kernel_version);
508 g_free(t->system_description->machine);
509 g_free(t->system_description->processor);
510 g_free(t->system_description->hardware_platform);
511 g_free(t->system_description->operating_system);
512 g_free(t->system_description);
513
514 //free control_tracefiles
515 for(i=0;i<t->control_tracefile_number;i++){
516 tf = (LttTracefile*)g_ptr_array_index(t->control_tracefiles,i);
517 ltt_tracefile_close(tf);
518 }
519 g_ptr_array_free(t->control_tracefiles, FALSE);
520
521 //free per_cpu_tracefiles
522 for(i=0;i<t->per_cpu_tracefile_number;i++){
523 tf = (LttTracefile*)g_ptr_array_index(t->per_cpu_tracefiles,i);
524 ltt_tracefile_close(tf);
525 }
526 g_ptr_array_free(t->per_cpu_tracefiles, FALSE);
527
528 //free facilities
529 for(i=0;i<t->facility_number;i++){
530 f = (LttFacility*)g_ptr_array_index(t->facilities,i);
531 ltt_facility_close(f);
532 }
533 g_ptr_array_free(t->facilities, FALSE);
534
535 g_free(t);
6cd62ccf 536}
537
963b5f2d 538
6cd62ccf 539/*****************************************************************************
963b5f2d 540 *Get the system description of the trace
6cd62ccf 541 ****************************************************************************/
542
963b5f2d 543LttSystemDescription *ltt_trace_system_description(LttTrace *t)
6cd62ccf 544{
963b5f2d 545 return t->system_description;
6cd62ccf 546}
547
548/*****************************************************************************
963b5f2d 549 * The following functions discover the facilities of the trace
6cd62ccf 550 ****************************************************************************/
551
963b5f2d 552unsigned ltt_trace_facility_number(LttTrace *t)
553{
554 return (unsigned)(t->facility_number);
555}
556
557LttFacility *ltt_trace_facility_get(LttTrace *t, unsigned i)
6cd62ccf 558{
963b5f2d 559 return (LttFacility*)g_ptr_array_index(t->facilities, i);
6cd62ccf 560}
561
562/*****************************************************************************
563 *Function name
963b5f2d 564 * ltt_trace_facility_find : find facilities in the trace
6cd62ccf 565 *Input params
963b5f2d 566 * t : the trace
567 * name : facility name
568 *Output params
569 * position : position of the facility in the trace
6cd62ccf 570 *Return value
963b5f2d 571 * : the number of facilities
6cd62ccf 572 ****************************************************************************/
573
963b5f2d 574unsigned ltt_trace_facility_find(LttTrace *t, char *name, unsigned *position)
6cd62ccf 575{
963b5f2d 576 int i, count=0;
577 LttFacility * f;
578 for(i=0;i=t->facility_number;i++){
579 f = (LttFacility*)g_ptr_array_index(t->facilities, i);
580 if(strcmp(f->name,name)==0){
581 count++;
582 if(count==1) *position = i;
583 }else{
584 if(count) break;
585 }
586 }
587 return count;
6cd62ccf 588}
589
590/*****************************************************************************
963b5f2d 591 * Functions to discover all the event types in the trace
6cd62ccf 592 ****************************************************************************/
593
963b5f2d 594unsigned ltt_trace_eventtype_number(LttTrace *t)
6cd62ccf 595{
963b5f2d 596 int i;
597 unsigned count = 0;
598 LttFacility * f;
599 for(i=0;i=t->facility_number;i++){
600 f = (LttFacility*)g_ptr_array_index(t->facilities, i);
601 count += f->event_number;
602 }
603 return count;
6cd62ccf 604}
605
963b5f2d 606LttFacility * ltt_trace_facility_by_id(LttTrace * trace, unsigned id)
6cd62ccf 607{
963b5f2d 608 LttFacility * facility;
609 int i;
610 for(i=0;i<trace->facility_number;i++){
611 facility = (LttFacility*) g_ptr_array_index(trace->facilities,i);
612 if(id >= facility->base_id &&
613 id < facility->base_id + facility->event_number)
614 break;
615 }
616 if(i==trace->facility_number) return NULL;
617 else return facility;
6cd62ccf 618}
619
963b5f2d 620LttEventType *ltt_trace_eventtype_get(LttTrace *t, unsigned evId)
6cd62ccf 621{
963b5f2d 622 LttFacility * f;
623 f = ltt_trace_facility_by_id(t,evId);
624 if(!f) return NULL;
625 return f->events[evId - f->base_id];
6cd62ccf 626}
627
628/*****************************************************************************
963b5f2d 629 *There is one "per cpu" tracefile for each CPU, numbered from 0 to
630 *the maximum number of CPU in the system. When the number of CPU installed
631 *is less than the maximum, some positions are unused. There are also a
632 *number of "control" tracefiles (facilities, interrupts...).
6cd62ccf 633 ****************************************************************************/
963b5f2d 634unsigned ltt_trace_control_tracefile_number(LttTrace *t)
6cd62ccf 635{
963b5f2d 636 return t->control_tracefile_number;
6cd62ccf 637}
638
963b5f2d 639unsigned ltt_trace_per_cpu_tracefile_number(LttTrace *t)
6cd62ccf 640{
963b5f2d 641 return t->per_cpu_tracefile_number;
6cd62ccf 642}
643
644/*****************************************************************************
963b5f2d 645 *It is possible to search for the tracefiles by name or by CPU position.
646 *The index within the tracefiles of the same type is returned if found
647 *and a negative value otherwise.
6cd62ccf 648 ****************************************************************************/
649
963b5f2d 650int ltt_trace_control_tracefile_find(LttTrace *t, char *name)
6cd62ccf 651{
963b5f2d 652 LttTracefile * tracefile;
653 int i;
654 for(i=0;i<t->control_tracefile_number;i++){
655 tracefile = (LttTracefile*)g_ptr_array_index(t->control_tracefiles, i);
656 if(strcmp(tracefile->name, name)==0)break;
657 }
658 if(i == t->control_tracefile_number) return -1;
659 return i;
6cd62ccf 660}
661
963b5f2d 662int ltt_trace_per_cpu_tracefile_find(LttTrace *t, unsigned i)
6cd62ccf 663{
963b5f2d 664 LttTracefile * tracefile;
665 int j, name;
666 for(j=0;j<t->per_cpu_tracefile_number;j++){
667 tracefile = (LttTracefile*)g_ptr_array_index(t->per_cpu_tracefiles, j);
668 name = atoi(tracefile->name);
669 if(name == (int)i)break;
670 }
671 if(j == t->per_cpu_tracefile_number) return -1;
672 return j;
6cd62ccf 673}
674
675/*****************************************************************************
963b5f2d 676 *Get a specific tracefile
6cd62ccf 677 ****************************************************************************/
678
963b5f2d 679LttTracefile *ltt_trace_control_tracefile_get(LttTrace *t, unsigned i)
6cd62ccf 680{
963b5f2d 681 return (LttTracefile*)g_ptr_array_index(t->per_cpu_tracefiles, i);
682}
683
684LttTracefile *ltt_trace_per_cpu_tracefile_get(LttTrace *t, unsigned i)
685{
686 return (LttTracefile*)g_ptr_array_index(t->per_cpu_tracefiles, i);
6cd62ccf 687}
688
689/*****************************************************************************
963b5f2d 690 *Get the name of a tracefile
6cd62ccf 691 ****************************************************************************/
692
963b5f2d 693char *ltt_tracefile_name(LttTracefile *tf)
6cd62ccf 694{
963b5f2d 695 return tf->name;
6cd62ccf 696}
697
698/*****************************************************************************
699 *Function name
700 * ltt_tracefile_seek_time: seek to the first event of the trace with time
701 * larger or equal to time
702 *Input params
703 * t : tracefile
704 * time : criteria of the time
6cd62ccf 705 ****************************************************************************/
706
963b5f2d 707void ltt_tracefile_seek_time(LttTracefile *t, LttTime time)
6cd62ccf 708{
709 int err;
963b5f2d 710 LttTime lttTime;
711 int headTime = timecmp(&(t->a_block_start->time), &time);
712 int tailTime = timecmp(&(t->a_block_end->time), &time);
6cd62ccf 713
714 if(headTime < 0 && tailTime > 0){
715 lttTime = getEventTime(t);
716 err = timecmp(&lttTime, &time);
963b5f2d 717 if(err > 0){
40331ba8 718 if(t->which_event==2 || timecmp(&t->prev_event_time,&time)<0){
963b5f2d 719 return;
720 }else{
6cd62ccf 721 updateTracefile(t);
722 return ltt_tracefile_seek_time(t, time);
723 }
724 }else if(err < 0){
725 err = t->which_block;
963b5f2d 726 if(ltt_tracefile_read(t) == NULL){
25975c93 727 g_print("End of file\n");
963b5f2d 728 return;
729 }
6cd62ccf 730 if(t->which_block == err)
731 return ltt_tracefile_seek_time(t,time);
963b5f2d 732 }else return;
6cd62ccf 733 }else if(headTime > 0){
734 if(t->which_block == 1){
735 updateTracefile(t);
736 }else{
40331ba8 737 if(timecmp(&(t->prev_block_end_time),&time) >= 0 ){
6cd62ccf 738 err=readBlock(t,t->which_block-1);
963b5f2d 739 if(err) g_error("Can not read tracefile: %s\n", t->name);
6cd62ccf 740 return ltt_tracefile_seek_time(t, time) ;
741 }else{
742 updateTracefile(t);
743 }
744 }
40331ba8 745 }else if(tailTime < 0){
6cd62ccf 746 if(t->which_block != t->block_number){
747 err=readBlock(t,t->which_block+1);
963b5f2d 748 if(err) g_error("Can not read tracefile: %s\n", t->name);
749 }else {
25975c93 750 g_print("End of file\n");
963b5f2d 751 return;
752 }
6cd62ccf 753 if(tailTime < 0) return ltt_tracefile_seek_time(t, time);
754 }else if(headTime == 0){
755 updateTracefile(t);
40331ba8 756 }else if(tailTime == 0){
757 t->cur_event_pos = t->a_block_end - EVENT_HEADER_SIZE;
758 return;
6cd62ccf 759 }
6cd62ccf 760}
761
762/*****************************************************************************
763 *Function name
40331ba8 764 * ltt_tracefile_read : read the current event, set the pointer to the next
6cd62ccf 765 *Input params
766 * t : tracefile
767 *Return value
963b5f2d 768 * LttEvent * : an event to be processed
6cd62ccf 769 ****************************************************************************/
770
963b5f2d 771LttEvent *ltt_tracefile_read(LttTracefile *t)
6cd62ccf 772{
963b5f2d 773 LttEvent * lttEvent = (LttEvent *)g_new(LttEvent, 1);
774 int err;
6cd62ccf 775
963b5f2d 776 lttEvent->event_id = (int)(*(uint16_t *)(t->cur_event_pos));
777 if(lttEvent->event_id == TRACE_TIME_HEARTBEAT)
778 t->cur_heart_beat_number++;
6cd62ccf 779
40331ba8 780 t->prev_event_time = t->current_event_time;
6cd62ccf 781 t->current_event_time = getEventTime(t);
782
963b5f2d 783 lttEvent->time_delta = *(uint32_t*)(t->cur_event_pos + EVENT_ID_SIZE);
784 lttEvent->event_time = t->current_event_time;
785
786 lttEvent->event_cycle_count = ((uint64_t)1)<<32 * t->cur_heart_beat_number
787 + lttEvent->time_delta;
788
6cd62ccf 789 lttEvent->tracefile = t;
790 lttEvent->data = t->cur_event_pos + EVENT_HEADER_SIZE;
791
40331ba8 792 //update the fields of the current event and go to the next event
793 err = skipEvent(t);
99ff36b1 794 if(err == ENOMEM) return NULL;
795 if(err == ENOENT) return lttEvent;
40331ba8 796 if(err == ERANGE) g_error("event id is out of range\n");
797 if(err)g_error("Can not read tracefile\n");
798
6cd62ccf 799 return lttEvent;
800}
801
802/****************************************************************************
803 *Function name
804 * readFile : wrap function to read from a file
805 *Input Params
806 * fd : file descriptor
807 * buf : buf to contain the content
808 * size : number of bytes to be read
809 * mesg : message to be printed if some thing goes wrong
810 *return value
811 * 0 : success
812 * EIO : can not read from the file
813 ****************************************************************************/
814
815int readFile(int fd, void * buf, size_t size, char * mesg)
816{
817 ssize_t nbBytes;
818 nbBytes = read(fd, buf, size);
819 if(nbBytes != size){
820 printf("%s\n",mesg);
821 return EIO;
822 }
823 return 0;
824}
825
826/****************************************************************************
827 *Function name
828 * readBlock : read a block from the file
829 *Input Params
830 * lttdes : ltt trace file
831 * whichBlock : the block which will be read
832 *return value
833 * 0 : success
834 * EINVAL : lseek fail
835 * EIO : can not read from the file
836 ****************************************************************************/
837
963b5f2d 838int readBlock(LttTracefile * tf, int whichBlock)
6cd62ccf 839{
840 off_t nbBytes;
841 uint32_t lostSize;
842
843 if(whichBlock - tf->which_block == 1 && tf->which_block != 0){
963b5f2d 844 tf->prev_block_end_time = tf->a_block_end->time;
40331ba8 845 tf->prev_event_time = tf->a_block_end->time;
846 tf->current_event_time = tf->a_block_end->time;
6cd62ccf 847 }else{
848 tf->prev_block_end_time.tv_sec = 0;
849 tf->prev_block_end_time.tv_nsec = 0;
40331ba8 850 tf->prev_event_time.tv_sec = 0;
851 tf->prev_event_time.tv_nsec = 0;
852 tf->current_event_time.tv_sec = 0;
853 tf->current_event_time.tv_nsec = 0;
6cd62ccf 854 }
6cd62ccf 855
963b5f2d 856 nbBytes=lseek(tf->fd,(off_t)((whichBlock-1)*tf->block_size), SEEK_SET);
6cd62ccf 857 if(nbBytes == -1) return EINVAL;
858
963b5f2d 859 if(readFile(tf->fd,tf->buffer,tf->block_size,"Unable to read a block"))
860 return EIO;
6cd62ccf 861
963b5f2d 862 tf->a_block_start=(BlockStart *) (tf->buffer + EVENT_HEADER_SIZE);
863 lostSize = *(uint32_t*)(tf->buffer + tf->block_size - sizeof(uint32_t));
864 tf->a_block_end=(BlockEnd *)(tf->buffer + tf->block_size -
865 lostSize + EVENT_HEADER_SIZE);
6cd62ccf 866
6cd62ccf 867 tf->which_block = whichBlock;
963b5f2d 868 tf->which_event = 1;
40331ba8 869 tf->cur_event_pos = tf->buffer;//the beginning of the block, block start ev
6cd62ccf 870 tf->cur_heart_beat_number = 0;
963b5f2d 871
6cd62ccf 872 getCyclePerNsec(tf);
873
40331ba8 874 // tf->current_event_time = getEventTime(tf);
875
6cd62ccf 876 return 0;
877}
878
879/*****************************************************************************
880 *Function name
881 * updateTracefile : reinitialize the info of the block which is already
882 * in the buffer
883 *Input params
884 * tf : tracefile
885 ****************************************************************************/
886
963b5f2d 887void updateTracefile(LttTracefile * tf)
6cd62ccf 888{
963b5f2d 889 tf->which_event = 1;
40331ba8 890 tf->cur_event_pos = tf->buffer;
891 // tf->current_event_time = getEventTime(tf);
892 tf->current_event_time.tv_sec = 0;
893 tf->current_event_time.tv_nsec = 0;
6cd62ccf 894 tf->cur_heart_beat_number = 0;
895
896 tf->prev_event_time.tv_sec = 0;
897 tf->prev_event_time.tv_nsec = 0;
898}
899
900/*****************************************************************************
901 *Function name
902 * skipEvent : go to the next event, update the fields of the current event
903 *Input params
904 * t : tracefile
905 *return value
906 * 0 : success
907 * EINVAL : lseek fail
908 * EIO : can not read from the file
99ff36b1 909 * ENOMEM : end of file
910 * ENOENT : last event
6cd62ccf 911 * ERANGE : event id is out of range
912 ****************************************************************************/
913
963b5f2d 914int skipEvent(LttTracefile * t)
6cd62ccf 915{
916 int evId, err;
917 void * evData;
963b5f2d 918 LttEventType * evT;
919 LttField * rootFld;
99ff36b1 920 static int evCount = 0;
921
922 if(evCount){
923 if(t->which_block == t->block_number &&
924 evCount == t->which_event){
925 return ENOMEM;
926 }else evCount = 0;
927 }
6cd62ccf 928
963b5f2d 929 evId = (int)(*(uint16_t *)(t->cur_event_pos));
6cd62ccf 930 evData = t->cur_event_pos + EVENT_HEADER_SIZE;
6cd62ccf 931
47a166fc 932 //regard BLOCK_START, END and HEARTBEAT as special case, there are buildin events
933 if(evId != TRACE_BLOCK_START && evId != TRACE_BLOCK_END && evId != TRACE_TIME_HEARTBEAT){
934 evT = ltt_trace_eventtype_get(t->trace,(unsigned)evId);
935
936 if(evT) rootFld = evT->root_field;
937 else return ERANGE;
6cd62ccf 938
47a166fc 939 if(rootFld){
940 //event has string/sequence or the last event is not the same event
941 if((evT->latest_block!=t->which_block || evT->latest_event!=t->which_event)
942 && rootFld->field_fixed == 0){
943 setFieldsOffset(t, evT, evData, t->trace);
944 }
945 t->cur_event_pos += EVENT_HEADER_SIZE + rootFld->field_size;
946 }else t->cur_event_pos += EVENT_HEADER_SIZE;
947
948 evT->latest_block = t->which_block;
949 evT->latest_event = t->which_event;
950 }else{
951 if(evId == TRACE_BLOCK_START || evId == TRACE_BLOCK_END){
952 t->cur_event_pos += sizeof(BlockStart) + EVENT_HEADER_SIZE;
953 }else{
954 t->cur_event_pos += sizeof(TimeHeartbeat) + EVENT_HEADER_SIZE;
955 }
6cd62ccf 956 }
6cd62ccf 957
958 //the next event is in the next block
963b5f2d 959 if(evId == TRACE_BLOCK_END){
99ff36b1 960 if(t->which_block == t->block_number){
961 t->which_event++;
962 evCount = t->which_event;
963 return ENOENT;
964 }
6cd62ccf 965 err = readBlock(t, t->which_block + 1);
966 if(err) return err;
967 }else{
968 t->which_event++;
969 }
970
971 return 0;
972}
973
974/*****************************************************************************
975 *Function name
976 * getCyclePerNsec : calculate cycles per nsec for current block
977 *Input Params
978 * t : tracefile
979 ****************************************************************************/
980
963b5f2d 981void getCyclePerNsec(LttTracefile * t)
6cd62ccf 982{
963b5f2d 983 LttTime lBufTotalTime; /* Total time for this buffer */
984 LttCycleCount lBufTotalNSec; /* Total time for this buffer in nsecs */
985 LttCycleCount lBufTotalCycle;/* Total cycles for this buffer */
6cd62ccf 986
987 /* Calculate the total time for this buffer */
963b5f2d 988 TimeSub(lBufTotalTime,t->a_block_end->time, t->a_block_start->time);
6cd62ccf 989
990 /* Calculate the total cycles for this bufffer */
963b5f2d 991 lBufTotalCycle = t->a_block_end->cycle_count
992 - t->a_block_start->cycle_count;
6cd62ccf 993
994 /* Convert the total time to nsecs */
995 lBufTotalNSec = lBufTotalTime.tv_sec * 1000000000 + lBufTotalTime.tv_nsec;
996
997 t->cycle_per_nsec = (double)lBufTotalCycle / (double)lBufTotalNSec;
998}
999
1000/****************************************************************************
1001 *Function name
1002 * getEventTime : obtain the time of an event
1003 *Input params
1004 * tf : tracefile
1005 *Return value
963b5f2d 1006 * LttTime : the time of the event
6cd62ccf 1007 ****************************************************************************/
1008
963b5f2d 1009LttTime getEventTime(LttTracefile * tf)
6cd62ccf 1010{
963b5f2d 1011 LttTime time;
1012 LttCycleCount cycle_count; // cycle count for the current event
1013 LttCycleCount lEventTotalCycle; // Total cycles from start for event
1014 double lEventNSec; // Total usecs from start for event
1015 LttTime lTimeOffset; // Time offset in struct LttTime
40331ba8 1016 uint16_t evId;
6cd62ccf 1017
40331ba8 1018 evId = *(uint16_t*)tf->cur_event_pos;
1019 if(evId == TRACE_BLOCK_START)
1020 return tf->a_block_start->time;
1021 else if(evId == TRACE_BLOCK_END)
1022 return tf->a_block_end->time;
1023
1024
963b5f2d 1025 // Calculate total time in cycles from start of buffer for this event
1026 cycle_count = (LttCycleCount)*(uint32_t*)(tf->cur_event_pos + EVENT_ID_SIZE);
6cd62ccf 1027 if(tf->cur_heart_beat_number)
1028 cycle_count += ((uint64_t)1)<<32 * tf->cur_heart_beat_number;
963b5f2d 1029 lEventTotalCycle = cycle_count - tf->a_block_start->cycle_count;
6cd62ccf 1030
963b5f2d 1031 // Convert it to nsecs
6cd62ccf 1032 lEventNSec = lEventTotalCycle / tf->cycle_per_nsec;
1033
963b5f2d 1034 // Determine offset in struct LttTime
6cd62ccf 1035 lTimeOffset.tv_nsec = (long)lEventNSec % 1000000000;
1036 lTimeOffset.tv_sec = (long)lEventNSec / 1000000000;
1037
963b5f2d 1038 TimeAdd(time, tf->a_block_start->time, lTimeOffset);
6cd62ccf 1039
1040 return time;
1041}
1042
1043/*****************************************************************************
1044 *Function name
1045 * setFieldsOffset : set offset of the fields
1046 *Input params
1047 * tracefile : opened trace file
1048 * evT : the event type
1049 * evD : event data, it may be NULL
1050 ****************************************************************************/
1051
40331ba8 1052void setFieldsOffset(LttTracefile *tf,LttEventType *evT,void *evD,LttTrace* t)
6cd62ccf 1053{
963b5f2d 1054 LttField * rootFld = evT->root_field;
6cd62ccf 1055 // rootFld->base_address = evD;
1056
8710c6c7 1057 if(rootFld)
1058 rootFld->field_size = getFieldtypeSize(tf, evT, 0,0,rootFld, evD,t);
6cd62ccf 1059}
1060
1061/*****************************************************************************
1062 *Function name
1063 * getFieldtypeSize: get the size of the field type (primitive type)
1064 *Input params
1065 * tracefile : opened trace file
1066 * evT : event type
1067 * offsetRoot : offset from the root
1068 * offsetParent : offset from the parrent
1069 * fld : field
1070 * evD : event data, it may be NULL
1071 *Return value
1072 * int : size of the field
1073 ****************************************************************************/
1074
963b5f2d 1075int getFieldtypeSize(LttTracefile * t, LttEventType * evT, int offsetRoot,
40331ba8 1076 int offsetParent, LttField * fld, void *evD, LttTrace *trace)
6cd62ccf 1077{
1078 int size, size1, element_number, i, offset1, offset2;
963b5f2d 1079 LttType * type = fld->field_type;
6cd62ccf 1080
8710c6c7 1081 if(t){
963b5f2d 1082 if(evT->latest_block==t->which_block && evT->latest_event==t->which_event){
1083 return fld->field_size;
1084 }
1085 }
6cd62ccf 1086
1087 if(fld->field_fixed == 1){
1088 if(fld == evT->root_field) return fld->field_size;
1089 }
1090
1091 if(type->type_class != LTT_STRUCT && type->type_class != LTT_ARRAY &&
1092 type->type_class != LTT_SEQUENCE && type->type_class != LTT_STRING){
1093 if(fld->field_fixed == -1){
40331ba8 1094 size = (int) ltt_type_size(trace, type);
6cd62ccf 1095 fld->field_fixed = 1;
1096 }else size = fld->field_size;
1097
1098 }else if(type->type_class == LTT_ARRAY){
1099 element_number = (int) type->element_number;
1100 if(fld->field_fixed == -1){
40331ba8 1101 size = getFieldtypeSize(t, evT, offsetRoot,0,fld->child[0], NULL, trace);
6cd62ccf 1102 if(size == 0){ //has string or sequence
1103 fld->field_fixed = 0;
1104 }else{
1105 fld->field_fixed = 1;
1106 size *= element_number;
1107 }
1108 }else if(fld->field_fixed == 0){// has string or sequence
1109 size = 0;
1110 for(i=0;i<element_number;i++){
1111 size += getFieldtypeSize(t, evT, offsetRoot+size,size,
40331ba8 1112 fld->child[0], evD+size, trace);
6cd62ccf 1113 }
1114 }else size = fld->field_size;
1115
1116 }else if(type->type_class == LTT_SEQUENCE){
40331ba8 1117 size1 = (int) ltt_type_size(trace, type);
6cd62ccf 1118 if(fld->field_fixed == -1){
1119 fld->field_fixed = 0;
40331ba8 1120 size = getFieldtypeSize(t, evT, offsetRoot,0,fld->child[0], NULL, trace);
6cd62ccf 1121 fld->element_size = size;
1122 }else{//0: sequence
1123 element_number = getIntNumber(size1,evD);
1124 type->element_number = element_number;
1125 if(fld->element_size > 0){
1126 size = element_number * fld->element_size;
1127 }else{//sequence has string or sequence
1128 size = 0;
1129 for(i=0;i<element_number;i++){
1130 size += getFieldtypeSize(t, evT, offsetRoot+size+size1,size+size1,
40331ba8 1131 fld->child[0], evD+size+size1, trace);
6cd62ccf 1132 }
1133 }
1134 size += size1;
1135 }
1136
1137 }else if(type->type_class == LTT_STRING){
1138 size = 0;
1139 if(fld->field_fixed == -1){
1140 fld->field_fixed = 0;
1141 }else{//0: string
47a166fc 1142 size = strlen((char*)evD) + 1; //include end : '\0'
6cd62ccf 1143 }
1144
1145 }else if(type->type_class == LTT_STRUCT){
1146 element_number = (int) type->element_number;
1147 size = 0;
1148 if(fld->field_fixed == -1){
1149 offset1 = offsetRoot;
1150 offset2 = 0;
1151 for(i=0;i<element_number;i++){
40331ba8 1152 size1=getFieldtypeSize(t, evT,offset1,offset2, fld->child[i], NULL, trace);
6cd62ccf 1153 if(size1 > 0 && size >= 0){
1154 size += size1;
1155 if(offset1 >= 0) offset1 += size1;
1156 offset2 += size1;
1157 }else{
1158 size = -1;
1159 offset1 = -1;
1160 offset2 = -1;
1161 }
1162 }
1163 if(size == -1){
1164 fld->field_fixed = 0;
1165 size = 0;
1166 }else fld->field_fixed = 1;
1167 }else if(fld->field_fixed == 0){
1168 offset1 = offsetRoot;
1169 offset2 = 0;
1170 for(i=0;i<element_number;i++){
40331ba8 1171 size=getFieldtypeSize(t,evT,offset1,offset2,fld->child[i],evD+offset2, trace);
6cd62ccf 1172 offset1 += size;
1173 offset2 += size;
1174 }
1175 size = offset2;
1176 }else size = fld->field_size;
1177 }
1178
1179 fld->offset_root = offsetRoot;
1180 fld->offset_parent = offsetParent;
1181 if(!evD){
1182 fld->fixed_root = (offsetRoot==-1) ? 0 : 1;
1183 fld->fixed_parent = (offsetParent==-1) ? 0 : 1;
1184 }
1185 fld->field_size = size;
1186
1187 return size;
1188}
1189
1190/*****************************************************************************
1191 *Function name
1192 * timecmp : compare two time
1193 *Input params
1194 * t1 : first time
1195 * t2 : second time
1196 *Return value
1197 * int : 0: t1 == t2; -1: t1 < t2; 1: t1 > t2
1198 ****************************************************************************/
1199
963b5f2d 1200int timecmp(LttTime * t1, LttTime * t2)
6cd62ccf 1201{
963b5f2d 1202 LttTime T;
6cd62ccf 1203 TimeSub(T, *t1, *t2);
1204 if(T.tv_sec == 0 && T.tv_nsec == 0) return 0;
1205 else if(T.tv_sec > 0 || (T.tv_sec==0 && T.tv_nsec > 0)) return 1;
1206 else return -1;
1207}
1208
1209/*****************************************************************************
1210 *Function name
1211 * getIntNumber : get an integer number
1212 *Input params
1213 * size : the size of the integer
1214 * evD : the event data
1215 *Return value
1216 * int : an integer
1217 ****************************************************************************/
1218
1219int getIntNumber(int size, void *evD)
1220{
1221 int64_t i;
1222 if(size == 1) i = *(int8_t *)evD;
1223 else if(size == 2) i = *(int16_t *)evD;
1224 else if(size == 4) i = *(int32_t *)evD;
1225 else if(size == 8) i = *(int64_t *)evD;
1226
1227 return (int) i;
1228}
1229
1230/*****************************************************************************
1231 *Function name
1232 * getDataEndianType : get the data type size and endian type of the local
1233 * machine
1234 *Input params
1235 * size : size of data type
1236 * endian : endian type, little or big
1237 ****************************************************************************/
1238
963b5f2d 1239void getDataEndianType(LttArchSize * size, LttArchEndian * endian)
6cd62ccf 1240{
1241 int i = 1;
1242 char c = (char) i;
1243 int sizeInt=sizeof(int), sizeLong=sizeof(long), sizePointer=sizeof(void *);
1244
1245 if(c == 1) *endian = LTT_LITTLE_ENDIAN;
1246 else *endian = LTT_BIG_ENDIAN;
1247
1248 if(sizeInt == 2 && sizeLong == 4 && sizePointer == 4)
1249 *size = LTT_LP32;
1250 else if(sizeInt == 4 && sizeLong == 4 && sizePointer == 4)
1251 *size = LTT_ILP32;
1252 else if(sizeInt == 4 && sizeLong == 8 && sizePointer == 8)
1253 *size = LTT_LP64;
1254 else if(sizeInt == 8 && sizeLong == 8 && sizePointer == 8)
1255 *size = LTT_ILP64;
1256 else *size = LTT_UNKNOWN;
1257}
1258
This page took 0.078424 seconds and 4 git commands to generate.