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__))
45 /* obtain the time of an event */
47 static inline LttTime
getEventTime(LttTracefile
* tf
);
50 /* set the offset of the fields belonging to the event,
51 need the information of the archecture */
52 void setFieldsOffset(LttTracefile
*tf
,LttEventType
*evT
,void *evD
,LttTrace
*t
);
54 /* get the size of the field type according to the archtecture's
55 size and endian type(info of the archecture) */
56 int getFieldtypeSize(LttTracefile
* tf
, LttEventType
* evT
, int offsetRoot
,
57 int offsetParent
, LttField
*fld
, void *evD
, LttTrace
* t
);
59 /* read a fixed size or a block information from the file (fd) */
60 int readFile(int fd
, void * buf
, size_t size
, char * mesg
);
61 int readBlock(LttTracefile
* tf
, int whichBlock
);
63 /* calculate cycles per nsec for current block */
64 void getCyclePerNsec(LttTracefile
* t
);
66 /* reinitialize the info of the block which is already in the buffer */
67 void updateTracefile(LttTracefile
* tf
);
69 /* go to the next event */
70 int skipEvent(LttTracefile
* t
);
73 /* Functions to parse system.xml file (using glib xml parser) */
74 static void parser_start_element (GMarkupParseContext __UNUSED__
*context
,
75 const gchar
*element_name
,
76 const gchar
**attribute_names
,
77 const gchar
**attribute_values
,
82 LttSystemDescription
* des
= (LttSystemDescription
* )user_data
;
83 if(strcmp("system", element_name
)){
84 *error
= g_error_new(G_MARKUP_ERROR
,
86 "This is not system.xml file");
90 while(attribute_names
[i
]){
91 if(strcmp("node_name", attribute_names
[i
])==0){
92 des
->node_name
= g_strdup(attribute_values
[i
]);
93 }else if(strcmp("domainname", attribute_names
[i
])==0){
94 des
->domain_name
= g_strdup(attribute_values
[i
]);
95 }else if(strcmp("cpu", attribute_names
[i
])==0){
96 des
->nb_cpu
= atoi(attribute_values
[i
]);
97 }else if(strcmp("arch_size", attribute_names
[i
])==0){
98 if(strcmp(attribute_values
[i
],"LP32") == 0) des
->size
= LTT_LP32
;
99 else if(strcmp(attribute_values
[i
],"ILP32") == 0) des
->size
= LTT_ILP32
;
100 else if(strcmp(attribute_values
[i
],"LP64") == 0) des
->size
= LTT_LP64
;
101 else if(strcmp(attribute_values
[i
],"ILP64") == 0) des
->size
= LTT_ILP64
;
102 else if(strcmp(attribute_values
[i
],"UNKNOWN") == 0) des
->size
= LTT_UNKNOWN
;
103 }else if(strcmp("endian", attribute_names
[i
])==0){
104 if(strcmp(attribute_values
[i
],"LITTLE_ENDIAN") == 0)
105 des
->endian
= LTT_LITTLE_ENDIAN
;
106 else if(strcmp(attribute_values
[i
],"BIG_ENDIAN") == 0)
107 des
->endian
= LTT_BIG_ENDIAN
;
108 }else if(strcmp("kernel_name", attribute_names
[i
])==0){
109 des
->kernel_name
= g_strdup(attribute_values
[i
]);
110 }else if(strcmp("kernel_release", attribute_names
[i
])==0){
111 des
->kernel_release
= g_strdup(attribute_values
[i
]);
112 }else if(strcmp("kernel_version", attribute_names
[i
])==0){
113 des
->kernel_version
= g_strdup(attribute_values
[i
]);
114 }else if(strcmp("machine", attribute_names
[i
])==0){
115 des
->machine
= g_strdup(attribute_values
[i
]);
116 }else if(strcmp("processor", attribute_names
[i
])==0){
117 des
->processor
= g_strdup(attribute_values
[i
]);
118 }else if(strcmp("hardware_platform", attribute_names
[i
])==0){
119 des
->hardware_platform
= g_strdup(attribute_values
[i
]);
120 }else if(strcmp("operating_system", attribute_names
[i
])==0){
121 des
->operating_system
= g_strdup(attribute_values
[i
]);
122 }else if(strcmp("ltt_major_version", attribute_names
[i
])==0){
123 des
->ltt_major_version
= atoi(attribute_values
[i
]);
124 }else if(strcmp("ltt_minor_version", attribute_names
[i
])==0){
125 des
->ltt_minor_version
= atoi(attribute_values
[i
]);
126 }else if(strcmp("ltt_block_size", attribute_names
[i
])==0){
127 des
->ltt_block_size
= atoi(attribute_values
[i
]);
129 *error
= g_error_new(G_MARKUP_ERROR
,
131 "Not a valid attribute");
138 static void parser_characters (GMarkupParseContext __UNUSED__
*context
,
140 gsize __UNUSED__ text_len
,
142 GError __UNUSED__
**error
)
144 LttSystemDescription
* des
= (LttSystemDescription
* )user_data
;
145 des
->description
= g_strdup(text
);
149 /*****************************************************************************
151 * ltt_tracefile_open : open a trace file, construct a LttTracefile
153 * t : the trace containing the tracefile
154 * fileName : path name of the trace file
156 * : a pointer to a tracefile
157 ****************************************************************************/
159 LttTracefile
* ltt_tracefile_open(LttTrace
* t
, char * fileName
)
162 struct stat lTDFStat
; /* Trace data file status */
164 tf
= g_new(LttTracefile
, 1);
167 tf
->name
= g_strdup(fileName
);
169 tf
->fd
= open(fileName
, O_RDONLY
, 0);
171 g_warning("Unable to open input data file %s\n", fileName
);
177 // Get the file's status
178 if(fstat(tf
->fd
, &lTDFStat
) < 0){
179 g_warning("Unable to get the status of the input data file %s\n", fileName
);
186 // Is the file large enough to contain a trace
187 if(lTDFStat
.st_size
< (off_t
)(sizeof(BlockStart
) + EVENT_HEADER_SIZE
)){
188 g_print("The input data file %s does not contain a trace\n", fileName
);
195 //store the size of the file
196 tf
->file_size
= lTDFStat
.st_size
;
197 tf
->block_size
= t
->system_description
->ltt_block_size
;
198 tf
->block_number
= tf
->file_size
/ tf
->block_size
;
201 //allocate memory to contain the info of a block
202 tf
->buffer
= (void *) g_new(char, t
->system_description
->ltt_block_size
);
204 //read the first block
205 if(readBlock(tf
,1)) exit(1);
211 /*****************************************************************************
212 *Open control and per cpu tracefiles
213 ****************************************************************************/
215 void ltt_tracefile_open_cpu(LttTrace
*t
, char * tracefile_name
)
218 tf
= ltt_tracefile_open(t
,tracefile_name
);
220 t
->per_cpu_tracefile_number
++;
221 g_ptr_array_add(t
->per_cpu_tracefiles
, tf
);
224 gint
ltt_tracefile_open_control(LttTrace
*t
, char * control_name
)
233 tf
= ltt_tracefile_open(t
,control_name
);
235 g_warning("ltt_tracefile_open_control : bad file descriptor");
238 t
->control_tracefile_number
++;
239 g_ptr_array_add(t
->control_tracefiles
,tf
);
241 //parse facilities tracefile to get base_id
242 if(strcmp(&control_name
[strlen(control_name
)-10],"facilities") ==0){
244 if(!ltt_tracefile_read(tf
,&ev
)) return 0; // end of file
246 if(ev
.event_id
== TRACE_FACILITY_LOAD
){
248 fLoad
.name
= (char*)pos
;
249 fLoad
.checksum
= *(LttChecksum
*)(pos
+ strlen(fLoad
.name
));
250 fLoad
.base_code
= *(guint32
*)(pos
+ strlen(fLoad
.name
) + sizeof(LttChecksum
));
252 for(i
=0;i
<t
->facility_number
;i
++){
253 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
,i
);
254 if(strcmp(f
->name
,fLoad
.name
)==0 && fLoad
.checksum
==f
->checksum
){
255 f
->base_id
= fLoad
.base_code
;
259 if(i
==t
->facility_number
) {
260 g_warning("Facility: %s, checksum: %u is not found",
261 fLoad
.name
,(unsigned int)fLoad
.checksum
);
264 }else if(ev
.event_id
== TRACE_BLOCK_START
){
266 }else if(ev
.event_id
== TRACE_BLOCK_END
){
269 g_warning("Not valid facilities trace file");
277 /*****************************************************************************
279 * ltt_tracefile_close: close a trace file,
281 * t : tracefile which will be closed
282 ****************************************************************************/
284 void ltt_tracefile_close(LttTracefile
*t
)
293 /*****************************************************************************
294 *Get system information
295 ****************************************************************************/
296 gint
getSystemInfo(LttSystemDescription
* des
, char * pathname
)
299 char buf
[DIR_NAME_SIZE
];
301 GMarkupParseContext
* context
;
302 GError
* error
= NULL
;
303 GMarkupParser markup_parser
=
305 parser_start_element
,
308 NULL
, /* passthrough */
312 fp
= fopen(pathname
,"r");
314 g_warning("Can not open file : %s\n", pathname
);
318 context
= g_markup_parse_context_new(&markup_parser
, 0, des
,NULL
);
320 while(fgets(buf
,DIR_NAME_SIZE
, fp
) != NULL
){
321 if(!g_markup_parse_context_parse(context
, buf
, DIR_NAME_SIZE
, &error
)){
323 g_warning("Can not parse xml file: \n%s\n", error
->message
);
326 g_markup_parse_context_free(context
);
331 g_markup_parse_context_free(context
);
336 /*****************************************************************************
337 *The following functions get facility/tracefile information
338 ****************************************************************************/
340 gint
getFacilityInfo(LttTrace
*t
, char* eventdefs
)
343 struct dirent
*entry
;
348 char name
[DIR_NAME_SIZE
];
350 dir
= opendir(eventdefs
);
352 g_warning("Can not open directory: %s\n", eventdefs
);
356 while((entry
= readdir(dir
)) != NULL
){
357 ptr
= &entry
->d_name
[strlen(entry
->d_name
)-4];
358 if(strcmp(ptr
,".xml") != 0) continue;
359 strcpy(name
,eventdefs
);
360 strcat(name
,entry
->d_name
);
361 ltt_facility_open(t
,name
);
365 for(j
=0;j
<t
->facility_number
;j
++){
366 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
, j
);
367 for(i
=0; i
<f
->event_number
; i
++){
369 setFieldsOffset(NULL
, et
, NULL
, t
);
375 gint
getControlFileInfo(LttTrace
*t
, char* control
)
378 struct dirent
*entry
;
379 char name
[DIR_NAME_SIZE
];
381 dir
= opendir(control
);
383 g_warning("Can not open directory: %s\n", control
);
387 while((entry
= readdir(dir
)) != NULL
){
388 if(strcmp(entry
->d_name
,"facilities") != 0 &&
389 strcmp(entry
->d_name
,"interrupts") != 0 &&
390 strcmp(entry
->d_name
,"processes") != 0) continue;
392 strcpy(name
,control
);
393 strcat(name
,entry
->d_name
);
394 if(ltt_tracefile_open_control(t
,name
))
401 gint
getCpuFileInfo(LttTrace
*t
, char* cpu
)
404 struct dirent
*entry
;
405 char name
[DIR_NAME_SIZE
];
409 g_warning("Can not open directory: %s\n", cpu
);
413 while((entry
= readdir(dir
)) != NULL
){
414 if(strcmp(entry
->d_name
,".") != 0 &&
415 strcmp(entry
->d_name
,"..") != 0 &&
416 strcmp(entry
->d_name
,".svn") != 0){
418 strcat(name
,entry
->d_name
);
419 ltt_tracefile_open_cpu(t
,name
);
426 /*****************************************************************************
427 *A trace is specified as a pathname to the directory containing all the
428 *associated data (control tracefiles, per cpu tracefiles, event
431 *When a trace is closed, all the associated facilities, types and fields
432 *are released as well.
436 /****************************************************************************
437 * get_absolute_pathname
439 * return the unique pathname in the system
441 * MD : Fixed this function so it uses realpath, dealing well with
442 * forgotten cases (.. were not used correctly before).
444 ****************************************************************************/
445 void get_absolute_pathname(const char *pathname
, char * abs_pathname
)
447 abs_pathname
[0] = '\0';
449 if ( realpath (pathname
, abs_pathname
) != NULL
)
453 /* error, return the original path unmodified */
454 strcpy(abs_pathname
, pathname
);
460 LttTrace
*ltt_trace_open(const char *pathname
)
463 LttSystemDescription
* sys_description
;
464 char eventdefs
[DIR_NAME_SIZE
];
465 char info
[DIR_NAME_SIZE
];
466 char control
[DIR_NAME_SIZE
];
467 char cpu
[DIR_NAME_SIZE
];
468 char tmp
[DIR_NAME_SIZE
];
469 char abs_path
[DIR_NAME_SIZE
];
470 gboolean has_slash
= FALSE
;
472 get_absolute_pathname(pathname
, abs_path
);
473 //establish the pathname to different directories
474 if(abs_path
[strlen(abs_path
)-1] == '/')has_slash
= TRUE
;
475 strcpy(eventdefs
,abs_path
);
476 if(!has_slash
)strcat(eventdefs
,"/");
477 strcat(eventdefs
,"eventdefs/");
479 strcpy(info
,abs_path
);
480 if(!has_slash
)strcat(info
,"/");
481 strcat(info
,"info/");
483 strcpy(control
,abs_path
);
484 if(!has_slash
)strcat(control
,"/");
485 strcat(control
,"control/");
487 strcpy(cpu
,abs_path
);
488 if(!has_slash
)strcat(cpu
,"/");
492 sys_description
= g_new(LttSystemDescription
, 1);
493 t
= g_new(LttTrace
, 1);
494 t
->pathname
= g_strdup(abs_path
);
495 t
->facility_number
= 0;
496 t
->control_tracefile_number
= 0;
497 t
->per_cpu_tracefile_number
= 0;
498 t
->system_description
= sys_description
;
499 t
->control_tracefiles
= g_ptr_array_new();
500 t
->per_cpu_tracefiles
= g_ptr_array_new();
501 t
->facilities
= g_ptr_array_new();
502 getDataEndianType(&(t
->my_arch_size
), &(t
->my_arch_endian
));
504 //get system description
506 strcat(tmp
,"system.xml");
507 if(getSystemInfo(sys_description
, tmp
)) {
508 g_ptr_array_free(t
->facilities
, TRUE
);
509 g_ptr_array_free(t
->per_cpu_tracefiles
, TRUE
);
510 g_ptr_array_free(t
->control_tracefiles
, TRUE
);
511 g_free(sys_description
);
519 //get facilities info
520 if(getFacilityInfo(t
,eventdefs
)) {
521 g_ptr_array_free(t
->facilities
, TRUE
);
522 g_ptr_array_free(t
->per_cpu_tracefiles
, TRUE
);
523 g_ptr_array_free(t
->control_tracefiles
, TRUE
);
524 g_free(sys_description
);
530 //get control tracefile info
531 getControlFileInfo(t
,control
);
533 if(getControlFileInfo(t,control)) {
534 g_ptr_array_free(t->facilities, TRUE);
535 g_ptr_array_free(t->per_cpu_tracefiles, TRUE);
536 g_ptr_array_free(t->control_tracefiles, TRUE);
537 g_free(sys_description);
541 }*/ // With fatal error
543 //get cpu tracefile info
544 if(getCpuFileInfo(t
,cpu
)) {
545 g_ptr_array_free(t
->facilities
, TRUE
);
546 g_ptr_array_free(t
->per_cpu_tracefiles
, TRUE
);
547 g_ptr_array_free(t
->control_tracefiles
, TRUE
);
548 g_free(sys_description
);
557 char * ltt_trace_name(LttTrace
*t
)
563 /******************************************************************************
564 * When we copy a trace, we want all the opening actions to happen again :
565 * the trace will be reopened and totally independant from the original.
566 * That's why we call ltt_trace_open.
567 *****************************************************************************/
568 LttTrace
*ltt_trace_copy(LttTrace
*self
)
570 return ltt_trace_open(self
->pathname
);
573 void ltt_trace_close(LttTrace
*t
)
581 //free system_description
582 g_free(t
->system_description
->description
);
583 g_free(t
->system_description
->node_name
);
584 g_free(t
->system_description
->domain_name
);
585 g_free(t
->system_description
->kernel_name
);
586 g_free(t
->system_description
->kernel_release
);
587 g_free(t
->system_description
->kernel_version
);
588 g_free(t
->system_description
->machine
);
589 g_free(t
->system_description
->processor
);
590 g_free(t
->system_description
->hardware_platform
);
591 g_free(t
->system_description
->operating_system
);
592 g_free(t
->system_description
);
594 //free control_tracefiles
595 for(i
=0;i
<t
->control_tracefile_number
;i
++){
596 tf
= (LttTracefile
*)g_ptr_array_index(t
->control_tracefiles
,i
);
597 ltt_tracefile_close(tf
);
599 g_ptr_array_free(t
->control_tracefiles
, TRUE
);
601 //free per_cpu_tracefiles
602 for(i
=0;i
<t
->per_cpu_tracefile_number
;i
++){
603 tf
= (LttTracefile
*)g_ptr_array_index(t
->per_cpu_tracefiles
,i
);
604 ltt_tracefile_close(tf
);
606 g_ptr_array_free(t
->per_cpu_tracefiles
, TRUE
);
609 for(i
=0;i
<t
->facility_number
;i
++){
610 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
,i
);
611 ltt_facility_close(f
);
613 g_ptr_array_free(t
->facilities
, TRUE
);
621 /*****************************************************************************
622 *Get the system description of the trace
623 ****************************************************************************/
625 LttSystemDescription
*ltt_trace_system_description(LttTrace
*t
)
627 return t
->system_description
;
630 /*****************************************************************************
631 * The following functions discover the facilities of the trace
632 ****************************************************************************/
634 unsigned ltt_trace_facility_number(LttTrace
*t
)
636 return (unsigned)(t
->facility_number
);
639 LttFacility
*ltt_trace_facility_get(LttTrace
*t
, unsigned i
)
641 return (LttFacility
*)g_ptr_array_index(t
->facilities
, i
);
644 /*****************************************************************************
646 * ltt_trace_facility_find : find facilities in the trace
649 * name : facility name
651 * position : position of the facility in the trace
653 * : the number of facilities
654 ****************************************************************************/
656 unsigned ltt_trace_facility_find(LttTrace
*t
, char *name
, unsigned *position
)
658 unsigned int i
, count
=0;
660 for(i
=0;i
<t
->facility_number
;i
++){
661 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
, i
);
662 if(strcmp(f
->name
,name
)==0){
664 if(count
==1) *position
= i
;
672 /*****************************************************************************
673 * Functions to discover all the event types in the trace
674 ****************************************************************************/
676 unsigned ltt_trace_eventtype_number(LttTrace
*t
)
681 for(i
=0;i
<t
->facility_number
;i
++){
682 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
, i
);
683 count
+= f
->event_number
;
688 LttFacility
* ltt_trace_facility_by_id(LttTrace
* trace
, unsigned id
)
690 LttFacility
* facility
= NULL
;
693 for(i
=0;i
<trace
->facility_number
;i
++){
694 LttFacility
*iter_facility
=
695 (LttFacility
*) g_ptr_array_index(trace
->facilities
,i
);
696 if(id
>= iter_facility
->base_id
&&
697 id
< iter_facility
->base_id
+ iter_facility
->event_number
) {
698 facility
= iter_facility
;
706 LttEventType
*ltt_trace_eventtype_get(LttTrace
*t
, unsigned evId
)
709 f
= ltt_trace_facility_by_id(t
,evId
);
711 return f
->events
[evId
- f
->base_id
];
714 /*****************************************************************************
715 *There is one "per cpu" tracefile for each CPU, numbered from 0 to
716 *the maximum number of CPU in the system. When the number of CPU installed
717 *is less than the maximum, some positions are unused. There are also a
718 *number of "control" tracefiles (facilities, interrupts...).
719 ****************************************************************************/
720 unsigned ltt_trace_control_tracefile_number(LttTrace
*t
)
722 return t
->control_tracefile_number
;
725 unsigned ltt_trace_per_cpu_tracefile_number(LttTrace
*t
)
727 return t
->per_cpu_tracefile_number
;
730 /*****************************************************************************
731 *It is possible to search for the tracefiles by name or by CPU position.
732 *The index within the tracefiles of the same type is returned if found
733 *and a negative value otherwise.
734 ****************************************************************************/
736 int ltt_trace_control_tracefile_find(LttTrace
*t
, const gchar
*name
)
738 LttTracefile
* tracefile
;
740 for(i
=0;i
<t
->control_tracefile_number
;i
++){
741 tracefile
= (LttTracefile
*)g_ptr_array_index(t
->control_tracefiles
, i
);
742 if(strcmp(tracefile
->name
, name
)==0)break;
744 if(i
== t
->control_tracefile_number
) return -1;
748 /* not really useful. We just have to know that cpu tracefiles
749 * comes before control tracefiles.
751 int ltt_trace_per_cpu_tracefile_find(LttTrace
*t
, const gchar
*name
)
753 LttTracefile
* tracefile
;
755 for(i
=0;i
<t
->per_cpu_tracefile_number
;i
++){
756 tracefile
= (LttTracefile
*)g_ptr_array_index(t
->per_cpu_tracefiles
, i
);
757 if(strcmp(tracefile
->name
, name
)==0)break;
759 if(i
== t
->per_cpu_tracefile_number
) return -1;
763 /*****************************************************************************
764 *Get a specific tracefile
765 ****************************************************************************/
767 LttTracefile
*ltt_trace_control_tracefile_get(LttTrace
*t
, unsigned i
)
769 return (LttTracefile
*)g_ptr_array_index(t
->control_tracefiles
, i
);
772 LttTracefile
*ltt_trace_per_cpu_tracefile_get(LttTrace
*t
, unsigned i
)
774 return (LttTracefile
*)g_ptr_array_index(t
->per_cpu_tracefiles
, i
);
777 /*****************************************************************************
778 * Get the start time and end time of the trace
779 ****************************************************************************/
781 void ltt_trace_time_span_get(LttTrace
*t
, LttTime
*start
, LttTime
*end
)
783 LttTime startSmall
, startTmp
, endBig
, endTmp
;
787 for(i
=0;i
<t
->control_tracefile_number
;i
++){
788 tf
= g_ptr_array_index(t
->control_tracefiles
, i
);
790 startTmp
= tf
->a_block_start
->time
;
791 readBlock(tf
,tf
->block_number
);
792 endTmp
= tf
->a_block_end
->time
;
794 startSmall
= startTmp
;
799 if(ltt_time_compare(startSmall
,startTmp
) > 0) startSmall
= startTmp
;
800 if(ltt_time_compare(endBig
,endTmp
) < 0) endBig
= endTmp
;
803 for(i
=0;i
<t
->per_cpu_tracefile_number
;i
++){
804 tf
= g_ptr_array_index(t
->per_cpu_tracefiles
, i
);
806 startTmp
= tf
->a_block_start
->time
;
807 readBlock(tf
,tf
->block_number
);
808 endTmp
= tf
->a_block_end
->time
;
810 startSmall
= startTmp
;
814 if(ltt_time_compare(startSmall
,startTmp
) > 0) startSmall
= startTmp
;
815 if(ltt_time_compare(endBig
,endTmp
) < 0) endBig
= endTmp
;
818 if(start
!= NULL
) *start
= startSmall
;
819 if(end
!= NULL
) *end
= endBig
;
823 /*****************************************************************************
824 *Get the name of a tracefile
825 ****************************************************************************/
827 char *ltt_tracefile_name(LttTracefile
*tf
)
832 /*****************************************************************************
833 * Get the number of blocks in the tracefile
834 ****************************************************************************/
836 unsigned ltt_tracefile_block_number(LttTracefile
*tf
)
838 return tf
->block_number
;
841 /*****************************************************************************
843 * ltt_tracefile_seek_time: seek to the first event of the trace with time
844 * larger or equal to time
847 * time : criteria of the time
848 ****************************************************************************/
849 void ltt_tracefile_find_time_block(LttTracefile
*t
, LttTime time
,
850 int start_block
, int end_block
)
852 int err
, tmp_block
, s
, e
;
856 err
=readBlock(t
,start_block
);
857 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
858 if(start_block
== end_block
)return;
860 tailTime
= ltt_time_compare(t
->a_block_end
->time
, time
);
861 if(tailTime
>= 0) return;
863 err
=readBlock(t
,end_block
);
864 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
865 if(start_block
+1 == end_block
)return;
867 headTime
= ltt_time_compare(t
->a_block_start
->time
, time
);
868 if(headTime
<= 0 ) return;
870 tmp_block
= (end_block
+ start_block
)/2;
871 err
=readBlock(t
,tmp_block
);
872 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
874 headTime
= ltt_time_compare(t
->a_block_start
->time
, time
);
875 tailTime
= ltt_time_compare(t
->a_block_end
->time
, time
);
876 if(headTime
<= 0 && tailTime
>= 0) return;
882 ltt_tracefile_find_time_block(t
, time
, s
, e
);
890 ltt_tracefile_find_time_block(t
, time
, s
, e
);
895 void ltt_tracefile_backward_find_time_block(LttTracefile
*t
, LttTime time
)
897 int t_time
, h_time
, err
;
898 err
=readBlock(t
,t
->which_block
-1);
899 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
900 h_time
= ltt_time_compare(t
->a_block_start
->time
, time
);
901 t_time
= ltt_time_compare(t
->a_block_end
->time
, time
);
904 if(t
->which_block
== 1) return;
905 err
=readBlock(t
,t
->which_block
-1);
906 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
907 tmp
= ltt_time_compare(t
->a_block_end
->time
, time
);
908 if(tmp
== 0) return ltt_tracefile_seek_time(t
, time
);
909 err
=readBlock(t
,t
->which_block
+1);
910 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
911 }else if(h_time
> 0){
912 ltt_tracefile_find_time_block(t
, time
, 1, t
->which_block
);
913 return ltt_tracefile_seek_time(t
, time
) ;
915 if(t_time
>= 0) return ltt_tracefile_seek_time(t
, time
);
916 err
=readBlock(t
,t
->which_block
+1);
917 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
921 void ltt_tracefile_seek_time(LttTracefile
*t
, LttTime time
)
925 int headTime
= ltt_time_compare(t
->a_block_start
->time
, time
);
926 int tailTime
= ltt_time_compare(t
->a_block_end
->time
, time
);
929 if(headTime
< 0 && tailTime
> 0){
930 if(ltt_time_compare(t
->a_block_end
->time
, t
->current_event_time
) !=0) {
931 lttTime
= getEventTime(t
);
932 err
= ltt_time_compare(lttTime
, time
);
934 if(t
->which_event
==2 || ltt_time_compare(t
->prev_event_time
,time
)<0){
938 return ltt_tracefile_seek_time(t
, time
);
942 if(ltt_tracefile_read(t
,&ev
) == NULL
) {
943 g_print("End of file\n");
946 lttTime
= getEventTime(t
);
947 err
= ltt_time_compare(lttTime
, time
);
951 }else{//we are at the end of the block
953 return ltt_tracefile_seek_time(t
, time
);
955 }else if(headTime
>= 0){
956 if(t
->which_block
== 1){
959 if(ltt_time_compare(t
->prev_block_end_time
, time
) >= 0 ||
960 (t
->prev_block_end_time
.tv_sec
== 0 &&
961 t
->prev_block_end_time
.tv_nsec
== 0 )){
962 ltt_tracefile_backward_find_time_block(t
, time
);
967 }else if(tailTime
< 0){
968 if(t
->which_block
!= t
->block_number
){
969 ltt_tracefile_find_time_block(t
, time
, t
->which_block
+1, t
->block_number
);
970 return ltt_tracefile_seek_time(t
, time
);
972 t
->cur_event_pos
= t
->buffer
+ t
->block_size
;
973 g_print("End of file\n");
976 }else if(tailTime
== 0){
977 t
->cur_event_pos
= t
->last_event_pos
;
978 t
->current_event_time
= time
;
979 t
->cur_heart_beat_number
= 0;
980 t
->prev_event_time
.tv_sec
= 0;
981 t
->prev_event_time
.tv_nsec
= 0;
986 /*****************************************************************************
987 * Seek to the first event with position equal or larger to ep
989 * Modified by Mathieu Desnoyers to used faster offset position instead of
990 * re-reading the whole buffer.
991 ****************************************************************************/
993 void ltt_tracefile_seek_position(LttTracefile
*t
, const LttEventPosition
*ep
)
995 //if we are at the right place, just return
996 if(t
->which_block
== ep
->block_num
&& t
->which_event
== ep
->event_num
)
999 if(t
->which_block
== ep
->block_num
) updateTracefile(t
);
1000 else readBlock(t
,ep
->block_num
);
1001 //event offset is available
1002 if(ep
->old_position
){
1005 t
->which_event
= ep
->event_num
;
1006 t
->cur_event_pos
= t
->buffer
+ ep
->event_offset
;
1007 t
->prev_event_time
= ep
->event_time
;
1008 t
->current_event_time
= ep
->event_time
;
1009 t
->cur_heart_beat_number
= ep
->heart_beat_number
;
1010 t
->cur_cycle_count
= ep
->event_cycle_count
;
1012 /* This is a workaround for fast position seek */
1013 t
->last_event_pos
= ep
->last_event_pos
;
1014 t
->prev_block_end_time
= ep
->prev_block_end_time
;
1015 t
->prev_event_time
= ep
->prev_event_time
;
1016 t
->pre_cycle_count
= ep
->pre_cycle_count
;
1017 t
->count
= ep
->count
;
1018 /* end of workaround */
1020 //update the fields of the current event and go to the next event
1022 if(err
== ERANGE
) g_error("event id is out of range\n");
1027 //only block number and event index are available
1028 //MD: warning : this is slow!
1029 g_warning("using slow O(n) tracefile seek position");
1032 while(t
->which_event
< ep
->event_num
) ltt_tracefile_read(t
, &event
);
1037 /*****************************************************************************
1039 * ltt_tracefile_read : read the current event, set the pointer to the next
1043 * LttEvent * : an event to be processed
1044 ****************************************************************************/
1046 LttEvent
*ltt_tracefile_read(LttTracefile
*t
, LttEvent
*event
)
1050 if(t
->cur_event_pos
== t
->buffer
+ t
->block_size
){
1051 if(t
->which_block
== t
->block_number
){
1054 err
= readBlock(t
, t
->which_block
+ 1);
1055 if(err
)g_error("Can not read tracefile");
1058 event
->event_id
= (int)(*(guint16
*)(t
->cur_event_pos
));
1059 if(event
->event_id
== TRACE_TIME_HEARTBEAT
)
1060 t
->cur_heart_beat_number
++;
1062 t
->prev_event_time
= t
->current_event_time
;
1063 // t->current_event_time = getEventTime(t);
1065 event
->time_delta
= *(guint32
*)(t
->cur_event_pos
+ EVENT_ID_SIZE
);
1066 event
->event_time
= t
->current_event_time
;
1067 event
->event_cycle_count
= t
->cur_cycle_count
;
1069 event
->tracefile
= t
;
1070 event
->data
= t
->cur_event_pos
+ EVENT_HEADER_SIZE
;
1071 event
->which_block
= t
->which_block
;
1072 event
->which_event
= t
->which_event
;
1074 /* This is a workaround for fast position seek */
1075 event
->last_event_pos
= t
->last_event_pos
;
1076 event
->prev_block_end_time
= t
->prev_block_end_time
;
1077 event
->prev_event_time
= t
->prev_event_time
;
1078 event
->pre_cycle_count
= t
->pre_cycle_count
;
1079 event
->count
= t
->count
;
1080 /* end of workaround */
1084 //update the fields of the current event and go to the next event
1086 if(err
== ERANGE
) g_error("event id is out of range\n");
1091 /****************************************************************************
1093 * readFile : wrap function to read from a file
1095 * fd : file descriptor
1096 * buf : buf to contain the content
1097 * size : number of bytes to be read
1098 * mesg : message to be printed if some thing goes wrong
1101 * EIO : can not read from the file
1102 ****************************************************************************/
1104 int readFile(int fd
, void * buf
, size_t size
, char * mesg
)
1106 ssize_t nbBytes
= read(fd
, buf
, size
);
1108 if((size_t)nbBytes
!= size
) {
1110 perror("Error in readFile : ");
1112 g_warning("%s",mesg
);
1119 /****************************************************************************
1121 * readBlock : read a block from the file
1123 * lttdes : ltt trace file
1124 * whichBlock : the block which will be read
1127 * EINVAL : lseek fail
1128 * EIO : can not read from the file
1129 ****************************************************************************/
1131 int readBlock(LttTracefile
* tf
, int whichBlock
)
1136 if(whichBlock
- tf
->which_block
== 1 && tf
->which_block
!= 0){
1137 tf
->prev_block_end_time
= tf
->a_block_end
->time
;
1138 tf
->prev_event_time
= tf
->a_block_end
->time
;
1140 tf
->prev_block_end_time
.tv_sec
= 0;
1141 tf
->prev_block_end_time
.tv_nsec
= 0;
1142 tf
->prev_event_time
.tv_sec
= 0;
1143 tf
->prev_event_time
.tv_nsec
= 0;
1146 nbBytes
=lseek(tf
->fd
,(off_t
)((whichBlock
-1)*tf
->block_size
), SEEK_SET
);
1147 if(nbBytes
== -1) return EINVAL
;
1149 if(readFile(tf
->fd
,tf
->buffer
,tf
->block_size
,"Unable to read a block"))
1152 tf
->a_block_start
=(BlockStart
*) (tf
->buffer
+ EVENT_HEADER_SIZE
);
1153 lostSize
= *(guint32
*)(tf
->buffer
+ tf
->block_size
- sizeof(guint32
));
1154 tf
->a_block_end
=(BlockEnd
*)(tf
->buffer
+ tf
->block_size
-
1155 lostSize
+ EVENT_HEADER_SIZE
);
1156 tf
->last_event_pos
= tf
->buffer
+ tf
->block_size
- lostSize
;
1158 tf
->which_block
= whichBlock
;
1159 tf
->which_event
= 1;
1160 tf
->cur_event_pos
= tf
->buffer
;//the beginning of the block, block start ev
1161 tf
->cur_heart_beat_number
= 0;
1163 getCyclePerNsec(tf
);
1165 tf
->current_event_time
= getEventTime(tf
);
1170 /*****************************************************************************
1172 * updateTracefile : reinitialize the info of the block which is already
1176 ****************************************************************************/
1178 void updateTracefile(LttTracefile
* tf
)
1180 tf
->which_event
= 1;
1181 tf
->cur_event_pos
= tf
->buffer
;
1182 tf
->current_event_time
= getEventTime(tf
);
1183 tf
->cur_heart_beat_number
= 0;
1185 tf
->prev_event_time
.tv_sec
= 0;
1186 tf
->prev_event_time
.tv_nsec
= 0;
1189 /*****************************************************************************
1191 * skipEvent : go to the next event, update the fields of the current event
1196 * ERANGE : event id is out of range
1197 ****************************************************************************/
1199 int skipEvent(LttTracefile
* t
)
1206 evId
= (int)(*(guint16
*)(t
->cur_event_pos
));
1207 evData
= t
->cur_event_pos
+ EVENT_HEADER_SIZE
;
1209 evT
= ltt_trace_eventtype_get(t
->trace
,(unsigned)evId
);
1211 if(evT
) rootFld
= evT
->root_field
;
1215 //event has string/sequence or the last event is not the same event
1216 if((evT
->latest_block
!=t
->which_block
|| evT
->latest_event
!=t
->which_event
)
1217 && rootFld
->field_fixed
== 0){
1218 setFieldsOffset(t
, evT
, evData
, t
->trace
);
1220 t
->cur_event_pos
+= EVENT_HEADER_SIZE
+ rootFld
->field_size
;
1221 }else t
->cur_event_pos
+= EVENT_HEADER_SIZE
;
1223 evT
->latest_block
= t
->which_block
;
1224 evT
->latest_event
= t
->which_event
;
1226 //the next event is in the next block
1227 if(evId
== TRACE_BLOCK_END
){
1228 t
->cur_event_pos
= t
->buffer
+ t
->block_size
;
1231 t
->current_event_time
= getEventTime(t
);
1238 /*****************************************************************************
1240 * getCyclePerNsec : calculate cycles per nsec for current block
1243 ****************************************************************************/
1245 void getCyclePerNsec(LttTracefile
* t
)
1247 LttTime lBufTotalTime
; /* Total time for this buffer */
1248 LttCycleCount lBufTotalNSec
; /* Total time for this buffer in nsecs */
1249 LttCycleCount lBufTotalCycle
;/* Total cycles for this buffer */
1251 /* Calculate the total time for this buffer */
1252 lBufTotalTime
= ltt_time_sub(t
->a_block_end
->time
, t
->a_block_start
->time
);
1254 /* Calculate the total cycles for this bufffer */
1255 lBufTotalCycle
= t
->a_block_end
->cycle_count
;
1256 lBufTotalCycle
-= t
->a_block_start
->cycle_count
;
1258 /* Convert the total time to nsecs */
1259 lBufTotalNSec
= lBufTotalTime
.tv_sec
;
1260 lBufTotalNSec
*= NANOSECONDS_PER_SECOND
;
1261 lBufTotalNSec
+= lBufTotalTime
.tv_nsec
;
1263 t
->cycle_per_nsec
= (double)lBufTotalCycle
/ (double)lBufTotalNSec
;
1266 /****************************************************************************
1268 * getEventTime : obtain the time of an event
1272 * LttTime : the time of the event
1273 ****************************************************************************/
1275 static inline LttTime
getEventTime(LttTracefile
* tf
)
1278 LttCycleCount cycle_count
; // cycle count for the current event
1279 LttCycleCount lEventTotalCycle
; // Total cycles from start for event
1280 double lEventNSec
; // Total nsecs from start for event
1281 LttTime lTimeOffset
; // Time offset in struct LttTime
1284 evId
= *(guint16
*)tf
->cur_event_pos
;
1285 if(evId
== TRACE_BLOCK_START
){
1287 tf
->pre_cycle_count
= 0;
1288 tf
->cur_cycle_count
= tf
->a_block_start
->cycle_count
;
1289 return tf
->a_block_start
->time
;
1290 }else if(evId
== TRACE_BLOCK_END
){
1292 tf
->pre_cycle_count
= 0;
1293 tf
->cur_cycle_count
= tf
->a_block_end
->cycle_count
;
1294 return tf
->a_block_end
->time
;
1297 // Calculate total time in cycles from start of buffer for this event
1298 cycle_count
= (LttCycleCount
)*(guint32
*)(tf
->cur_event_pos
+ EVENT_ID_SIZE
);
1300 if(cycle_count
< tf
->pre_cycle_count
)tf
->count
++;
1301 tf
->pre_cycle_count
= cycle_count
;
1302 cycle_count
+= (LttCycleCount
)tf
->count
<< 32;
1304 // if(tf->cur_heart_beat_number > tf->count)
1305 // cycle_count += tmpCycleCount * (tf->cur_heart_beat_number - tf->count);
1307 tf
->cur_cycle_count
= cycle_count
;
1309 lEventTotalCycle
= cycle_count
;
1310 lEventTotalCycle
-= tf
->a_block_start
->cycle_count
;
1312 // Convert it to nsecs
1313 lEventNSec
= (double)lEventTotalCycle
/ (double)tf
->cycle_per_nsec
;
1315 // Determine offset in struct LttTime
1316 lTimeOffset
= ltt_time_from_double(lEventNSec
);
1318 time
= ltt_time_add(tf
->a_block_start
->time
, lTimeOffset
);
1323 /*****************************************************************************
1325 * setFieldsOffset : set offset of the fields
1327 * tracefile : opened trace file
1328 * evT : the event type
1329 * evD : event data, it may be NULL
1330 ****************************************************************************/
1332 void setFieldsOffset(LttTracefile
*tf
,LttEventType
*evT
,void *evD
,LttTrace
* t
)
1334 LttField
* rootFld
= evT
->root_field
;
1335 // rootFld->base_address = evD;
1338 rootFld
->field_size
= getFieldtypeSize(tf
, evT
, 0,0,rootFld
, evD
,t
);
1341 /*****************************************************************************
1343 * getFieldtypeSize: get the size of the field type (primitive type)
1345 * tracefile : opened trace file
1347 * offsetRoot : offset from the root
1348 * offsetParent : offset from the parrent
1350 * evD : event data, it may be NULL
1352 * int : size of the field
1353 ****************************************************************************/
1355 int getFieldtypeSize(LttTracefile
* t
, LttEventType
* evT
, int offsetRoot
,
1356 int offsetParent
, LttField
* fld
, void *evD
, LttTrace
*trace
)
1358 int size
, size1
, element_number
, i
, offset1
, offset2
;
1359 LttType
* type
= fld
->field_type
;
1362 if(evT
->latest_block
==t
->which_block
&& evT
->latest_event
==t
->which_event
){
1363 return fld
->field_size
;
1367 if(fld
->field_fixed
== 1){
1368 if(fld
== evT
->root_field
) return fld
->field_size
;
1371 switch(type
->type_class
) {
1373 element_number
= (int) type
->element_number
;
1374 if(fld
->field_fixed
== -1){
1375 size
= getFieldtypeSize(t
, evT
, offsetRoot
,
1376 0,fld
->child
[0], NULL
, trace
);
1377 if(size
== 0){ //has string or sequence
1378 fld
->field_fixed
= 0;
1380 fld
->field_fixed
= 1;
1381 size
*= element_number
;
1383 }else if(fld
->field_fixed
== 0){// has string or sequence
1385 for(i
=0;i
<element_number
;i
++){
1386 size
+= getFieldtypeSize(t
, evT
, offsetRoot
+size
,size
,
1387 fld
->child
[0], evD
+size
, trace
);
1389 }else size
= fld
->field_size
;
1393 size1
= (int) ltt_type_size(trace
, type
);
1394 if(fld
->field_fixed
== -1){
1395 fld
->sequ_number_size
= size1
;
1396 fld
->field_fixed
= 0;
1397 size
= getFieldtypeSize(t
, evT
, offsetRoot
,
1398 0,fld
->child
[0], NULL
, trace
);
1399 fld
->element_size
= size
;
1401 element_number
= getIntNumber(size1
,evD
);
1402 type
->element_number
= element_number
;
1403 if(fld
->element_size
> 0){
1404 size
= element_number
* fld
->element_size
;
1405 }else{//sequence has string or sequence
1407 for(i
=0;i
<element_number
;i
++){
1408 size
+= getFieldtypeSize(t
, evT
, offsetRoot
+size
+size1
,size
+size1
,
1409 fld
->child
[0], evD
+size
+size1
, trace
);
1418 if(fld
->field_fixed
== -1){
1419 fld
->field_fixed
= 0;
1421 size
= strlen((char*)evD
) + 1; //include end : '\0'
1426 element_number
= (int) type
->element_number
;
1428 if(fld
->field_fixed
== -1){
1429 offset1
= offsetRoot
;
1431 for(i
=0;i
<element_number
;i
++){
1432 size1
=getFieldtypeSize(t
, evT
,offset1
,offset2
,
1433 fld
->child
[i
], NULL
, trace
);
1434 if(size1
> 0 && size
>= 0){
1436 if(offset1
>= 0) offset1
+= size1
;
1445 fld
->field_fixed
= 0;
1447 }else fld
->field_fixed
= 1;
1448 }else if(fld
->field_fixed
== 0){
1449 offset1
= offsetRoot
;
1451 for(i
=0;i
<element_number
;i
++){
1452 size
=getFieldtypeSize(t
,evT
,offset1
,offset2
,
1453 fld
->child
[i
],evD
+offset2
, trace
);
1458 }else size
= fld
->field_size
;
1462 if(fld
->field_fixed
== -1){
1463 size
= (int) ltt_type_size(trace
, type
);
1464 fld
->field_fixed
= 1;
1465 }else size
= fld
->field_size
;
1472 if(type
->type_class
!= LTT_STRUCT
&& type
->type_class
!= LTT_ARRAY
&&
1473 type
->type_class
!= LTT_SEQUENCE
&& type
->type_class
!= LTT_STRING
){
1474 if(fld
->field_fixed
== -1){
1475 size
= (int) ltt_type_size(trace
, type
);
1476 fld
->field_fixed
= 1;
1477 }else size
= fld
->field_size
;
1479 }else if(type
->type_class
== LTT_ARRAY
){
1480 element_number
= (int) type
->element_number
;
1481 if(fld
->field_fixed
== -1){
1482 size
= getFieldtypeSize(t
, evT
, offsetRoot
,0,fld
->child
[0], NULL
, trace
);
1483 if(size
== 0){ //has string or sequence
1484 fld
->field_fixed
= 0;
1486 fld
->field_fixed
= 1;
1487 size
*= element_number
;
1489 }else if(fld
->field_fixed
== 0){// has string or sequence
1491 for(i
=0;i
<element_number
;i
++){
1492 size
+= getFieldtypeSize(t
, evT
, offsetRoot
+size
,size
,
1493 fld
->child
[0], evD
+size
, trace
);
1495 }else size
= fld
->field_size
;
1497 }else if(type
->type_class
== LTT_SEQUENCE
){
1498 size1
= (int) ltt_type_size(trace
, type
);
1499 if(fld
->field_fixed
== -1){
1500 fld
->sequ_number_size
= size1
;
1501 fld
->field_fixed
= 0;
1502 size
= getFieldtypeSize(t
, evT
, offsetRoot
,0,fld
->child
[0], NULL
, trace
);
1503 fld
->element_size
= size
;
1505 element_number
= getIntNumber(size1
,evD
);
1506 type
->element_number
= element_number
;
1507 if(fld
->element_size
> 0){
1508 size
= element_number
* fld
->element_size
;
1509 }else{//sequence has string or sequence
1511 for(i
=0;i
<element_number
;i
++){
1512 size
+= getFieldtypeSize(t
, evT
, offsetRoot
+size
+size1
,size
+size1
,
1513 fld
->child
[0], evD
+size
+size1
, trace
);
1519 }else if(type
->type_class
== LTT_STRING
){
1521 if(fld
->field_fixed
== -1){
1522 fld
->field_fixed
= 0;
1524 size
= strlen((char*)evD
) + 1; //include end : '\0'
1527 }else if(type
->type_class
== LTT_STRUCT
){
1528 element_number
= (int) type
->element_number
;
1530 if(fld
->field_fixed
== -1){
1531 offset1
= offsetRoot
;
1533 for(i
=0;i
<element_number
;i
++){
1534 size1
=getFieldtypeSize(t
, evT
,offset1
,offset2
, fld
->child
[i
], NULL
, trace
);
1535 if(size1
> 0 && size
>= 0){
1537 if(offset1
>= 0) offset1
+= size1
;
1546 fld
->field_fixed
= 0;
1548 }else fld
->field_fixed
= 1;
1549 }else if(fld
->field_fixed
== 0){
1550 offset1
= offsetRoot
;
1552 for(i
=0;i
<element_number
;i
++){
1553 size
=getFieldtypeSize(t
,evT
,offset1
,offset2
,fld
->child
[i
],evD
+offset2
, trace
);
1558 }else size
= fld
->field_size
;
1562 fld
->offset_root
= offsetRoot
;
1563 fld
->offset_parent
= offsetParent
;
1565 fld
->fixed_root
= (offsetRoot
==-1) ? 0 : 1;
1566 fld
->fixed_parent
= (offsetParent
==-1) ? 0 : 1;
1568 fld
->field_size
= size
;
1574 /*****************************************************************************
1576 * getIntNumber : get an integer number
1578 * size : the size of the integer
1579 * evD : the event data
1581 * gint64 : a 64 bits integer
1582 ****************************************************************************/
1584 gint64
getIntNumber(int size
, void *evD
)
1589 case 1: i
= *(gint8
*)evD
; break;
1590 case 2: i
= *(gint16
*)evD
; break;
1591 case 4: i
= *(gint32
*)evD
; break;
1592 case 8: i
= *(gint64
*)evD
; break;
1593 default: i
= *(gint64
*)evD
;
1594 g_critical("getIntNumber : integer size %d unknown", size
);
1599 if(size
== 1) i
= *(gint8
*)evD
;
1600 else if(size
== 2) i
= *(gint16
*)evD
;
1601 else if(size
== 4) i
= *(gint32
*)evD
;
1602 else if(size
== 8) i
= *(gint64
*)evD
;
1608 /*****************************************************************************
1610 * getDataEndianType : get the data type size and endian type of the local
1613 * size : size of data type
1614 * endian : endian type, little or big
1615 ****************************************************************************/
1617 void getDataEndianType(LttArchSize
* size
, LttArchEndian
* endian
)
1621 int sizeInt
=sizeof(int), sizeLong
=sizeof(long), sizePointer
=sizeof(void *);
1623 if(c
== 1) *endian
= LTT_LITTLE_ENDIAN
;
1624 else *endian
= LTT_BIG_ENDIAN
;
1626 if(sizeInt
== 2 && sizeLong
== 4 && sizePointer
== 4)
1628 else if(sizeInt
== 4 && sizeLong
== 4 && sizePointer
== 4)
1630 else if(sizeInt
== 4 && sizeLong
== 8 && sizePointer
== 8)
1632 else if(sizeInt
== 8 && sizeLong
== 8 && sizePointer
== 8)
1634 else *size
= LTT_UNKNOWN
;
1637 /* get the node name of the system */
1639 char * ltt_trace_system_description_node_name (LttSystemDescription
* s
)
1641 return s
->node_name
;
1645 /* get the domain name of the system */
1647 char * ltt_trace_system_description_domain_name (LttSystemDescription
* s
)
1649 return s
->domain_name
;
1653 /* get the description of the system */
1655 char * ltt_trace_system_description_description (LttSystemDescription
* s
)
1657 return s
->description
;
1661 /* get the start time of the trace */
1663 LttTime
ltt_trace_system_description_trace_start_time(LttSystemDescription
*s
)
1665 return s
->trace_start
;
1669 LttTracefile
*ltt_tracefile_new()
1671 return g_new(LttTracefile
, 1);
1674 void ltt_tracefile_destroy(LttTracefile
*tf
)
1679 void ltt_tracefile_copy(LttTracefile
*dest
, const LttTracefile
*src
)