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>
28 #include <glib/gstdio.h>
37 #include "ltt-private.h"
38 #include <ltt/trace.h>
39 #include <ltt/facility.h>
40 #include <ltt/event.h>
42 #include <ltt/ltt-types.h>
44 #define DIR_NAME_SIZE 256
45 #define __UNUSED__ __attribute__((__unused__))
47 #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
48 #define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format)
52 /* obtain the time of an event */
54 static inline LttTime
getEventTime(LttTracefile
* tf
);
57 /* set the offset of the fields belonging to the event,
58 need the information of the archecture */
59 void setFieldsOffset(LttTracefile
*tf
,LttEventType
*evT
,void *evD
,LttTrace
*t
);
61 /* get the size of the field type according to the archtecture's
62 size and endian type(info of the archecture) */
63 static inline gint
getFieldtypeSize(LttTracefile
* tf
,
64 LttEventType
* evT
, gint offsetRoot
,
65 gint offsetParent
, LttField
*fld
, void *evD
, LttTrace
* t
);
67 /* read a fixed size or a block information from the file (fd) */
68 int readFile(int fd
, void * buf
, size_t size
, gchar
* mesg
);
69 int readBlock(LttTracefile
* tf
, int whichBlock
);
71 /* calculate cycles per nsec for current block */
72 void getCyclePerNsec(LttTracefile
* t
);
74 /* reinitialize the info of the block which is already in the buffer */
75 void updateTracefile(LttTracefile
* tf
);
77 /* go to the next event */
78 int skipEvent(LttTracefile
* t
);
81 /* Functions to parse system.xml file (using glib xml parser) */
82 static void parser_start_element (GMarkupParseContext __UNUSED__
*context
,
83 const gchar
*element_name
,
84 const gchar
**attribute_names
,
85 const gchar
**attribute_values
,
90 LttSystemDescription
* des
= (LttSystemDescription
* )user_data
;
91 if(strcmp("system", element_name
)){
92 *error
= g_error_new(G_MARKUP_ERROR
,
94 "This is not system.xml file");
98 while(attribute_names
[i
]){
99 if(strcmp("node_name", attribute_names
[i
])==0){
100 des
->node_name
= g_strdup(attribute_values
[i
]);
101 }else if(strcmp("domainname", attribute_names
[i
])==0){
102 des
->domain_name
= g_strdup(attribute_values
[i
]);
103 }else if(strcmp("cpu", attribute_names
[i
])==0){
104 des
->nb_cpu
= atoi(attribute_values
[i
]);
105 }else if(strcmp("arch_size", attribute_names
[i
])==0){
106 if(strcmp(attribute_values
[i
],"LP32") == 0) des
->size
= LTT_LP32
;
107 else if(strcmp(attribute_values
[i
],"ILP32") == 0) des
->size
= LTT_ILP32
;
108 else if(strcmp(attribute_values
[i
],"LP64") == 0) des
->size
= LTT_LP64
;
109 else if(strcmp(attribute_values
[i
],"ILP64") == 0) des
->size
= LTT_ILP64
;
110 else if(strcmp(attribute_values
[i
],"UNKNOWN") == 0) des
->size
= LTT_UNKNOWN
;
111 }else if(strcmp("endian", attribute_names
[i
])==0){
112 if(strcmp(attribute_values
[i
],"LITTLE_ENDIAN") == 0)
113 des
->endian
= LTT_LITTLE_ENDIAN
;
114 else if(strcmp(attribute_values
[i
],"BIG_ENDIAN") == 0)
115 des
->endian
= LTT_BIG_ENDIAN
;
116 }else if(strcmp("kernel_name", attribute_names
[i
])==0){
117 des
->kernel_name
= g_strdup(attribute_values
[i
]);
118 }else if(strcmp("kernel_release", attribute_names
[i
])==0){
119 des
->kernel_release
= g_strdup(attribute_values
[i
]);
120 }else if(strcmp("kernel_version", attribute_names
[i
])==0){
121 des
->kernel_version
= g_strdup(attribute_values
[i
]);
122 }else if(strcmp("machine", attribute_names
[i
])==0){
123 des
->machine
= g_strdup(attribute_values
[i
]);
124 }else if(strcmp("processor", attribute_names
[i
])==0){
125 des
->processor
= g_strdup(attribute_values
[i
]);
126 }else if(strcmp("hardware_platform", attribute_names
[i
])==0){
127 des
->hardware_platform
= g_strdup(attribute_values
[i
]);
128 }else if(strcmp("operating_system", attribute_names
[i
])==0){
129 des
->operating_system
= g_strdup(attribute_values
[i
]);
130 }else if(strcmp("ltt_major_version", attribute_names
[i
])==0){
131 des
->ltt_major_version
= atoi(attribute_values
[i
]);
132 }else if(strcmp("ltt_minor_version", attribute_names
[i
])==0){
133 des
->ltt_minor_version
= atoi(attribute_values
[i
]);
134 }else if(strcmp("ltt_block_size", attribute_names
[i
])==0){
135 des
->ltt_block_size
= atoi(attribute_values
[i
]);
137 *error
= g_error_new(G_MARKUP_ERROR
,
139 "Not a valid attribute");
146 static void parser_characters (GMarkupParseContext __UNUSED__
*context
,
148 gsize __UNUSED__ text_len
,
150 GError __UNUSED__
**error
)
152 LttSystemDescription
* des
= (LttSystemDescription
* )user_data
;
153 des
->description
= g_strdup(text
);
157 /*****************************************************************************
159 * ltt_tracefile_open : open a trace file, construct a LttTracefile
161 * t : the trace containing the tracefile
162 * fileName : path name of the trace file
164 * : a pointer to a tracefile
165 ****************************************************************************/
167 LttTracefile
* ltt_tracefile_open(LttTrace
* t
, gchar
* fileName
)
170 struct stat lTDFStat
; /* Trace data file status */
172 tf
= g_new(LttTracefile
, 1);
175 tf
->name
= g_strdup(fileName
);
177 tf
->fd
= g_open(fileName
, O_RDONLY
, 0);
179 g_warning("Unable to open input data file %s\n", fileName
);
185 // Get the file's status
186 if(fstat(tf
->fd
, &lTDFStat
) < 0){
187 g_warning("Unable to get the status of the input data file %s\n", fileName
);
194 // Is the file large enough to contain a trace
195 if(lTDFStat
.st_size
< (off_t
)(sizeof(BlockStart
) + EVENT_HEADER_SIZE
)){
196 g_print("The input data file %s does not contain a trace\n", fileName
);
203 //store the size of the file
204 tf
->file_size
= lTDFStat
.st_size
;
205 tf
->block_size
= t
->system_description
->ltt_block_size
;
206 tf
->block_number
= tf
->file_size
/ tf
->block_size
;
209 //allocate memory to contain the info of a block
210 tf
->buffer
= (void *) g_new(gchar
, t
->system_description
->ltt_block_size
);
212 //read the first block
213 if(readBlock(tf
,1)) exit(1);
219 /*****************************************************************************
220 *Open control and per cpu tracefiles
221 ****************************************************************************/
223 void ltt_tracefile_open_cpu(LttTrace
*t
, gchar
* tracefile_name
)
226 tf
= ltt_tracefile_open(t
,tracefile_name
);
228 t
->per_cpu_tracefile_number
++;
229 g_ptr_array_add(t
->per_cpu_tracefiles
, tf
);
232 gint
ltt_tracefile_open_control(LttTrace
*t
, gchar
* control_name
)
241 tf
= ltt_tracefile_open(t
,control_name
);
243 g_warning("ltt_tracefile_open_control : bad file descriptor");
246 t
->control_tracefile_number
++;
247 g_ptr_array_add(t
->control_tracefiles
,tf
);
249 //parse facilities tracefile to get base_id
250 if(strcmp(&control_name
[strlen(control_name
)-10],"facilities") ==0){
252 if(!ltt_tracefile_read(tf
,&ev
)) return 0; // end of file
254 if(ev
.event_id
== TRACE_FACILITY_LOAD
){
256 fLoad
.name
= (gchar
*)pos
;
257 fLoad
.checksum
= *(LttChecksum
*)(pos
+ strlen(fLoad
.name
));
258 fLoad
.base_code
= *(guint32
*)(pos
+ strlen(fLoad
.name
) + sizeof(LttChecksum
));
260 for(i
=0;i
<t
->facility_number
;i
++){
261 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
,i
);
262 if(strcmp(f
->name
,fLoad
.name
)==0 && fLoad
.checksum
==f
->checksum
){
263 f
->base_id
= fLoad
.base_code
;
267 if(i
==t
->facility_number
) {
268 g_warning("Facility: %s, checksum: %u is not found",
269 fLoad
.name
,(unsigned int)fLoad
.checksum
);
272 }else if(ev
.event_id
== TRACE_BLOCK_START
){
274 }else if(ev
.event_id
== TRACE_BLOCK_END
){
277 g_warning("Not valid facilities trace file");
285 /*****************************************************************************
287 * ltt_tracefile_close: close a trace file,
289 * t : tracefile which will be closed
290 ****************************************************************************/
292 void ltt_tracefile_close(LttTracefile
*t
)
301 /*****************************************************************************
302 *Get system information
303 ****************************************************************************/
304 gint
getSystemInfo(LttSystemDescription
* des
, gchar
* pathname
)
311 GMarkupParseContext
* context
;
312 GError
* error
= NULL
;
313 GMarkupParser markup_parser
=
315 parser_start_element
,
318 NULL
, /* passthrough */
322 fd
= g_open(pathname
, O_RDONLY
, 0);
324 g_warning("Can not open file : %s\n", pathname
);
328 iochan
= g_io_channel_unix_new(fd
);
330 context
= g_markup_parse_context_new(&markup_parser
, 0, des
,NULL
);
332 //while(fgets(buf,DIR_NAME_SIZE, fp) != NULL){
333 while(g_io_channel_read_line(iochan
, &buf
, &length
, NULL
, &error
)
334 != G_IO_STATUS_EOF
) {
337 g_warning("Can not read xml file: \n%s\n", error
->message
);
340 if(!g_markup_parse_context_parse(context
, buf
, length
, &error
)){
342 g_warning("Can not parse xml file: \n%s\n", error
->message
);
345 g_markup_parse_context_free(context
);
347 g_io_channel_shutdown(iochan
, FALSE
, &error
); /* No flush */
349 g_warning("Can not close file: \n%s\n", error
->message
);
357 g_markup_parse_context_free(context
);
359 g_io_channel_shutdown(iochan
, FALSE
, &error
); /* No flush */
361 g_warning("Can not close file: \n%s\n", error
->message
);
371 /*****************************************************************************
372 *The following functions get facility/tracefile information
373 ****************************************************************************/
375 gint
getFacilityInfo(LttTrace
*t
, gchar
* eventdefs
)
382 gchar fullname
[DIR_NAME_SIZE
];
383 GError
* error
= NULL
;
385 dir
= g_dir_open(eventdefs
, 0, &error
);
388 g_warning("Can not open directory: %s, %s\n", eventdefs
, error
->message
);
393 while((name
= g_dir_read_name(dir
)) != NULL
){
394 if(!g_pattern_match_simple("*.xml", name
)) continue;
395 strcpy(fullname
,eventdefs
);
396 strcat(fullname
,name
);
397 ltt_facility_open(t
,fullname
);
401 for(j
=0;j
<t
->facility_number
;j
++){
402 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
, j
);
403 for(i
=0; i
<f
->event_number
; i
++){
405 setFieldsOffset(NULL
, et
, NULL
, t
);
411 gint
getControlFileInfo(LttTrace
*t
, gchar
* control
)
415 gchar fullname
[DIR_NAME_SIZE
];
416 GError
* error
= NULL
;
418 dir
= g_dir_open(control
, 0, &error
);
421 g_warning("Can not open directory: %s, %s\n", control
, error
->message
);
426 while((name
= g_dir_read_name(dir
)) != NULL
){
427 if(strcmp(name
,"facilities") != 0 &&
428 strcmp(name
,"interrupts") != 0 &&
429 strcmp(name
,"processes") != 0) continue;
431 strcpy(fullname
,control
);
432 strcat(fullname
,name
);
433 if(ltt_tracefile_open_control(t
,fullname
)) {
442 gint
getCpuFileInfo(LttTrace
*t
, char* cpu
)
446 gchar fullname
[DIR_NAME_SIZE
];
447 GError
* error
= NULL
;
449 dir
= g_dir_open(cpu
, 0, &error
);
452 g_warning("Can not open directory: %s, %s\n", cpu
, error
->message
);
457 while((name
= g_dir_read_name(dir
)) != NULL
){
458 if(strcmp(name
,".svn") != 0){ /* . and .. already excluded */
459 strcpy(fullname
,cpu
);
460 strcat(fullname
,name
);
461 ltt_tracefile_open_cpu(t
,fullname
);
468 /*****************************************************************************
469 *A trace is specified as a pathname to the directory containing all the
470 *associated data (control tracefiles, per cpu tracefiles, event
473 *When a trace is closed, all the associated facilities, types and fields
474 *are released as well.
478 /****************************************************************************
479 * get_absolute_pathname
481 * return the unique pathname in the system
483 * MD : Fixed this function so it uses realpath, dealing well with
484 * forgotten cases (.. were not used correctly before).
486 ****************************************************************************/
487 void get_absolute_pathname(const gchar
*pathname
, gchar
* abs_pathname
)
489 abs_pathname
[0] = '\0';
491 if ( realpath (pathname
, abs_pathname
) != NULL
)
495 /* error, return the original path unmodified */
496 strcpy(abs_pathname
, pathname
);
502 LttTrace
*ltt_trace_open(const gchar
*pathname
)
505 LttSystemDescription
* sys_description
;
506 gchar eventdefs
[DIR_NAME_SIZE
];
507 gchar info
[DIR_NAME_SIZE
];
508 gchar control
[DIR_NAME_SIZE
];
509 gchar cpu
[DIR_NAME_SIZE
];
510 gchar tmp
[DIR_NAME_SIZE
];
511 gchar abs_path
[DIR_NAME_SIZE
];
512 gboolean has_slash
= FALSE
;
514 get_absolute_pathname(pathname
, abs_path
);
515 //establish the pathname to different directories
516 if(abs_path
[strlen(abs_path
)-1] == '/')has_slash
= TRUE
;
517 strcpy(eventdefs
,abs_path
);
518 if(!has_slash
)strcat(eventdefs
,"/");
519 strcat(eventdefs
,"eventdefs/");
521 strcpy(info
,abs_path
);
522 if(!has_slash
)strcat(info
,"/");
523 strcat(info
,"info/");
525 strcpy(control
,abs_path
);
526 if(!has_slash
)strcat(control
,"/");
527 strcat(control
,"control/");
529 strcpy(cpu
,abs_path
);
530 if(!has_slash
)strcat(cpu
,"/");
534 sys_description
= g_new(LttSystemDescription
, 1);
535 t
= g_new(LttTrace
, 1);
536 t
->pathname
= g_strdup(abs_path
);
537 t
->facility_number
= 0;
538 t
->control_tracefile_number
= 0;
539 t
->per_cpu_tracefile_number
= 0;
540 t
->system_description
= sys_description
;
541 t
->control_tracefiles
= g_ptr_array_new();
542 t
->per_cpu_tracefiles
= g_ptr_array_new();
543 t
->facilities
= g_ptr_array_new();
544 //getDataEndianType(&(t->my_arch_size), &(t->my_arch_endian));
546 //get system description
548 strcat(tmp
,"system.xml");
549 if(getSystemInfo(sys_description
, tmp
)) {
550 g_ptr_array_free(t
->facilities
, TRUE
);
551 g_ptr_array_free(t
->per_cpu_tracefiles
, TRUE
);
552 g_ptr_array_free(t
->control_tracefiles
, TRUE
);
553 g_free(sys_description
);
559 /* Set the reverse byte order between trace and reader */
560 if(sys_description
->endian
== LTT_LITTLE_ENDIAN
561 && G_BYTE_ORDER
!= G_LITTLE_ENDIAN
) {
562 t
->reverse_byte_order
= 1;
563 } else if(sys_description
->endian
== LTT_BIG_ENDIAN
564 && G_BYTE_ORDER
!= G_BIG_ENDIAN
) {
565 t
->reverse_byte_order
= 1;
566 } else t
->reverse_byte_order
= 0;
568 //get facilities info
569 if(getFacilityInfo(t
,eventdefs
)) {
570 g_ptr_array_free(t
->facilities
, TRUE
);
571 g_ptr_array_free(t
->per_cpu_tracefiles
, TRUE
);
572 g_ptr_array_free(t
->control_tracefiles
, TRUE
);
573 g_free(sys_description
);
579 //get control tracefile info
580 getControlFileInfo(t
,control
);
582 if(getControlFileInfo(t,control)) {
583 g_ptr_array_free(t->facilities, TRUE);
584 g_ptr_array_free(t->per_cpu_tracefiles, TRUE);
585 g_ptr_array_free(t->control_tracefiles, TRUE);
586 g_free(sys_description);
590 }*/ // With fatal error
592 //get cpu tracefile info
593 if(getCpuFileInfo(t
,cpu
)) {
594 g_ptr_array_free(t
->facilities
, TRUE
);
595 g_ptr_array_free(t
->per_cpu_tracefiles
, TRUE
);
596 g_ptr_array_free(t
->control_tracefiles
, TRUE
);
597 g_free(sys_description
);
606 char * ltt_trace_name(LttTrace
*t
)
612 /******************************************************************************
613 * When we copy a trace, we want all the opening actions to happen again :
614 * the trace will be reopened and totally independant from the original.
615 * That's why we call ltt_trace_open.
616 *****************************************************************************/
617 LttTrace
*ltt_trace_copy(LttTrace
*self
)
619 return ltt_trace_open(self
->pathname
);
622 void ltt_trace_close(LttTrace
*t
)
630 //free system_description
631 g_free(t
->system_description
->description
);
632 g_free(t
->system_description
->node_name
);
633 g_free(t
->system_description
->domain_name
);
634 g_free(t
->system_description
->kernel_name
);
635 g_free(t
->system_description
->kernel_release
);
636 g_free(t
->system_description
->kernel_version
);
637 g_free(t
->system_description
->machine
);
638 g_free(t
->system_description
->processor
);
639 g_free(t
->system_description
->hardware_platform
);
640 g_free(t
->system_description
->operating_system
);
641 g_free(t
->system_description
);
643 //free control_tracefiles
644 for(i
=0;i
<t
->control_tracefile_number
;i
++){
645 tf
= (LttTracefile
*)g_ptr_array_index(t
->control_tracefiles
,i
);
646 ltt_tracefile_close(tf
);
648 g_ptr_array_free(t
->control_tracefiles
, TRUE
);
650 //free per_cpu_tracefiles
651 for(i
=0;i
<t
->per_cpu_tracefile_number
;i
++){
652 tf
= (LttTracefile
*)g_ptr_array_index(t
->per_cpu_tracefiles
,i
);
653 ltt_tracefile_close(tf
);
655 g_ptr_array_free(t
->per_cpu_tracefiles
, TRUE
);
658 for(i
=0;i
<t
->facility_number
;i
++){
659 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
,i
);
660 ltt_facility_close(f
);
662 g_ptr_array_free(t
->facilities
, TRUE
);
670 /*****************************************************************************
671 *Get the system description of the trace
672 ****************************************************************************/
674 LttSystemDescription
*ltt_trace_system_description(LttTrace
*t
)
676 return t
->system_description
;
679 /*****************************************************************************
680 * The following functions discover the facilities of the trace
681 ****************************************************************************/
683 unsigned ltt_trace_facility_number(LttTrace
*t
)
685 return (unsigned)(t
->facility_number
);
688 LttFacility
*ltt_trace_facility_get(LttTrace
*t
, unsigned i
)
690 return (LttFacility
*)g_ptr_array_index(t
->facilities
, i
);
693 /*****************************************************************************
695 * ltt_trace_facility_find : find facilities in the trace
698 * name : facility name
700 * position : position of the facility in the trace
702 * : the number of facilities
703 ****************************************************************************/
705 unsigned ltt_trace_facility_find(LttTrace
*t
, char *name
, unsigned *position
)
707 unsigned int i
, count
=0;
709 for(i
=0;i
<t
->facility_number
;i
++){
710 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
, i
);
711 if(strcmp(f
->name
,name
)==0){
713 if(count
==1) *position
= i
;
721 /*****************************************************************************
722 * Functions to discover all the event types in the trace
723 ****************************************************************************/
725 unsigned ltt_trace_eventtype_number(LttTrace
*t
)
729 unsigned int num
= t
->facility_number
;
733 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
, i
);
734 count
+= f
->event_number
;
739 /* FIXME : performances could be improved with a better design for this
740 * function : sequential search through a container has never been the
741 * best on the critical path. */
742 LttFacility
* ltt_trace_facility_by_id(LttTrace
* trace
, unsigned id
)
744 LttFacility
* facility
= NULL
;
746 unsigned int num
= trace
->facility_number
;
747 GPtrArray
*facilities
= trace
->facilities
;
749 for(i
=0;unlikely(i
<num
);){
750 LttFacility
*iter_facility
=
751 (LttFacility
*) g_ptr_array_index(facilities
,i
);
752 unsigned base_id
= iter_facility
->base_id
;
754 if(likely(id
>= base_id
&&
755 id
< base_id
+ iter_facility
->event_number
)) {
756 facility
= iter_facility
;
766 LttEventType
*ltt_trace_eventtype_get(LttTrace
*t
, unsigned evId
)
768 LttEventType
*event_type
;
771 f
= ltt_trace_facility_by_id(t
,evId
);
773 if(unlikely(!f
)) event_type
= NULL
;
774 else event_type
= f
->events
[evId
- f
->base_id
];
779 /*****************************************************************************
780 *There is one "per cpu" tracefile for each CPU, numbered from 0 to
781 *the maximum number of CPU in the system. When the number of CPU installed
782 *is less than the maximum, some positions are unused. There are also a
783 *number of "control" tracefiles (facilities, interrupts...).
784 ****************************************************************************/
785 unsigned ltt_trace_control_tracefile_number(LttTrace
*t
)
787 return t
->control_tracefile_number
;
790 unsigned ltt_trace_per_cpu_tracefile_number(LttTrace
*t
)
792 return t
->per_cpu_tracefile_number
;
795 /*****************************************************************************
796 *It is possible to search for the tracefiles by name or by CPU position.
797 *The index within the tracefiles of the same type is returned if found
798 *and a negative value otherwise.
799 ****************************************************************************/
801 int ltt_trace_control_tracefile_find(LttTrace
*t
, const gchar
*name
)
803 LttTracefile
* tracefile
;
805 for(i
=0;i
<t
->control_tracefile_number
;i
++){
806 tracefile
= (LttTracefile
*)g_ptr_array_index(t
->control_tracefiles
, i
);
807 if(strcmp(tracefile
->name
, name
)==0)break;
809 if(i
== t
->control_tracefile_number
) return -1;
813 /* not really useful. We just have to know that cpu tracefiles
814 * comes before control tracefiles.
816 int ltt_trace_per_cpu_tracefile_find(LttTrace
*t
, const gchar
*name
)
818 LttTracefile
* tracefile
;
820 for(i
=0;i
<t
->per_cpu_tracefile_number
;i
++){
821 tracefile
= (LttTracefile
*)g_ptr_array_index(t
->per_cpu_tracefiles
, i
);
822 if(strcmp(tracefile
->name
, name
)==0)break;
824 if(i
== t
->per_cpu_tracefile_number
) return -1;
828 /*****************************************************************************
829 *Get a specific tracefile
830 ****************************************************************************/
832 LttTracefile
*ltt_trace_control_tracefile_get(LttTrace
*t
, unsigned i
)
834 return (LttTracefile
*)g_ptr_array_index(t
->control_tracefiles
, i
);
837 LttTracefile
*ltt_trace_per_cpu_tracefile_get(LttTrace
*t
, unsigned i
)
839 return (LttTracefile
*)g_ptr_array_index(t
->per_cpu_tracefiles
, i
);
842 /*****************************************************************************
843 * Get the start time and end time of the trace
844 ****************************************************************************/
846 void ltt_trace_time_span_get(LttTrace
*t
, LttTime
*start
, LttTime
*end
)
848 LttTime startSmall
, startTmp
, endBig
, endTmp
;
852 for(i
=0;i
<t
->control_tracefile_number
;i
++){
853 tf
= g_ptr_array_index(t
->control_tracefiles
, i
);
855 startTmp
= ltt_get_time(t
->reverse_byte_order
, &tf
->a_block_start
->time
);
856 readBlock(tf
,tf
->block_number
);
857 endTmp
= ltt_get_time(t
->reverse_byte_order
, &tf
->a_block_end
->time
);
859 startSmall
= startTmp
;
864 if(ltt_time_compare(startSmall
,startTmp
) > 0) startSmall
= startTmp
;
865 if(ltt_time_compare(endBig
,endTmp
) < 0) endBig
= endTmp
;
868 for(i
=0;i
<t
->per_cpu_tracefile_number
;i
++){
869 tf
= g_ptr_array_index(t
->per_cpu_tracefiles
, i
);
871 startTmp
= ltt_get_time(t
->reverse_byte_order
, &tf
->a_block_start
->time
);
872 readBlock(tf
,tf
->block_number
);
873 endTmp
= ltt_get_time(t
->reverse_byte_order
, &tf
->a_block_end
->time
);
875 startSmall
= startTmp
;
879 if(ltt_time_compare(startSmall
,startTmp
) > 0) startSmall
= startTmp
;
880 if(ltt_time_compare(endBig
,endTmp
) < 0) endBig
= endTmp
;
883 if(start
!= NULL
) *start
= startSmall
;
884 if(end
!= NULL
) *end
= endBig
;
888 /*****************************************************************************
889 *Get the name of a tracefile
890 ****************************************************************************/
892 char *ltt_tracefile_name(LttTracefile
*tf
)
897 /*****************************************************************************
898 * Get the number of blocks in the tracefile
899 ****************************************************************************/
901 unsigned ltt_tracefile_block_number(LttTracefile
*tf
)
903 return tf
->block_number
;
906 /*****************************************************************************
908 * ltt_tracefile_seek_time: seek to the first event of the trace with time
909 * larger or equal to time
912 * time : criteria of the time
913 ****************************************************************************/
914 void ltt_tracefile_find_time_block(LttTracefile
*t
, LttTime time
,
915 int start_block
, int end_block
)
917 int err
, tmp_block
, s
, e
;
921 err
=readBlock(t
,start_block
);
922 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
923 if(start_block
== end_block
)return;
925 tailTime
= ltt_time_compare(ltt_get_time(t
->trace
->reverse_byte_order
,
926 &t
->a_block_end
->time
), time
);
927 if(tailTime
>= 0) return;
929 err
=readBlock(t
,end_block
);
930 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
931 if(start_block
+1 == end_block
)return;
933 headTime
= ltt_time_compare(ltt_get_time(t
->trace
->reverse_byte_order
,
934 &t
->a_block_start
->time
), time
);
935 if(headTime
<= 0 ) return;
937 tmp_block
= (end_block
+ start_block
)/2;
938 err
=readBlock(t
,tmp_block
);
939 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
941 headTime
= ltt_time_compare(ltt_get_time(t
->trace
->reverse_byte_order
,
942 &t
->a_block_start
->time
), time
);
943 tailTime
= ltt_time_compare(ltt_get_time(t
->trace
->reverse_byte_order
,
944 &t
->a_block_end
->time
), time
);
945 if(headTime
<= 0 && tailTime
>= 0) return;
951 ltt_tracefile_find_time_block(t
, time
, s
, e
);
959 ltt_tracefile_find_time_block(t
, time
, s
, e
);
964 void ltt_tracefile_backward_find_time_block(LttTracefile
*t
, LttTime time
)
966 int t_time
, h_time
, err
;
967 err
=readBlock(t
,t
->which_block
-1);
968 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
969 h_time
= ltt_time_compare(ltt_get_time(t
->trace
->reverse_byte_order
,
970 &t
->a_block_start
->time
), time
);
971 t_time
= ltt_time_compare(ltt_get_time(t
->trace
->reverse_byte_order
,
972 &t
->a_block_end
->time
), time
);
975 if(t
->which_block
== 1) return;
976 err
=readBlock(t
,t
->which_block
-1);
977 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
978 tmp
= ltt_time_compare(ltt_get_time(t
->trace
->reverse_byte_order
,
979 &t
->a_block_end
->time
), time
);
980 if(tmp
== 0) return ltt_tracefile_seek_time(t
, time
);
981 err
=readBlock(t
,t
->which_block
+1);
982 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
983 }else if(h_time
> 0){
984 ltt_tracefile_find_time_block(t
, time
, 1, t
->which_block
);
985 return ltt_tracefile_seek_time(t
, time
) ;
987 if(t_time
>= 0) return ltt_tracefile_seek_time(t
, time
);
988 err
=readBlock(t
,t
->which_block
+1);
989 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
993 void ltt_tracefile_seek_time(LttTracefile
*t
, LttTime time
)
997 int headTime
= ltt_time_compare(ltt_get_time(t
->trace
->reverse_byte_order
,
998 &t
->a_block_start
->time
), time
);
999 int tailTime
= ltt_time_compare(ltt_get_time(t
->trace
->reverse_byte_order
,
1000 &t
->a_block_end
->time
), time
);
1003 if(headTime
< 0 && tailTime
> 0){
1004 if(ltt_time_compare(ltt_get_time(t
->trace
->reverse_byte_order
,
1005 &t
->a_block_end
->time
),
1006 t
->current_event_time
) !=0) {
1007 lttTime
= getEventTime(t
);
1008 err
= ltt_time_compare(lttTime
, time
);
1010 if(t
->which_event
==2 || ltt_time_compare(t
->prev_event_time
,time
)<0){
1014 return ltt_tracefile_seek_time(t
, time
);
1018 if(ltt_tracefile_read(t
,&ev
) == NULL
) {
1019 g_print("End of file\n");
1022 lttTime
= getEventTime(t
);
1023 err
= ltt_time_compare(lttTime
, time
);
1027 }else{//we are at the end of the block
1029 return ltt_tracefile_seek_time(t
, time
);
1031 }else if(headTime
>= 0){
1032 if(t
->which_block
== 1){
1035 if(ltt_time_compare(t
->prev_block_end_time
, time
) >= 0 ||
1036 (t
->prev_block_end_time
.tv_sec
== 0 &&
1037 t
->prev_block_end_time
.tv_nsec
== 0 )){
1038 ltt_tracefile_backward_find_time_block(t
, time
);
1043 }else if(tailTime
< 0){
1044 if(t
->which_block
!= t
->block_number
){
1045 ltt_tracefile_find_time_block(t
, time
, t
->which_block
+1, t
->block_number
);
1046 return ltt_tracefile_seek_time(t
, time
);
1048 t
->cur_event_pos
= t
->buffer
+ t
->block_size
;
1049 g_print("End of file\n");
1052 }else if(tailTime
== 0){
1053 t
->cur_event_pos
= t
->last_event_pos
;
1054 t
->current_event_time
= time
;
1055 t
->cur_heart_beat_number
= 0;
1056 t
->prev_event_time
.tv_sec
= 0;
1057 t
->prev_event_time
.tv_nsec
= 0;
1062 /*****************************************************************************
1063 * Seek to the first event with position equal or larger to ep
1065 * Modified by Mathieu Desnoyers to used faster offset position instead of
1066 * re-reading the whole buffer.
1067 ****************************************************************************/
1069 void ltt_tracefile_seek_position(LttTracefile
*t
, const LttEventPosition
*ep
)
1071 //if we are at the right place, just return
1072 if(likely(t
->which_block
== ep
->block_num
&& t
->which_event
== ep
->event_num
))
1075 if(likely(t
->which_block
== ep
->block_num
)) updateTracefile(t
);
1076 else readBlock(t
,ep
->block_num
);
1077 //event offset is available
1078 if(likely(ep
->old_position
)){
1081 t
->which_event
= ep
->event_num
;
1082 t
->cur_event_pos
= t
->buffer
+ ep
->event_offset
;
1083 t
->prev_event_time
= ep
->event_time
;
1084 t
->current_event_time
= ep
->event_time
;
1085 t
->cur_heart_beat_number
= ep
->heart_beat_number
;
1086 t
->cur_cycle_count
= ep
->event_cycle_count
;
1088 /* This is a workaround for fast position seek */
1089 t
->last_event_pos
= ep
->last_event_pos
;
1090 t
->prev_block_end_time
= ep
->prev_block_end_time
;
1091 t
->prev_event_time
= ep
->prev_event_time
;
1092 t
->pre_cycle_count
= ep
->pre_cycle_count
;
1093 t
->count
= ep
->count
;
1094 t
->overflow_nsec
= ep
->overflow_nsec
;
1095 t
->last_heartbeat
= ep
->last_heartbeat
;
1096 /* end of workaround */
1098 //update the fields of the current event and go to the next event
1100 if(unlikely(err
== ERANGE
)) g_error("event id is out of range\n");
1105 //only block number and event index are available
1106 //MD: warning : this is slow!
1107 g_warning("using slow O(n) tracefile seek position");
1110 while(likely(t
->which_event
< ep
->event_num
)) ltt_tracefile_read(t
, &event
);
1115 /*****************************************************************************
1117 * ltt_tracefile_read : read the current event, set the pointer to the next
1121 * LttEvent * : an event to be processed
1122 ****************************************************************************/
1124 LttEvent
*ltt_tracefile_read(LttTracefile
*t
, LttEvent
*event
)
1128 if(unlikely(t
->cur_event_pos
== t
->buffer
+ t
->block_size
)){
1129 if(unlikely(t
->which_block
== t
->block_number
)){
1132 err
= readBlock(t
, t
->which_block
+ 1);
1133 if(unlikely(err
))g_error("Can not read tracefile");
1136 event
->event_id
= ltt_get_uint16(t
->trace
->reverse_byte_order
, t
->cur_event_pos
);
1137 if(unlikely(event
->event_id
== TRACE_TIME_HEARTBEAT
))
1138 t
->cur_heart_beat_number
++;
1140 t
->prev_event_time
= t
->current_event_time
;
1141 // t->current_event_time = getEventTime(t);
1143 event
->time_delta
= ltt_get_uint32(t
->trace
->reverse_byte_order
, t
->cur_event_pos
+ EVENT_ID_SIZE
);
1144 event
->event_time
= t
->current_event_time
;
1145 event
->event_cycle_count
= t
->cur_cycle_count
;
1147 event
->tracefile
= t
;
1148 event
->data
= t
->cur_event_pos
+ EVENT_HEADER_SIZE
;
1149 event
->which_block
= t
->which_block
;
1150 event
->which_event
= t
->which_event
;
1152 /* This is a workaround for fast position seek */
1153 event
->last_event_pos
= t
->last_event_pos
;
1154 event
->prev_block_end_time
= t
->prev_block_end_time
;
1155 event
->prev_event_time
= t
->prev_event_time
;
1156 event
->pre_cycle_count
= t
->pre_cycle_count
;
1157 event
->count
= t
->count
;
1158 event
->overflow_nsec
= t
->overflow_nsec
;
1159 event
->last_heartbeat
= t
->last_heartbeat
;
1161 /* end of workaround */
1165 //update the fields of the current event and go to the next event
1167 if(unlikely(err
== ERANGE
)) g_error("event id is out of range\n");
1172 /****************************************************************************
1174 * readFile : wrap function to read from a file
1176 * fd : file descriptor
1177 * buf : buf to contain the content
1178 * size : number of bytes to be read
1179 * mesg : message to be printed if some thing goes wrong
1182 * EIO : can not read from the file
1183 ****************************************************************************/
1185 int readFile(int fd
, void * buf
, size_t size
, char * mesg
)
1187 ssize_t nbBytes
= read(fd
, buf
, size
);
1189 if((size_t)nbBytes
!= size
) {
1191 perror("Error in readFile : ");
1193 g_warning("%s",mesg
);
1201 /****************************************************************************
1203 * readBlock : read a block from the file
1205 * lttdes : ltt trace file
1206 * whichBlock : the block which will be read
1209 * EINVAL : lseek fail
1210 * EIO : can not read from the file
1211 ****************************************************************************/
1213 int readBlock(LttTracefile
* tf
, int whichBlock
)
1218 /* same block already opened requested */
1219 if((guint
)whichBlock
== tf
->which_block
) return 0;
1221 if(likely(whichBlock
- tf
->which_block
== 1 && tf
->which_block
!= 0)){
1222 tf
->prev_block_end_time
= ltt_get_time(tf
->trace
->reverse_byte_order
,
1223 &tf
->a_block_end
->time
);
1224 tf
->prev_event_time
= ltt_get_time(tf
->trace
->reverse_byte_order
,
1225 &tf
->a_block_end
->time
);
1227 tf
->prev_block_end_time
.tv_sec
= 0;
1228 tf
->prev_block_end_time
.tv_nsec
= 0;
1229 tf
->prev_event_time
.tv_sec
= 0;
1230 tf
->prev_event_time
.tv_nsec
= 0;
1233 nbBytes
=lseek(tf
->fd
,(off_t
)((whichBlock
-1)*tf
->block_size
), SEEK_SET
);
1234 if(unlikely(nbBytes
== -1)) return EINVAL
;
1236 if(unlikely(readFile(tf
->fd
,tf
->buffer
,tf
->block_size
,"Unable to read a block")))
1239 tf
->a_block_start
=(BlockStart
*) (tf
->buffer
+ EVENT_HEADER_SIZE
);
1240 lostSize
= *(guint32
*)(tf
->buffer
+ tf
->block_size
- sizeof(guint32
));
1241 tf
->a_block_end
=(BlockEnd
*)(tf
->buffer
+ tf
->block_size
1242 - sizeof(guint32
) - lostSize
- sizeof(BlockEnd
));
1243 tf
->last_event_pos
= tf
->buffer
+ tf
->block_size
-
1244 sizeof(guint32
) - lostSize
1245 - sizeof(BlockEnd
) - EVENT_HEADER_SIZE
;
1247 tf
->which_block
= whichBlock
;
1248 tf
->which_event
= 1;
1249 tf
->cur_event_pos
= tf
->buffer
;//the beginning of the block, block start ev
1250 tf
->cur_heart_beat_number
= 0;
1251 tf
->last_heartbeat
= NULL
;
1253 /* read the whole block to precalculate total of cycles in it */
1255 tf
->pre_cycle_count
= 0;
1256 tf
->cur_cycle_count
= ltt_get_uint32(tf
->trace
->reverse_byte_order
, tf
->cur_event_pos
+ EVENT_ID_SIZE
);
1258 getCyclePerNsec(tf
);
1262 (ltt_get_uint64(tf
->trace
->reverse_byte_order
,
1263 &tf
->a_block_start
->cycle_count
)&0xFFFFFFFF))
1264 * tf
->nsec_per_cycle
);
1266 tf
->current_event_time
= getEventTime(tf
);
1271 /*****************************************************************************
1273 * updateTracefile : reinitialize the info of the block which is already
1277 ****************************************************************************/
1279 void updateTracefile(LttTracefile
* tf
)
1281 tf
->which_event
= 1;
1282 tf
->cur_event_pos
= tf
->buffer
;
1283 tf
->current_event_time
= getEventTime(tf
);
1284 tf
->cur_heart_beat_number
= 0;
1286 tf
->prev_event_time
.tv_sec
= 0;
1287 tf
->prev_event_time
.tv_nsec
= 0;
1291 (-((double)ltt_get_uint64(tf
->trace
->reverse_byte_order
,
1292 &tf
->a_block_start
->cycle_count
))
1293 * tf
->nsec_per_cycle
);
1297 /*****************************************************************************
1299 * skipEvent : go to the next event, update the fields of the current event
1304 * ERANGE : event id is out of range
1305 ****************************************************************************/
1307 int skipEvent(LttTracefile
* t
)
1314 evId
= ltt_get_uint16(t
->trace
->reverse_byte_order
, t
->cur_event_pos
);
1315 evData
= t
->cur_event_pos
+ EVENT_HEADER_SIZE
;
1317 evT
= ltt_trace_eventtype_get(t
->trace
,(unsigned)evId
);
1319 if(likely(evT
)) rootFld
= evT
->root_field
;
1322 if(likely(rootFld
)){
1323 //event has string/sequence or the last event is not the same event
1324 if(likely((evT
->latest_block
!=t
->which_block
|| evT
->latest_event
!=t
->which_event
)
1325 && rootFld
->field_fixed
== 0)){
1326 setFieldsOffset(t
, evT
, evData
, t
->trace
);
1328 t
->cur_event_pos
+= EVENT_HEADER_SIZE
+ rootFld
->field_size
;
1329 }else t
->cur_event_pos
+= EVENT_HEADER_SIZE
;
1331 evT
->latest_block
= t
->which_block
;
1332 evT
->latest_event
= t
->which_event
;
1334 //the next event is in the next block
1335 if(unlikely(evId
== TRACE_BLOCK_END
)){
1336 t
->cur_event_pos
= t
->buffer
+ t
->block_size
;
1338 t
->cur_cycle_count
= ltt_get_uint32(t
->trace
->reverse_byte_order
,
1339 t
->cur_event_pos
+ EVENT_ID_SIZE
);
1341 t
->current_event_time
= getEventTime(t
);
1348 /*****************************************************************************
1350 * getCyclePerNsec : calculate cycles per nsec for current block
1351 * MD: should have tracefile_read the whole block, so we know the
1352 * total of cycles in it before being called.
1355 ****************************************************************************/
1357 void getCyclePerNsec(LttTracefile
* t
)
1359 LttTime lBufTotalTime
; /* Total time for this buffer */
1360 double lBufTotalNSec
; /* Total time for this buffer in nsecs */
1361 LttCycleCount lBufTotalCycle
;/* Total cycles for this buffer */
1363 /* Calculate the total time for this buffer */
1364 lBufTotalTime
= ltt_time_sub(
1365 ltt_get_time(t
->trace
->reverse_byte_order
, &t
->a_block_end
->time
),
1366 ltt_get_time(t
->trace
->reverse_byte_order
, &t
->a_block_start
->time
));
1368 /* Calculate the total cycles for this bufffer */
1369 lBufTotalCycle
= ltt_get_uint64(t
->trace
->reverse_byte_order
,
1370 &t
->a_block_end
->cycle_count
);
1371 lBufTotalCycle
-= ltt_get_uint64(t
->trace
->reverse_byte_order
,
1372 &t
->a_block_start
->cycle_count
);
1374 /* Convert the total time to double */
1375 lBufTotalNSec
= ltt_time_to_double(lBufTotalTime
);
1377 t
->nsec_per_cycle
= (double)lBufTotalNSec
/ (double)lBufTotalCycle
;
1379 /* Pre-multiply one overflow (2^32 cycles) by nsec_per_cycle */
1380 t
->one_overflow_nsec
= t
->nsec_per_cycle
* (double)0x100000000ULL
;
1384 /****************************************************************************
1386 * getEventTime : obtain the time of an event
1387 * NOTE : this function _really_ is on critical path.
1391 * LttTime : the time of the event
1392 ****************************************************************************/
1394 static inline LttTime
getEventTime(LttTracefile
* tf
)
1397 LttCycleCount cycle_count
; // cycle count for the current event
1398 //LttCycleCount lEventTotalCycle; // Total cycles from start for event
1399 gint64 lEventNSec
; // Total nsecs from start for event
1400 LttTime lTimeOffset
; // Time offset in struct LttTime
1403 evId
= ltt_get_uint16(tf
->trace
->reverse_byte_order
,
1406 cycle_count
= ltt_get_uint32(tf
->trace
->reverse_byte_order
,
1407 tf
->cur_event_pos
+ EVENT_ID_SIZE
);
1409 gboolean comp_count
= cycle_count
< tf
->pre_cycle_count
;
1411 tf
->pre_cycle_count
= cycle_count
;
1413 if(unlikely(comp_count
)) {
1415 tf
->overflow_nsec
+= tf
->one_overflow_nsec
;
1416 tf
->count
++; //increment overflow count
1419 if(unlikely(evId
== TRACE_BLOCK_START
)) {
1421 } else if(unlikely(evId
== TRACE_BLOCK_END
)) {
1422 lEventNSec
= ((double)
1423 (ltt_get_uint64(tf
->trace
->reverse_byte_order
,
1424 &tf
->a_block_end
->cycle_count
)
1425 - ltt_get_uint64(tf
->trace
->reverse_byte_order
,
1426 &tf
->a_block_start
->cycle_count
))
1427 * tf
->nsec_per_cycle
);
1430 /* If you want to make heart beat a special case and use their own 64 bits
1431 * TSC, activate this.
1433 else if(unlikely(evId
== TRACE_TIME_HEARTBEAT
)) {
1435 tf
->last_heartbeat
= (TimeHeartbeat
*)(tf
->cur_event_pos
+EVENT_HEADER_SIZE
);
1436 lEventNSec
= ((double)(tf
->last_heartbeat
->cycle_count
1437 - tf
->a_block_start
->cycle_count
)
1438 * tf
->nsec_per_cycle
);
1442 lEventNSec
= (gint64
)((double)cycle_count
* tf
->nsec_per_cycle
)
1446 lTimeOffset
= ltt_time_from_uint64(lEventNSec
);
1448 time
= ltt_time_add(ltt_get_time(tf
->trace
->reverse_byte_order
,
1449 &tf
->a_block_start
->time
), lTimeOffset
);
1454 /*****************************************************************************
1456 * setFieldsOffset : set offset of the fields
1458 * tracefile : opened trace file
1459 * evT : the event type
1460 * evD : event data, it may be NULL
1461 ****************************************************************************/
1463 void setFieldsOffset(LttTracefile
*tf
,LttEventType
*evT
,void *evD
,LttTrace
* t
)
1465 LttField
* rootFld
= evT
->root_field
;
1466 // rootFld->base_address = evD;
1469 rootFld
->field_size
= getFieldtypeSize(tf
, evT
, 0,0,rootFld
, evD
,t
);
1472 /*****************************************************************************
1474 * getFieldtypeSize: get the size of the field type (primitive type)
1476 * tracefile : opened trace file
1478 * offsetRoot : offset from the root
1479 * offsetParent : offset from the parrent
1481 * evD : event data, it may be NULL
1483 * int : size of the field
1484 ****************************************************************************/
1486 static inline gint
getFieldtypeSize(LttTracefile
* t
,
1487 LttEventType
* evT
, gint offsetRoot
,
1488 gint offsetParent
, LttField
* fld
, void *evD
, LttTrace
*trace
)
1490 gint size
, size1
, element_number
, i
, offset1
, offset2
;
1491 LttType
* type
= fld
->field_type
;
1493 if(unlikely(t
&& evT
->latest_block
==t
->which_block
&&
1494 evT
->latest_event
==t
->which_event
)){
1495 size
= fld
->field_size
;
1496 goto end_getFieldtypeSize
;
1498 /* This likely has been tested with gcov : half of them.. */
1499 if(unlikely(fld
->field_fixed
== 1)){
1501 if(unlikely(fld
== evT
->root_field
)) {
1502 size
= fld
->field_size
;
1503 goto end_getFieldtypeSize
;
1507 /* From gcov profiling : half string, half struct, can we gain something
1508 * from that ? (Mathieu) */
1509 switch(type
->type_class
) {
1511 element_number
= (int) type
->element_number
;
1512 if(fld
->field_fixed
== -1){
1513 size
= getFieldtypeSize(t
, evT
, offsetRoot
,
1514 0,fld
->child
[0], NULL
, trace
);
1515 if(size
== 0){ //has string or sequence
1516 fld
->field_fixed
= 0;
1518 fld
->field_fixed
= 1;
1519 size
*= element_number
;
1521 }else if(fld
->field_fixed
== 0){// has string or sequence
1523 for(i
=0;i
<element_number
;i
++){
1524 size
+= getFieldtypeSize(t
, evT
, offsetRoot
+size
,size
,
1525 fld
->child
[0], evD
+size
, trace
);
1527 }else size
= fld
->field_size
;
1529 fld
->fixed_root
= (offsetRoot
==-1) ? 0 : 1;
1530 fld
->fixed_parent
= (offsetParent
==-1) ? 0 : 1;
1536 size1
= (int) ltt_type_size(trace
, type
);
1537 if(fld
->field_fixed
== -1){
1538 fld
->sequ_number_size
= size1
;
1539 fld
->field_fixed
= 0;
1540 size
= getFieldtypeSize(t
, evT
, offsetRoot
,
1541 0,fld
->child
[0], NULL
, trace
);
1542 fld
->element_size
= size
;
1544 element_number
= getIntNumber(t
->trace
->reverse_byte_order
,size1
,evD
);
1545 type
->element_number
= element_number
;
1546 if(fld
->element_size
> 0){
1547 size
= element_number
* fld
->element_size
;
1548 }else{//sequence has string or sequence
1550 for(i
=0;i
<element_number
;i
++){
1551 size
+= getFieldtypeSize(t
, evT
, offsetRoot
+size
+size1
,size
+size1
,
1552 fld
->child
[0], evD
+size
+size1
, trace
);
1558 fld
->fixed_root
= (offsetRoot
==-1) ? 0 : 1;
1559 fld
->fixed_parent
= (offsetParent
==-1) ? 0 : 1;
1566 if(fld
->field_fixed
== -1){
1567 fld
->field_fixed
= 0;
1569 /* Hope my implementation is faster than strlen (Mathieu) */
1570 char *ptr
=(char*)evD
;
1572 /* from gcov : many many strings are empty, make it the common case.*/
1573 while(unlikely(*ptr
!= '\0')) { size
++; ptr
++; }
1574 //size = ptr - (char*)evD + 1; //include end : '\0'
1576 fld
->fixed_root
= (offsetRoot
==-1) ? 0 : 1;
1577 fld
->fixed_parent
= (offsetParent
==-1) ? 0 : 1;
1582 element_number
= (int) type
->element_number
;
1584 /* tested with gcov */
1585 if(unlikely(fld
->field_fixed
== -1)){
1586 offset1
= offsetRoot
;
1588 for(i
=0;i
<element_number
;i
++){
1589 size1
=getFieldtypeSize(t
, evT
,offset1
,offset2
,
1590 fld
->child
[i
], NULL
, trace
);
1591 if(likely(size1
> 0 && size
>= 0)){
1593 if(likely(offset1
>= 0)) offset1
+= size1
;
1601 if(unlikely(size
== -1)){
1602 fld
->field_fixed
= 0;
1604 }else fld
->field_fixed
= 1;
1605 }else if(likely(fld
->field_fixed
== 0)){
1606 offset1
= offsetRoot
;
1608 for(i
=0;unlikely(i
<element_number
);i
++){
1609 size
=getFieldtypeSize(t
,evT
,offset1
,offset2
,
1610 fld
->child
[i
],evD
+offset2
, trace
);
1615 }else size
= fld
->field_size
;
1616 fld
->fixed_root
= (offsetRoot
==-1) ? 0 : 1;
1617 fld
->fixed_parent
= (offsetParent
==-1) ? 0 : 1;
1621 if(unlikely(fld
->field_fixed
== -1)){
1622 size
= (int) ltt_type_size(trace
, type
);
1623 fld
->field_fixed
= 1;
1624 }else size
= fld
->field_size
;
1626 fld
->fixed_root
= (offsetRoot
==-1) ? 0 : 1;
1627 fld
->fixed_parent
= (offsetParent
==-1) ? 0 : 1;
1633 fld
->offset_root
= offsetRoot
;
1634 fld
->offset_parent
= offsetParent
;
1635 fld
->field_size
= size
;
1637 end_getFieldtypeSize
:
1643 /*****************************************************************************
1645 * getIntNumber : get an integer number
1647 * size : the size of the integer
1648 * evD : the event data
1650 * gint64 : a 64 bits integer
1651 ****************************************************************************/
1653 gint64
getIntNumber(gboolean reverse_byte_order
, int size
, void *evD
)
1658 case 1: i
= *((gint8
*)evD
); break;
1659 case 2: i
= ltt_get_int16(reverse_byte_order
, evD
); break;
1660 case 4: i
= ltt_get_int32(reverse_byte_order
, evD
); break;
1661 case 8: i
= ltt_get_int64(reverse_byte_order
, evD
); break;
1662 default: i
= ltt_get_int64(reverse_byte_order
, evD
);
1663 g_critical("getIntNumber : integer size %d unknown", size
);
1670 /*****************************************************************************
1672 * getDataEndianType : get the data type size and endian type of the local
1675 * size : size of data type
1676 * endian : endian type, little or big
1677 ****************************************************************************/
1679 void getDataEndianType(LttArchSize
* size
, LttArchEndian
* endian
)
1683 int sizeInt
=sizeof(int), sizeLong
=sizeof(long), sizePointer
=sizeof(void *);
1685 if(c
== 1) *endian
= LTT_LITTLE_ENDIAN
;
1686 else *endian
= LTT_BIG_ENDIAN
;
1688 if(sizeInt
== 2 && sizeLong
== 4 && sizePointer
== 4)
1690 else if(sizeInt
== 4 && sizeLong
== 4 && sizePointer
== 4)
1692 else if(sizeInt
== 4 && sizeLong
== 8 && sizePointer
== 8)
1694 else if(sizeInt
== 8 && sizeLong
== 8 && sizePointer
== 8)
1696 else *size
= LTT_UNKNOWN
;
1699 /* get the node name of the system */
1701 char * ltt_trace_system_description_node_name (LttSystemDescription
* s
)
1703 return s
->node_name
;
1707 /* get the domain name of the system */
1709 char * ltt_trace_system_description_domain_name (LttSystemDescription
* s
)
1711 return s
->domain_name
;
1715 /* get the description of the system */
1717 char * ltt_trace_system_description_description (LttSystemDescription
* s
)
1719 return s
->description
;
1723 /* get the start time of the trace */
1725 LttTime
ltt_trace_system_description_trace_start_time(LttSystemDescription
*s
)
1727 return s
->trace_start
;
1731 LttTracefile
*ltt_tracefile_new()
1733 return g_new(LttTracefile
, 1);
1736 void ltt_tracefile_destroy(LttTracefile
*tf
)
1741 void ltt_tracefile_copy(LttTracefile
*dest
, const LttTracefile
*src
)