1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Xiangxiu Yang
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation;
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
24 #include <sys/types.h>
35 #include "ltt-private.h"
36 #include <ltt/trace.h>
37 #include <ltt/facility.h>
38 #include <ltt/event.h>
41 #define DIR_NAME_SIZE 256
42 #define __UNUSED__ __attribute__((__unused__))
44 /* set the offset of the fields belonging to the event,
45 need the information of the archecture */
46 void setFieldsOffset(LttTracefile
*tf
,LttEventType
*evT
,void *evD
,LttTrace
*t
);
48 /* get the size of the field type according to the archtecture's
49 size and endian type(info of the archecture) */
50 int getFieldtypeSize(LttTracefile
* tf
, LttEventType
* evT
, int offsetRoot
,
51 int offsetParent
, LttField
*fld
, void *evD
, LttTrace
* t
);
53 /* read a fixed size or a block information from the file (fd) */
54 int readFile(int fd
, void * buf
, size_t size
, char * mesg
);
55 int readBlock(LttTracefile
* tf
, int whichBlock
);
57 /* calculate cycles per nsec for current block */
58 void getCyclePerNsec(LttTracefile
* t
);
60 /* reinitialize the info of the block which is already in the buffer */
61 void updateTracefile(LttTracefile
* tf
);
63 /* go to the next event */
64 int skipEvent(LttTracefile
* t
);
67 /* Functions to parse system.xml file (using glib xml parser) */
68 static void parser_start_element (GMarkupParseContext __UNUSED__
*context
,
69 const gchar
*element_name
,
70 const gchar
**attribute_names
,
71 const gchar
**attribute_values
,
76 LttSystemDescription
* des
= (LttSystemDescription
* )user_data
;
77 if(strcmp("system", element_name
)){
78 *error
= g_error_new(G_MARKUP_ERROR
,
80 "This is not system.xml file");
84 while(attribute_names
[i
]){
85 if(strcmp("node_name", attribute_names
[i
])==0){
86 des
->node_name
= g_strdup(attribute_values
[i
]);
87 }else if(strcmp("domainname", attribute_names
[i
])==0){
88 des
->domain_name
= g_strdup(attribute_values
[i
]);
89 }else if(strcmp("cpu", attribute_names
[i
])==0){
90 des
->nb_cpu
= atoi(attribute_values
[i
]);
91 }else if(strcmp("arch_size", attribute_names
[i
])==0){
92 if(strcmp(attribute_values
[i
],"LP32") == 0) des
->size
= LTT_LP32
;
93 else if(strcmp(attribute_values
[i
],"ILP32") == 0) des
->size
= LTT_ILP32
;
94 else if(strcmp(attribute_values
[i
],"LP64") == 0) des
->size
= LTT_LP64
;
95 else if(strcmp(attribute_values
[i
],"ILP64") == 0) des
->size
= LTT_ILP64
;
96 else if(strcmp(attribute_values
[i
],"UNKNOWN") == 0) des
->size
= LTT_UNKNOWN
;
97 }else if(strcmp("endian", attribute_names
[i
])==0){
98 if(strcmp(attribute_values
[i
],"LITTLE_ENDIAN") == 0)
99 des
->endian
= LTT_LITTLE_ENDIAN
;
100 else if(strcmp(attribute_values
[i
],"BIG_ENDIAN") == 0)
101 des
->endian
= LTT_BIG_ENDIAN
;
102 }else if(strcmp("kernel_name", attribute_names
[i
])==0){
103 des
->kernel_name
= g_strdup(attribute_values
[i
]);
104 }else if(strcmp("kernel_release", attribute_names
[i
])==0){
105 des
->kernel_release
= g_strdup(attribute_values
[i
]);
106 }else if(strcmp("kernel_version", attribute_names
[i
])==0){
107 des
->kernel_version
= g_strdup(attribute_values
[i
]);
108 }else if(strcmp("machine", attribute_names
[i
])==0){
109 des
->machine
= g_strdup(attribute_values
[i
]);
110 }else if(strcmp("processor", attribute_names
[i
])==0){
111 des
->processor
= g_strdup(attribute_values
[i
]);
112 }else if(strcmp("hardware_platform", attribute_names
[i
])==0){
113 des
->hardware_platform
= g_strdup(attribute_values
[i
]);
114 }else if(strcmp("operating_system", attribute_names
[i
])==0){
115 des
->operating_system
= g_strdup(attribute_values
[i
]);
116 }else if(strcmp("ltt_major_version", attribute_names
[i
])==0){
117 des
->ltt_major_version
= atoi(attribute_values
[i
]);
118 }else if(strcmp("ltt_minor_version", attribute_names
[i
])==0){
119 des
->ltt_minor_version
= atoi(attribute_values
[i
]);
120 }else if(strcmp("ltt_block_size", attribute_names
[i
])==0){
121 des
->ltt_block_size
= atoi(attribute_values
[i
]);
123 *error
= g_error_new(G_MARKUP_ERROR
,
125 "Not a valid attribute");
132 static void parser_characters (GMarkupParseContext __UNUSED__
*context
,
134 gsize __UNUSED__ text_len
,
136 GError __UNUSED__
**error
)
138 LttSystemDescription
* des
= (LttSystemDescription
* )user_data
;
139 des
->description
= g_strdup(text
);
143 /*****************************************************************************
145 * ltt_tracefile_open : open a trace file, construct a LttTracefile
147 * t : the trace containing the tracefile
148 * fileName : path name of the trace file
150 * : a pointer to a tracefile
151 ****************************************************************************/
153 LttTracefile
* ltt_tracefile_open(LttTrace
* t
, char * fileName
)
156 struct stat lTDFStat
; /* Trace data file status */
158 tf
= g_new(LttTracefile
, 1);
161 tf
->name
= g_strdup(fileName
);
163 tf
->fd
= open(fileName
, O_RDONLY
, 0);
165 g_warning("Unable to open input data file %s\n", fileName
);
171 // Get the file's status
172 if(fstat(tf
->fd
, &lTDFStat
) < 0){
173 g_warning("Unable to get the status of the input data file %s\n", fileName
);
180 // Is the file large enough to contain a trace
181 if(lTDFStat
.st_size
< (off_t
)(sizeof(BlockStart
) + EVENT_HEADER_SIZE
)){
182 g_print("The input data file %s does not contain a trace\n", fileName
);
189 //store the size of the file
190 tf
->file_size
= lTDFStat
.st_size
;
191 tf
->block_size
= t
->system_description
->ltt_block_size
;
192 tf
->block_number
= tf
->file_size
/ tf
->block_size
;
195 //allocate memory to contain the info of a block
196 tf
->buffer
= (void *) g_new(char, t
->system_description
->ltt_block_size
);
198 //read the first block
199 if(readBlock(tf
,1)) exit(1);
205 /*****************************************************************************
206 *Open control and per cpu tracefiles
207 ****************************************************************************/
209 void ltt_tracefile_open_cpu(LttTrace
*t
, char * tracefile_name
)
212 tf
= ltt_tracefile_open(t
,tracefile_name
);
214 t
->per_cpu_tracefile_number
++;
215 g_ptr_array_add(t
->per_cpu_tracefiles
, tf
);
218 gint
ltt_tracefile_open_control(LttTrace
*t
, char * control_name
)
227 tf
= ltt_tracefile_open(t
,control_name
);
229 g_warning("ltt_tracefile_open_control : bad file descriptor");
232 t
->control_tracefile_number
++;
233 g_ptr_array_add(t
->control_tracefiles
,tf
);
235 //parse facilities tracefile to get base_id
236 if(strcmp(&control_name
[strlen(control_name
)-10],"facilities") ==0){
238 if(!ltt_tracefile_read(tf
,&ev
)) return 0; // end of file
240 if(ev
.event_id
== TRACE_FACILITY_LOAD
){
242 fLoad
.name
= (char*)pos
;
243 fLoad
.checksum
= *(LttChecksum
*)(pos
+ strlen(fLoad
.name
));
244 fLoad
.base_code
= *(guint32
*)(pos
+ strlen(fLoad
.name
) + sizeof(LttChecksum
));
246 for(i
=0;i
<t
->facility_number
;i
++){
247 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
,i
);
248 if(strcmp(f
->name
,fLoad
.name
)==0 && fLoad
.checksum
==f
->checksum
){
249 f
->base_id
= fLoad
.base_code
;
253 if(i
==t
->facility_number
) {
254 g_warning("Facility: %s, checksum: %u is not found",
255 fLoad
.name
,(unsigned int)fLoad
.checksum
);
258 }else if(ev
.event_id
== TRACE_BLOCK_START
){
260 }else if(ev
.event_id
== TRACE_BLOCK_END
){
263 g_warning("Not valid facilities trace file");
271 /*****************************************************************************
273 * ltt_tracefile_close: close a trace file,
275 * t : tracefile which will be closed
276 ****************************************************************************/
278 void ltt_tracefile_close(LttTracefile
*t
)
287 /*****************************************************************************
288 *Get system information
289 ****************************************************************************/
290 gint
getSystemInfo(LttSystemDescription
* des
, char * pathname
)
293 char buf
[DIR_NAME_SIZE
];
295 GMarkupParseContext
* context
;
296 GError
* error
= NULL
;
297 GMarkupParser markup_parser
=
299 parser_start_element
,
302 NULL
, /* passthrough */
306 fp
= fopen(pathname
,"r");
308 g_warning("Can not open file : %s\n", pathname
);
312 context
= g_markup_parse_context_new(&markup_parser
, 0, des
,NULL
);
314 while(fgets(buf
,DIR_NAME_SIZE
, fp
) != NULL
){
315 if(!g_markup_parse_context_parse(context
, buf
, DIR_NAME_SIZE
, &error
)){
317 g_warning("Can not parse xml file: \n%s\n", error
->message
);
320 g_markup_parse_context_free(context
);
325 g_markup_parse_context_free(context
);
330 /*****************************************************************************
331 *The following functions get facility/tracefile information
332 ****************************************************************************/
334 gint
getFacilityInfo(LttTrace
*t
, char* eventdefs
)
337 struct dirent
*entry
;
342 char name
[DIR_NAME_SIZE
];
344 dir
= opendir(eventdefs
);
346 g_warning("Can not open directory: %s\n", eventdefs
);
350 while((entry
= readdir(dir
)) != NULL
){
351 ptr
= &entry
->d_name
[strlen(entry
->d_name
)-4];
352 if(strcmp(ptr
,".xml") != 0) continue;
353 strcpy(name
,eventdefs
);
354 strcat(name
,entry
->d_name
);
355 ltt_facility_open(t
,name
);
359 for(j
=0;j
<t
->facility_number
;j
++){
360 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
, j
);
361 for(i
=0; i
<f
->event_number
; i
++){
363 setFieldsOffset(NULL
, et
, NULL
, t
);
369 gint
getControlFileInfo(LttTrace
*t
, char* control
)
372 struct dirent
*entry
;
373 char name
[DIR_NAME_SIZE
];
375 dir
= opendir(control
);
377 g_warning("Can not open directory: %s\n", control
);
381 while((entry
= readdir(dir
)) != NULL
){
382 if(strcmp(entry
->d_name
,"facilities") != 0 &&
383 strcmp(entry
->d_name
,"interrupts") != 0 &&
384 strcmp(entry
->d_name
,"processes") != 0) continue;
386 strcpy(name
,control
);
387 strcat(name
,entry
->d_name
);
388 if(ltt_tracefile_open_control(t
,name
))
395 gint
getCpuFileInfo(LttTrace
*t
, char* cpu
)
398 struct dirent
*entry
;
399 char name
[DIR_NAME_SIZE
];
403 g_warning("Can not open directory: %s\n", cpu
);
407 while((entry
= readdir(dir
)) != NULL
){
408 if(strcmp(entry
->d_name
,".") != 0 &&
409 strcmp(entry
->d_name
,"..") != 0 &&
410 strcmp(entry
->d_name
,".svn") != 0){
412 strcat(name
,entry
->d_name
);
413 ltt_tracefile_open_cpu(t
,name
);
420 /*****************************************************************************
421 *A trace is specified as a pathname to the directory containing all the
422 *associated data (control tracefiles, per cpu tracefiles, event
425 *When a trace is closed, all the associated facilities, types and fields
426 *are released as well.
430 /****************************************************************************
431 * get_absolute_pathname
433 * return the unique pathname in the system
435 * MD : Fixed this function so it uses realpath, dealing well with
436 * forgotten cases (.. were not used correctly before).
438 ****************************************************************************/
439 void get_absolute_pathname(const char *pathname
, char * abs_pathname
)
441 abs_pathname
[0] = '\0';
443 if ( realpath (pathname
, abs_pathname
) != NULL
)
447 /* error, return the original path unmodified */
448 strcpy(abs_pathname
, pathname
);
454 LttTrace
*ltt_trace_open(const char *pathname
)
457 LttSystemDescription
* sys_description
;
458 char eventdefs
[DIR_NAME_SIZE
];
459 char info
[DIR_NAME_SIZE
];
460 char control
[DIR_NAME_SIZE
];
461 char cpu
[DIR_NAME_SIZE
];
462 char tmp
[DIR_NAME_SIZE
];
463 char abs_path
[DIR_NAME_SIZE
];
464 gboolean has_slash
= FALSE
;
466 get_absolute_pathname(pathname
, abs_path
);
467 //establish the pathname to different directories
468 if(abs_path
[strlen(abs_path
)-1] == '/')has_slash
= TRUE
;
469 strcpy(eventdefs
,abs_path
);
470 if(!has_slash
)strcat(eventdefs
,"/");
471 strcat(eventdefs
,"eventdefs/");
473 strcpy(info
,abs_path
);
474 if(!has_slash
)strcat(info
,"/");
475 strcat(info
,"info/");
477 strcpy(control
,abs_path
);
478 if(!has_slash
)strcat(control
,"/");
479 strcat(control
,"control/");
481 strcpy(cpu
,abs_path
);
482 if(!has_slash
)strcat(cpu
,"/");
486 sys_description
= g_new(LttSystemDescription
, 1);
487 t
= g_new(LttTrace
, 1);
488 t
->pathname
= g_strdup(abs_path
);
489 t
->facility_number
= 0;
490 t
->control_tracefile_number
= 0;
491 t
->per_cpu_tracefile_number
= 0;
492 t
->system_description
= sys_description
;
493 t
->control_tracefiles
= g_ptr_array_new();
494 t
->per_cpu_tracefiles
= g_ptr_array_new();
495 t
->facilities
= g_ptr_array_new();
496 getDataEndianType(&(t
->my_arch_size
), &(t
->my_arch_endian
));
498 //get system description
500 strcat(tmp
,"system.xml");
501 if(getSystemInfo(sys_description
, tmp
)) {
502 g_ptr_array_free(t
->facilities
, TRUE
);
503 g_ptr_array_free(t
->per_cpu_tracefiles
, TRUE
);
504 g_ptr_array_free(t
->control_tracefiles
, TRUE
);
505 g_free(sys_description
);
513 //get facilities info
514 if(getFacilityInfo(t
,eventdefs
)) {
515 g_ptr_array_free(t
->facilities
, TRUE
);
516 g_ptr_array_free(t
->per_cpu_tracefiles
, TRUE
);
517 g_ptr_array_free(t
->control_tracefiles
, TRUE
);
518 g_free(sys_description
);
524 //get control tracefile info
525 getControlFileInfo(t
,control
);
527 if(getControlFileInfo(t,control)) {
528 g_ptr_array_free(t->facilities, TRUE);
529 g_ptr_array_free(t->per_cpu_tracefiles, TRUE);
530 g_ptr_array_free(t->control_tracefiles, TRUE);
531 g_free(sys_description);
535 }*/ // With fatal error
537 //get cpu tracefile info
538 if(getCpuFileInfo(t
,cpu
)) {
539 g_ptr_array_free(t
->facilities
, TRUE
);
540 g_ptr_array_free(t
->per_cpu_tracefiles
, TRUE
);
541 g_ptr_array_free(t
->control_tracefiles
, TRUE
);
542 g_free(sys_description
);
551 char * ltt_trace_name(LttTrace
*t
)
557 /******************************************************************************
558 * When we copy a trace, we want all the opening actions to happen again :
559 * the trace will be reopened and totally independant from the original.
560 * That's why we call ltt_trace_open.
561 *****************************************************************************/
562 LttTrace
*ltt_trace_copy(LttTrace
*self
)
564 return ltt_trace_open(self
->pathname
);
567 void ltt_trace_close(LttTrace
*t
)
575 //free system_description
576 g_free(t
->system_description
->description
);
577 g_free(t
->system_description
->node_name
);
578 g_free(t
->system_description
->domain_name
);
579 g_free(t
->system_description
->kernel_name
);
580 g_free(t
->system_description
->kernel_release
);
581 g_free(t
->system_description
->kernel_version
);
582 g_free(t
->system_description
->machine
);
583 g_free(t
->system_description
->processor
);
584 g_free(t
->system_description
->hardware_platform
);
585 g_free(t
->system_description
->operating_system
);
586 g_free(t
->system_description
);
588 //free control_tracefiles
589 for(i
=0;i
<t
->control_tracefile_number
;i
++){
590 tf
= (LttTracefile
*)g_ptr_array_index(t
->control_tracefiles
,i
);
591 ltt_tracefile_close(tf
);
593 g_ptr_array_free(t
->control_tracefiles
, TRUE
);
595 //free per_cpu_tracefiles
596 for(i
=0;i
<t
->per_cpu_tracefile_number
;i
++){
597 tf
= (LttTracefile
*)g_ptr_array_index(t
->per_cpu_tracefiles
,i
);
598 ltt_tracefile_close(tf
);
600 g_ptr_array_free(t
->per_cpu_tracefiles
, TRUE
);
603 for(i
=0;i
<t
->facility_number
;i
++){
604 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
,i
);
605 ltt_facility_close(f
);
607 g_ptr_array_free(t
->facilities
, TRUE
);
615 /*****************************************************************************
616 *Get the system description of the trace
617 ****************************************************************************/
619 LttSystemDescription
*ltt_trace_system_description(LttTrace
*t
)
621 return t
->system_description
;
624 /*****************************************************************************
625 * The following functions discover the facilities of the trace
626 ****************************************************************************/
628 unsigned ltt_trace_facility_number(LttTrace
*t
)
630 return (unsigned)(t
->facility_number
);
633 LttFacility
*ltt_trace_facility_get(LttTrace
*t
, unsigned i
)
635 return (LttFacility
*)g_ptr_array_index(t
->facilities
, i
);
638 /*****************************************************************************
640 * ltt_trace_facility_find : find facilities in the trace
643 * name : facility name
645 * position : position of the facility in the trace
647 * : the number of facilities
648 ****************************************************************************/
650 unsigned ltt_trace_facility_find(LttTrace
*t
, char *name
, unsigned *position
)
652 unsigned int i
, count
=0;
654 for(i
=0;i
<t
->facility_number
;i
++){
655 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
, i
);
656 if(strcmp(f
->name
,name
)==0){
658 if(count
==1) *position
= i
;
666 /*****************************************************************************
667 * Functions to discover all the event types in the trace
668 ****************************************************************************/
670 unsigned ltt_trace_eventtype_number(LttTrace
*t
)
675 for(i
=0;i
<t
->facility_number
;i
++){
676 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
, i
);
677 count
+= f
->event_number
;
682 LttFacility
* ltt_trace_facility_by_id(LttTrace
* trace
, unsigned id
)
684 LttFacility
* facility
= NULL
;
687 for(i
=0;i
<trace
->facility_number
;i
++){
688 LttFacility
*iter_facility
=
689 (LttFacility
*) g_ptr_array_index(trace
->facilities
,i
);
690 if(id
>= iter_facility
->base_id
&&
691 id
< iter_facility
->base_id
+ iter_facility
->event_number
) {
692 facility
= iter_facility
;
700 LttEventType
*ltt_trace_eventtype_get(LttTrace
*t
, unsigned evId
)
703 f
= ltt_trace_facility_by_id(t
,evId
);
705 return f
->events
[evId
- f
->base_id
];
708 /*****************************************************************************
709 *There is one "per cpu" tracefile for each CPU, numbered from 0 to
710 *the maximum number of CPU in the system. When the number of CPU installed
711 *is less than the maximum, some positions are unused. There are also a
712 *number of "control" tracefiles (facilities, interrupts...).
713 ****************************************************************************/
714 unsigned ltt_trace_control_tracefile_number(LttTrace
*t
)
716 return t
->control_tracefile_number
;
719 unsigned ltt_trace_per_cpu_tracefile_number(LttTrace
*t
)
721 return t
->per_cpu_tracefile_number
;
724 /*****************************************************************************
725 *It is possible to search for the tracefiles by name or by CPU position.
726 *The index within the tracefiles of the same type is returned if found
727 *and a negative value otherwise.
728 ****************************************************************************/
730 int ltt_trace_control_tracefile_find(LttTrace
*t
, const gchar
*name
)
732 LttTracefile
* tracefile
;
734 for(i
=0;i
<t
->control_tracefile_number
;i
++){
735 tracefile
= (LttTracefile
*)g_ptr_array_index(t
->control_tracefiles
, i
);
736 if(strcmp(tracefile
->name
, name
)==0)break;
738 if(i
== t
->control_tracefile_number
) return -1;
742 /* not really useful. We just have to know that cpu tracefiles
743 * comes before control tracefiles.
745 int ltt_trace_per_cpu_tracefile_find(LttTrace
*t
, const gchar
*name
)
747 LttTracefile
* tracefile
;
749 for(i
=0;i
<t
->per_cpu_tracefile_number
;i
++){
750 tracefile
= (LttTracefile
*)g_ptr_array_index(t
->per_cpu_tracefiles
, i
);
751 if(strcmp(tracefile
->name
, name
)==0)break;
753 if(i
== t
->per_cpu_tracefile_number
) return -1;
757 /*****************************************************************************
758 *Get a specific tracefile
759 ****************************************************************************/
761 LttTracefile
*ltt_trace_control_tracefile_get(LttTrace
*t
, unsigned i
)
763 return (LttTracefile
*)g_ptr_array_index(t
->control_tracefiles
, i
);
766 LttTracefile
*ltt_trace_per_cpu_tracefile_get(LttTrace
*t
, unsigned i
)
768 return (LttTracefile
*)g_ptr_array_index(t
->per_cpu_tracefiles
, i
);
771 /*****************************************************************************
772 * Get the start time and end time of the trace
773 ****************************************************************************/
775 void ltt_trace_time_span_get(LttTrace
*t
, LttTime
*start
, LttTime
*end
)
777 LttTime startSmall
, startTmp
, endBig
, endTmp
;
781 for(i
=0;i
<t
->control_tracefile_number
;i
++){
782 tf
= g_ptr_array_index(t
->control_tracefiles
, i
);
784 startTmp
= tf
->a_block_start
->time
;
785 readBlock(tf
,tf
->block_number
);
786 endTmp
= tf
->a_block_end
->time
;
788 startSmall
= startTmp
;
793 if(ltt_time_compare(startSmall
,startTmp
) > 0) startSmall
= startTmp
;
794 if(ltt_time_compare(endBig
,endTmp
) < 0) endBig
= endTmp
;
797 for(i
=0;i
<t
->per_cpu_tracefile_number
;i
++){
798 tf
= g_ptr_array_index(t
->per_cpu_tracefiles
, i
);
800 startTmp
= tf
->a_block_start
->time
;
801 readBlock(tf
,tf
->block_number
);
802 endTmp
= tf
->a_block_end
->time
;
804 startSmall
= startTmp
;
808 if(ltt_time_compare(startSmall
,startTmp
) > 0) startSmall
= startTmp
;
809 if(ltt_time_compare(endBig
,endTmp
) < 0) endBig
= endTmp
;
812 if(start
!= NULL
) *start
= startSmall
;
813 if(end
!= NULL
) *end
= endBig
;
817 /*****************************************************************************
818 *Get the name of a tracefile
819 ****************************************************************************/
821 char *ltt_tracefile_name(LttTracefile
*tf
)
826 /*****************************************************************************
827 * Get the number of blocks in the tracefile
828 ****************************************************************************/
830 unsigned ltt_tracefile_block_number(LttTracefile
*tf
)
832 return tf
->block_number
;
835 /*****************************************************************************
837 * ltt_tracefile_seek_time: seek to the first event of the trace with time
838 * larger or equal to time
841 * time : criteria of the time
842 ****************************************************************************/
843 void ltt_tracefile_find_time_block(LttTracefile
*t
, LttTime time
,
844 int start_block
, int end_block
)
846 int err
, tmp_block
, s
, e
;
850 err
=readBlock(t
,start_block
);
851 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
852 if(start_block
== end_block
)return;
854 tailTime
= ltt_time_compare(t
->a_block_end
->time
, time
);
855 if(tailTime
>= 0) return;
857 err
=readBlock(t
,end_block
);
858 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
859 if(start_block
+1 == end_block
)return;
861 headTime
= ltt_time_compare(t
->a_block_start
->time
, time
);
862 if(headTime
<= 0 ) return;
864 tmp_block
= (end_block
+ start_block
)/2;
865 err
=readBlock(t
,tmp_block
);
866 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
868 headTime
= ltt_time_compare(t
->a_block_start
->time
, time
);
869 tailTime
= ltt_time_compare(t
->a_block_end
->time
, time
);
870 if(headTime
<= 0 && tailTime
>= 0) return;
876 ltt_tracefile_find_time_block(t
, time
, s
, e
);
884 ltt_tracefile_find_time_block(t
, time
, s
, e
);
889 void ltt_tracefile_backward_find_time_block(LttTracefile
*t
, LttTime time
)
891 int t_time
, h_time
, err
;
892 err
=readBlock(t
,t
->which_block
-1);
893 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
894 h_time
= ltt_time_compare(t
->a_block_start
->time
, time
);
895 t_time
= ltt_time_compare(t
->a_block_end
->time
, time
);
898 if(t
->which_block
== 1) return;
899 err
=readBlock(t
,t
->which_block
-1);
900 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
901 tmp
= ltt_time_compare(t
->a_block_end
->time
, time
);
902 if(tmp
== 0) return ltt_tracefile_seek_time(t
, time
);
903 err
=readBlock(t
,t
->which_block
+1);
904 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
905 }else if(h_time
> 0){
906 ltt_tracefile_find_time_block(t
, time
, 1, t
->which_block
);
907 return ltt_tracefile_seek_time(t
, time
) ;
909 if(t_time
>= 0) return ltt_tracefile_seek_time(t
, time
);
910 err
=readBlock(t
,t
->which_block
+1);
911 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
915 void ltt_tracefile_seek_time(LttTracefile
*t
, LttTime time
)
919 int headTime
= ltt_time_compare(t
->a_block_start
->time
, time
);
920 int tailTime
= ltt_time_compare(t
->a_block_end
->time
, time
);
923 if(headTime
< 0 && tailTime
> 0){
924 if(ltt_time_compare(t
->a_block_end
->time
, t
->current_event_time
) !=0) {
925 lttTime
= getEventTime(t
);
926 err
= ltt_time_compare(lttTime
, time
);
928 if(t
->which_event
==2 || ltt_time_compare(t
->prev_event_time
,time
)<0){
932 return ltt_tracefile_seek_time(t
, time
);
936 if(ltt_tracefile_read(t
,&ev
) == NULL
) {
937 g_print("End of file\n");
940 lttTime
= getEventTime(t
);
941 err
= ltt_time_compare(lttTime
, time
);
945 }else{//we are at the end of the block
947 return ltt_tracefile_seek_time(t
, time
);
949 }else if(headTime
>= 0){
950 if(t
->which_block
== 1){
953 if(ltt_time_compare(t
->prev_block_end_time
, time
) >= 0 ||
954 (t
->prev_block_end_time
.tv_sec
== 0 &&
955 t
->prev_block_end_time
.tv_nsec
== 0 )){
956 ltt_tracefile_backward_find_time_block(t
, time
);
961 }else if(tailTime
< 0){
962 if(t
->which_block
!= t
->block_number
){
963 ltt_tracefile_find_time_block(t
, time
, t
->which_block
+1, t
->block_number
);
964 return ltt_tracefile_seek_time(t
, time
);
966 t
->cur_event_pos
= t
->buffer
+ t
->block_size
;
967 g_print("End of file\n");
970 }else if(tailTime
== 0){
971 t
->cur_event_pos
= t
->last_event_pos
;
972 t
->current_event_time
= time
;
973 t
->cur_heart_beat_number
= 0;
974 t
->prev_event_time
.tv_sec
= 0;
975 t
->prev_event_time
.tv_nsec
= 0;
980 /*****************************************************************************
981 * Seek to the first event with position equal or larger to ep
983 * Modified by Mathieu Desnoyers to used faster offset position instead of
984 * re-reading the whole buffer.
985 ****************************************************************************/
987 void ltt_tracefile_seek_position(LttTracefile
*t
, const LttEventPosition
*ep
)
989 //if we are at the right place, just return
990 if(t
->which_block
== ep
->block_num
&& t
->which_event
== ep
->event_num
)
993 if(t
->which_block
== ep
->block_num
) updateTracefile(t
);
994 else readBlock(t
,ep
->block_num
);
995 //event offset is available
996 if(ep
->old_position
){
999 t
->which_event
= ep
->event_num
;
1000 t
->cur_event_pos
= t
->buffer
+ ep
->event_offset
;
1001 t
->prev_event_time
= ep
->event_time
;
1002 t
->current_event_time
= ep
->event_time
;
1003 t
->cur_heart_beat_number
= ep
->heart_beat_number
;
1004 t
->cur_cycle_count
= ep
->event_cycle_count
;
1006 /* This is a workaround for fast position seek */
1007 t
->last_event_pos
= ep
->last_event_pos
;
1008 t
->prev_block_end_time
= ep
->prev_block_end_time
;
1009 t
->prev_event_time
= ep
->prev_event_time
;
1010 t
->pre_cycle_count
= ep
->pre_cycle_count
;
1011 t
->count
= ep
->count
;
1012 /* end of workaround */
1014 //update the fields of the current event and go to the next event
1016 if(err
== ERANGE
) g_error("event id is out of range\n");
1021 //only block number and event index are available
1022 //MD: warning : this is slow!
1023 g_warning("using slow O(n) tracefile seek position");
1026 while(t
->which_event
< ep
->event_num
) ltt_tracefile_read(t
, &event
);
1031 /*****************************************************************************
1033 * ltt_tracefile_read : read the current event, set the pointer to the next
1037 * LttEvent * : an event to be processed
1038 ****************************************************************************/
1040 LttEvent
*ltt_tracefile_read(LttTracefile
*t
, LttEvent
*event
)
1044 if(t
->cur_event_pos
== t
->buffer
+ t
->block_size
){
1045 if(t
->which_block
== t
->block_number
){
1048 err
= readBlock(t
, t
->which_block
+ 1);
1049 if(err
)g_error("Can not read tracefile");
1052 event
->event_id
= (int)(*(guint16
*)(t
->cur_event_pos
));
1053 if(event
->event_id
== TRACE_TIME_HEARTBEAT
)
1054 t
->cur_heart_beat_number
++;
1056 t
->prev_event_time
= t
->current_event_time
;
1057 // t->current_event_time = getEventTime(t);
1059 event
->time_delta
= *(guint32
*)(t
->cur_event_pos
+ EVENT_ID_SIZE
);
1060 event
->event_time
= t
->current_event_time
;
1061 event
->event_cycle_count
= t
->cur_cycle_count
;
1063 event
->tracefile
= t
;
1064 event
->data
= t
->cur_event_pos
+ EVENT_HEADER_SIZE
;
1065 event
->which_block
= t
->which_block
;
1066 event
->which_event
= t
->which_event
;
1068 /* This is a workaround for fast position seek */
1069 event
->last_event_pos
= t
->last_event_pos
;
1070 event
->prev_block_end_time
= t
->prev_block_end_time
;
1071 event
->prev_event_time
= t
->prev_event_time
;
1072 event
->pre_cycle_count
= t
->pre_cycle_count
;
1073 event
->count
= t
->count
;
1074 /* end of workaround */
1078 //update the fields of the current event and go to the next event
1080 if(err
== ERANGE
) g_error("event id is out of range\n");
1085 /****************************************************************************
1087 * readFile : wrap function to read from a file
1089 * fd : file descriptor
1090 * buf : buf to contain the content
1091 * size : number of bytes to be read
1092 * mesg : message to be printed if some thing goes wrong
1095 * EIO : can not read from the file
1096 ****************************************************************************/
1098 int readFile(int fd
, void * buf
, size_t size
, char * mesg
)
1100 ssize_t nbBytes
= read(fd
, buf
, size
);
1102 if((size_t)nbBytes
!= size
) {
1104 perror("Error in readFile : ");
1106 g_warning("%s",mesg
);
1113 /****************************************************************************
1115 * readBlock : read a block from the file
1117 * lttdes : ltt trace file
1118 * whichBlock : the block which will be read
1121 * EINVAL : lseek fail
1122 * EIO : can not read from the file
1123 ****************************************************************************/
1125 int readBlock(LttTracefile
* tf
, int whichBlock
)
1130 if(whichBlock
- tf
->which_block
== 1 && tf
->which_block
!= 0){
1131 tf
->prev_block_end_time
= tf
->a_block_end
->time
;
1132 tf
->prev_event_time
= tf
->a_block_end
->time
;
1134 tf
->prev_block_end_time
.tv_sec
= 0;
1135 tf
->prev_block_end_time
.tv_nsec
= 0;
1136 tf
->prev_event_time
.tv_sec
= 0;
1137 tf
->prev_event_time
.tv_nsec
= 0;
1140 nbBytes
=lseek(tf
->fd
,(off_t
)((whichBlock
-1)*tf
->block_size
), SEEK_SET
);
1141 if(nbBytes
== -1) return EINVAL
;
1143 if(readFile(tf
->fd
,tf
->buffer
,tf
->block_size
,"Unable to read a block"))
1146 tf
->a_block_start
=(BlockStart
*) (tf
->buffer
+ EVENT_HEADER_SIZE
);
1147 lostSize
= *(guint32
*)(tf
->buffer
+ tf
->block_size
- sizeof(guint32
));
1148 tf
->a_block_end
=(BlockEnd
*)(tf
->buffer
+ tf
->block_size
-
1149 lostSize
+ EVENT_HEADER_SIZE
);
1150 tf
->last_event_pos
= tf
->buffer
+ tf
->block_size
- lostSize
;
1152 tf
->which_block
= whichBlock
;
1153 tf
->which_event
= 1;
1154 tf
->cur_event_pos
= tf
->buffer
;//the beginning of the block, block start ev
1155 tf
->cur_heart_beat_number
= 0;
1157 getCyclePerNsec(tf
);
1159 tf
->current_event_time
= getEventTime(tf
);
1164 /*****************************************************************************
1166 * updateTracefile : reinitialize the info of the block which is already
1170 ****************************************************************************/
1172 void updateTracefile(LttTracefile
* tf
)
1174 tf
->which_event
= 1;
1175 tf
->cur_event_pos
= tf
->buffer
;
1176 tf
->current_event_time
= getEventTime(tf
);
1177 tf
->cur_heart_beat_number
= 0;
1179 tf
->prev_event_time
.tv_sec
= 0;
1180 tf
->prev_event_time
.tv_nsec
= 0;
1183 /*****************************************************************************
1185 * skipEvent : go to the next event, update the fields of the current event
1190 * ERANGE : event id is out of range
1191 ****************************************************************************/
1193 int skipEvent(LttTracefile
* t
)
1200 evId
= (int)(*(guint16
*)(t
->cur_event_pos
));
1201 evData
= t
->cur_event_pos
+ EVENT_HEADER_SIZE
;
1203 evT
= ltt_trace_eventtype_get(t
->trace
,(unsigned)evId
);
1205 if(evT
) rootFld
= evT
->root_field
;
1209 //event has string/sequence or the last event is not the same event
1210 if((evT
->latest_block
!=t
->which_block
|| evT
->latest_event
!=t
->which_event
)
1211 && rootFld
->field_fixed
== 0){
1212 setFieldsOffset(t
, evT
, evData
, t
->trace
);
1214 t
->cur_event_pos
+= EVENT_HEADER_SIZE
+ rootFld
->field_size
;
1215 }else t
->cur_event_pos
+= EVENT_HEADER_SIZE
;
1217 evT
->latest_block
= t
->which_block
;
1218 evT
->latest_event
= t
->which_event
;
1220 //the next event is in the next block
1221 if(evId
== TRACE_BLOCK_END
){
1222 t
->cur_event_pos
= t
->buffer
+ t
->block_size
;
1225 t
->current_event_time
= getEventTime(t
);
1232 /*****************************************************************************
1234 * getCyclePerNsec : calculate cycles per nsec for current block
1237 ****************************************************************************/
1239 void getCyclePerNsec(LttTracefile
* t
)
1241 LttTime lBufTotalTime
; /* Total time for this buffer */
1242 LttCycleCount lBufTotalNSec
; /* Total time for this buffer in nsecs */
1243 LttCycleCount lBufTotalCycle
;/* Total cycles for this buffer */
1245 /* Calculate the total time for this buffer */
1246 lBufTotalTime
= ltt_time_sub(t
->a_block_end
->time
, t
->a_block_start
->time
);
1248 /* Calculate the total cycles for this bufffer */
1249 lBufTotalCycle
= t
->a_block_end
->cycle_count
;
1250 lBufTotalCycle
-= t
->a_block_start
->cycle_count
;
1252 /* Convert the total time to nsecs */
1253 lBufTotalNSec
= lBufTotalTime
.tv_sec
;
1254 lBufTotalNSec
*= NANOSECONDS_PER_SECOND
;
1255 lBufTotalNSec
+= lBufTotalTime
.tv_nsec
;
1257 t
->cycle_per_nsec
= (double)lBufTotalCycle
/ (double)lBufTotalNSec
;
1260 /****************************************************************************
1262 * getEventTime : obtain the time of an event
1266 * LttTime : the time of the event
1267 ****************************************************************************/
1269 LttTime
getEventTime(LttTracefile
* tf
)
1272 LttCycleCount cycle_count
; // cycle count for the current event
1273 LttCycleCount lEventTotalCycle
; // Total cycles from start for event
1274 LttCycleCount lEventNSec
; // Total usecs from start for event
1275 LttTime lTimeOffset
; // Time offset in struct LttTime
1277 LttCycleCount tmpCycleCount
= (((LttCycleCount
)1)<<32);
1279 evId
= *(guint16
*)tf
->cur_event_pos
;
1280 if(evId
== TRACE_BLOCK_START
){
1282 tf
->pre_cycle_count
= 0;
1283 tf
->cur_cycle_count
= tf
->a_block_start
->cycle_count
;
1284 return tf
->a_block_start
->time
;
1285 }else if(evId
== TRACE_BLOCK_END
){
1287 tf
->pre_cycle_count
= 0;
1288 tf
->cur_cycle_count
= tf
->a_block_end
->cycle_count
;
1289 return tf
->a_block_end
->time
;
1292 // Calculate total time in cycles from start of buffer for this event
1293 cycle_count
= (LttCycleCount
)*(guint32
*)(tf
->cur_event_pos
+ EVENT_ID_SIZE
);
1295 if(cycle_count
< tf
->pre_cycle_count
)tf
->count
++;
1296 tf
->pre_cycle_count
= cycle_count
;
1297 cycle_count
+= tmpCycleCount
* tf
->count
;
1299 // if(tf->cur_heart_beat_number > tf->count)
1300 // cycle_count += tmpCycleCount * (tf->cur_heart_beat_number - tf->count);
1302 tf
->cur_cycle_count
= cycle_count
;
1304 lEventTotalCycle
= cycle_count
;
1305 lEventTotalCycle
-= tf
->a_block_start
->cycle_count
;
1307 // Convert it to nsecs
1308 lEventNSec
= (double)lEventTotalCycle
/ (double)tf
->cycle_per_nsec
;
1310 // Determine offset in struct LttTime
1311 lTimeOffset
.tv_nsec
= lEventNSec
% NANOSECONDS_PER_SECOND
;
1312 lTimeOffset
.tv_sec
= lEventNSec
/ NANOSECONDS_PER_SECOND
;
1314 time
= ltt_time_add(tf
->a_block_start
->time
, lTimeOffset
);
1319 /*****************************************************************************
1321 * setFieldsOffset : set offset of the fields
1323 * tracefile : opened trace file
1324 * evT : the event type
1325 * evD : event data, it may be NULL
1326 ****************************************************************************/
1328 void setFieldsOffset(LttTracefile
*tf
,LttEventType
*evT
,void *evD
,LttTrace
* t
)
1330 LttField
* rootFld
= evT
->root_field
;
1331 // rootFld->base_address = evD;
1334 rootFld
->field_size
= getFieldtypeSize(tf
, evT
, 0,0,rootFld
, evD
,t
);
1337 /*****************************************************************************
1339 * getFieldtypeSize: get the size of the field type (primitive type)
1341 * tracefile : opened trace file
1343 * offsetRoot : offset from the root
1344 * offsetParent : offset from the parrent
1346 * evD : event data, it may be NULL
1348 * int : size of the field
1349 ****************************************************************************/
1351 int getFieldtypeSize(LttTracefile
* t
, LttEventType
* evT
, int offsetRoot
,
1352 int offsetParent
, LttField
* fld
, void *evD
, LttTrace
*trace
)
1354 int size
, size1
, element_number
, i
, offset1
, offset2
;
1355 LttType
* type
= fld
->field_type
;
1358 if(evT
->latest_block
==t
->which_block
&& evT
->latest_event
==t
->which_event
){
1359 return fld
->field_size
;
1363 if(fld
->field_fixed
== 1){
1364 if(fld
== evT
->root_field
) return fld
->field_size
;
1367 switch(type
->type_class
) {
1369 element_number
= (int) type
->element_number
;
1370 if(fld
->field_fixed
== -1){
1371 size
= getFieldtypeSize(t
, evT
, offsetRoot
,
1372 0,fld
->child
[0], NULL
, trace
);
1373 if(size
== 0){ //has string or sequence
1374 fld
->field_fixed
= 0;
1376 fld
->field_fixed
= 1;
1377 size
*= element_number
;
1379 }else if(fld
->field_fixed
== 0){// has string or sequence
1381 for(i
=0;i
<element_number
;i
++){
1382 size
+= getFieldtypeSize(t
, evT
, offsetRoot
+size
,size
,
1383 fld
->child
[0], evD
+size
, trace
);
1385 }else size
= fld
->field_size
;
1389 size1
= (int) ltt_type_size(trace
, type
);
1390 if(fld
->field_fixed
== -1){
1391 fld
->sequ_number_size
= size1
;
1392 fld
->field_fixed
= 0;
1393 size
= getFieldtypeSize(t
, evT
, offsetRoot
,
1394 0,fld
->child
[0], NULL
, trace
);
1395 fld
->element_size
= size
;
1397 element_number
= getIntNumber(size1
,evD
);
1398 type
->element_number
= element_number
;
1399 if(fld
->element_size
> 0){
1400 size
= element_number
* fld
->element_size
;
1401 }else{//sequence has string or sequence
1403 for(i
=0;i
<element_number
;i
++){
1404 size
+= getFieldtypeSize(t
, evT
, offsetRoot
+size
+size1
,size
+size1
,
1405 fld
->child
[0], evD
+size
+size1
, trace
);
1414 if(fld
->field_fixed
== -1){
1415 fld
->field_fixed
= 0;
1417 size
= strlen((char*)evD
) + 1; //include end : '\0'
1422 element_number
= (int) type
->element_number
;
1424 if(fld
->field_fixed
== -1){
1425 offset1
= offsetRoot
;
1427 for(i
=0;i
<element_number
;i
++){
1428 size1
=getFieldtypeSize(t
, evT
,offset1
,offset2
,
1429 fld
->child
[i
], NULL
, trace
);
1430 if(size1
> 0 && size
>= 0){
1432 if(offset1
>= 0) offset1
+= size1
;
1441 fld
->field_fixed
= 0;
1443 }else fld
->field_fixed
= 1;
1444 }else if(fld
->field_fixed
== 0){
1445 offset1
= offsetRoot
;
1447 for(i
=0;i
<element_number
;i
++){
1448 size
=getFieldtypeSize(t
,evT
,offset1
,offset2
,
1449 fld
->child
[i
],evD
+offset2
, trace
);
1454 }else size
= fld
->field_size
;
1458 if(fld
->field_fixed
== -1){
1459 size
= (int) ltt_type_size(trace
, type
);
1460 fld
->field_fixed
= 1;
1461 }else size
= fld
->field_size
;
1468 if(type
->type_class
!= LTT_STRUCT
&& type
->type_class
!= LTT_ARRAY
&&
1469 type
->type_class
!= LTT_SEQUENCE
&& type
->type_class
!= LTT_STRING
){
1470 if(fld
->field_fixed
== -1){
1471 size
= (int) ltt_type_size(trace
, type
);
1472 fld
->field_fixed
= 1;
1473 }else size
= fld
->field_size
;
1475 }else if(type
->type_class
== LTT_ARRAY
){
1476 element_number
= (int) type
->element_number
;
1477 if(fld
->field_fixed
== -1){
1478 size
= getFieldtypeSize(t
, evT
, offsetRoot
,0,fld
->child
[0], NULL
, trace
);
1479 if(size
== 0){ //has string or sequence
1480 fld
->field_fixed
= 0;
1482 fld
->field_fixed
= 1;
1483 size
*= element_number
;
1485 }else if(fld
->field_fixed
== 0){// has string or sequence
1487 for(i
=0;i
<element_number
;i
++){
1488 size
+= getFieldtypeSize(t
, evT
, offsetRoot
+size
,size
,
1489 fld
->child
[0], evD
+size
, trace
);
1491 }else size
= fld
->field_size
;
1493 }else if(type
->type_class
== LTT_SEQUENCE
){
1494 size1
= (int) ltt_type_size(trace
, type
);
1495 if(fld
->field_fixed
== -1){
1496 fld
->sequ_number_size
= size1
;
1497 fld
->field_fixed
= 0;
1498 size
= getFieldtypeSize(t
, evT
, offsetRoot
,0,fld
->child
[0], NULL
, trace
);
1499 fld
->element_size
= size
;
1501 element_number
= getIntNumber(size1
,evD
);
1502 type
->element_number
= element_number
;
1503 if(fld
->element_size
> 0){
1504 size
= element_number
* fld
->element_size
;
1505 }else{//sequence has string or sequence
1507 for(i
=0;i
<element_number
;i
++){
1508 size
+= getFieldtypeSize(t
, evT
, offsetRoot
+size
+size1
,size
+size1
,
1509 fld
->child
[0], evD
+size
+size1
, trace
);
1515 }else if(type
->type_class
== LTT_STRING
){
1517 if(fld
->field_fixed
== -1){
1518 fld
->field_fixed
= 0;
1520 size
= strlen((char*)evD
) + 1; //include end : '\0'
1523 }else if(type
->type_class
== LTT_STRUCT
){
1524 element_number
= (int) type
->element_number
;
1526 if(fld
->field_fixed
== -1){
1527 offset1
= offsetRoot
;
1529 for(i
=0;i
<element_number
;i
++){
1530 size1
=getFieldtypeSize(t
, evT
,offset1
,offset2
, fld
->child
[i
], NULL
, trace
);
1531 if(size1
> 0 && size
>= 0){
1533 if(offset1
>= 0) offset1
+= size1
;
1542 fld
->field_fixed
= 0;
1544 }else fld
->field_fixed
= 1;
1545 }else if(fld
->field_fixed
== 0){
1546 offset1
= offsetRoot
;
1548 for(i
=0;i
<element_number
;i
++){
1549 size
=getFieldtypeSize(t
,evT
,offset1
,offset2
,fld
->child
[i
],evD
+offset2
, trace
);
1554 }else size
= fld
->field_size
;
1558 fld
->offset_root
= offsetRoot
;
1559 fld
->offset_parent
= offsetParent
;
1561 fld
->fixed_root
= (offsetRoot
==-1) ? 0 : 1;
1562 fld
->fixed_parent
= (offsetParent
==-1) ? 0 : 1;
1564 fld
->field_size
= size
;
1570 /*****************************************************************************
1572 * getIntNumber : get an integer number
1574 * size : the size of the integer
1575 * evD : the event data
1577 * gint64 : a 64 bits integer
1578 ****************************************************************************/
1580 gint64
getIntNumber(int size
, void *evD
)
1585 case 1: i
= *(gint8
*)evD
; break;
1586 case 2: i
= *(gint16
*)evD
; break;
1587 case 4: i
= *(gint32
*)evD
; break;
1588 case 8: i
= *(gint64
*)evD
; break;
1589 default: i
= *(gint64
*)evD
;
1590 g_critical("getIntNumber : integer size %d unknown", size
);
1595 if(size
== 1) i
= *(gint8
*)evD
;
1596 else if(size
== 2) i
= *(gint16
*)evD
;
1597 else if(size
== 4) i
= *(gint32
*)evD
;
1598 else if(size
== 8) i
= *(gint64
*)evD
;
1604 /*****************************************************************************
1606 * getDataEndianType : get the data type size and endian type of the local
1609 * size : size of data type
1610 * endian : endian type, little or big
1611 ****************************************************************************/
1613 void getDataEndianType(LttArchSize
* size
, LttArchEndian
* endian
)
1617 int sizeInt
=sizeof(int), sizeLong
=sizeof(long), sizePointer
=sizeof(void *);
1619 if(c
== 1) *endian
= LTT_LITTLE_ENDIAN
;
1620 else *endian
= LTT_BIG_ENDIAN
;
1622 if(sizeInt
== 2 && sizeLong
== 4 && sizePointer
== 4)
1624 else if(sizeInt
== 4 && sizeLong
== 4 && sizePointer
== 4)
1626 else if(sizeInt
== 4 && sizeLong
== 8 && sizePointer
== 8)
1628 else if(sizeInt
== 8 && sizeLong
== 8 && sizePointer
== 8)
1630 else *size
= LTT_UNKNOWN
;
1633 /* get the node name of the system */
1635 char * ltt_trace_system_description_node_name (LttSystemDescription
* s
)
1637 return s
->node_name
;
1641 /* get the domain name of the system */
1643 char * ltt_trace_system_description_domain_name (LttSystemDescription
* s
)
1645 return s
->domain_name
;
1649 /* get the description of the system */
1651 char * ltt_trace_system_description_description (LttSystemDescription
* s
)
1653 return s
->description
;
1657 /* get the start time of the trace */
1659 LttTime
ltt_trace_system_description_trace_start_time(LttSystemDescription
*s
)
1661 return s
->trace_start
;
1665 LttTracefile
*ltt_tracefile_new()
1667 return g_new(LttTracefile
, 1);
1670 void ltt_tracefile_destroy(LttTracefile
*tf
)
1675 void ltt_tracefile_copy(LttTracefile
*dest
, const LttTracefile
*src
)