1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Xiangxiu Yang, Mathieu Desnoyers
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 #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
45 #define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format)
48 /* obtain the time of an event */
50 static inline LttTime
getEventTime(LttTracefile
* tf
);
53 /* set the offset of the fields belonging to the event,
54 need the information of the archecture */
55 void setFieldsOffset(LttTracefile
*tf
,LttEventType
*evT
,void *evD
,LttTrace
*t
);
57 /* get the size of the field type according to the archtecture's
58 size and endian type(info of the archecture) */
59 static inline gint
getFieldtypeSize(LttTracefile
* tf
,
60 LttEventType
* evT
, gint offsetRoot
,
61 gint offsetParent
, LttField
*fld
, void *evD
, LttTrace
* t
);
63 /* read a fixed size or a block information from the file (fd) */
64 int readFile(int fd
, void * buf
, size_t size
, char * mesg
);
65 int readBlock(LttTracefile
* tf
, int whichBlock
);
67 /* calculate cycles per nsec for current block */
68 void getCyclePerNsec(LttTracefile
* t
);
70 /* reinitialize the info of the block which is already in the buffer */
71 void updateTracefile(LttTracefile
* tf
);
73 /* go to the next event */
74 int skipEvent(LttTracefile
* t
);
77 /* Functions to parse system.xml file (using glib xml parser) */
78 static void parser_start_element (GMarkupParseContext __UNUSED__
*context
,
79 const gchar
*element_name
,
80 const gchar
**attribute_names
,
81 const gchar
**attribute_values
,
86 LttSystemDescription
* des
= (LttSystemDescription
* )user_data
;
87 if(strcmp("system", element_name
)){
88 *error
= g_error_new(G_MARKUP_ERROR
,
90 "This is not system.xml file");
94 while(attribute_names
[i
]){
95 if(strcmp("node_name", attribute_names
[i
])==0){
96 des
->node_name
= g_strdup(attribute_values
[i
]);
97 }else if(strcmp("domainname", attribute_names
[i
])==0){
98 des
->domain_name
= g_strdup(attribute_values
[i
]);
99 }else if(strcmp("cpu", attribute_names
[i
])==0){
100 des
->nb_cpu
= atoi(attribute_values
[i
]);
101 }else if(strcmp("arch_size", attribute_names
[i
])==0){
102 if(strcmp(attribute_values
[i
],"LP32") == 0) des
->size
= LTT_LP32
;
103 else if(strcmp(attribute_values
[i
],"ILP32") == 0) des
->size
= LTT_ILP32
;
104 else if(strcmp(attribute_values
[i
],"LP64") == 0) des
->size
= LTT_LP64
;
105 else if(strcmp(attribute_values
[i
],"ILP64") == 0) des
->size
= LTT_ILP64
;
106 else if(strcmp(attribute_values
[i
],"UNKNOWN") == 0) des
->size
= LTT_UNKNOWN
;
107 }else if(strcmp("endian", attribute_names
[i
])==0){
108 if(strcmp(attribute_values
[i
],"LITTLE_ENDIAN") == 0)
109 des
->endian
= LTT_LITTLE_ENDIAN
;
110 else if(strcmp(attribute_values
[i
],"BIG_ENDIAN") == 0)
111 des
->endian
= LTT_BIG_ENDIAN
;
112 }else if(strcmp("kernel_name", attribute_names
[i
])==0){
113 des
->kernel_name
= g_strdup(attribute_values
[i
]);
114 }else if(strcmp("kernel_release", attribute_names
[i
])==0){
115 des
->kernel_release
= g_strdup(attribute_values
[i
]);
116 }else if(strcmp("kernel_version", attribute_names
[i
])==0){
117 des
->kernel_version
= g_strdup(attribute_values
[i
]);
118 }else if(strcmp("machine", attribute_names
[i
])==0){
119 des
->machine
= g_strdup(attribute_values
[i
]);
120 }else if(strcmp("processor", attribute_names
[i
])==0){
121 des
->processor
= g_strdup(attribute_values
[i
]);
122 }else if(strcmp("hardware_platform", attribute_names
[i
])==0){
123 des
->hardware_platform
= g_strdup(attribute_values
[i
]);
124 }else if(strcmp("operating_system", attribute_names
[i
])==0){
125 des
->operating_system
= g_strdup(attribute_values
[i
]);
126 }else if(strcmp("ltt_major_version", attribute_names
[i
])==0){
127 des
->ltt_major_version
= atoi(attribute_values
[i
]);
128 }else if(strcmp("ltt_minor_version", attribute_names
[i
])==0){
129 des
->ltt_minor_version
= atoi(attribute_values
[i
]);
130 }else if(strcmp("ltt_block_size", attribute_names
[i
])==0){
131 des
->ltt_block_size
= atoi(attribute_values
[i
]);
133 *error
= g_error_new(G_MARKUP_ERROR
,
135 "Not a valid attribute");
142 static void parser_characters (GMarkupParseContext __UNUSED__
*context
,
144 gsize __UNUSED__ text_len
,
146 GError __UNUSED__
**error
)
148 LttSystemDescription
* des
= (LttSystemDescription
* )user_data
;
149 des
->description
= g_strdup(text
);
153 /*****************************************************************************
155 * ltt_tracefile_open : open a trace file, construct a LttTracefile
157 * t : the trace containing the tracefile
158 * fileName : path name of the trace file
160 * : a pointer to a tracefile
161 ****************************************************************************/
163 LttTracefile
* ltt_tracefile_open(LttTrace
* t
, char * fileName
)
166 struct stat lTDFStat
; /* Trace data file status */
168 tf
= g_new(LttTracefile
, 1);
171 tf
->name
= g_strdup(fileName
);
173 tf
->fd
= open(fileName
, O_RDONLY
, 0);
175 g_warning("Unable to open input data file %s\n", fileName
);
181 // Get the file's status
182 if(fstat(tf
->fd
, &lTDFStat
) < 0){
183 g_warning("Unable to get the status of the input data file %s\n", fileName
);
190 // Is the file large enough to contain a trace
191 if(lTDFStat
.st_size
< (off_t
)(sizeof(BlockStart
) + EVENT_HEADER_SIZE
)){
192 g_print("The input data file %s does not contain a trace\n", fileName
);
199 //store the size of the file
200 tf
->file_size
= lTDFStat
.st_size
;
201 tf
->block_size
= t
->system_description
->ltt_block_size
;
202 tf
->block_number
= tf
->file_size
/ tf
->block_size
;
205 //allocate memory to contain the info of a block
206 tf
->buffer
= (void *) g_new(char, t
->system_description
->ltt_block_size
);
208 //read the first block
209 if(readBlock(tf
,1)) exit(1);
215 /*****************************************************************************
216 *Open control and per cpu tracefiles
217 ****************************************************************************/
219 void ltt_tracefile_open_cpu(LttTrace
*t
, char * tracefile_name
)
222 tf
= ltt_tracefile_open(t
,tracefile_name
);
224 t
->per_cpu_tracefile_number
++;
225 g_ptr_array_add(t
->per_cpu_tracefiles
, tf
);
228 gint
ltt_tracefile_open_control(LttTrace
*t
, char * control_name
)
237 tf
= ltt_tracefile_open(t
,control_name
);
239 g_warning("ltt_tracefile_open_control : bad file descriptor");
242 t
->control_tracefile_number
++;
243 g_ptr_array_add(t
->control_tracefiles
,tf
);
245 //parse facilities tracefile to get base_id
246 if(strcmp(&control_name
[strlen(control_name
)-10],"facilities") ==0){
248 if(!ltt_tracefile_read(tf
,&ev
)) return 0; // end of file
250 if(ev
.event_id
== TRACE_FACILITY_LOAD
){
252 fLoad
.name
= (char*)pos
;
253 fLoad
.checksum
= *(LttChecksum
*)(pos
+ strlen(fLoad
.name
));
254 fLoad
.base_code
= *(guint32
*)(pos
+ strlen(fLoad
.name
) + sizeof(LttChecksum
));
256 for(i
=0;i
<t
->facility_number
;i
++){
257 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
,i
);
258 if(strcmp(f
->name
,fLoad
.name
)==0 && fLoad
.checksum
==f
->checksum
){
259 f
->base_id
= fLoad
.base_code
;
263 if(i
==t
->facility_number
) {
264 g_warning("Facility: %s, checksum: %u is not found",
265 fLoad
.name
,(unsigned int)fLoad
.checksum
);
268 }else if(ev
.event_id
== TRACE_BLOCK_START
){
270 }else if(ev
.event_id
== TRACE_BLOCK_END
){
273 g_warning("Not valid facilities trace file");
281 /*****************************************************************************
283 * ltt_tracefile_close: close a trace file,
285 * t : tracefile which will be closed
286 ****************************************************************************/
288 void ltt_tracefile_close(LttTracefile
*t
)
297 /*****************************************************************************
298 *Get system information
299 ****************************************************************************/
300 gint
getSystemInfo(LttSystemDescription
* des
, char * pathname
)
303 char buf
[DIR_NAME_SIZE
];
305 GMarkupParseContext
* context
;
306 GError
* error
= NULL
;
307 GMarkupParser markup_parser
=
309 parser_start_element
,
312 NULL
, /* passthrough */
316 fp
= fopen(pathname
,"r");
318 g_warning("Can not open file : %s\n", pathname
);
322 context
= g_markup_parse_context_new(&markup_parser
, 0, des
,NULL
);
324 while(fgets(buf
,DIR_NAME_SIZE
, fp
) != NULL
){
325 if(!g_markup_parse_context_parse(context
, buf
, DIR_NAME_SIZE
, &error
)){
327 g_warning("Can not parse xml file: \n%s\n", error
->message
);
330 g_markup_parse_context_free(context
);
335 g_markup_parse_context_free(context
);
340 /*****************************************************************************
341 *The following functions get facility/tracefile information
342 ****************************************************************************/
344 gint
getFacilityInfo(LttTrace
*t
, char* eventdefs
)
347 struct dirent
*entry
;
352 char name
[DIR_NAME_SIZE
];
354 dir
= opendir(eventdefs
);
356 g_warning("Can not open directory: %s\n", eventdefs
);
360 while((entry
= readdir(dir
)) != NULL
){
361 ptr
= &entry
->d_name
[strlen(entry
->d_name
)-4];
362 if(strcmp(ptr
,".xml") != 0) continue;
363 strcpy(name
,eventdefs
);
364 strcat(name
,entry
->d_name
);
365 ltt_facility_open(t
,name
);
369 for(j
=0;j
<t
->facility_number
;j
++){
370 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
, j
);
371 for(i
=0; i
<f
->event_number
; i
++){
373 setFieldsOffset(NULL
, et
, NULL
, t
);
379 gint
getControlFileInfo(LttTrace
*t
, char* control
)
382 struct dirent
*entry
;
383 char name
[DIR_NAME_SIZE
];
385 dir
= opendir(control
);
387 g_warning("Can not open directory: %s\n", control
);
391 while((entry
= readdir(dir
)) != NULL
){
392 if(strcmp(entry
->d_name
,"facilities") != 0 &&
393 strcmp(entry
->d_name
,"interrupts") != 0 &&
394 strcmp(entry
->d_name
,"processes") != 0) continue;
396 strcpy(name
,control
);
397 strcat(name
,entry
->d_name
);
398 if(ltt_tracefile_open_control(t
,name
))
405 gint
getCpuFileInfo(LttTrace
*t
, char* cpu
)
408 struct dirent
*entry
;
409 char name
[DIR_NAME_SIZE
];
413 g_warning("Can not open directory: %s\n", cpu
);
417 while((entry
= readdir(dir
)) != NULL
){
418 if(strcmp(entry
->d_name
,".") != 0 &&
419 strcmp(entry
->d_name
,"..") != 0 &&
420 strcmp(entry
->d_name
,".svn") != 0){
422 strcat(name
,entry
->d_name
);
423 ltt_tracefile_open_cpu(t
,name
);
430 /*****************************************************************************
431 *A trace is specified as a pathname to the directory containing all the
432 *associated data (control tracefiles, per cpu tracefiles, event
435 *When a trace is closed, all the associated facilities, types and fields
436 *are released as well.
440 /****************************************************************************
441 * get_absolute_pathname
443 * return the unique pathname in the system
445 * MD : Fixed this function so it uses realpath, dealing well with
446 * forgotten cases (.. were not used correctly before).
448 ****************************************************************************/
449 void get_absolute_pathname(const char *pathname
, char * abs_pathname
)
451 abs_pathname
[0] = '\0';
453 if ( realpath (pathname
, abs_pathname
) != NULL
)
457 /* error, return the original path unmodified */
458 strcpy(abs_pathname
, pathname
);
464 LttTrace
*ltt_trace_open(const char *pathname
)
467 LttSystemDescription
* sys_description
;
468 char eventdefs
[DIR_NAME_SIZE
];
469 char info
[DIR_NAME_SIZE
];
470 char control
[DIR_NAME_SIZE
];
471 char cpu
[DIR_NAME_SIZE
];
472 char tmp
[DIR_NAME_SIZE
];
473 char abs_path
[DIR_NAME_SIZE
];
474 gboolean has_slash
= FALSE
;
476 get_absolute_pathname(pathname
, abs_path
);
477 //establish the pathname to different directories
478 if(abs_path
[strlen(abs_path
)-1] == '/')has_slash
= TRUE
;
479 strcpy(eventdefs
,abs_path
);
480 if(!has_slash
)strcat(eventdefs
,"/");
481 strcat(eventdefs
,"eventdefs/");
483 strcpy(info
,abs_path
);
484 if(!has_slash
)strcat(info
,"/");
485 strcat(info
,"info/");
487 strcpy(control
,abs_path
);
488 if(!has_slash
)strcat(control
,"/");
489 strcat(control
,"control/");
491 strcpy(cpu
,abs_path
);
492 if(!has_slash
)strcat(cpu
,"/");
496 sys_description
= g_new(LttSystemDescription
, 1);
497 t
= g_new(LttTrace
, 1);
498 t
->pathname
= g_strdup(abs_path
);
499 t
->facility_number
= 0;
500 t
->control_tracefile_number
= 0;
501 t
->per_cpu_tracefile_number
= 0;
502 t
->system_description
= sys_description
;
503 t
->control_tracefiles
= g_ptr_array_new();
504 t
->per_cpu_tracefiles
= g_ptr_array_new();
505 t
->facilities
= g_ptr_array_new();
506 getDataEndianType(&(t
->my_arch_size
), &(t
->my_arch_endian
));
508 //get system description
510 strcat(tmp
,"system.xml");
511 if(getSystemInfo(sys_description
, tmp
)) {
512 g_ptr_array_free(t
->facilities
, TRUE
);
513 g_ptr_array_free(t
->per_cpu_tracefiles
, TRUE
);
514 g_ptr_array_free(t
->control_tracefiles
, TRUE
);
515 g_free(sys_description
);
523 //get facilities info
524 if(getFacilityInfo(t
,eventdefs
)) {
525 g_ptr_array_free(t
->facilities
, TRUE
);
526 g_ptr_array_free(t
->per_cpu_tracefiles
, TRUE
);
527 g_ptr_array_free(t
->control_tracefiles
, TRUE
);
528 g_free(sys_description
);
534 //get control tracefile info
535 getControlFileInfo(t
,control
);
537 if(getControlFileInfo(t,control)) {
538 g_ptr_array_free(t->facilities, TRUE);
539 g_ptr_array_free(t->per_cpu_tracefiles, TRUE);
540 g_ptr_array_free(t->control_tracefiles, TRUE);
541 g_free(sys_description);
545 }*/ // With fatal error
547 //get cpu tracefile info
548 if(getCpuFileInfo(t
,cpu
)) {
549 g_ptr_array_free(t
->facilities
, TRUE
);
550 g_ptr_array_free(t
->per_cpu_tracefiles
, TRUE
);
551 g_ptr_array_free(t
->control_tracefiles
, TRUE
);
552 g_free(sys_description
);
561 char * ltt_trace_name(LttTrace
*t
)
567 /******************************************************************************
568 * When we copy a trace, we want all the opening actions to happen again :
569 * the trace will be reopened and totally independant from the original.
570 * That's why we call ltt_trace_open.
571 *****************************************************************************/
572 LttTrace
*ltt_trace_copy(LttTrace
*self
)
574 return ltt_trace_open(self
->pathname
);
577 void ltt_trace_close(LttTrace
*t
)
585 //free system_description
586 g_free(t
->system_description
->description
);
587 g_free(t
->system_description
->node_name
);
588 g_free(t
->system_description
->domain_name
);
589 g_free(t
->system_description
->kernel_name
);
590 g_free(t
->system_description
->kernel_release
);
591 g_free(t
->system_description
->kernel_version
);
592 g_free(t
->system_description
->machine
);
593 g_free(t
->system_description
->processor
);
594 g_free(t
->system_description
->hardware_platform
);
595 g_free(t
->system_description
->operating_system
);
596 g_free(t
->system_description
);
598 //free control_tracefiles
599 for(i
=0;i
<t
->control_tracefile_number
;i
++){
600 tf
= (LttTracefile
*)g_ptr_array_index(t
->control_tracefiles
,i
);
601 ltt_tracefile_close(tf
);
603 g_ptr_array_free(t
->control_tracefiles
, TRUE
);
605 //free per_cpu_tracefiles
606 for(i
=0;i
<t
->per_cpu_tracefile_number
;i
++){
607 tf
= (LttTracefile
*)g_ptr_array_index(t
->per_cpu_tracefiles
,i
);
608 ltt_tracefile_close(tf
);
610 g_ptr_array_free(t
->per_cpu_tracefiles
, TRUE
);
613 for(i
=0;i
<t
->facility_number
;i
++){
614 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
,i
);
615 ltt_facility_close(f
);
617 g_ptr_array_free(t
->facilities
, TRUE
);
625 /*****************************************************************************
626 *Get the system description of the trace
627 ****************************************************************************/
629 LttSystemDescription
*ltt_trace_system_description(LttTrace
*t
)
631 return t
->system_description
;
634 /*****************************************************************************
635 * The following functions discover the facilities of the trace
636 ****************************************************************************/
638 unsigned ltt_trace_facility_number(LttTrace
*t
)
640 return (unsigned)(t
->facility_number
);
643 LttFacility
*ltt_trace_facility_get(LttTrace
*t
, unsigned i
)
645 return (LttFacility
*)g_ptr_array_index(t
->facilities
, i
);
648 /*****************************************************************************
650 * ltt_trace_facility_find : find facilities in the trace
653 * name : facility name
655 * position : position of the facility in the trace
657 * : the number of facilities
658 ****************************************************************************/
660 unsigned ltt_trace_facility_find(LttTrace
*t
, char *name
, unsigned *position
)
662 unsigned int i
, count
=0;
664 for(i
=0;i
<t
->facility_number
;i
++){
665 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
, i
);
666 if(strcmp(f
->name
,name
)==0){
668 if(count
==1) *position
= i
;
676 /*****************************************************************************
677 * Functions to discover all the event types in the trace
678 ****************************************************************************/
680 unsigned ltt_trace_eventtype_number(LttTrace
*t
)
684 unsigned int num
= t
->facility_number
;
688 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
, i
);
689 count
+= f
->event_number
;
694 /* FIXME : performances could be improved with a better design for this
695 * function : sequential search through a container has never been the
696 * best on the critical path. */
697 LttFacility
* ltt_trace_facility_by_id(LttTrace
* trace
, unsigned id
)
699 LttFacility
* facility
= NULL
;
701 unsigned int num
= trace
->facility_number
;
702 GPtrArray
*facilities
= trace
->facilities
;
704 for(i
=0;unlikely(i
<num
);){
705 LttFacility
*iter_facility
=
706 (LttFacility
*) g_ptr_array_index(facilities
,i
);
707 unsigned base_id
= iter_facility
->base_id
;
709 if(likely(id
>= base_id
&&
710 id
< base_id
+ iter_facility
->event_number
)) {
711 facility
= iter_facility
;
721 LttEventType
*ltt_trace_eventtype_get(LttTrace
*t
, unsigned evId
)
723 LttEventType
*event_type
;
726 f
= ltt_trace_facility_by_id(t
,evId
);
728 if(unlikely(!f
)) event_type
= NULL
;
729 else event_type
= f
->events
[evId
- f
->base_id
];
734 /*****************************************************************************
735 *There is one "per cpu" tracefile for each CPU, numbered from 0 to
736 *the maximum number of CPU in the system. When the number of CPU installed
737 *is less than the maximum, some positions are unused. There are also a
738 *number of "control" tracefiles (facilities, interrupts...).
739 ****************************************************************************/
740 unsigned ltt_trace_control_tracefile_number(LttTrace
*t
)
742 return t
->control_tracefile_number
;
745 unsigned ltt_trace_per_cpu_tracefile_number(LttTrace
*t
)
747 return t
->per_cpu_tracefile_number
;
750 /*****************************************************************************
751 *It is possible to search for the tracefiles by name or by CPU position.
752 *The index within the tracefiles of the same type is returned if found
753 *and a negative value otherwise.
754 ****************************************************************************/
756 int ltt_trace_control_tracefile_find(LttTrace
*t
, const gchar
*name
)
758 LttTracefile
* tracefile
;
760 for(i
=0;i
<t
->control_tracefile_number
;i
++){
761 tracefile
= (LttTracefile
*)g_ptr_array_index(t
->control_tracefiles
, i
);
762 if(strcmp(tracefile
->name
, name
)==0)break;
764 if(i
== t
->control_tracefile_number
) return -1;
768 /* not really useful. We just have to know that cpu tracefiles
769 * comes before control tracefiles.
771 int ltt_trace_per_cpu_tracefile_find(LttTrace
*t
, const gchar
*name
)
773 LttTracefile
* tracefile
;
775 for(i
=0;i
<t
->per_cpu_tracefile_number
;i
++){
776 tracefile
= (LttTracefile
*)g_ptr_array_index(t
->per_cpu_tracefiles
, i
);
777 if(strcmp(tracefile
->name
, name
)==0)break;
779 if(i
== t
->per_cpu_tracefile_number
) return -1;
783 /*****************************************************************************
784 *Get a specific tracefile
785 ****************************************************************************/
787 LttTracefile
*ltt_trace_control_tracefile_get(LttTrace
*t
, unsigned i
)
789 return (LttTracefile
*)g_ptr_array_index(t
->control_tracefiles
, i
);
792 LttTracefile
*ltt_trace_per_cpu_tracefile_get(LttTrace
*t
, unsigned i
)
794 return (LttTracefile
*)g_ptr_array_index(t
->per_cpu_tracefiles
, i
);
797 /*****************************************************************************
798 * Get the start time and end time of the trace
799 ****************************************************************************/
801 void ltt_trace_time_span_get(LttTrace
*t
, LttTime
*start
, LttTime
*end
)
803 LttTime startSmall
, startTmp
, endBig
, endTmp
;
807 for(i
=0;i
<t
->control_tracefile_number
;i
++){
808 tf
= g_ptr_array_index(t
->control_tracefiles
, i
);
810 startTmp
= tf
->a_block_start
->time
;
811 readBlock(tf
,tf
->block_number
);
812 endTmp
= tf
->a_block_end
->time
;
814 startSmall
= startTmp
;
819 if(ltt_time_compare(startSmall
,startTmp
) > 0) startSmall
= startTmp
;
820 if(ltt_time_compare(endBig
,endTmp
) < 0) endBig
= endTmp
;
823 for(i
=0;i
<t
->per_cpu_tracefile_number
;i
++){
824 tf
= g_ptr_array_index(t
->per_cpu_tracefiles
, i
);
826 startTmp
= tf
->a_block_start
->time
;
827 readBlock(tf
,tf
->block_number
);
828 endTmp
= tf
->a_block_end
->time
;
830 startSmall
= startTmp
;
834 if(ltt_time_compare(startSmall
,startTmp
) > 0) startSmall
= startTmp
;
835 if(ltt_time_compare(endBig
,endTmp
) < 0) endBig
= endTmp
;
838 if(start
!= NULL
) *start
= startSmall
;
839 if(end
!= NULL
) *end
= endBig
;
843 /*****************************************************************************
844 *Get the name of a tracefile
845 ****************************************************************************/
847 char *ltt_tracefile_name(LttTracefile
*tf
)
852 /*****************************************************************************
853 * Get the number of blocks in the tracefile
854 ****************************************************************************/
856 unsigned ltt_tracefile_block_number(LttTracefile
*tf
)
858 return tf
->block_number
;
861 /*****************************************************************************
863 * ltt_tracefile_seek_time: seek to the first event of the trace with time
864 * larger or equal to time
867 * time : criteria of the time
868 ****************************************************************************/
869 void ltt_tracefile_find_time_block(LttTracefile
*t
, LttTime time
,
870 int start_block
, int end_block
)
872 int err
, tmp_block
, s
, e
;
876 err
=readBlock(t
,start_block
);
877 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
878 if(start_block
== end_block
)return;
880 tailTime
= ltt_time_compare(t
->a_block_end
->time
, time
);
881 if(tailTime
>= 0) return;
883 err
=readBlock(t
,end_block
);
884 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
885 if(start_block
+1 == end_block
)return;
887 headTime
= ltt_time_compare(t
->a_block_start
->time
, time
);
888 if(headTime
<= 0 ) return;
890 tmp_block
= (end_block
+ start_block
)/2;
891 err
=readBlock(t
,tmp_block
);
892 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
894 headTime
= ltt_time_compare(t
->a_block_start
->time
, time
);
895 tailTime
= ltt_time_compare(t
->a_block_end
->time
, time
);
896 if(headTime
<= 0 && tailTime
>= 0) return;
902 ltt_tracefile_find_time_block(t
, time
, s
, e
);
910 ltt_tracefile_find_time_block(t
, time
, s
, e
);
915 void ltt_tracefile_backward_find_time_block(LttTracefile
*t
, LttTime time
)
917 int t_time
, h_time
, err
;
918 err
=readBlock(t
,t
->which_block
-1);
919 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
920 h_time
= ltt_time_compare(t
->a_block_start
->time
, time
);
921 t_time
= ltt_time_compare(t
->a_block_end
->time
, time
);
924 if(t
->which_block
== 1) return;
925 err
=readBlock(t
,t
->which_block
-1);
926 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
927 tmp
= ltt_time_compare(t
->a_block_end
->time
, time
);
928 if(tmp
== 0) return ltt_tracefile_seek_time(t
, time
);
929 err
=readBlock(t
,t
->which_block
+1);
930 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
931 }else if(h_time
> 0){
932 ltt_tracefile_find_time_block(t
, time
, 1, t
->which_block
);
933 return ltt_tracefile_seek_time(t
, time
) ;
935 if(t_time
>= 0) return ltt_tracefile_seek_time(t
, time
);
936 err
=readBlock(t
,t
->which_block
+1);
937 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
941 void ltt_tracefile_seek_time(LttTracefile
*t
, LttTime time
)
945 int headTime
= ltt_time_compare(t
->a_block_start
->time
, time
);
946 int tailTime
= ltt_time_compare(t
->a_block_end
->time
, time
);
949 if(headTime
< 0 && tailTime
> 0){
950 if(ltt_time_compare(t
->a_block_end
->time
, t
->current_event_time
) !=0) {
951 lttTime
= getEventTime(t
);
952 err
= ltt_time_compare(lttTime
, time
);
954 if(t
->which_event
==2 || ltt_time_compare(t
->prev_event_time
,time
)<0){
958 return ltt_tracefile_seek_time(t
, time
);
962 if(ltt_tracefile_read(t
,&ev
) == NULL
) {
963 g_print("End of file\n");
966 lttTime
= getEventTime(t
);
967 err
= ltt_time_compare(lttTime
, time
);
971 }else{//we are at the end of the block
973 return ltt_tracefile_seek_time(t
, time
);
975 }else if(headTime
>= 0){
976 if(t
->which_block
== 1){
979 if(ltt_time_compare(t
->prev_block_end_time
, time
) >= 0 ||
980 (t
->prev_block_end_time
.tv_sec
== 0 &&
981 t
->prev_block_end_time
.tv_nsec
== 0 )){
982 ltt_tracefile_backward_find_time_block(t
, time
);
987 }else if(tailTime
< 0){
988 if(t
->which_block
!= t
->block_number
){
989 ltt_tracefile_find_time_block(t
, time
, t
->which_block
+1, t
->block_number
);
990 return ltt_tracefile_seek_time(t
, time
);
992 t
->cur_event_pos
= t
->buffer
+ t
->block_size
;
993 g_print("End of file\n");
996 }else if(tailTime
== 0){
997 t
->cur_event_pos
= t
->last_event_pos
;
998 t
->current_event_time
= time
;
999 t
->cur_heart_beat_number
= 0;
1000 t
->prev_event_time
.tv_sec
= 0;
1001 t
->prev_event_time
.tv_nsec
= 0;
1006 /*****************************************************************************
1007 * Seek to the first event with position equal or larger to ep
1009 * Modified by Mathieu Desnoyers to used faster offset position instead of
1010 * re-reading the whole buffer.
1011 ****************************************************************************/
1013 void ltt_tracefile_seek_position(LttTracefile
*t
, const LttEventPosition
*ep
)
1015 //if we are at the right place, just return
1016 if(likely(t
->which_block
== ep
->block_num
&& t
->which_event
== ep
->event_num
))
1019 if(likely(t
->which_block
== ep
->block_num
)) updateTracefile(t
);
1020 else readBlock(t
,ep
->block_num
);
1021 //event offset is available
1022 if(likely(ep
->old_position
)){
1025 t
->which_event
= ep
->event_num
;
1026 t
->cur_event_pos
= t
->buffer
+ ep
->event_offset
;
1027 t
->prev_event_time
= ep
->event_time
;
1028 t
->current_event_time
= ep
->event_time
;
1029 t
->cur_heart_beat_number
= ep
->heart_beat_number
;
1030 t
->cur_cycle_count
= ep
->event_cycle_count
;
1032 /* This is a workaround for fast position seek */
1033 t
->last_event_pos
= ep
->last_event_pos
;
1034 t
->prev_block_end_time
= ep
->prev_block_end_time
;
1035 t
->prev_event_time
= ep
->prev_event_time
;
1036 t
->pre_cycle_count
= ep
->pre_cycle_count
;
1037 t
->count
= ep
->count
;
1038 t
->overflow_nsec
= ep
->overflow_nsec
;
1039 t
->last_heartbeat
= ep
->last_heartbeat
;
1040 /* end of workaround */
1042 //update the fields of the current event and go to the next event
1044 if(unlikely(err
== ERANGE
)) g_error("event id is out of range\n");
1049 //only block number and event index are available
1050 //MD: warning : this is slow!
1051 g_warning("using slow O(n) tracefile seek position");
1054 while(likely(t
->which_event
< ep
->event_num
)) ltt_tracefile_read(t
, &event
);
1059 /*****************************************************************************
1061 * ltt_tracefile_read : read the current event, set the pointer to the next
1065 * LttEvent * : an event to be processed
1066 ****************************************************************************/
1068 LttEvent
*ltt_tracefile_read(LttTracefile
*t
, LttEvent
*event
)
1072 if(unlikely(t
->cur_event_pos
== t
->buffer
+ t
->block_size
)){
1073 if(unlikely(t
->which_block
== t
->block_number
)){
1076 err
= readBlock(t
, t
->which_block
+ 1);
1077 if(unlikely(err
))g_error("Can not read tracefile");
1080 event
->event_id
= (int)(*(guint16
*)(t
->cur_event_pos
));
1081 if(unlikely(event
->event_id
== TRACE_TIME_HEARTBEAT
))
1082 t
->cur_heart_beat_number
++;
1084 t
->prev_event_time
= t
->current_event_time
;
1085 // t->current_event_time = getEventTime(t);
1087 event
->time_delta
= *(guint32
*)(t
->cur_event_pos
+ EVENT_ID_SIZE
);
1088 event
->event_time
= t
->current_event_time
;
1089 event
->event_cycle_count
= t
->cur_cycle_count
;
1091 event
->tracefile
= t
;
1092 event
->data
= t
->cur_event_pos
+ EVENT_HEADER_SIZE
;
1093 event
->which_block
= t
->which_block
;
1094 event
->which_event
= t
->which_event
;
1096 /* This is a workaround for fast position seek */
1097 event
->last_event_pos
= t
->last_event_pos
;
1098 event
->prev_block_end_time
= t
->prev_block_end_time
;
1099 event
->prev_event_time
= t
->prev_event_time
;
1100 event
->pre_cycle_count
= t
->pre_cycle_count
;
1101 event
->count
= t
->count
;
1102 event
->overflow_nsec
= t
->overflow_nsec
;
1103 event
->last_heartbeat
= t
->last_heartbeat
;
1105 /* end of workaround */
1109 //update the fields of the current event and go to the next event
1111 if(unlikely(err
== ERANGE
)) g_error("event id is out of range\n");
1116 /****************************************************************************
1118 * readFile : wrap function to read from a file
1120 * fd : file descriptor
1121 * buf : buf to contain the content
1122 * size : number of bytes to be read
1123 * mesg : message to be printed if some thing goes wrong
1126 * EIO : can not read from the file
1127 ****************************************************************************/
1129 int readFile(int fd
, void * buf
, size_t size
, char * mesg
)
1131 ssize_t nbBytes
= read(fd
, buf
, size
);
1133 if((size_t)nbBytes
!= size
) {
1135 perror("Error in readFile : ");
1137 g_warning("%s",mesg
);
1145 /****************************************************************************
1147 * readBlock : read a block from the file
1149 * lttdes : ltt trace file
1150 * whichBlock : the block which will be read
1153 * EINVAL : lseek fail
1154 * EIO : can not read from the file
1155 ****************************************************************************/
1157 int readBlock(LttTracefile
* tf
, int whichBlock
)
1162 /* same block already opened requested */
1163 if((guint
)whichBlock
== tf
->which_block
) return 0;
1165 if(likely(whichBlock
- tf
->which_block
== 1 && tf
->which_block
!= 0)){
1166 tf
->prev_block_end_time
= tf
->a_block_end
->time
;
1167 tf
->prev_event_time
= tf
->a_block_end
->time
;
1169 tf
->prev_block_end_time
.tv_sec
= 0;
1170 tf
->prev_block_end_time
.tv_nsec
= 0;
1171 tf
->prev_event_time
.tv_sec
= 0;
1172 tf
->prev_event_time
.tv_nsec
= 0;
1175 nbBytes
=lseek(tf
->fd
,(off_t
)((whichBlock
-1)*tf
->block_size
), SEEK_SET
);
1176 if(unlikely(nbBytes
== -1)) return EINVAL
;
1178 if(unlikely(readFile(tf
->fd
,tf
->buffer
,tf
->block_size
,"Unable to read a block")))
1181 tf
->a_block_start
=(BlockStart
*) (tf
->buffer
+ EVENT_HEADER_SIZE
);
1182 lostSize
= *(guint32
*)(tf
->buffer
+ tf
->block_size
- sizeof(guint32
));
1183 tf
->a_block_end
=(BlockEnd
*)(tf
->buffer
+ tf
->block_size
1184 - sizeof(guint32
) - lostSize
- sizeof(BlockEnd
));
1185 tf
->last_event_pos
= tf
->buffer
+ tf
->block_size
-
1186 sizeof(guint32
) - lostSize
1187 - sizeof(BlockEnd
) - EVENT_HEADER_SIZE
;
1189 tf
->which_block
= whichBlock
;
1190 tf
->which_event
= 1;
1191 tf
->cur_event_pos
= tf
->buffer
;//the beginning of the block, block start ev
1192 tf
->cur_heart_beat_number
= 0;
1193 tf
->last_heartbeat
= NULL
;
1195 /* read the whole block to precalculate total of cycles in it */
1197 tf
->pre_cycle_count
= 0;
1198 tf
->cur_cycle_count
= 0;
1200 getCyclePerNsec(tf
);
1202 tf
->overflow_nsec
= (-((double)(tf
->a_block_start
->cycle_count
&0xFFFFFFFF))
1203 * tf
->nsec_per_cycle
);
1205 tf
->current_event_time
= getEventTime(tf
);
1210 /*****************************************************************************
1212 * updateTracefile : reinitialize the info of the block which is already
1216 ****************************************************************************/
1218 void updateTracefile(LttTracefile
* tf
)
1220 tf
->which_event
= 1;
1221 tf
->cur_event_pos
= tf
->buffer
;
1222 tf
->current_event_time
= getEventTime(tf
);
1223 tf
->cur_heart_beat_number
= 0;
1225 tf
->prev_event_time
.tv_sec
= 0;
1226 tf
->prev_event_time
.tv_nsec
= 0;
1229 tf
->overflow_nsec
= (-((double)tf
->a_block_start
->cycle_count
)
1230 * tf
->nsec_per_cycle
);
1234 /*****************************************************************************
1236 * skipEvent : go to the next event, update the fields of the current event
1241 * ERANGE : event id is out of range
1242 ****************************************************************************/
1244 int skipEvent(LttTracefile
* t
)
1251 evId
= (int)(*(guint16
*)(t
->cur_event_pos
));
1252 evData
= t
->cur_event_pos
+ EVENT_HEADER_SIZE
;
1254 evT
= ltt_trace_eventtype_get(t
->trace
,(unsigned)evId
);
1256 if(likely(evT
)) rootFld
= evT
->root_field
;
1259 if(likely(rootFld
)){
1260 //event has string/sequence or the last event is not the same event
1261 if(likely((evT
->latest_block
!=t
->which_block
|| evT
->latest_event
!=t
->which_event
)
1262 && rootFld
->field_fixed
== 0)){
1263 setFieldsOffset(t
, evT
, evData
, t
->trace
);
1265 t
->cur_event_pos
+= EVENT_HEADER_SIZE
+ rootFld
->field_size
;
1266 }else t
->cur_event_pos
+= EVENT_HEADER_SIZE
;
1268 evT
->latest_block
= t
->which_block
;
1269 evT
->latest_event
= t
->which_event
;
1271 //the next event is in the next block
1272 if(unlikely(evId
== TRACE_BLOCK_END
)){
1273 t
->cur_event_pos
= t
->buffer
+ t
->block_size
;
1276 t
->current_event_time
= getEventTime(t
);
1283 /*****************************************************************************
1285 * getCyclePerNsec : calculate cycles per nsec for current block
1286 * MD: should have tracefile_read the whole block, so we know the
1287 * total of cycles in it before being called.
1290 ****************************************************************************/
1292 void getCyclePerNsec(LttTracefile
* t
)
1294 LttTime lBufTotalTime
; /* Total time for this buffer */
1295 double lBufTotalNSec
; /* Total time for this buffer in nsecs */
1296 LttCycleCount lBufTotalCycle
;/* Total cycles for this buffer */
1298 /* Calculate the total time for this buffer */
1299 lBufTotalTime
= ltt_time_sub(t
->a_block_end
->time
, t
->a_block_start
->time
);
1301 /* Calculate the total cycles for this bufffer */
1302 lBufTotalCycle
= t
->a_block_end
->cycle_count
;
1303 lBufTotalCycle
-= t
->a_block_start
->cycle_count
;
1305 /* Convert the total time to double */
1306 lBufTotalNSec
= ltt_time_to_double(lBufTotalTime
);
1308 t
->nsec_per_cycle
= (double)lBufTotalNSec
/ (double)lBufTotalCycle
;
1310 /* Pre-multiply one overflow (2^32 cycles) by nsec_per_cycle */
1311 t
->one_overflow_nsec
= t
->nsec_per_cycle
* (double)0x100000000ULL
;
1315 /****************************************************************************
1317 * getEventTime : obtain the time of an event
1318 * NOTE : this function _really_ is on critical path.
1322 * LttTime : the time of the event
1323 ****************************************************************************/
1325 static inline LttTime
getEventTime(LttTracefile
* tf
)
1328 LttCycleCount cycle_count
; // cycle count for the current event
1329 //LttCycleCount lEventTotalCycle; // Total cycles from start for event
1330 gint64 lEventNSec
; // Total nsecs from start for event
1331 LttTime lTimeOffset
; // Time offset in struct LttTime
1334 evId
= *(guint16
*)tf
->cur_event_pos
;
1336 cycle_count
= (LttCycleCount
)*(guint32
*)(tf
->cur_event_pos
+ EVENT_ID_SIZE
);
1338 gboolean comp_count
= cycle_count
< tf
->pre_cycle_count
;
1340 tf
->pre_cycle_count
= cycle_count
;
1342 if(unlikely(comp_count
)) {
1344 tf
->overflow_nsec
+= tf
->one_overflow_nsec
;
1345 tf
->count
++; //increment overflow count
1348 if(unlikely(evId
== TRACE_BLOCK_START
)) {
1350 } else if(unlikely(evId
== TRACE_BLOCK_END
)) {
1351 lEventNSec
= ((double)
1352 (tf
->a_block_end
->cycle_count
- tf
->a_block_start
->cycle_count
)
1353 * tf
->nsec_per_cycle
);
1356 /* If you want to make heart beat a special case and use their own 64 bits
1357 * TSC, activate this.
1359 else if(unlikely(evId
== TRACE_TIME_HEARTBEAT
)) {
1361 tf
->last_heartbeat
= (TimeHeartbeat
*)(tf
->cur_event_pos
+EVENT_HEADER_SIZE
);
1362 lEventNSec
= ((double)(tf
->last_heartbeat
->cycle_count
1363 - tf
->a_block_start
->cycle_count
)
1364 * tf
->nsec_per_cycle
);
1368 lEventNSec
= (gint64
)((double)cycle_count
* tf
->nsec_per_cycle
)
1372 lTimeOffset
= ltt_time_from_uint64(lEventNSec
);
1374 time
= ltt_time_add(tf
->a_block_start
->time
, lTimeOffset
);
1379 /*****************************************************************************
1381 * setFieldsOffset : set offset of the fields
1383 * tracefile : opened trace file
1384 * evT : the event type
1385 * evD : event data, it may be NULL
1386 ****************************************************************************/
1388 void setFieldsOffset(LttTracefile
*tf
,LttEventType
*evT
,void *evD
,LttTrace
* t
)
1390 LttField
* rootFld
= evT
->root_field
;
1391 // rootFld->base_address = evD;
1394 rootFld
->field_size
= getFieldtypeSize(tf
, evT
, 0,0,rootFld
, evD
,t
);
1397 /*****************************************************************************
1399 * getFieldtypeSize: get the size of the field type (primitive type)
1401 * tracefile : opened trace file
1403 * offsetRoot : offset from the root
1404 * offsetParent : offset from the parrent
1406 * evD : event data, it may be NULL
1408 * int : size of the field
1409 ****************************************************************************/
1411 static inline gint
getFieldtypeSize(LttTracefile
* t
,
1412 LttEventType
* evT
, gint offsetRoot
,
1413 gint offsetParent
, LttField
* fld
, void *evD
, LttTrace
*trace
)
1415 gint size
, size1
, element_number
, i
, offset1
, offset2
;
1416 LttType
* type
= fld
->field_type
;
1418 if(unlikely(t
&& evT
->latest_block
==t
->which_block
&&
1419 evT
->latest_event
==t
->which_event
)){
1420 size
= fld
->field_size
;
1421 goto end_getFieldtypeSize
;
1423 /* This likely has been tested with gcov : half of them.. */
1424 if(unlikely(fld
->field_fixed
== 1)){
1426 if(unlikely(fld
== evT
->root_field
)) {
1427 size
= fld
->field_size
;
1428 goto end_getFieldtypeSize
;
1432 /* From gcov profiling : half string, half struct, can we gain something
1433 * from that ? (Mathieu) */
1434 switch(type
->type_class
) {
1436 element_number
= (int) type
->element_number
;
1437 if(fld
->field_fixed
== -1){
1438 size
= getFieldtypeSize(t
, evT
, offsetRoot
,
1439 0,fld
->child
[0], NULL
, trace
);
1440 if(size
== 0){ //has string or sequence
1441 fld
->field_fixed
= 0;
1443 fld
->field_fixed
= 1;
1444 size
*= element_number
;
1446 }else if(fld
->field_fixed
== 0){// has string or sequence
1448 for(i
=0;i
<element_number
;i
++){
1449 size
+= getFieldtypeSize(t
, evT
, offsetRoot
+size
,size
,
1450 fld
->child
[0], evD
+size
, trace
);
1452 }else size
= fld
->field_size
;
1454 fld
->fixed_root
= (offsetRoot
==-1) ? 0 : 1;
1455 fld
->fixed_parent
= (offsetParent
==-1) ? 0 : 1;
1461 size1
= (int) ltt_type_size(trace
, type
);
1462 if(fld
->field_fixed
== -1){
1463 fld
->sequ_number_size
= size1
;
1464 fld
->field_fixed
= 0;
1465 size
= getFieldtypeSize(t
, evT
, offsetRoot
,
1466 0,fld
->child
[0], NULL
, trace
);
1467 fld
->element_size
= size
;
1469 element_number
= getIntNumber(size1
,evD
);
1470 type
->element_number
= element_number
;
1471 if(fld
->element_size
> 0){
1472 size
= element_number
* fld
->element_size
;
1473 }else{//sequence has string or sequence
1475 for(i
=0;i
<element_number
;i
++){
1476 size
+= getFieldtypeSize(t
, evT
, offsetRoot
+size
+size1
,size
+size1
,
1477 fld
->child
[0], evD
+size
+size1
, trace
);
1483 fld
->fixed_root
= (offsetRoot
==-1) ? 0 : 1;
1484 fld
->fixed_parent
= (offsetParent
==-1) ? 0 : 1;
1491 if(fld
->field_fixed
== -1){
1492 fld
->field_fixed
= 0;
1494 /* Hope my implementation is faster than strlen (Mathieu) */
1495 char *ptr
=(char*)evD
;
1497 /* from gcov : many many strings are empty, make it the common case.*/
1498 while(unlikely(*ptr
!= '\0')) { size
++; ptr
++; }
1499 //size = ptr - (char*)evD + 1; //include end : '\0'
1501 fld
->fixed_root
= (offsetRoot
==-1) ? 0 : 1;
1502 fld
->fixed_parent
= (offsetParent
==-1) ? 0 : 1;
1507 element_number
= (int) type
->element_number
;
1509 /* tested with gcov */
1510 if(unlikely(fld
->field_fixed
== -1)){
1511 offset1
= offsetRoot
;
1513 for(i
=0;i
<element_number
;i
++){
1514 size1
=getFieldtypeSize(t
, evT
,offset1
,offset2
,
1515 fld
->child
[i
], NULL
, trace
);
1516 if(likely(size1
> 0 && size
>= 0)){
1518 if(likely(offset1
>= 0)) offset1
+= size1
;
1526 if(unlikely(size
== -1)){
1527 fld
->field_fixed
= 0;
1529 }else fld
->field_fixed
= 1;
1530 }else if(likely(fld
->field_fixed
== 0)){
1531 offset1
= offsetRoot
;
1533 for(i
=0;unlikely(i
<element_number
);i
++){
1534 size
=getFieldtypeSize(t
,evT
,offset1
,offset2
,
1535 fld
->child
[i
],evD
+offset2
, trace
);
1540 }else size
= fld
->field_size
;
1541 fld
->fixed_root
= (offsetRoot
==-1) ? 0 : 1;
1542 fld
->fixed_parent
= (offsetParent
==-1) ? 0 : 1;
1546 if(unlikely(fld
->field_fixed
== -1)){
1547 size
= (int) ltt_type_size(trace
, type
);
1548 fld
->field_fixed
= 1;
1549 }else size
= fld
->field_size
;
1551 fld
->fixed_root
= (offsetRoot
==-1) ? 0 : 1;
1552 fld
->fixed_parent
= (offsetParent
==-1) ? 0 : 1;
1558 fld
->offset_root
= offsetRoot
;
1559 fld
->offset_parent
= offsetParent
;
1560 fld
->field_size
= size
;
1562 end_getFieldtypeSize
:
1568 /*****************************************************************************
1570 * getIntNumber : get an integer number
1572 * size : the size of the integer
1573 * evD : the event data
1575 * gint64 : a 64 bits integer
1576 ****************************************************************************/
1578 gint64
getIntNumber(int size
, void *evD
)
1583 case 1: i
= *(gint8
*)evD
; break;
1584 case 2: i
= *(gint16
*)evD
; break;
1585 case 4: i
= *(gint32
*)evD
; break;
1586 case 8: i
= *(gint64
*)evD
; break;
1587 default: i
= *(gint64
*)evD
;
1588 g_critical("getIntNumber : integer size %d unknown", size
);
1595 /*****************************************************************************
1597 * getDataEndianType : get the data type size and endian type of the local
1600 * size : size of data type
1601 * endian : endian type, little or big
1602 ****************************************************************************/
1604 void getDataEndianType(LttArchSize
* size
, LttArchEndian
* endian
)
1608 int sizeInt
=sizeof(int), sizeLong
=sizeof(long), sizePointer
=sizeof(void *);
1610 if(c
== 1) *endian
= LTT_LITTLE_ENDIAN
;
1611 else *endian
= LTT_BIG_ENDIAN
;
1613 if(sizeInt
== 2 && sizeLong
== 4 && sizePointer
== 4)
1615 else if(sizeInt
== 4 && sizeLong
== 4 && sizePointer
== 4)
1617 else if(sizeInt
== 4 && sizeLong
== 8 && sizePointer
== 8)
1619 else if(sizeInt
== 8 && sizeLong
== 8 && sizePointer
== 8)
1621 else *size
= LTT_UNKNOWN
;
1624 /* get the node name of the system */
1626 char * ltt_trace_system_description_node_name (LttSystemDescription
* s
)
1628 return s
->node_name
;
1632 /* get the domain name of the system */
1634 char * ltt_trace_system_description_domain_name (LttSystemDescription
* s
)
1636 return s
->domain_name
;
1640 /* get the description of the system */
1642 char * ltt_trace_system_description_description (LttSystemDescription
* s
)
1644 return s
->description
;
1648 /* get the start time of the trace */
1650 LttTime
ltt_trace_system_description_trace_start_time(LttSystemDescription
*s
)
1652 return s
->trace_start
;
1656 LttTracefile
*ltt_tracefile_new()
1658 return g_new(LttTracefile
, 1);
1661 void ltt_tracefile_destroy(LttTracefile
*tf
)
1666 void ltt_tracefile_copy(LttTracefile
*dest
, const LttTracefile
*src
)