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,
28 #include <sys/types.h>
41 #include "ltt-private.h"
42 #include <ltt/trace.h>
43 #include <ltt/facility.h>
44 #include <ltt/event.h>
46 #include <ltt/ltt-types.h>
53 #define DIR_NAME_SIZE 256
54 #define __UNUSED__ __attribute__((__unused__))
56 #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
57 #define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format)
61 /* obtain the time of an event */
63 static inline LttTime
getEventTime(LttTracefile
* tf
);
66 /* set the offset of the fields belonging to the event,
67 need the information of the archecture */
68 void setFieldsOffset(LttTracefile
*tf
,LttEventType
*evT
,void *evD
,LttTrace
*t
);
70 /* get the size of the field type according to the archtecture's
71 size and endian type(info of the archecture) */
72 static inline gint
getFieldtypeSize(LttTracefile
* tf
,
73 LttEventType
* evT
, gint offsetRoot
,
74 gint offsetParent
, LttField
*fld
, void *evD
, LttTrace
* t
);
76 /* read a fixed size or a block information from the file (fd) */
77 int readFile(int fd
, void * buf
, size_t size
, gchar
* mesg
);
78 int readBlock(LttTracefile
* tf
, int whichBlock
);
80 /* calculate cycles per nsec for current block */
81 void getCyclePerNsec(LttTracefile
* t
);
83 /* reinitialize the info of the block which is already in the buffer */
84 void updateTracefile(LttTracefile
* tf
);
86 /* go to the next event */
87 int skipEvent(LttTracefile
* t
);
90 /* Functions to parse system.xml file (using glib xml parser) */
91 static void parser_start_element (GMarkupParseContext __UNUSED__
*context
,
92 const gchar
*element_name
,
93 const gchar
**attribute_names
,
94 const gchar
**attribute_values
,
99 LttSystemDescription
* des
= (LttSystemDescription
* )user_data
;
100 if(strcmp("system", element_name
)){
101 *error
= g_error_new(G_MARKUP_ERROR
,
103 "This is not system.xml file");
107 while(attribute_names
[i
]){
108 if(strcmp("node_name", attribute_names
[i
])==0){
109 des
->node_name
= g_strdup(attribute_values
[i
]);
110 }else if(strcmp("domainname", attribute_names
[i
])==0){
111 des
->domain_name
= g_strdup(attribute_values
[i
]);
112 }else if(strcmp("cpu", attribute_names
[i
])==0){
113 des
->nb_cpu
= atoi(attribute_values
[i
]);
114 }else if(strcmp("arch_size", attribute_names
[i
])==0){
115 if(strcmp(attribute_values
[i
],"LP32") == 0) des
->size
= LTT_LP32
;
116 else if(strcmp(attribute_values
[i
],"ILP32") == 0) des
->size
= LTT_ILP32
;
117 else if(strcmp(attribute_values
[i
],"LP64") == 0) des
->size
= LTT_LP64
;
118 else if(strcmp(attribute_values
[i
],"ILP64") == 0) des
->size
= LTT_ILP64
;
119 else if(strcmp(attribute_values
[i
],"UNKNOWN") == 0) des
->size
= LTT_UNKNOWN
;
120 }else if(strcmp("endian", attribute_names
[i
])==0){
121 if(strcmp(attribute_values
[i
],"LITTLE_ENDIAN") == 0)
122 des
->endian
= LTT_LITTLE_ENDIAN
;
123 else if(strcmp(attribute_values
[i
],"BIG_ENDIAN") == 0)
124 des
->endian
= LTT_BIG_ENDIAN
;
125 }else if(strcmp("kernel_name", attribute_names
[i
])==0){
126 des
->kernel_name
= g_strdup(attribute_values
[i
]);
127 }else if(strcmp("kernel_release", attribute_names
[i
])==0){
128 des
->kernel_release
= g_strdup(attribute_values
[i
]);
129 }else if(strcmp("kernel_version", attribute_names
[i
])==0){
130 des
->kernel_version
= g_strdup(attribute_values
[i
]);
131 }else if(strcmp("machine", attribute_names
[i
])==0){
132 des
->machine
= g_strdup(attribute_values
[i
]);
133 }else if(strcmp("processor", attribute_names
[i
])==0){
134 des
->processor
= g_strdup(attribute_values
[i
]);
135 }else if(strcmp("hardware_platform", attribute_names
[i
])==0){
136 des
->hardware_platform
= g_strdup(attribute_values
[i
]);
137 }else if(strcmp("operating_system", attribute_names
[i
])==0){
138 des
->operating_system
= g_strdup(attribute_values
[i
]);
139 }else if(strcmp("ltt_major_version", attribute_names
[i
])==0){
140 des
->ltt_major_version
= atoi(attribute_values
[i
]);
141 }else if(strcmp("ltt_minor_version", attribute_names
[i
])==0){
142 des
->ltt_minor_version
= atoi(attribute_values
[i
]);
143 }else if(strcmp("ltt_block_size", attribute_names
[i
])==0){
144 des
->ltt_block_size
= atoi(attribute_values
[i
]);
146 *error
= g_error_new(G_MARKUP_ERROR
,
148 "Not a valid attribute");
155 static void parser_characters (GMarkupParseContext __UNUSED__
*context
,
157 gsize __UNUSED__ text_len
,
159 GError __UNUSED__
**error
)
161 LttSystemDescription
* des
= (LttSystemDescription
* )user_data
;
162 des
->description
= g_strdup(text
);
166 /*****************************************************************************
168 * ltt_tracefile_open : open a trace file, construct a LttTracefile
170 * t : the trace containing the tracefile
171 * fileName : path name of the trace file
173 * : a pointer to a tracefile
174 ****************************************************************************/
176 LttTracefile
* ltt_tracefile_open(LttTrace
* t
, gchar
* fileName
)
179 struct stat lTDFStat
; /* Trace data file status */
181 tf
= g_new(LttTracefile
, 1);
184 tf
->name
= g_strdup(fileName
);
186 tf
->fd
= g_open(fileName
, O_RDONLY
, 0);
188 g_warning("Unable to open input data file %s\n", fileName
);
194 // Get the file's status
195 if(fstat(tf
->fd
, &lTDFStat
) < 0){
196 g_warning("Unable to get the status of the input data file %s\n", fileName
);
203 // Is the file large enough to contain a trace
204 if(lTDFStat
.st_size
< (off_t
)(sizeof(BlockStart
) + EVENT_HEADER_SIZE
)){
205 g_print("The input data file %s does not contain a trace\n", fileName
);
212 //store the size of the file
213 tf
->file_size
= lTDFStat
.st_size
;
214 tf
->block_size
= t
->system_description
->ltt_block_size
;
215 tf
->block_number
= tf
->file_size
/ tf
->block_size
;
218 //allocate memory to contain the info of a block
219 tf
->buffer
= (void *) g_new(gchar
, t
->system_description
->ltt_block_size
);
221 //read the first block
222 if(readBlock(tf
,1)) exit(1);
228 /*****************************************************************************
229 *Open control and per cpu tracefiles
230 ****************************************************************************/
232 void ltt_tracefile_open_cpu(LttTrace
*t
, gchar
* tracefile_name
)
235 tf
= ltt_tracefile_open(t
,tracefile_name
);
237 t
->per_cpu_tracefile_number
++;
238 g_ptr_array_add(t
->per_cpu_tracefiles
, tf
);
241 gint
ltt_tracefile_open_control(LttTrace
*t
, gchar
* control_name
)
250 tf
= ltt_tracefile_open(t
,control_name
);
252 g_warning("ltt_tracefile_open_control : bad file descriptor");
255 t
->control_tracefile_number
++;
256 g_ptr_array_add(t
->control_tracefiles
,tf
);
258 //parse facilities tracefile to get base_id
259 if(strcmp(&control_name
[strlen(control_name
)-10],"facilities") ==0){
261 if(!ltt_tracefile_read(tf
,&ev
)) return 0; // end of file
263 if(ev
.event_id
== TRACE_FACILITY_LOAD
){
265 fLoad
.name
= (gchar
*)pos
;
266 fLoad
.checksum
= *(LttChecksum
*)(pos
+ strlen(fLoad
.name
));
267 fLoad
.base_code
= *(guint32
*)(pos
+ strlen(fLoad
.name
) + sizeof(LttChecksum
));
269 for(i
=0;i
<t
->facility_number
;i
++){
270 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
,i
);
271 if(strcmp(f
->name
,fLoad
.name
)==0 && fLoad
.checksum
==f
->checksum
){
272 f
->base_id
= fLoad
.base_code
;
276 if(i
==t
->facility_number
) {
277 g_warning("Facility: %s, checksum: %u is not found",
278 fLoad
.name
,(unsigned int)fLoad
.checksum
);
281 }else if(ev
.event_id
== TRACE_BLOCK_START
){
283 }else if(ev
.event_id
== TRACE_BLOCK_END
){
286 g_warning("Not valid facilities trace file");
294 /*****************************************************************************
296 * ltt_tracefile_close: close a trace file,
298 * t : tracefile which will be closed
299 ****************************************************************************/
301 void ltt_tracefile_close(LttTracefile
*t
)
310 /*****************************************************************************
311 *Get system information
312 ****************************************************************************/
313 gint
getSystemInfo(LttSystemDescription
* des
, gchar
* pathname
)
320 GMarkupParseContext
* context
;
321 GError
* error
= NULL
;
322 GMarkupParser markup_parser
=
324 parser_start_element
,
327 NULL
, /* passthrough */
331 fd
= g_open(pathname
, O_RDONLY
, 0);
333 g_warning("Can not open file : %s\n", pathname
);
337 iochan
= g_io_channel_unix_new(fd
);
339 context
= g_markup_parse_context_new(&markup_parser
, 0, des
,NULL
);
341 //while(fgets(buf,DIR_NAME_SIZE, fp) != NULL){
342 while(g_io_channel_read_line(iochan
, &buf
, &length
, NULL
, &error
)
343 != G_IO_STATUS_EOF
) {
346 g_warning("Can not read xml file: \n%s\n", error
->message
);
349 if(!g_markup_parse_context_parse(context
, buf
, length
, &error
)){
351 g_warning("Can not parse xml file: \n%s\n", error
->message
);
354 g_markup_parse_context_free(context
);
356 g_io_channel_shutdown(iochan
, FALSE
, &error
); /* No flush */
358 g_warning("Can not close file: \n%s\n", error
->message
);
366 g_markup_parse_context_free(context
);
368 g_io_channel_shutdown(iochan
, FALSE
, &error
); /* No flush */
370 g_warning("Can not close file: \n%s\n", error
->message
);
380 /*****************************************************************************
381 *The following functions get facility/tracefile information
382 ****************************************************************************/
384 gint
getFacilityInfo(LttTrace
*t
, gchar
* eventdefs
)
391 gchar fullname
[DIR_NAME_SIZE
];
392 GError
* error
= NULL
;
394 dir
= g_dir_open(eventdefs
, 0, &error
);
397 g_warning("Can not open directory: %s, %s\n", eventdefs
, error
->message
);
402 while((name
= g_dir_read_name(dir
)) != NULL
){
403 if(!g_pattern_match_simple("*.xml", name
)) continue;
404 strcpy(fullname
,eventdefs
);
405 strcat(fullname
,name
);
406 ltt_facility_open(t
,fullname
);
410 for(j
=0;j
<t
->facility_number
;j
++){
411 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
, j
);
412 for(i
=0; i
<f
->event_number
; i
++){
414 setFieldsOffset(NULL
, et
, NULL
, t
);
420 gint
getControlFileInfo(LttTrace
*t
, gchar
* control
)
424 gchar fullname
[DIR_NAME_SIZE
];
425 GError
* error
= NULL
;
427 dir
= g_dir_open(control
, 0, &error
);
430 g_warning("Can not open directory: %s, %s\n", control
, error
->message
);
435 while((name
= g_dir_read_name(dir
)) != NULL
){
436 if(strcmp(name
,"facilities") != 0 &&
437 strcmp(name
,"interrupts") != 0 &&
438 strcmp(name
,"processes") != 0) continue;
440 strcpy(fullname
,control
);
441 strcat(fullname
,name
);
442 if(ltt_tracefile_open_control(t
,fullname
)) {
451 gint
getCpuFileInfo(LttTrace
*t
, char* cpu
)
455 gchar fullname
[DIR_NAME_SIZE
];
456 GError
* error
= NULL
;
458 dir
= g_dir_open(cpu
, 0, &error
);
461 g_warning("Can not open directory: %s, %s\n", cpu
, error
->message
);
466 while((name
= g_dir_read_name(dir
)) != NULL
){
467 if(strcmp(name
,".svn") != 0){ /* . and .. already excluded */
468 strcpy(fullname
,cpu
);
469 strcat(fullname
,name
);
470 ltt_tracefile_open_cpu(t
,fullname
);
477 /*****************************************************************************
478 *A trace is specified as a pathname to the directory containing all the
479 *associated data (control tracefiles, per cpu tracefiles, event
482 *When a trace is closed, all the associated facilities, types and fields
483 *are released as well.
487 /****************************************************************************
488 * get_absolute_pathname
490 * return the unique pathname in the system
492 * MD : Fixed this function so it uses realpath, dealing well with
493 * forgotten cases (.. were not used correctly before).
495 ****************************************************************************/
496 void get_absolute_pathname(const gchar
*pathname
, gchar
* abs_pathname
)
498 abs_pathname
[0] = '\0';
500 if ( realpath (pathname
, abs_pathname
) != NULL
)
504 /* error, return the original path unmodified */
505 strcpy(abs_pathname
, pathname
);
511 LttTrace
*ltt_trace_open(const gchar
*pathname
)
514 LttSystemDescription
* sys_description
;
515 gchar eventdefs
[DIR_NAME_SIZE
];
516 gchar info
[DIR_NAME_SIZE
];
517 gchar control
[DIR_NAME_SIZE
];
518 gchar cpu
[DIR_NAME_SIZE
];
519 gchar tmp
[DIR_NAME_SIZE
];
520 gchar abs_path
[DIR_NAME_SIZE
];
521 gboolean has_slash
= FALSE
;
523 get_absolute_pathname(pathname
, abs_path
);
524 //establish the pathname to different directories
525 if(abs_path
[strlen(abs_path
)-1] == '/')has_slash
= TRUE
;
526 strcpy(eventdefs
,abs_path
);
527 if(!has_slash
)strcat(eventdefs
,"/");
528 strcat(eventdefs
,"eventdefs/");
530 strcpy(info
,abs_path
);
531 if(!has_slash
)strcat(info
,"/");
532 strcat(info
,"info/");
534 strcpy(control
,abs_path
);
535 if(!has_slash
)strcat(control
,"/");
536 strcat(control
,"control/");
538 strcpy(cpu
,abs_path
);
539 if(!has_slash
)strcat(cpu
,"/");
543 sys_description
= g_new(LttSystemDescription
, 1);
544 t
= g_new(LttTrace
, 1);
545 t
->pathname
= g_strdup(abs_path
);
546 t
->facility_number
= 0;
547 t
->control_tracefile_number
= 0;
548 t
->per_cpu_tracefile_number
= 0;
549 t
->system_description
= sys_description
;
550 t
->control_tracefiles
= g_ptr_array_new();
551 t
->per_cpu_tracefiles
= g_ptr_array_new();
552 t
->facilities
= g_ptr_array_new();
553 //getDataEndianType(&(t->my_arch_size), &(t->my_arch_endian));
555 //get system description
557 strcat(tmp
,"system.xml");
558 if(getSystemInfo(sys_description
, tmp
)) {
559 g_ptr_array_free(t
->facilities
, TRUE
);
560 g_ptr_array_free(t
->per_cpu_tracefiles
, TRUE
);
561 g_ptr_array_free(t
->control_tracefiles
, TRUE
);
562 g_free(sys_description
);
568 /* Set the reverse byte order between trace and reader */
569 if(sys_description
->endian
== LTT_LITTLE_ENDIAN
570 && G_BYTE_ORDER
!= G_LITTLE_ENDIAN
) {
571 t
->reverse_byte_order
= 1;
572 } else if(sys_description
->endian
== LTT_BIG_ENDIAN
573 && G_BYTE_ORDER
!= G_BIG_ENDIAN
) {
574 t
->reverse_byte_order
= 1;
575 } else t
->reverse_byte_order
= 0;
577 //get facilities info
578 if(getFacilityInfo(t
,eventdefs
)) {
579 g_ptr_array_free(t
->facilities
, TRUE
);
580 g_ptr_array_free(t
->per_cpu_tracefiles
, TRUE
);
581 g_ptr_array_free(t
->control_tracefiles
, TRUE
);
582 g_free(sys_description
);
588 //get control tracefile info
589 getControlFileInfo(t
,control
);
591 if(getControlFileInfo(t,control)) {
592 g_ptr_array_free(t->facilities, TRUE);
593 g_ptr_array_free(t->per_cpu_tracefiles, TRUE);
594 g_ptr_array_free(t->control_tracefiles, TRUE);
595 g_free(sys_description);
599 }*/ // With fatal error
601 //get cpu tracefile info
602 if(getCpuFileInfo(t
,cpu
)) {
603 g_ptr_array_free(t
->facilities
, TRUE
);
604 g_ptr_array_free(t
->per_cpu_tracefiles
, TRUE
);
605 g_ptr_array_free(t
->control_tracefiles
, TRUE
);
606 g_free(sys_description
);
615 char * ltt_trace_name(LttTrace
*t
)
621 /******************************************************************************
622 * When we copy a trace, we want all the opening actions to happen again :
623 * the trace will be reopened and totally independant from the original.
624 * That's why we call ltt_trace_open.
625 *****************************************************************************/
626 LttTrace
*ltt_trace_copy(LttTrace
*self
)
628 return ltt_trace_open(self
->pathname
);
631 void ltt_trace_close(LttTrace
*t
)
639 //free system_description
640 g_free(t
->system_description
->description
);
641 g_free(t
->system_description
->node_name
);
642 g_free(t
->system_description
->domain_name
);
643 g_free(t
->system_description
->kernel_name
);
644 g_free(t
->system_description
->kernel_release
);
645 g_free(t
->system_description
->kernel_version
);
646 g_free(t
->system_description
->machine
);
647 g_free(t
->system_description
->processor
);
648 g_free(t
->system_description
->hardware_platform
);
649 g_free(t
->system_description
->operating_system
);
650 g_free(t
->system_description
);
652 //free control_tracefiles
653 for(i
=0;i
<t
->control_tracefile_number
;i
++){
654 tf
= (LttTracefile
*)g_ptr_array_index(t
->control_tracefiles
,i
);
655 ltt_tracefile_close(tf
);
657 g_ptr_array_free(t
->control_tracefiles
, TRUE
);
659 //free per_cpu_tracefiles
660 for(i
=0;i
<t
->per_cpu_tracefile_number
;i
++){
661 tf
= (LttTracefile
*)g_ptr_array_index(t
->per_cpu_tracefiles
,i
);
662 ltt_tracefile_close(tf
);
664 g_ptr_array_free(t
->per_cpu_tracefiles
, TRUE
);
667 for(i
=0;i
<t
->facility_number
;i
++){
668 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
,i
);
669 ltt_facility_close(f
);
671 g_ptr_array_free(t
->facilities
, TRUE
);
679 /*****************************************************************************
680 *Get the system description of the trace
681 ****************************************************************************/
683 LttSystemDescription
*ltt_trace_system_description(LttTrace
*t
)
685 return t
->system_description
;
688 /*****************************************************************************
689 * The following functions discover the facilities of the trace
690 ****************************************************************************/
692 unsigned ltt_trace_facility_number(LttTrace
*t
)
694 return (unsigned)(t
->facility_number
);
697 LttFacility
*ltt_trace_facility_get(LttTrace
*t
, unsigned i
)
699 return (LttFacility
*)g_ptr_array_index(t
->facilities
, i
);
702 /*****************************************************************************
704 * ltt_trace_facility_find : find facilities in the trace
707 * name : facility name
709 * position : position of the facility in the trace
711 * : the number of facilities
712 ****************************************************************************/
714 unsigned ltt_trace_facility_find(LttTrace
*t
, char *name
, unsigned *position
)
716 unsigned int i
, count
=0;
718 for(i
=0;i
<t
->facility_number
;i
++){
719 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
, i
);
720 if(strcmp(f
->name
,name
)==0){
722 if(count
==1) *position
= i
;
730 /*****************************************************************************
731 * Functions to discover all the event types in the trace
732 ****************************************************************************/
734 unsigned ltt_trace_eventtype_number(LttTrace
*t
)
738 unsigned int num
= t
->facility_number
;
742 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
, i
);
743 count
+= f
->event_number
;
748 /* FIXME : performances could be improved with a better design for this
749 * function : sequential search through a container has never been the
750 * best on the critical path. */
751 LttFacility
* ltt_trace_facility_by_id(LttTrace
* trace
, unsigned id
)
753 LttFacility
* facility
= NULL
;
755 unsigned int num
= trace
->facility_number
;
756 GPtrArray
*facilities
= trace
->facilities
;
758 for(i
=0;unlikely(i
<num
);){
759 LttFacility
*iter_facility
=
760 (LttFacility
*) g_ptr_array_index(facilities
,i
);
761 unsigned base_id
= iter_facility
->base_id
;
763 if(likely(id
>= base_id
&&
764 id
< base_id
+ iter_facility
->event_number
)) {
765 facility
= iter_facility
;
775 LttEventType
*ltt_trace_eventtype_get(LttTrace
*t
, unsigned evId
)
777 LttEventType
*event_type
;
780 f
= ltt_trace_facility_by_id(t
,evId
);
782 if(unlikely(!f
)) event_type
= NULL
;
783 else event_type
= f
->events
[evId
- f
->base_id
];
788 /*****************************************************************************
789 *There is one "per cpu" tracefile for each CPU, numbered from 0 to
790 *the maximum number of CPU in the system. When the number of CPU installed
791 *is less than the maximum, some positions are unused. There are also a
792 *number of "control" tracefiles (facilities, interrupts...).
793 ****************************************************************************/
794 unsigned ltt_trace_control_tracefile_number(LttTrace
*t
)
796 return t
->control_tracefile_number
;
799 unsigned ltt_trace_per_cpu_tracefile_number(LttTrace
*t
)
801 return t
->per_cpu_tracefile_number
;
804 /*****************************************************************************
805 *It is possible to search for the tracefiles by name or by CPU position.
806 *The index within the tracefiles of the same type is returned if found
807 *and a negative value otherwise.
808 ****************************************************************************/
810 int ltt_trace_control_tracefile_find(LttTrace
*t
, const gchar
*name
)
812 LttTracefile
* tracefile
;
814 for(i
=0;i
<t
->control_tracefile_number
;i
++){
815 tracefile
= (LttTracefile
*)g_ptr_array_index(t
->control_tracefiles
, i
);
816 if(strcmp(tracefile
->name
, name
)==0)break;
818 if(i
== t
->control_tracefile_number
) return -1;
822 /* not really useful. We just have to know that cpu tracefiles
823 * comes before control tracefiles.
825 int ltt_trace_per_cpu_tracefile_find(LttTrace
*t
, const gchar
*name
)
827 LttTracefile
* tracefile
;
829 for(i
=0;i
<t
->per_cpu_tracefile_number
;i
++){
830 tracefile
= (LttTracefile
*)g_ptr_array_index(t
->per_cpu_tracefiles
, i
);
831 if(strcmp(tracefile
->name
, name
)==0)break;
833 if(i
== t
->per_cpu_tracefile_number
) return -1;
837 /*****************************************************************************
838 *Get a specific tracefile
839 ****************************************************************************/
841 LttTracefile
*ltt_trace_control_tracefile_get(LttTrace
*t
, unsigned i
)
843 return (LttTracefile
*)g_ptr_array_index(t
->control_tracefiles
, i
);
846 LttTracefile
*ltt_trace_per_cpu_tracefile_get(LttTrace
*t
, unsigned i
)
848 return (LttTracefile
*)g_ptr_array_index(t
->per_cpu_tracefiles
, i
);
851 /*****************************************************************************
852 * Get the start time and end time of the trace
853 ****************************************************************************/
855 void ltt_trace_time_span_get(LttTrace
*t
, LttTime
*start
, LttTime
*end
)
857 LttTime startSmall
, startTmp
, endBig
, endTmp
;
861 for(i
=0;i
<t
->control_tracefile_number
;i
++){
862 tf
= g_ptr_array_index(t
->control_tracefiles
, i
);
864 startTmp
= ltt_get_time(t
->reverse_byte_order
, &tf
->a_block_start
->time
);
865 readBlock(tf
,tf
->block_number
);
866 endTmp
= ltt_get_time(t
->reverse_byte_order
, &tf
->a_block_end
->time
);
868 startSmall
= startTmp
;
873 if(ltt_time_compare(startSmall
,startTmp
) > 0) startSmall
= startTmp
;
874 if(ltt_time_compare(endBig
,endTmp
) < 0) endBig
= endTmp
;
877 for(i
=0;i
<t
->per_cpu_tracefile_number
;i
++){
878 tf
= g_ptr_array_index(t
->per_cpu_tracefiles
, i
);
880 startTmp
= ltt_get_time(t
->reverse_byte_order
, &tf
->a_block_start
->time
);
881 readBlock(tf
,tf
->block_number
);
882 endTmp
= ltt_get_time(t
->reverse_byte_order
, &tf
->a_block_end
->time
);
884 startSmall
= startTmp
;
888 if(ltt_time_compare(startSmall
,startTmp
) > 0) startSmall
= startTmp
;
889 if(ltt_time_compare(endBig
,endTmp
) < 0) endBig
= endTmp
;
892 if(start
!= NULL
) *start
= startSmall
;
893 if(end
!= NULL
) *end
= endBig
;
897 /*****************************************************************************
898 *Get the name of a tracefile
899 ****************************************************************************/
901 char *ltt_tracefile_name(LttTracefile
*tf
)
906 /*****************************************************************************
907 * Get the number of blocks in the tracefile
908 ****************************************************************************/
910 unsigned ltt_tracefile_block_number(LttTracefile
*tf
)
912 return tf
->block_number
;
915 /*****************************************************************************
917 * ltt_tracefile_seek_time: seek to the first event of the trace with time
918 * larger or equal to time
921 * time : criteria of the time
922 ****************************************************************************/
923 void ltt_tracefile_find_time_block(LttTracefile
*t
, LttTime time
,
924 int start_block
, int end_block
)
926 int err
, tmp_block
, s
, e
;
930 err
=readBlock(t
,start_block
);
931 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
932 if(start_block
== end_block
)return;
934 tailTime
= ltt_time_compare(ltt_get_time(t
->trace
->reverse_byte_order
,
935 &t
->a_block_end
->time
), time
);
936 if(tailTime
>= 0) return;
938 err
=readBlock(t
,end_block
);
939 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
940 if(start_block
+1 == end_block
)return;
942 headTime
= ltt_time_compare(ltt_get_time(t
->trace
->reverse_byte_order
,
943 &t
->a_block_start
->time
), time
);
944 if(headTime
<= 0 ) return;
946 tmp_block
= (end_block
+ start_block
)/2;
947 err
=readBlock(t
,tmp_block
);
948 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
950 headTime
= ltt_time_compare(ltt_get_time(t
->trace
->reverse_byte_order
,
951 &t
->a_block_start
->time
), time
);
952 tailTime
= ltt_time_compare(ltt_get_time(t
->trace
->reverse_byte_order
,
953 &t
->a_block_end
->time
), time
);
954 if(headTime
<= 0 && tailTime
>= 0) return;
960 ltt_tracefile_find_time_block(t
, time
, s
, e
);
968 ltt_tracefile_find_time_block(t
, time
, s
, e
);
973 void ltt_tracefile_backward_find_time_block(LttTracefile
*t
, LttTime time
)
975 int t_time
, h_time
, err
;
976 err
=readBlock(t
,t
->which_block
-1);
977 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
978 h_time
= ltt_time_compare(ltt_get_time(t
->trace
->reverse_byte_order
,
979 &t
->a_block_start
->time
), time
);
980 t_time
= ltt_time_compare(ltt_get_time(t
->trace
->reverse_byte_order
,
981 &t
->a_block_end
->time
), time
);
984 if(t
->which_block
== 1) return;
985 err
=readBlock(t
,t
->which_block
-1);
986 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
987 tmp
= ltt_time_compare(ltt_get_time(t
->trace
->reverse_byte_order
,
988 &t
->a_block_end
->time
), time
);
989 if(tmp
== 0) return ltt_tracefile_seek_time(t
, time
);
990 err
=readBlock(t
,t
->which_block
+1);
991 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
992 }else if(h_time
> 0){
993 ltt_tracefile_find_time_block(t
, time
, 1, t
->which_block
);
994 return ltt_tracefile_seek_time(t
, time
) ;
996 if(t_time
>= 0) return ltt_tracefile_seek_time(t
, time
);
997 err
=readBlock(t
,t
->which_block
+1);
998 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
1002 void ltt_tracefile_seek_time(LttTracefile
*t
, LttTime time
)
1006 int headTime
= ltt_time_compare(ltt_get_time(t
->trace
->reverse_byte_order
,
1007 &t
->a_block_start
->time
), time
);
1008 int tailTime
= ltt_time_compare(ltt_get_time(t
->trace
->reverse_byte_order
,
1009 &t
->a_block_end
->time
), time
);
1012 if(headTime
< 0 && tailTime
> 0){
1013 if(ltt_time_compare(ltt_get_time(t
->trace
->reverse_byte_order
,
1014 &t
->a_block_end
->time
),
1015 t
->current_event_time
) !=0) {
1016 lttTime
= getEventTime(t
);
1017 err
= ltt_time_compare(lttTime
, time
);
1019 if(t
->which_event
==2 || ltt_time_compare(t
->prev_event_time
,time
)<0){
1023 return ltt_tracefile_seek_time(t
, time
);
1027 if(ltt_tracefile_read(t
,&ev
) == NULL
) {
1028 g_print("End of file\n");
1031 lttTime
= getEventTime(t
);
1032 err
= ltt_time_compare(lttTime
, time
);
1036 }else{//we are at the end of the block
1038 return ltt_tracefile_seek_time(t
, time
);
1040 }else if(headTime
>= 0){
1041 if(t
->which_block
== 1){
1044 if(ltt_time_compare(t
->prev_block_end_time
, time
) >= 0 ||
1045 (t
->prev_block_end_time
.tv_sec
== 0 &&
1046 t
->prev_block_end_time
.tv_nsec
== 0 )){
1047 ltt_tracefile_backward_find_time_block(t
, time
);
1052 }else if(tailTime
< 0){
1053 if(t
->which_block
!= t
->block_number
){
1054 ltt_tracefile_find_time_block(t
, time
, t
->which_block
+1, t
->block_number
);
1055 return ltt_tracefile_seek_time(t
, time
);
1057 t
->cur_event_pos
= t
->buffer
+ t
->block_size
;
1058 g_print("End of file\n");
1061 }else if(tailTime
== 0){
1062 t
->cur_event_pos
= t
->last_event_pos
;
1063 t
->current_event_time
= time
;
1064 t
->cur_heart_beat_number
= 0;
1065 t
->prev_event_time
.tv_sec
= 0;
1066 t
->prev_event_time
.tv_nsec
= 0;
1071 /*****************************************************************************
1072 * Seek to the first event with position equal or larger to ep
1074 * Modified by Mathieu Desnoyers to used faster offset position instead of
1075 * re-reading the whole buffer.
1076 ****************************************************************************/
1078 void ltt_tracefile_seek_position(LttTracefile
*t
, const LttEventPosition
*ep
)
1080 //if we are at the right place, just return
1081 if(likely(t
->which_block
== ep
->block_num
&& t
->which_event
== ep
->event_num
))
1084 if(likely(t
->which_block
== ep
->block_num
)) updateTracefile(t
);
1085 else readBlock(t
,ep
->block_num
);
1086 //event offset is available
1087 if(likely(ep
->old_position
)){
1090 t
->which_event
= ep
->event_num
;
1091 t
->cur_event_pos
= t
->buffer
+ ep
->event_offset
;
1092 t
->prev_event_time
= ep
->event_time
;
1093 t
->current_event_time
= ep
->event_time
;
1094 t
->cur_heart_beat_number
= ep
->heart_beat_number
;
1095 t
->cur_cycle_count
= ep
->event_cycle_count
;
1097 /* This is a workaround for fast position seek */
1098 t
->last_event_pos
= ep
->last_event_pos
;
1099 t
->prev_block_end_time
= ep
->prev_block_end_time
;
1100 t
->prev_event_time
= ep
->prev_event_time
;
1101 t
->pre_cycle_count
= ep
->pre_cycle_count
;
1102 t
->count
= ep
->count
;
1103 t
->overflow_nsec
= ep
->overflow_nsec
;
1104 t
->last_heartbeat
= ep
->last_heartbeat
;
1105 /* end of workaround */
1107 //update the fields of the current event and go to the next event
1109 if(unlikely(err
== ERANGE
)) g_error("event id is out of range\n");
1114 //only block number and event index are available
1115 //MD: warning : this is slow!
1116 g_warning("using slow O(n) tracefile seek position");
1119 while(likely(t
->which_event
< ep
->event_num
)) ltt_tracefile_read(t
, &event
);
1124 /*****************************************************************************
1126 * ltt_tracefile_read : read the current event, set the pointer to the next
1130 * LttEvent * : an event to be processed
1131 ****************************************************************************/
1133 LttEvent
*ltt_tracefile_read(LttTracefile
*t
, LttEvent
*event
)
1137 if(unlikely(t
->cur_event_pos
== t
->buffer
+ t
->block_size
)){
1138 if(unlikely(t
->which_block
== t
->block_number
)){
1141 err
= readBlock(t
, t
->which_block
+ 1);
1142 if(unlikely(err
))g_error("Can not read tracefile");
1145 event
->event_id
= ltt_get_uint16(t
->trace
->reverse_byte_order
, t
->cur_event_pos
);
1146 if(unlikely(event
->event_id
== TRACE_TIME_HEARTBEAT
))
1147 t
->cur_heart_beat_number
++;
1149 t
->prev_event_time
= t
->current_event_time
;
1150 // t->current_event_time = getEventTime(t);
1152 event
->time_delta
= ltt_get_uint32(t
->trace
->reverse_byte_order
, t
->cur_event_pos
+ EVENT_ID_SIZE
);
1153 event
->event_time
= t
->current_event_time
;
1154 event
->event_cycle_count
= t
->cur_cycle_count
;
1156 event
->tracefile
= t
;
1157 event
->data
= t
->cur_event_pos
+ EVENT_HEADER_SIZE
;
1158 event
->which_block
= t
->which_block
;
1159 event
->which_event
= t
->which_event
;
1161 /* This is a workaround for fast position seek */
1162 event
->last_event_pos
= t
->last_event_pos
;
1163 event
->prev_block_end_time
= t
->prev_block_end_time
;
1164 event
->prev_event_time
= t
->prev_event_time
;
1165 event
->pre_cycle_count
= t
->pre_cycle_count
;
1166 event
->count
= t
->count
;
1167 event
->overflow_nsec
= t
->overflow_nsec
;
1168 event
->last_heartbeat
= t
->last_heartbeat
;
1170 /* end of workaround */
1174 //update the fields of the current event and go to the next event
1176 if(unlikely(err
== ERANGE
)) g_error("event id is out of range\n");
1181 /****************************************************************************
1183 * readFile : wrap function to read from a file
1185 * fd : file descriptor
1186 * buf : buf to contain the content
1187 * size : number of bytes to be read
1188 * mesg : message to be printed if some thing goes wrong
1191 * EIO : can not read from the file
1192 ****************************************************************************/
1194 int readFile(int fd
, void * buf
, size_t size
, char * mesg
)
1196 ssize_t nbBytes
= read(fd
, buf
, size
);
1198 if((size_t)nbBytes
!= size
) {
1200 perror("Error in readFile : ");
1202 g_warning("%s",mesg
);
1210 /****************************************************************************
1212 * readBlock : read a block from the file
1214 * lttdes : ltt trace file
1215 * whichBlock : the block which will be read
1218 * EINVAL : lseek fail
1219 * EIO : can not read from the file
1220 ****************************************************************************/
1222 int readBlock(LttTracefile
* tf
, int whichBlock
)
1227 /* same block already opened requested */
1228 if((guint
)whichBlock
== tf
->which_block
) return 0;
1230 if(likely(whichBlock
- tf
->which_block
== 1 && tf
->which_block
!= 0)){
1231 tf
->prev_block_end_time
= ltt_get_time(tf
->trace
->reverse_byte_order
,
1232 &tf
->a_block_end
->time
);
1233 tf
->prev_event_time
= ltt_get_time(tf
->trace
->reverse_byte_order
,
1234 &tf
->a_block_end
->time
);
1236 tf
->prev_block_end_time
.tv_sec
= 0;
1237 tf
->prev_block_end_time
.tv_nsec
= 0;
1238 tf
->prev_event_time
.tv_sec
= 0;
1239 tf
->prev_event_time
.tv_nsec
= 0;
1242 nbBytes
=lseek(tf
->fd
,(off_t
)((whichBlock
-1)*tf
->block_size
), SEEK_SET
);
1243 if(unlikely(nbBytes
== -1)) return EINVAL
;
1245 if(unlikely(readFile(tf
->fd
,tf
->buffer
,tf
->block_size
,"Unable to read a block")))
1248 tf
->a_block_start
=(BlockStart
*) (tf
->buffer
+ EVENT_HEADER_SIZE
);
1249 lostSize
= *(guint32
*)(tf
->buffer
+ tf
->block_size
- sizeof(guint32
));
1250 tf
->a_block_end
=(BlockEnd
*)(tf
->buffer
+ tf
->block_size
1251 - sizeof(guint32
) - lostSize
- sizeof(BlockEnd
));
1252 tf
->last_event_pos
= tf
->buffer
+ tf
->block_size
-
1253 sizeof(guint32
) - lostSize
1254 - sizeof(BlockEnd
) - EVENT_HEADER_SIZE
;
1256 tf
->which_block
= whichBlock
;
1257 tf
->which_event
= 1;
1258 tf
->cur_event_pos
= tf
->buffer
;//the beginning of the block, block start ev
1259 tf
->cur_heart_beat_number
= 0;
1260 tf
->last_heartbeat
= NULL
;
1262 /* read the whole block to precalculate total of cycles in it */
1264 tf
->pre_cycle_count
= 0;
1265 tf
->cur_cycle_count
= ltt_get_uint32(tf
->trace
->reverse_byte_order
, tf
->cur_event_pos
+ EVENT_ID_SIZE
);
1267 getCyclePerNsec(tf
);
1271 (ltt_get_uint64(tf
->trace
->reverse_byte_order
,
1272 &tf
->a_block_start
->cycle_count
)&0xFFFFFFFF))
1273 * tf
->nsec_per_cycle
);
1275 tf
->current_event_time
= getEventTime(tf
);
1280 /*****************************************************************************
1282 * updateTracefile : reinitialize the info of the block which is already
1286 ****************************************************************************/
1288 void updateTracefile(LttTracefile
* tf
)
1290 tf
->which_event
= 1;
1291 tf
->cur_event_pos
= tf
->buffer
;
1292 tf
->current_event_time
= getEventTime(tf
);
1293 tf
->cur_heart_beat_number
= 0;
1295 tf
->prev_event_time
.tv_sec
= 0;
1296 tf
->prev_event_time
.tv_nsec
= 0;
1300 (-((double)ltt_get_uint64(tf
->trace
->reverse_byte_order
,
1301 &tf
->a_block_start
->cycle_count
))
1302 * tf
->nsec_per_cycle
);
1306 /*****************************************************************************
1308 * skipEvent : go to the next event, update the fields of the current event
1313 * ERANGE : event id is out of range
1314 ****************************************************************************/
1316 int skipEvent(LttTracefile
* t
)
1323 evId
= ltt_get_uint16(t
->trace
->reverse_byte_order
, t
->cur_event_pos
);
1324 evData
= t
->cur_event_pos
+ EVENT_HEADER_SIZE
;
1326 evT
= ltt_trace_eventtype_get(t
->trace
,(unsigned)evId
);
1328 if(likely(evT
)) rootFld
= evT
->root_field
;
1331 if(likely(rootFld
)){
1332 //event has string/sequence or the last event is not the same event
1333 if(likely((evT
->latest_block
!=t
->which_block
|| evT
->latest_event
!=t
->which_event
)
1334 && rootFld
->field_fixed
== 0)){
1335 setFieldsOffset(t
, evT
, evData
, t
->trace
);
1337 t
->cur_event_pos
+= EVENT_HEADER_SIZE
+ rootFld
->field_size
;
1338 }else t
->cur_event_pos
+= EVENT_HEADER_SIZE
;
1340 evT
->latest_block
= t
->which_block
;
1341 evT
->latest_event
= t
->which_event
;
1343 //the next event is in the next block
1344 if(unlikely(evId
== TRACE_BLOCK_END
)){
1345 t
->cur_event_pos
= t
->buffer
+ t
->block_size
;
1347 t
->cur_cycle_count
= ltt_get_uint32(t
->trace
->reverse_byte_order
,
1348 t
->cur_event_pos
+ EVENT_ID_SIZE
);
1350 t
->current_event_time
= getEventTime(t
);
1357 /*****************************************************************************
1359 * getCyclePerNsec : calculate cycles per nsec for current block
1360 * MD: should have tracefile_read the whole block, so we know the
1361 * total of cycles in it before being called.
1364 ****************************************************************************/
1366 void getCyclePerNsec(LttTracefile
* t
)
1368 LttTime lBufTotalTime
; /* Total time for this buffer */
1369 double lBufTotalNSec
; /* Total time for this buffer in nsecs */
1370 LttCycleCount lBufTotalCycle
;/* Total cycles for this buffer */
1372 /* Calculate the total time for this buffer */
1373 lBufTotalTime
= ltt_time_sub(
1374 ltt_get_time(t
->trace
->reverse_byte_order
, &t
->a_block_end
->time
),
1375 ltt_get_time(t
->trace
->reverse_byte_order
, &t
->a_block_start
->time
));
1377 /* Calculate the total cycles for this bufffer */
1378 lBufTotalCycle
= ltt_get_uint64(t
->trace
->reverse_byte_order
,
1379 &t
->a_block_end
->cycle_count
);
1380 lBufTotalCycle
-= ltt_get_uint64(t
->trace
->reverse_byte_order
,
1381 &t
->a_block_start
->cycle_count
);
1383 /* Convert the total time to double */
1384 lBufTotalNSec
= ltt_time_to_double(lBufTotalTime
);
1386 t
->nsec_per_cycle
= (double)lBufTotalNSec
/ (double)lBufTotalCycle
;
1388 /* Pre-multiply one overflow (2^32 cycles) by nsec_per_cycle */
1389 t
->one_overflow_nsec
= t
->nsec_per_cycle
* (double)0x100000000ULL
;
1393 /****************************************************************************
1395 * getEventTime : obtain the time of an event
1396 * NOTE : this function _really_ is on critical path.
1400 * LttTime : the time of the event
1401 ****************************************************************************/
1403 static inline LttTime
getEventTime(LttTracefile
* tf
)
1406 LttCycleCount cycle_count
; // cycle count for the current event
1407 //LttCycleCount lEventTotalCycle; // Total cycles from start for event
1408 gint64 lEventNSec
; // Total nsecs from start for event
1409 LttTime lTimeOffset
; // Time offset in struct LttTime
1412 evId
= ltt_get_uint16(tf
->trace
->reverse_byte_order
,
1415 cycle_count
= ltt_get_uint32(tf
->trace
->reverse_byte_order
,
1416 tf
->cur_event_pos
+ EVENT_ID_SIZE
);
1418 gboolean comp_count
= cycle_count
< tf
->pre_cycle_count
;
1420 tf
->pre_cycle_count
= cycle_count
;
1422 if(unlikely(comp_count
)) {
1424 tf
->overflow_nsec
+= tf
->one_overflow_nsec
;
1425 tf
->count
++; //increment overflow count
1428 if(unlikely(evId
== TRACE_BLOCK_START
)) {
1430 } else if(unlikely(evId
== TRACE_BLOCK_END
)) {
1431 lEventNSec
= ((double)
1432 (ltt_get_uint64(tf
->trace
->reverse_byte_order
,
1433 &tf
->a_block_end
->cycle_count
)
1434 - ltt_get_uint64(tf
->trace
->reverse_byte_order
,
1435 &tf
->a_block_start
->cycle_count
))
1436 * tf
->nsec_per_cycle
);
1439 /* If you want to make heart beat a special case and use their own 64 bits
1440 * TSC, activate this.
1442 else if(unlikely(evId
== TRACE_TIME_HEARTBEAT
)) {
1444 tf
->last_heartbeat
= (TimeHeartbeat
*)(tf
->cur_event_pos
+EVENT_HEADER_SIZE
);
1445 lEventNSec
= ((double)(tf
->last_heartbeat
->cycle_count
1446 - tf
->a_block_start
->cycle_count
)
1447 * tf
->nsec_per_cycle
);
1451 lEventNSec
= (gint64
)((double)cycle_count
* tf
->nsec_per_cycle
)
1455 lTimeOffset
= ltt_time_from_uint64(lEventNSec
);
1457 time
= ltt_time_add(ltt_get_time(tf
->trace
->reverse_byte_order
,
1458 &tf
->a_block_start
->time
), lTimeOffset
);
1463 /*****************************************************************************
1465 * setFieldsOffset : set offset of the fields
1467 * tracefile : opened trace file
1468 * evT : the event type
1469 * evD : event data, it may be NULL
1470 ****************************************************************************/
1472 void setFieldsOffset(LttTracefile
*tf
,LttEventType
*evT
,void *evD
,LttTrace
* t
)
1474 LttField
* rootFld
= evT
->root_field
;
1475 // rootFld->base_address = evD;
1478 rootFld
->field_size
= getFieldtypeSize(tf
, evT
, 0,0,rootFld
, evD
,t
);
1481 /*****************************************************************************
1483 * getFieldtypeSize: get the size of the field type (primitive type)
1485 * tracefile : opened trace file
1487 * offsetRoot : offset from the root
1488 * offsetParent : offset from the parrent
1490 * evD : event data, it may be NULL
1492 * int : size of the field
1493 ****************************************************************************/
1495 static inline gint
getFieldtypeSize(LttTracefile
* t
,
1496 LttEventType
* evT
, gint offsetRoot
,
1497 gint offsetParent
, LttField
* fld
, void *evD
, LttTrace
*trace
)
1499 gint size
, size1
, element_number
, i
, offset1
, offset2
;
1500 LttType
* type
= fld
->field_type
;
1502 if(unlikely(t
&& evT
->latest_block
==t
->which_block
&&
1503 evT
->latest_event
==t
->which_event
)){
1504 size
= fld
->field_size
;
1505 goto end_getFieldtypeSize
;
1507 /* This likely has been tested with gcov : half of them.. */
1508 if(unlikely(fld
->field_fixed
== 1)){
1510 if(unlikely(fld
== evT
->root_field
)) {
1511 size
= fld
->field_size
;
1512 goto end_getFieldtypeSize
;
1516 /* From gcov profiling : half string, half struct, can we gain something
1517 * from that ? (Mathieu) */
1518 switch(type
->type_class
) {
1520 element_number
= (int) type
->element_number
;
1521 if(fld
->field_fixed
== -1){
1522 size
= getFieldtypeSize(t
, evT
, offsetRoot
,
1523 0,fld
->child
[0], NULL
, trace
);
1524 if(size
== 0){ //has string or sequence
1525 fld
->field_fixed
= 0;
1527 fld
->field_fixed
= 1;
1528 size
*= element_number
;
1530 }else if(fld
->field_fixed
== 0){// has string or sequence
1532 for(i
=0;i
<element_number
;i
++){
1533 size
+= getFieldtypeSize(t
, evT
, offsetRoot
+size
,size
,
1534 fld
->child
[0], evD
+size
, trace
);
1536 }else size
= fld
->field_size
;
1538 fld
->fixed_root
= (offsetRoot
==-1) ? 0 : 1;
1539 fld
->fixed_parent
= (offsetParent
==-1) ? 0 : 1;
1545 size1
= (int) ltt_type_size(trace
, type
);
1546 if(fld
->field_fixed
== -1){
1547 fld
->sequ_number_size
= size1
;
1548 fld
->field_fixed
= 0;
1549 size
= getFieldtypeSize(t
, evT
, offsetRoot
,
1550 0,fld
->child
[0], NULL
, trace
);
1551 fld
->element_size
= size
;
1553 element_number
= getIntNumber(t
->trace
->reverse_byte_order
,size1
,evD
);
1554 type
->element_number
= element_number
;
1555 if(fld
->element_size
> 0){
1556 size
= element_number
* fld
->element_size
;
1557 }else{//sequence has string or sequence
1559 for(i
=0;i
<element_number
;i
++){
1560 size
+= getFieldtypeSize(t
, evT
, offsetRoot
+size
+size1
,size
+size1
,
1561 fld
->child
[0], evD
+size
+size1
, trace
);
1567 fld
->fixed_root
= (offsetRoot
==-1) ? 0 : 1;
1568 fld
->fixed_parent
= (offsetParent
==-1) ? 0 : 1;
1575 if(fld
->field_fixed
== -1){
1576 fld
->field_fixed
= 0;
1578 /* Hope my implementation is faster than strlen (Mathieu) */
1579 char *ptr
=(char*)evD
;
1581 /* from gcov : many many strings are empty, make it the common case.*/
1582 while(unlikely(*ptr
!= '\0')) { size
++; ptr
++; }
1583 //size = ptr - (char*)evD + 1; //include end : '\0'
1585 fld
->fixed_root
= (offsetRoot
==-1) ? 0 : 1;
1586 fld
->fixed_parent
= (offsetParent
==-1) ? 0 : 1;
1591 element_number
= (int) type
->element_number
;
1593 /* tested with gcov */
1594 if(unlikely(fld
->field_fixed
== -1)){
1595 offset1
= offsetRoot
;
1597 for(i
=0;i
<element_number
;i
++){
1598 size1
=getFieldtypeSize(t
, evT
,offset1
,offset2
,
1599 fld
->child
[i
], NULL
, trace
);
1600 if(likely(size1
> 0 && size
>= 0)){
1602 if(likely(offset1
>= 0)) offset1
+= size1
;
1610 if(unlikely(size
== -1)){
1611 fld
->field_fixed
= 0;
1613 }else fld
->field_fixed
= 1;
1614 }else if(likely(fld
->field_fixed
== 0)){
1615 offset1
= offsetRoot
;
1617 for(i
=0;unlikely(i
<element_number
);i
++){
1618 size
=getFieldtypeSize(t
,evT
,offset1
,offset2
,
1619 fld
->child
[i
],evD
+offset2
, trace
);
1624 }else size
= fld
->field_size
;
1625 fld
->fixed_root
= (offsetRoot
==-1) ? 0 : 1;
1626 fld
->fixed_parent
= (offsetParent
==-1) ? 0 : 1;
1630 if(unlikely(fld
->field_fixed
== -1)){
1631 size
= (int) ltt_type_size(trace
, type
);
1632 fld
->field_fixed
= 1;
1633 }else size
= fld
->field_size
;
1635 fld
->fixed_root
= (offsetRoot
==-1) ? 0 : 1;
1636 fld
->fixed_parent
= (offsetParent
==-1) ? 0 : 1;
1642 fld
->offset_root
= offsetRoot
;
1643 fld
->offset_parent
= offsetParent
;
1644 fld
->field_size
= size
;
1646 end_getFieldtypeSize
:
1652 /*****************************************************************************
1654 * getIntNumber : get an integer number
1656 * size : the size of the integer
1657 * evD : the event data
1659 * gint64 : a 64 bits integer
1660 ****************************************************************************/
1662 gint64
getIntNumber(gboolean reverse_byte_order
, int size
, void *evD
)
1667 case 1: i
= *((gint8
*)evD
); break;
1668 case 2: i
= ltt_get_int16(reverse_byte_order
, evD
); break;
1669 case 4: i
= ltt_get_int32(reverse_byte_order
, evD
); break;
1670 case 8: i
= ltt_get_int64(reverse_byte_order
, evD
); break;
1671 default: i
= ltt_get_int64(reverse_byte_order
, evD
);
1672 g_critical("getIntNumber : integer size %d unknown", size
);
1679 /*****************************************************************************
1681 * getDataEndianType : get the data type size and endian type of the local
1684 * size : size of data type
1685 * endian : endian type, little or big
1686 ****************************************************************************/
1688 void getDataEndianType(LttArchSize
* size
, LttArchEndian
* endian
)
1692 int sizeInt
=sizeof(int), sizeLong
=sizeof(long), sizePointer
=sizeof(void *);
1694 if(c
== 1) *endian
= LTT_LITTLE_ENDIAN
;
1695 else *endian
= LTT_BIG_ENDIAN
;
1697 if(sizeInt
== 2 && sizeLong
== 4 && sizePointer
== 4)
1699 else if(sizeInt
== 4 && sizeLong
== 4 && sizePointer
== 4)
1701 else if(sizeInt
== 4 && sizeLong
== 8 && sizePointer
== 8)
1703 else if(sizeInt
== 8 && sizeLong
== 8 && sizePointer
== 8)
1705 else *size
= LTT_UNKNOWN
;
1708 /* get the node name of the system */
1710 char * ltt_trace_system_description_node_name (LttSystemDescription
* s
)
1712 return s
->node_name
;
1716 /* get the domain name of the system */
1718 char * ltt_trace_system_description_domain_name (LttSystemDescription
* s
)
1720 return s
->domain_name
;
1724 /* get the description of the system */
1726 char * ltt_trace_system_description_description (LttSystemDescription
* s
)
1728 return s
->description
;
1732 /* get the start time of the trace */
1734 LttTime
ltt_trace_system_description_trace_start_time(LttSystemDescription
*s
)
1736 return s
->trace_start
;
1740 LttTracefile
*ltt_tracefile_new()
1742 return g_new(LttTracefile
, 1);
1745 void ltt_tracefile_destroy(LttTracefile
*tf
)
1750 void ltt_tracefile_copy(LttTracefile
*dest
, const LttTracefile
*src
)