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