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>
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>
49 #define DIR_NAME_SIZE 256
50 #define __UNUSED__ __attribute__((__unused__))
52 #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
53 #define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format)
57 /* obtain the time of an event */
59 static inline LttTime
getEventTime(LttTracefile
* tf
);
62 /* set the offset of the fields belonging to the event,
63 need the information of the archecture */
64 void setFieldsOffset(LttTracefile
*tf
,LttEventType
*evT
,void *evD
,LttTrace
*t
);
66 /* get the size of the field type according to the archtecture's
67 size and endian type(info of the archecture) */
68 static inline gint
getFieldtypeSize(LttTracefile
* tf
,
69 LttEventType
* evT
, gint offsetRoot
,
70 gint offsetParent
, LttField
*fld
, void *evD
, LttTrace
* t
);
72 /* read a fixed size or a block information from the file (fd) */
73 int readFile(int fd
, void * buf
, size_t size
, gchar
* mesg
);
74 int readBlock(LttTracefile
* tf
, int whichBlock
);
76 /* calculate cycles per nsec for current block */
77 void getCyclePerNsec(LttTracefile
* t
);
79 /* reinitialize the info of the block which is already in the buffer */
80 void updateTracefile(LttTracefile
* tf
);
82 /* go to the next event */
83 int skipEvent(LttTracefile
* t
);
86 /* Functions to parse system.xml file (using glib xml parser) */
87 static void parser_start_element (GMarkupParseContext __UNUSED__
*context
,
88 const gchar
*element_name
,
89 const gchar
**attribute_names
,
90 const gchar
**attribute_values
,
95 LttSystemDescription
* des
= (LttSystemDescription
* )user_data
;
96 if(strcmp("system", element_name
)){
97 *error
= g_error_new(G_MARKUP_ERROR
,
99 "This is not system.xml file");
103 while(attribute_names
[i
]){
104 if(strcmp("node_name", attribute_names
[i
])==0){
105 des
->node_name
= g_strdup(attribute_values
[i
]);
106 }else if(strcmp("domainname", attribute_names
[i
])==0){
107 des
->domain_name
= g_strdup(attribute_values
[i
]);
108 }else if(strcmp("cpu", attribute_names
[i
])==0){
109 des
->nb_cpu
= atoi(attribute_values
[i
]);
110 }else if(strcmp("arch_size", attribute_names
[i
])==0){
111 if(strcmp(attribute_values
[i
],"LP32") == 0) des
->size
= LTT_LP32
;
112 else if(strcmp(attribute_values
[i
],"ILP32") == 0) des
->size
= LTT_ILP32
;
113 else if(strcmp(attribute_values
[i
],"LP64") == 0) des
->size
= LTT_LP64
;
114 else if(strcmp(attribute_values
[i
],"ILP64") == 0) des
->size
= LTT_ILP64
;
115 else if(strcmp(attribute_values
[i
],"UNKNOWN") == 0) des
->size
= LTT_UNKNOWN
;
116 }else if(strcmp("endian", attribute_names
[i
])==0){
117 if(strcmp(attribute_values
[i
],"LITTLE_ENDIAN") == 0)
118 des
->endian
= LTT_LITTLE_ENDIAN
;
119 else if(strcmp(attribute_values
[i
],"BIG_ENDIAN") == 0)
120 des
->endian
= LTT_BIG_ENDIAN
;
121 }else if(strcmp("kernel_name", attribute_names
[i
])==0){
122 des
->kernel_name
= g_strdup(attribute_values
[i
]);
123 }else if(strcmp("kernel_release", attribute_names
[i
])==0){
124 des
->kernel_release
= g_strdup(attribute_values
[i
]);
125 }else if(strcmp("kernel_version", attribute_names
[i
])==0){
126 des
->kernel_version
= g_strdup(attribute_values
[i
]);
127 }else if(strcmp("machine", attribute_names
[i
])==0){
128 des
->machine
= g_strdup(attribute_values
[i
]);
129 }else if(strcmp("processor", attribute_names
[i
])==0){
130 des
->processor
= g_strdup(attribute_values
[i
]);
131 }else if(strcmp("hardware_platform", attribute_names
[i
])==0){
132 des
->hardware_platform
= g_strdup(attribute_values
[i
]);
133 }else if(strcmp("operating_system", attribute_names
[i
])==0){
134 des
->operating_system
= g_strdup(attribute_values
[i
]);
135 }else if(strcmp("ltt_major_version", attribute_names
[i
])==0){
136 des
->ltt_major_version
= atoi(attribute_values
[i
]);
137 }else if(strcmp("ltt_minor_version", attribute_names
[i
])==0){
138 des
->ltt_minor_version
= atoi(attribute_values
[i
]);
139 }else if(strcmp("ltt_block_size", attribute_names
[i
])==0){
140 des
->ltt_block_size
= atoi(attribute_values
[i
]);
142 *error
= g_error_new(G_MARKUP_ERROR
,
144 "Not a valid attribute");
151 static void parser_characters (GMarkupParseContext __UNUSED__
*context
,
153 gsize __UNUSED__ text_len
,
155 GError __UNUSED__
**error
)
157 LttSystemDescription
* des
= (LttSystemDescription
* )user_data
;
158 des
->description
= g_strdup(text
);
162 /*****************************************************************************
164 * ltt_tracefile_open : open a trace file, construct a LttTracefile
166 * t : the trace containing the tracefile
167 * fileName : path name of the trace file
169 * : a pointer to a tracefile
170 ****************************************************************************/
172 LttTracefile
* ltt_tracefile_open(LttTrace
* t
, gchar
* fileName
)
175 struct stat lTDFStat
; /* Trace data file status */
177 tf
= g_new(LttTracefile
, 1);
180 tf
->name
= g_strdup(fileName
);
182 tf
->fd
= g_open(fileName
, O_RDONLY
, 0);
184 g_warning("Unable to open input data file %s\n", fileName
);
190 // Get the file's status
191 if(fstat(tf
->fd
, &lTDFStat
) < 0){
192 g_warning("Unable to get the status of the input data file %s\n", fileName
);
199 // Is the file large enough to contain a trace
200 if(lTDFStat
.st_size
< (off_t
)(sizeof(BlockStart
) + EVENT_HEADER_SIZE
)){
201 g_print("The input data file %s does not contain a trace\n", fileName
);
208 //store the size of the file
209 tf
->file_size
= lTDFStat
.st_size
;
210 tf
->block_size
= t
->system_description
->ltt_block_size
;
211 tf
->block_number
= tf
->file_size
/ tf
->block_size
;
214 //allocate memory to contain the info of a block
215 tf
->buffer
= (void *) g_new(gchar
, t
->system_description
->ltt_block_size
);
217 //read the first block
218 if(readBlock(tf
,1)) exit(1);
224 /*****************************************************************************
225 *Open control and per cpu tracefiles
226 ****************************************************************************/
228 void ltt_tracefile_open_cpu(LttTrace
*t
, gchar
* tracefile_name
)
231 tf
= ltt_tracefile_open(t
,tracefile_name
);
233 t
->per_cpu_tracefile_number
++;
234 g_ptr_array_add(t
->per_cpu_tracefiles
, tf
);
237 gint
ltt_tracefile_open_control(LttTrace
*t
, gchar
* control_name
)
246 tf
= ltt_tracefile_open(t
,control_name
);
248 g_warning("ltt_tracefile_open_control : bad file descriptor");
251 t
->control_tracefile_number
++;
252 g_ptr_array_add(t
->control_tracefiles
,tf
);
254 //parse facilities tracefile to get base_id
255 if(strcmp(&control_name
[strlen(control_name
)-10],"facilities") ==0){
257 if(!ltt_tracefile_read(tf
,&ev
)) return 0; // end of file
259 if(ev
.event_id
== TRACE_FACILITY_LOAD
){
261 fLoad
.name
= (gchar
*)pos
;
262 fLoad
.checksum
= *(LttChecksum
*)(pos
+ strlen(fLoad
.name
));
263 fLoad
.base_code
= *(guint32
*)(pos
+ strlen(fLoad
.name
) + sizeof(LttChecksum
));
265 for(i
=0;i
<t
->facility_number
;i
++){
266 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
,i
);
267 if(strcmp(f
->name
,fLoad
.name
)==0 && fLoad
.checksum
==f
->checksum
){
268 f
->base_id
= fLoad
.base_code
;
272 if(i
==t
->facility_number
) {
273 g_warning("Facility: %s, checksum: %u is not found",
274 fLoad
.name
,(unsigned int)fLoad
.checksum
);
277 }else if(ev
.event_id
== TRACE_BLOCK_START
){
279 }else if(ev
.event_id
== TRACE_BLOCK_END
){
282 g_warning("Not valid facilities trace file");
290 /*****************************************************************************
292 * ltt_tracefile_close: close a trace file,
294 * t : tracefile which will be closed
295 ****************************************************************************/
297 void ltt_tracefile_close(LttTracefile
*t
)
306 /*****************************************************************************
307 *Get system information
308 ****************************************************************************/
309 gint
getSystemInfo(LttSystemDescription
* des
, gchar
* pathname
)
316 GMarkupParseContext
* context
;
317 GError
* error
= NULL
;
318 GMarkupParser markup_parser
=
320 parser_start_element
,
323 NULL
, /* passthrough */
327 fd
= g_open(pathname
, O_RDONLY
, 0);
329 g_warning("Can not open file : %s\n", pathname
);
333 iochan
= g_io_channel_unix_new(fd
);
335 context
= g_markup_parse_context_new(&markup_parser
, 0, des
,NULL
);
337 //while(fgets(buf,DIR_NAME_SIZE, fp) != NULL){
338 while(g_io_channel_read_line(iochan
, &buf
, &length
, NULL
, &error
)
339 != G_IO_STATUS_EOF
) {
342 g_warning("Can not read xml file: \n%s\n", error
->message
);
345 if(!g_markup_parse_context_parse(context
, buf
, length
, &error
)){
347 g_warning("Can not parse xml file: \n%s\n", error
->message
);
350 g_markup_parse_context_free(context
);
352 g_io_channel_shutdown(iochan
, FALSE
, &error
); /* No flush */
354 g_warning("Can not close file: \n%s\n", error
->message
);
362 g_markup_parse_context_free(context
);
364 g_io_channel_shutdown(iochan
, FALSE
, &error
); /* No flush */
366 g_warning("Can not close file: \n%s\n", error
->message
);
376 /*****************************************************************************
377 *The following functions get facility/tracefile information
378 ****************************************************************************/
380 gint
getFacilityInfo(LttTrace
*t
, gchar
* eventdefs
)
387 gchar fullname
[DIR_NAME_SIZE
];
388 GError
* error
= NULL
;
390 dir
= g_dir_open(eventdefs
, 0, &error
);
393 g_warning("Can not open directory: %s, %s\n", eventdefs
, error
->message
);
398 while((name
= g_dir_read_name(dir
)) != NULL
){
399 if(!g_pattern_match_simple("*.xml", name
)) continue;
400 strcpy(fullname
,eventdefs
);
401 strcat(fullname
,name
);
402 ltt_facility_open(t
,fullname
);
406 for(j
=0;j
<t
->facility_number
;j
++){
407 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
, j
);
408 for(i
=0; i
<f
->event_number
; i
++){
410 setFieldsOffset(NULL
, et
, NULL
, t
);
416 gint
getControlFileInfo(LttTrace
*t
, gchar
* control
)
420 gchar fullname
[DIR_NAME_SIZE
];
421 GError
* error
= NULL
;
423 dir
= g_dir_open(control
, 0, &error
);
426 g_warning("Can not open directory: %s, %s\n", control
, error
->message
);
431 while((name
= g_dir_read_name(dir
)) != NULL
){
432 if(strcmp(name
,"facilities") != 0 &&
433 strcmp(name
,"interrupts") != 0 &&
434 strcmp(name
,"processes") != 0) continue;
436 strcpy(fullname
,control
);
437 strcat(fullname
,name
);
438 if(ltt_tracefile_open_control(t
,fullname
)) {
447 gint
getCpuFileInfo(LttTrace
*t
, char* cpu
)
451 gchar fullname
[DIR_NAME_SIZE
];
452 GError
* error
= NULL
;
454 dir
= g_dir_open(cpu
, 0, &error
);
457 g_warning("Can not open directory: %s, %s\n", cpu
, error
->message
);
462 while((name
= g_dir_read_name(dir
)) != NULL
){
463 if(strcmp(name
,".svn") != 0){ /* . and .. already excluded */
464 strcpy(fullname
,cpu
);
465 strcat(fullname
,name
);
466 ltt_tracefile_open_cpu(t
,fullname
);
473 /*****************************************************************************
474 *A trace is specified as a pathname to the directory containing all the
475 *associated data (control tracefiles, per cpu tracefiles, event
478 *When a trace is closed, all the associated facilities, types and fields
479 *are released as well.
483 /****************************************************************************
484 * get_absolute_pathname
486 * return the unique pathname in the system
488 * MD : Fixed this function so it uses realpath, dealing well with
489 * forgotten cases (.. were not used correctly before).
491 ****************************************************************************/
492 void get_absolute_pathname(const gchar
*pathname
, gchar
* abs_pathname
)
494 abs_pathname
[0] = '\0';
496 if ( realpath (pathname
, abs_pathname
) != NULL
)
500 /* error, return the original path unmodified */
501 strcpy(abs_pathname
, pathname
);
507 LttTrace
*ltt_trace_open(const gchar
*pathname
)
510 LttSystemDescription
* sys_description
;
511 gchar eventdefs
[DIR_NAME_SIZE
];
512 gchar info
[DIR_NAME_SIZE
];
513 gchar control
[DIR_NAME_SIZE
];
514 gchar cpu
[DIR_NAME_SIZE
];
515 gchar tmp
[DIR_NAME_SIZE
];
516 gchar abs_path
[DIR_NAME_SIZE
];
517 gboolean has_slash
= FALSE
;
519 get_absolute_pathname(pathname
, abs_path
);
520 //establish the pathname to different directories
521 if(abs_path
[strlen(abs_path
)-1] == '/')has_slash
= TRUE
;
522 strcpy(eventdefs
,abs_path
);
523 if(!has_slash
)strcat(eventdefs
,"/");
524 strcat(eventdefs
,"eventdefs/");
526 strcpy(info
,abs_path
);
527 if(!has_slash
)strcat(info
,"/");
528 strcat(info
,"info/");
530 strcpy(control
,abs_path
);
531 if(!has_slash
)strcat(control
,"/");
532 strcat(control
,"control/");
534 strcpy(cpu
,abs_path
);
535 if(!has_slash
)strcat(cpu
,"/");
539 sys_description
= g_new(LttSystemDescription
, 1);
540 t
= g_new(LttTrace
, 1);
541 t
->pathname
= g_strdup(abs_path
);
542 t
->facility_number
= 0;
543 t
->control_tracefile_number
= 0;
544 t
->per_cpu_tracefile_number
= 0;
545 t
->system_description
= sys_description
;
546 t
->control_tracefiles
= g_ptr_array_new();
547 t
->per_cpu_tracefiles
= g_ptr_array_new();
548 t
->facilities
= g_ptr_array_new();
549 //getDataEndianType(&(t->my_arch_size), &(t->my_arch_endian));
551 //get system description
553 strcat(tmp
,"system.xml");
554 if(getSystemInfo(sys_description
, tmp
)) {
555 g_ptr_array_free(t
->facilities
, TRUE
);
556 g_ptr_array_free(t
->per_cpu_tracefiles
, TRUE
);
557 g_ptr_array_free(t
->control_tracefiles
, TRUE
);
558 g_free(sys_description
);
564 /* Set the reverse byte order between trace and reader */
565 if(sys_description
->endian
== LTT_LITTLE_ENDIAN
566 && G_BYTE_ORDER
!= G_LITTLE_ENDIAN
) {
567 t
->reverse_byte_order
= 1;
568 } else if(sys_description
->endian
== LTT_BIG_ENDIAN
569 && G_BYTE_ORDER
!= G_BIG_ENDIAN
) {
570 t
->reverse_byte_order
= 1;
571 } else t
->reverse_byte_order
= 0;
573 //get facilities info
574 if(getFacilityInfo(t
,eventdefs
)) {
575 g_ptr_array_free(t
->facilities
, TRUE
);
576 g_ptr_array_free(t
->per_cpu_tracefiles
, TRUE
);
577 g_ptr_array_free(t
->control_tracefiles
, TRUE
);
578 g_free(sys_description
);
584 //get control tracefile info
585 getControlFileInfo(t
,control
);
587 if(getControlFileInfo(t,control)) {
588 g_ptr_array_free(t->facilities, TRUE);
589 g_ptr_array_free(t->per_cpu_tracefiles, TRUE);
590 g_ptr_array_free(t->control_tracefiles, TRUE);
591 g_free(sys_description);
595 }*/ // With fatal error
597 //get cpu tracefile info
598 if(getCpuFileInfo(t
,cpu
)) {
599 g_ptr_array_free(t
->facilities
, TRUE
);
600 g_ptr_array_free(t
->per_cpu_tracefiles
, TRUE
);
601 g_ptr_array_free(t
->control_tracefiles
, TRUE
);
602 g_free(sys_description
);
611 char * ltt_trace_name(LttTrace
*t
)
617 /******************************************************************************
618 * When we copy a trace, we want all the opening actions to happen again :
619 * the trace will be reopened and totally independant from the original.
620 * That's why we call ltt_trace_open.
621 *****************************************************************************/
622 LttTrace
*ltt_trace_copy(LttTrace
*self
)
624 return ltt_trace_open(self
->pathname
);
627 void ltt_trace_close(LttTrace
*t
)
635 //free system_description
636 g_free(t
->system_description
->description
);
637 g_free(t
->system_description
->node_name
);
638 g_free(t
->system_description
->domain_name
);
639 g_free(t
->system_description
->kernel_name
);
640 g_free(t
->system_description
->kernel_release
);
641 g_free(t
->system_description
->kernel_version
);
642 g_free(t
->system_description
->machine
);
643 g_free(t
->system_description
->processor
);
644 g_free(t
->system_description
->hardware_platform
);
645 g_free(t
->system_description
->operating_system
);
646 g_free(t
->system_description
);
648 //free control_tracefiles
649 for(i
=0;i
<t
->control_tracefile_number
;i
++){
650 tf
= (LttTracefile
*)g_ptr_array_index(t
->control_tracefiles
,i
);
651 ltt_tracefile_close(tf
);
653 g_ptr_array_free(t
->control_tracefiles
, TRUE
);
655 //free per_cpu_tracefiles
656 for(i
=0;i
<t
->per_cpu_tracefile_number
;i
++){
657 tf
= (LttTracefile
*)g_ptr_array_index(t
->per_cpu_tracefiles
,i
);
658 ltt_tracefile_close(tf
);
660 g_ptr_array_free(t
->per_cpu_tracefiles
, TRUE
);
663 for(i
=0;i
<t
->facility_number
;i
++){
664 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
,i
);
665 ltt_facility_close(f
);
667 g_ptr_array_free(t
->facilities
, TRUE
);
675 /*****************************************************************************
676 *Get the system description of the trace
677 ****************************************************************************/
679 LttSystemDescription
*ltt_trace_system_description(LttTrace
*t
)
681 return t
->system_description
;
684 /*****************************************************************************
685 * The following functions discover the facilities of the trace
686 ****************************************************************************/
688 unsigned ltt_trace_facility_number(LttTrace
*t
)
690 return (unsigned)(t
->facility_number
);
693 LttFacility
*ltt_trace_facility_get(LttTrace
*t
, unsigned i
)
695 return (LttFacility
*)g_ptr_array_index(t
->facilities
, i
);
698 /*****************************************************************************
700 * ltt_trace_facility_find : find facilities in the trace
703 * name : facility name
705 * position : position of the facility in the trace
707 * : the number of facilities
708 ****************************************************************************/
710 unsigned ltt_trace_facility_find(LttTrace
*t
, char *name
, unsigned *position
)
712 unsigned int i
, count
=0;
714 for(i
=0;i
<t
->facility_number
;i
++){
715 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
, i
);
716 if(strcmp(f
->name
,name
)==0){
718 if(count
==1) *position
= i
;
726 /*****************************************************************************
727 * Functions to discover all the event types in the trace
728 ****************************************************************************/
730 unsigned ltt_trace_eventtype_number(LttTrace
*t
)
734 unsigned int num
= t
->facility_number
;
738 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
, i
);
739 count
+= f
->event_number
;
744 /* FIXME : performances could be improved with a better design for this
745 * function : sequential search through a container has never been the
746 * best on the critical path. */
747 LttFacility
* ltt_trace_facility_by_id(LttTrace
* trace
, unsigned id
)
749 LttFacility
* facility
= NULL
;
751 unsigned int num
= trace
->facility_number
;
752 GPtrArray
*facilities
= trace
->facilities
;
754 for(i
=0;unlikely(i
<num
);){
755 LttFacility
*iter_facility
=
756 (LttFacility
*) g_ptr_array_index(facilities
,i
);
757 unsigned base_id
= iter_facility
->base_id
;
759 if(likely(id
>= base_id
&&
760 id
< base_id
+ iter_facility
->event_number
)) {
761 facility
= iter_facility
;
771 LttEventType
*ltt_trace_eventtype_get(LttTrace
*t
, unsigned evId
)
773 LttEventType
*event_type
;
776 f
= ltt_trace_facility_by_id(t
,evId
);
778 if(unlikely(!f
)) event_type
= NULL
;
779 else event_type
= f
->events
[evId
- f
->base_id
];
784 /*****************************************************************************
785 *There is one "per cpu" tracefile for each CPU, numbered from 0 to
786 *the maximum number of CPU in the system. When the number of CPU installed
787 *is less than the maximum, some positions are unused. There are also a
788 *number of "control" tracefiles (facilities, interrupts...).
789 ****************************************************************************/
790 unsigned ltt_trace_control_tracefile_number(LttTrace
*t
)
792 return t
->control_tracefile_number
;
795 unsigned ltt_trace_per_cpu_tracefile_number(LttTrace
*t
)
797 return t
->per_cpu_tracefile_number
;
800 /*****************************************************************************
801 *It is possible to search for the tracefiles by name or by CPU position.
802 *The index within the tracefiles of the same type is returned if found
803 *and a negative value otherwise.
804 ****************************************************************************/
806 int ltt_trace_control_tracefile_find(LttTrace
*t
, const gchar
*name
)
808 LttTracefile
* tracefile
;
810 for(i
=0;i
<t
->control_tracefile_number
;i
++){
811 tracefile
= (LttTracefile
*)g_ptr_array_index(t
->control_tracefiles
, i
);
812 if(strcmp(tracefile
->name
, name
)==0)break;
814 if(i
== t
->control_tracefile_number
) return -1;
818 /* not really useful. We just have to know that cpu tracefiles
819 * comes before control tracefiles.
821 int ltt_trace_per_cpu_tracefile_find(LttTrace
*t
, const gchar
*name
)
823 LttTracefile
* tracefile
;
825 for(i
=0;i
<t
->per_cpu_tracefile_number
;i
++){
826 tracefile
= (LttTracefile
*)g_ptr_array_index(t
->per_cpu_tracefiles
, i
);
827 if(strcmp(tracefile
->name
, name
)==0)break;
829 if(i
== t
->per_cpu_tracefile_number
) return -1;
833 /*****************************************************************************
834 *Get a specific tracefile
835 ****************************************************************************/
837 LttTracefile
*ltt_trace_control_tracefile_get(LttTrace
*t
, unsigned i
)
839 return (LttTracefile
*)g_ptr_array_index(t
->control_tracefiles
, i
);
842 LttTracefile
*ltt_trace_per_cpu_tracefile_get(LttTrace
*t
, unsigned i
)
844 return (LttTracefile
*)g_ptr_array_index(t
->per_cpu_tracefiles
, i
);
847 /*****************************************************************************
848 * Get the start time and end time of the trace
849 ****************************************************************************/
851 void ltt_trace_time_span_get(LttTrace
*t
, LttTime
*start
, LttTime
*end
)
853 LttTime startSmall
, startTmp
, endBig
, endTmp
;
857 for(i
=0;i
<t
->control_tracefile_number
;i
++){
858 tf
= g_ptr_array_index(t
->control_tracefiles
, i
);
860 startTmp
= ltt_get_time(t
->reverse_byte_order
, &tf
->a_block_start
->time
);
861 readBlock(tf
,tf
->block_number
);
862 endTmp
= ltt_get_time(t
->reverse_byte_order
, &tf
->a_block_end
->time
);
864 startSmall
= startTmp
;
869 if(ltt_time_compare(startSmall
,startTmp
) > 0) startSmall
= startTmp
;
870 if(ltt_time_compare(endBig
,endTmp
) < 0) endBig
= endTmp
;
873 for(i
=0;i
<t
->per_cpu_tracefile_number
;i
++){
874 tf
= g_ptr_array_index(t
->per_cpu_tracefiles
, i
);
876 startTmp
= ltt_get_time(t
->reverse_byte_order
, &tf
->a_block_start
->time
);
877 readBlock(tf
,tf
->block_number
);
878 endTmp
= ltt_get_time(t
->reverse_byte_order
, &tf
->a_block_end
->time
);
880 startSmall
= startTmp
;
884 if(ltt_time_compare(startSmall
,startTmp
) > 0) startSmall
= startTmp
;
885 if(ltt_time_compare(endBig
,endTmp
) < 0) endBig
= endTmp
;
888 if(start
!= NULL
) *start
= startSmall
;
889 if(end
!= NULL
) *end
= endBig
;
893 /*****************************************************************************
894 *Get the name of a tracefile
895 ****************************************************************************/
897 char *ltt_tracefile_name(LttTracefile
*tf
)
902 /*****************************************************************************
903 * Get the number of blocks in the tracefile
904 ****************************************************************************/
906 unsigned ltt_tracefile_block_number(LttTracefile
*tf
)
908 return tf
->block_number
;
911 /*****************************************************************************
913 * ltt_tracefile_seek_time: seek to the first event of the trace with time
914 * larger or equal to time
917 * time : criteria of the time
918 ****************************************************************************/
919 void ltt_tracefile_find_time_block(LttTracefile
*t
, LttTime time
,
920 int start_block
, int end_block
)
922 int err
, tmp_block
, s
, e
;
926 err
=readBlock(t
,start_block
);
927 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
928 if(start_block
== end_block
)return;
930 tailTime
= ltt_time_compare(ltt_get_time(t
->trace
->reverse_byte_order
,
931 &t
->a_block_end
->time
), time
);
932 if(tailTime
>= 0) return;
934 err
=readBlock(t
,end_block
);
935 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
936 if(start_block
+1 == end_block
)return;
938 headTime
= ltt_time_compare(ltt_get_time(t
->trace
->reverse_byte_order
,
939 &t
->a_block_start
->time
), time
);
940 if(headTime
<= 0 ) return;
942 tmp_block
= (end_block
+ start_block
)/2;
943 err
=readBlock(t
,tmp_block
);
944 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
946 headTime
= ltt_time_compare(ltt_get_time(t
->trace
->reverse_byte_order
,
947 &t
->a_block_start
->time
), time
);
948 tailTime
= ltt_time_compare(ltt_get_time(t
->trace
->reverse_byte_order
,
949 &t
->a_block_end
->time
), time
);
950 if(headTime
<= 0 && tailTime
>= 0) return;
956 ltt_tracefile_find_time_block(t
, time
, s
, e
);
964 ltt_tracefile_find_time_block(t
, time
, s
, e
);
969 void ltt_tracefile_backward_find_time_block(LttTracefile
*t
, LttTime time
)
971 int t_time
, h_time
, err
;
972 err
=readBlock(t
,t
->which_block
-1);
973 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
974 h_time
= ltt_time_compare(ltt_get_time(t
->trace
->reverse_byte_order
,
975 &t
->a_block_start
->time
), time
);
976 t_time
= ltt_time_compare(ltt_get_time(t
->trace
->reverse_byte_order
,
977 &t
->a_block_end
->time
), time
);
980 if(t
->which_block
== 1) return;
981 err
=readBlock(t
,t
->which_block
-1);
982 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
983 tmp
= ltt_time_compare(ltt_get_time(t
->trace
->reverse_byte_order
,
984 &t
->a_block_end
->time
), time
);
985 if(tmp
== 0) return ltt_tracefile_seek_time(t
, time
);
986 err
=readBlock(t
,t
->which_block
+1);
987 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
988 }else if(h_time
> 0){
989 ltt_tracefile_find_time_block(t
, time
, 1, t
->which_block
);
990 return ltt_tracefile_seek_time(t
, time
) ;
992 if(t_time
>= 0) return ltt_tracefile_seek_time(t
, time
);
993 err
=readBlock(t
,t
->which_block
+1);
994 if(err
) g_error("Can not read tracefile: %s\n", t
->name
);
998 void ltt_tracefile_seek_time(LttTracefile
*t
, LttTime time
)
1002 int headTime
= ltt_time_compare(ltt_get_time(t
->trace
->reverse_byte_order
,
1003 &t
->a_block_start
->time
), time
);
1004 int tailTime
= ltt_time_compare(ltt_get_time(t
->trace
->reverse_byte_order
,
1005 &t
->a_block_end
->time
), time
);
1008 if(headTime
< 0 && tailTime
> 0){
1009 if(ltt_time_compare(ltt_get_time(t
->trace
->reverse_byte_order
,
1010 &t
->a_block_end
->time
),
1011 t
->current_event_time
) !=0) {
1012 lttTime
= getEventTime(t
);
1013 err
= ltt_time_compare(lttTime
, time
);
1015 if(t
->which_event
==2 || ltt_time_compare(t
->prev_event_time
,time
)<0){
1019 return ltt_tracefile_seek_time(t
, time
);
1023 if(ltt_tracefile_read(t
,&ev
) == NULL
) {
1024 g_print("End of file\n");
1027 lttTime
= getEventTime(t
);
1028 err
= ltt_time_compare(lttTime
, time
);
1032 }else{//we are at the end of the block
1034 return ltt_tracefile_seek_time(t
, time
);
1036 }else if(headTime
>= 0){
1037 if(t
->which_block
== 1){
1040 if(ltt_time_compare(t
->prev_block_end_time
, time
) >= 0 ||
1041 (t
->prev_block_end_time
.tv_sec
== 0 &&
1042 t
->prev_block_end_time
.tv_nsec
== 0 )){
1043 ltt_tracefile_backward_find_time_block(t
, time
);
1048 }else if(tailTime
< 0){
1049 if(t
->which_block
!= t
->block_number
){
1050 ltt_tracefile_find_time_block(t
, time
, t
->which_block
+1, t
->block_number
);
1051 return ltt_tracefile_seek_time(t
, time
);
1053 t
->cur_event_pos
= t
->buffer
+ t
->block_size
;
1054 g_print("End of file\n");
1057 }else if(tailTime
== 0){
1058 t
->cur_event_pos
= t
->last_event_pos
;
1059 t
->current_event_time
= time
;
1060 t
->cur_heart_beat_number
= 0;
1061 t
->prev_event_time
.tv_sec
= 0;
1062 t
->prev_event_time
.tv_nsec
= 0;
1067 /*****************************************************************************
1068 * Seek to the first event with position equal or larger to ep
1070 * Modified by Mathieu Desnoyers to used faster offset position instead of
1071 * re-reading the whole buffer.
1072 ****************************************************************************/
1074 void ltt_tracefile_seek_position(LttTracefile
*t
, const LttEventPosition
*ep
)
1076 //if we are at the right place, just return
1077 if(likely(t
->which_block
== ep
->block_num
&& t
->which_event
== ep
->event_num
))
1080 if(likely(t
->which_block
== ep
->block_num
)) updateTracefile(t
);
1081 else readBlock(t
,ep
->block_num
);
1082 //event offset is available
1083 if(likely(ep
->old_position
)){
1086 t
->which_event
= ep
->event_num
;
1087 t
->cur_event_pos
= t
->buffer
+ ep
->event_offset
;
1088 t
->prev_event_time
= ep
->event_time
;
1089 t
->current_event_time
= ep
->event_time
;
1090 t
->cur_heart_beat_number
= ep
->heart_beat_number
;
1091 t
->cur_cycle_count
= ep
->event_cycle_count
;
1093 /* This is a workaround for fast position seek */
1094 t
->last_event_pos
= ep
->last_event_pos
;
1095 t
->prev_block_end_time
= ep
->prev_block_end_time
;
1096 t
->prev_event_time
= ep
->prev_event_time
;
1097 t
->pre_cycle_count
= ep
->pre_cycle_count
;
1098 t
->count
= ep
->count
;
1099 t
->overflow_nsec
= ep
->overflow_nsec
;
1100 t
->last_heartbeat
= ep
->last_heartbeat
;
1101 /* end of workaround */
1103 //update the fields of the current event and go to the next event
1105 if(unlikely(err
== ERANGE
)) g_error("event id is out of range\n");
1110 //only block number and event index are available
1111 //MD: warning : this is slow!
1112 g_warning("using slow O(n) tracefile seek position");
1115 while(likely(t
->which_event
< ep
->event_num
)) ltt_tracefile_read(t
, &event
);
1120 /*****************************************************************************
1122 * ltt_tracefile_read : read the current event, set the pointer to the next
1126 * LttEvent * : an event to be processed
1127 ****************************************************************************/
1129 LttEvent
*ltt_tracefile_read(LttTracefile
*t
, LttEvent
*event
)
1133 if(unlikely(t
->cur_event_pos
== t
->buffer
+ t
->block_size
)){
1134 if(unlikely(t
->which_block
== t
->block_number
)){
1137 err
= readBlock(t
, t
->which_block
+ 1);
1138 if(unlikely(err
))g_error("Can not read tracefile");
1141 event
->event_id
= ltt_get_uint16(t
->trace
->reverse_byte_order
, t
->cur_event_pos
);
1142 if(unlikely(event
->event_id
== TRACE_TIME_HEARTBEAT
))
1143 t
->cur_heart_beat_number
++;
1145 t
->prev_event_time
= t
->current_event_time
;
1146 // t->current_event_time = getEventTime(t);
1148 event
->time_delta
= ltt_get_uint32(t
->trace
->reverse_byte_order
, t
->cur_event_pos
+ EVENT_ID_SIZE
);
1149 event
->event_time
= t
->current_event_time
;
1150 event
->event_cycle_count
= t
->cur_cycle_count
;
1152 event
->tracefile
= t
;
1153 event
->data
= t
->cur_event_pos
+ EVENT_HEADER_SIZE
;
1154 event
->which_block
= t
->which_block
;
1155 event
->which_event
= t
->which_event
;
1157 /* This is a workaround for fast position seek */
1158 event
->last_event_pos
= t
->last_event_pos
;
1159 event
->prev_block_end_time
= t
->prev_block_end_time
;
1160 event
->prev_event_time
= t
->prev_event_time
;
1161 event
->pre_cycle_count
= t
->pre_cycle_count
;
1162 event
->count
= t
->count
;
1163 event
->overflow_nsec
= t
->overflow_nsec
;
1164 event
->last_heartbeat
= t
->last_heartbeat
;
1166 /* end of workaround */
1170 //update the fields of the current event and go to the next event
1172 if(unlikely(err
== ERANGE
)) g_error("event id is out of range\n");
1177 /****************************************************************************
1179 * readFile : wrap function to read from a file
1181 * fd : file descriptor
1182 * buf : buf to contain the content
1183 * size : number of bytes to be read
1184 * mesg : message to be printed if some thing goes wrong
1187 * EIO : can not read from the file
1188 ****************************************************************************/
1190 int readFile(int fd
, void * buf
, size_t size
, char * mesg
)
1192 ssize_t nbBytes
= read(fd
, buf
, size
);
1194 if((size_t)nbBytes
!= size
) {
1196 perror("Error in readFile : ");
1198 g_warning("%s",mesg
);
1206 /****************************************************************************
1208 * readBlock : read a block from the file
1210 * lttdes : ltt trace file
1211 * whichBlock : the block which will be read
1214 * EINVAL : lseek fail
1215 * EIO : can not read from the file
1216 ****************************************************************************/
1218 int readBlock(LttTracefile
* tf
, int whichBlock
)
1223 /* same block already opened requested */
1224 if((guint
)whichBlock
== tf
->which_block
) return 0;
1226 if(likely(whichBlock
- tf
->which_block
== 1 && tf
->which_block
!= 0)){
1227 tf
->prev_block_end_time
= ltt_get_time(tf
->trace
->reverse_byte_order
,
1228 &tf
->a_block_end
->time
);
1229 tf
->prev_event_time
= ltt_get_time(tf
->trace
->reverse_byte_order
,
1230 &tf
->a_block_end
->time
);
1232 tf
->prev_block_end_time
.tv_sec
= 0;
1233 tf
->prev_block_end_time
.tv_nsec
= 0;
1234 tf
->prev_event_time
.tv_sec
= 0;
1235 tf
->prev_event_time
.tv_nsec
= 0;
1238 nbBytes
=lseek(tf
->fd
,(off_t
)((whichBlock
-1)*tf
->block_size
), SEEK_SET
);
1239 if(unlikely(nbBytes
== -1)) return EINVAL
;
1241 if(unlikely(readFile(tf
->fd
,tf
->buffer
,tf
->block_size
,"Unable to read a block")))
1244 tf
->a_block_start
=(BlockStart
*) (tf
->buffer
+ EVENT_HEADER_SIZE
);
1245 lostSize
= *(guint32
*)(tf
->buffer
+ tf
->block_size
- sizeof(guint32
));
1246 tf
->a_block_end
=(BlockEnd
*)(tf
->buffer
+ tf
->block_size
1247 - sizeof(guint32
) - lostSize
- sizeof(BlockEnd
));
1248 tf
->last_event_pos
= tf
->buffer
+ tf
->block_size
-
1249 sizeof(guint32
) - lostSize
1250 - sizeof(BlockEnd
) - EVENT_HEADER_SIZE
;
1252 tf
->which_block
= whichBlock
;
1253 tf
->which_event
= 1;
1254 tf
->cur_event_pos
= tf
->buffer
;//the beginning of the block, block start ev
1255 tf
->cur_heart_beat_number
= 0;
1256 tf
->last_heartbeat
= NULL
;
1258 /* read the whole block to precalculate total of cycles in it */
1260 tf
->pre_cycle_count
= 0;
1261 tf
->cur_cycle_count
= ltt_get_uint32(tf
->trace
->reverse_byte_order
, tf
->cur_event_pos
+ EVENT_ID_SIZE
);
1263 getCyclePerNsec(tf
);
1267 (ltt_get_uint64(tf
->trace
->reverse_byte_order
,
1268 &tf
->a_block_start
->cycle_count
)&0xFFFFFFFF))
1269 * tf
->nsec_per_cycle
);
1271 tf
->current_event_time
= getEventTime(tf
);
1276 /*****************************************************************************
1278 * updateTracefile : reinitialize the info of the block which is already
1282 ****************************************************************************/
1284 void updateTracefile(LttTracefile
* tf
)
1286 tf
->which_event
= 1;
1287 tf
->cur_event_pos
= tf
->buffer
;
1288 tf
->current_event_time
= getEventTime(tf
);
1289 tf
->cur_heart_beat_number
= 0;
1291 tf
->prev_event_time
.tv_sec
= 0;
1292 tf
->prev_event_time
.tv_nsec
= 0;
1296 (-((double)ltt_get_uint64(tf
->trace
->reverse_byte_order
,
1297 &tf
->a_block_start
->cycle_count
))
1298 * tf
->nsec_per_cycle
);
1302 /*****************************************************************************
1304 * skipEvent : go to the next event, update the fields of the current event
1309 * ERANGE : event id is out of range
1310 ****************************************************************************/
1312 int skipEvent(LttTracefile
* t
)
1319 evId
= ltt_get_uint16(t
->trace
->reverse_byte_order
, t
->cur_event_pos
);
1320 evData
= t
->cur_event_pos
+ EVENT_HEADER_SIZE
;
1322 evT
= ltt_trace_eventtype_get(t
->trace
,(unsigned)evId
);
1324 if(likely(evT
)) rootFld
= evT
->root_field
;
1327 if(likely(rootFld
)){
1328 //event has string/sequence or the last event is not the same event
1329 if(likely((evT
->latest_block
!=t
->which_block
|| evT
->latest_event
!=t
->which_event
)
1330 && rootFld
->field_fixed
== 0)){
1331 setFieldsOffset(t
, evT
, evData
, t
->trace
);
1333 t
->cur_event_pos
+= EVENT_HEADER_SIZE
+ rootFld
->field_size
;
1334 }else t
->cur_event_pos
+= EVENT_HEADER_SIZE
;
1336 evT
->latest_block
= t
->which_block
;
1337 evT
->latest_event
= t
->which_event
;
1339 //the next event is in the next block
1340 if(unlikely(evId
== TRACE_BLOCK_END
)){
1341 t
->cur_event_pos
= t
->buffer
+ t
->block_size
;
1343 t
->cur_cycle_count
= ltt_get_uint32(t
->trace
->reverse_byte_order
,
1344 t
->cur_event_pos
+ EVENT_ID_SIZE
);
1346 t
->current_event_time
= getEventTime(t
);
1353 /*****************************************************************************
1355 * getCyclePerNsec : calculate cycles per nsec for current block
1356 * MD: should have tracefile_read the whole block, so we know the
1357 * total of cycles in it before being called.
1360 ****************************************************************************/
1362 void getCyclePerNsec(LttTracefile
* t
)
1364 LttTime lBufTotalTime
; /* Total time for this buffer */
1365 double lBufTotalNSec
; /* Total time for this buffer in nsecs */
1366 LttCycleCount lBufTotalCycle
;/* Total cycles for this buffer */
1368 /* Calculate the total time for this buffer */
1369 lBufTotalTime
= ltt_time_sub(
1370 ltt_get_time(t
->trace
->reverse_byte_order
, &t
->a_block_end
->time
),
1371 ltt_get_time(t
->trace
->reverse_byte_order
, &t
->a_block_start
->time
));
1373 /* Calculate the total cycles for this bufffer */
1374 lBufTotalCycle
= ltt_get_uint64(t
->trace
->reverse_byte_order
,
1375 &t
->a_block_end
->cycle_count
);
1376 lBufTotalCycle
-= ltt_get_uint64(t
->trace
->reverse_byte_order
,
1377 &t
->a_block_start
->cycle_count
);
1379 /* Convert the total time to double */
1380 lBufTotalNSec
= ltt_time_to_double(lBufTotalTime
);
1382 t
->nsec_per_cycle
= (double)lBufTotalNSec
/ (double)lBufTotalCycle
;
1384 /* Pre-multiply one overflow (2^32 cycles) by nsec_per_cycle */
1385 t
->one_overflow_nsec
= t
->nsec_per_cycle
* (double)0x100000000ULL
;
1389 /****************************************************************************
1391 * getEventTime : obtain the time of an event
1392 * NOTE : this function _really_ is on critical path.
1396 * LttTime : the time of the event
1397 ****************************************************************************/
1399 static inline LttTime
getEventTime(LttTracefile
* tf
)
1402 LttCycleCount cycle_count
; // cycle count for the current event
1403 //LttCycleCount lEventTotalCycle; // Total cycles from start for event
1404 gint64 lEventNSec
; // Total nsecs from start for event
1405 LttTime lTimeOffset
; // Time offset in struct LttTime
1408 evId
= ltt_get_uint16(tf
->trace
->reverse_byte_order
,
1411 cycle_count
= ltt_get_uint32(tf
->trace
->reverse_byte_order
,
1412 tf
->cur_event_pos
+ EVENT_ID_SIZE
);
1414 gboolean comp_count
= cycle_count
< tf
->pre_cycle_count
;
1416 tf
->pre_cycle_count
= cycle_count
;
1418 if(unlikely(comp_count
)) {
1420 tf
->overflow_nsec
+= tf
->one_overflow_nsec
;
1421 tf
->count
++; //increment overflow count
1424 if(unlikely(evId
== TRACE_BLOCK_START
)) {
1426 } else if(unlikely(evId
== TRACE_BLOCK_END
)) {
1427 lEventNSec
= ((double)
1428 (ltt_get_uint64(tf
->trace
->reverse_byte_order
,
1429 &tf
->a_block_end
->cycle_count
)
1430 - ltt_get_uint64(tf
->trace
->reverse_byte_order
,
1431 &tf
->a_block_start
->cycle_count
))
1432 * tf
->nsec_per_cycle
);
1435 /* If you want to make heart beat a special case and use their own 64 bits
1436 * TSC, activate this.
1438 else if(unlikely(evId
== TRACE_TIME_HEARTBEAT
)) {
1440 tf
->last_heartbeat
= (TimeHeartbeat
*)(tf
->cur_event_pos
+EVENT_HEADER_SIZE
);
1441 lEventNSec
= ((double)(tf
->last_heartbeat
->cycle_count
1442 - tf
->a_block_start
->cycle_count
)
1443 * tf
->nsec_per_cycle
);
1447 lEventNSec
= (gint64
)((double)cycle_count
* tf
->nsec_per_cycle
)
1451 lTimeOffset
= ltt_time_from_uint64(lEventNSec
);
1453 time
= ltt_time_add(ltt_get_time(tf
->trace
->reverse_byte_order
,
1454 &tf
->a_block_start
->time
), lTimeOffset
);
1459 /*****************************************************************************
1461 * setFieldsOffset : set offset of the fields
1463 * tracefile : opened trace file
1464 * evT : the event type
1465 * evD : event data, it may be NULL
1466 ****************************************************************************/
1468 void setFieldsOffset(LttTracefile
*tf
,LttEventType
*evT
,void *evD
,LttTrace
* t
)
1470 LttField
* rootFld
= evT
->root_field
;
1471 // rootFld->base_address = evD;
1474 rootFld
->field_size
= getFieldtypeSize(tf
, evT
, 0,0,rootFld
, evD
,t
);
1477 /*****************************************************************************
1479 * getFieldtypeSize: get the size of the field type (primitive type)
1481 * tracefile : opened trace file
1483 * offsetRoot : offset from the root
1484 * offsetParent : offset from the parrent
1486 * evD : event data, it may be NULL
1488 * int : size of the field
1489 ****************************************************************************/
1491 static inline gint
getFieldtypeSize(LttTracefile
* t
,
1492 LttEventType
* evT
, gint offsetRoot
,
1493 gint offsetParent
, LttField
* fld
, void *evD
, LttTrace
*trace
)
1495 gint size
, size1
, element_number
, i
, offset1
, offset2
;
1496 LttType
* type
= fld
->field_type
;
1498 if(unlikely(t
&& evT
->latest_block
==t
->which_block
&&
1499 evT
->latest_event
==t
->which_event
)){
1500 size
= fld
->field_size
;
1501 goto end_getFieldtypeSize
;
1503 /* This likely has been tested with gcov : half of them.. */
1504 if(unlikely(fld
->field_fixed
== 1)){
1506 if(unlikely(fld
== evT
->root_field
)) {
1507 size
= fld
->field_size
;
1508 goto end_getFieldtypeSize
;
1512 /* From gcov profiling : half string, half struct, can we gain something
1513 * from that ? (Mathieu) */
1514 switch(type
->type_class
) {
1516 element_number
= (int) type
->element_number
;
1517 if(fld
->field_fixed
== -1){
1518 size
= getFieldtypeSize(t
, evT
, offsetRoot
,
1519 0,fld
->child
[0], NULL
, trace
);
1520 if(size
== 0){ //has string or sequence
1521 fld
->field_fixed
= 0;
1523 fld
->field_fixed
= 1;
1524 size
*= element_number
;
1526 }else if(fld
->field_fixed
== 0){// has string or sequence
1528 for(i
=0;i
<element_number
;i
++){
1529 size
+= getFieldtypeSize(t
, evT
, offsetRoot
+size
,size
,
1530 fld
->child
[0], evD
+size
, trace
);
1532 }else size
= fld
->field_size
;
1534 fld
->fixed_root
= (offsetRoot
==-1) ? 0 : 1;
1535 fld
->fixed_parent
= (offsetParent
==-1) ? 0 : 1;
1541 size1
= (int) ltt_type_size(trace
, type
);
1542 if(fld
->field_fixed
== -1){
1543 fld
->sequ_number_size
= size1
;
1544 fld
->field_fixed
= 0;
1545 size
= getFieldtypeSize(t
, evT
, offsetRoot
,
1546 0,fld
->child
[0], NULL
, trace
);
1547 fld
->element_size
= size
;
1549 element_number
= getIntNumber(t
->trace
->reverse_byte_order
,size1
,evD
);
1550 type
->element_number
= element_number
;
1551 if(fld
->element_size
> 0){
1552 size
= element_number
* fld
->element_size
;
1553 }else{//sequence has string or sequence
1555 for(i
=0;i
<element_number
;i
++){
1556 size
+= getFieldtypeSize(t
, evT
, offsetRoot
+size
+size1
,size
+size1
,
1557 fld
->child
[0], evD
+size
+size1
, trace
);
1563 fld
->fixed_root
= (offsetRoot
==-1) ? 0 : 1;
1564 fld
->fixed_parent
= (offsetParent
==-1) ? 0 : 1;
1571 if(fld
->field_fixed
== -1){
1572 fld
->field_fixed
= 0;
1574 /* Hope my implementation is faster than strlen (Mathieu) */
1575 char *ptr
=(char*)evD
;
1577 /* from gcov : many many strings are empty, make it the common case.*/
1578 while(unlikely(*ptr
!= '\0')) { size
++; ptr
++; }
1579 //size = ptr - (char*)evD + 1; //include end : '\0'
1581 fld
->fixed_root
= (offsetRoot
==-1) ? 0 : 1;
1582 fld
->fixed_parent
= (offsetParent
==-1) ? 0 : 1;
1587 element_number
= (int) type
->element_number
;
1589 /* tested with gcov */
1590 if(unlikely(fld
->field_fixed
== -1)){
1591 offset1
= offsetRoot
;
1593 for(i
=0;i
<element_number
;i
++){
1594 size1
=getFieldtypeSize(t
, evT
,offset1
,offset2
,
1595 fld
->child
[i
], NULL
, trace
);
1596 if(likely(size1
> 0 && size
>= 0)){
1598 if(likely(offset1
>= 0)) offset1
+= size1
;
1606 if(unlikely(size
== -1)){
1607 fld
->field_fixed
= 0;
1609 }else fld
->field_fixed
= 1;
1610 }else if(likely(fld
->field_fixed
== 0)){
1611 offset1
= offsetRoot
;
1613 for(i
=0;unlikely(i
<element_number
);i
++){
1614 size
=getFieldtypeSize(t
,evT
,offset1
,offset2
,
1615 fld
->child
[i
],evD
+offset2
, trace
);
1620 }else size
= fld
->field_size
;
1621 fld
->fixed_root
= (offsetRoot
==-1) ? 0 : 1;
1622 fld
->fixed_parent
= (offsetParent
==-1) ? 0 : 1;
1626 if(unlikely(fld
->field_fixed
== -1)){
1627 size
= (int) ltt_type_size(trace
, type
);
1628 fld
->field_fixed
= 1;
1629 }else size
= fld
->field_size
;
1631 fld
->fixed_root
= (offsetRoot
==-1) ? 0 : 1;
1632 fld
->fixed_parent
= (offsetParent
==-1) ? 0 : 1;
1638 fld
->offset_root
= offsetRoot
;
1639 fld
->offset_parent
= offsetParent
;
1640 fld
->field_size
= size
;
1642 end_getFieldtypeSize
:
1648 /*****************************************************************************
1650 * getIntNumber : get an integer number
1652 * size : the size of the integer
1653 * evD : the event data
1655 * gint64 : a 64 bits integer
1656 ****************************************************************************/
1658 gint64
getIntNumber(gboolean reverse_byte_order
, int size
, void *evD
)
1663 case 1: i
= *((gint8
*)evD
); break;
1664 case 2: i
= ltt_get_int16(reverse_byte_order
, evD
); break;
1665 case 4: i
= ltt_get_int32(reverse_byte_order
, evD
); break;
1666 case 8: i
= ltt_get_int64(reverse_byte_order
, evD
); break;
1667 default: i
= ltt_get_int64(reverse_byte_order
, evD
);
1668 g_critical("getIntNumber : integer size %d unknown", size
);
1675 /*****************************************************************************
1677 * getDataEndianType : get the data type size and endian type of the local
1680 * size : size of data type
1681 * endian : endian type, little or big
1682 ****************************************************************************/
1684 void getDataEndianType(LttArchSize
* size
, LttArchEndian
* endian
)
1688 int sizeInt
=sizeof(int), sizeLong
=sizeof(long), sizePointer
=sizeof(void *);
1690 if(c
== 1) *endian
= LTT_LITTLE_ENDIAN
;
1691 else *endian
= LTT_BIG_ENDIAN
;
1693 if(sizeInt
== 2 && sizeLong
== 4 && sizePointer
== 4)
1695 else if(sizeInt
== 4 && sizeLong
== 4 && sizePointer
== 4)
1697 else if(sizeInt
== 4 && sizeLong
== 8 && sizePointer
== 8)
1699 else if(sizeInt
== 8 && sizeLong
== 8 && sizePointer
== 8)
1701 else *size
= LTT_UNKNOWN
;
1704 /* get the node name of the system */
1706 char * ltt_trace_system_description_node_name (LttSystemDescription
* s
)
1708 return s
->node_name
;
1712 /* get the domain name of the system */
1714 char * ltt_trace_system_description_domain_name (LttSystemDescription
* s
)
1716 return s
->domain_name
;
1720 /* get the description of the system */
1722 char * ltt_trace_system_description_description (LttSystemDescription
* s
)
1724 return s
->description
;
1728 /* get the start time of the trace */
1730 LttTime
ltt_trace_system_description_trace_start_time(LttSystemDescription
*s
)
1732 return s
->trace_start
;
1736 LttTracefile
*ltt_tracefile_new()
1738 return g_new(LttTracefile
, 1);
1741 void ltt_tracefile_destroy(LttTracefile
*tf
)
1746 void ltt_tracefile_copy(LttTracefile
*dest
, const LttTracefile
*src
)