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