1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2005 Mathieu Desnoyers
4 * Complete rewrite from the original version made by XangXiu Yang.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License Version 2 as
8 * published by the Free Software Foundation;
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
30 #include <sys/types.h>
45 #include "ltt-private.h"
46 #include <ltt/trace.h>
47 #include <ltt/facility.h>
48 #include <ltt/event.h>
50 #include <ltt/ltt-types.h>
53 /* Facility names used in this file */
55 GQuark LTT_FACILITY_NAME_HEARTBEAT
,
56 LTT_EVENT_NAME_HEARTBEAT
;
57 GQuark LTT_TRACEFILE_NAME_FACILITIES
;
64 #define __UNUSED__ __attribute__((__unused__))
66 #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
69 #define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format)
74 /* Those macros must be called from within a function where page_size is a known
76 #define PAGE_MASK (~(page_size-1))
77 #define PAGE_ALIGN(addr) (((addr)+page_size-1)&PAGE_MASK)
79 /* set the offset of the fields belonging to the event,
80 need the information of the archecture */
81 //void set_fields_offsets(LttTracefile *tf, LttEventType *event_type);
82 //size_t get_fields_offsets(LttTracefile *tf, LttEventType *event_type, void *data);
84 /* get the size of the field type according to
85 * The facility size information. */
87 static inline void preset_field_type_size(LttTracefile
*tf
,
88 LttEventType
*event_type
,
89 off_t offset_root
, off_t offset_parent
,
90 enum field_status
*fixed_root
, enum field_status
*fixed_parent
,
94 /* map a fixed size or a block information from the file (fd) */
95 static gint
map_block(LttTracefile
* tf
, guint block_num
);
97 /* calculate nsec per cycles for current block */
99 static guint32
calc_nsecs_per_cycle(LttTracefile
* t
);
100 static guint64
cycles_2_ns(LttTracefile
*tf
, guint64 cycles
);
103 /* go to the next event */
104 static int ltt_seek_next_event(LttTracefile
*tf
);
106 void ltt_update_event_size(LttTracefile
*tf
);
109 /* Functions to parse system.xml file (using glib xml parser) */
110 static void parser_start_element (GMarkupParseContext __UNUSED__
*context
,
111 const gchar
*element_name
,
112 const gchar
**attribute_names
,
113 const gchar
**attribute_values
,
118 LttSystemDescription
* des
= (LttSystemDescription
* )user_data
;
119 if(strcmp("system", element_name
)){
120 *error
= g_error_new(G_MARKUP_ERROR
,
122 "This is not system.xml file");
126 while(attribute_names
[i
]){
127 if(strcmp("node_name", attribute_names
[i
])==0){
128 des
->node_name
= g_strdup(attribute_values
[i
]);
129 }else if(strcmp("domainname", attribute_names
[i
])==0){
130 des
->domain_name
= g_strdup(attribute_values
[i
]);
131 }else if(strcmp("cpu", attribute_names
[i
])==0){
132 des
->nb_cpu
= atoi(attribute_values
[i
]);
133 }else if(strcmp("arch_size", attribute_names
[i
])==0){
134 if(strcmp(attribute_values
[i
],"LP32") == 0) des
->size
= LTT_LP32
;
135 else if(strcmp(attribute_values
[i
],"ILP32") == 0) des
->size
= LTT_ILP32
;
136 else if(strcmp(attribute_values
[i
],"LP64") == 0) des
->size
= LTT_LP64
;
137 else if(strcmp(attribute_values
[i
],"ILP64") == 0) des
->size
= LTT_ILP64
;
138 else if(strcmp(attribute_values
[i
],"UNKNOWN") == 0) des
->size
= LTT_UNKNOWN
;
139 }else if(strcmp("endian", attribute_names
[i
])==0){
140 if(strcmp(attribute_values
[i
],"LITTLE_ENDIAN") == 0)
141 des
->endian
= LTT_LITTLE_ENDIAN
;
142 else if(strcmp(attribute_values
[i
],"BIG_ENDIAN") == 0)
143 des
->endian
= LTT_BIG_ENDIAN
;
144 }else if(strcmp("kernel_name", attribute_names
[i
])==0){
145 des
->kernel_name
= g_strdup(attribute_values
[i
]);
146 }else if(strcmp("kernel_release", attribute_names
[i
])==0){
147 des
->kernel_release
= g_strdup(attribute_values
[i
]);
148 }else if(strcmp("kernel_version", attribute_names
[i
])==0){
149 des
->kernel_version
= g_strdup(attribute_values
[i
]);
150 }else if(strcmp("machine", attribute_names
[i
])==0){
151 des
->machine
= g_strdup(attribute_values
[i
]);
152 }else if(strcmp("processor", attribute_names
[i
])==0){
153 des
->processor
= g_strdup(attribute_values
[i
]);
154 }else if(strcmp("hardware_platform", attribute_names
[i
])==0){
155 des
->hardware_platform
= g_strdup(attribute_values
[i
]);
156 }else if(strcmp("operating_system", attribute_names
[i
])==0){
157 des
->operating_system
= g_strdup(attribute_values
[i
]);
158 }else if(strcmp("ltt_major_version", attribute_names
[i
])==0){
159 des
->ltt_major_version
= atoi(attribute_values
[i
]);
160 }else if(strcmp("ltt_minor_version", attribute_names
[i
])==0){
161 des
->ltt_minor_version
= atoi(attribute_values
[i
]);
162 }else if(strcmp("ltt_block_size", attribute_names
[i
])==0){
163 des
->ltt_block_size
= atoi(attribute_values
[i
]);
165 *error
= g_error_new(G_MARKUP_ERROR
,
167 "Not a valid attribute");
174 static void parser_characters (GMarkupParseContext __UNUSED__
*context
,
176 gsize __UNUSED__ text_len
,
178 GError __UNUSED__
**error
)
180 LttSystemDescription
* des
= (LttSystemDescription
* )user_data
;
181 des
->description
= g_strdup(text
);
186 LttFacility
*ltt_trace_get_facility_by_num(LttTrace
*t
,
189 g_assert(num
< t
->facilities_by_num
->len
);
191 return &g_array_index(t
->facilities_by_num
, LttFacility
, num
);
195 guint
ltt_trace_get_num_cpu(LttTrace
*t
)
203 * Return value : 0 success, 1 bad tracefile
205 int parse_trace_header(void *header
, LttTracefile
*tf
, LttTrace
*t
)
207 guint32
*magic_number
= (guint32
*)header
;
208 struct ltt_trace_header_any
*any
= (struct ltt_trace_header_any
*)header
;
210 if(*magic_number
== LTT_MAGIC_NUMBER
)
212 else if(*magic_number
== LTT_REV_MAGIC_NUMBER
)
214 else /* invalid magic number, bad tracefile ! */
217 /* Get float byte order : might be different from int byte order
218 * (or is set to 0 if the trace has no float (kernel trace)) */
219 tf
->float_word_order
= any
->float_word_order
;
220 tf
->has_alignment
= any
->has_alignment
;
223 t
->arch_type
= ltt_get_uint32(LTT_GET_BO(tf
),
225 t
->arch_variant
= ltt_get_uint32(LTT_GET_BO(tf
),
227 t
->arch_size
= any
->arch_size
;
228 t
->ltt_major_version
= any
->major_version
;
229 t
->ltt_minor_version
= any
->minor_version
;
230 t
->flight_recorder
= any
->flight_recorder
;
231 t
->has_heartbeat
= any
->has_heartbeat
;
232 t
->has_tsc
= any
->has_tsc
;
236 switch(any
->major_version
) {
239 switch(any
->minor_version
) {
242 tf
->buffer_header_size
=
243 sizeof(struct ltt_block_start_header
)
244 + sizeof(struct ltt_trace_header_0_3
);
245 g_warning("Unsupported trace version : %hhu.%hhu",
246 any
->major_version
, any
->minor_version
);
252 struct ltt_trace_header_0_4
*vheader
=
253 (struct ltt_trace_header_0_4
*)header
;
254 tf
->buffer_header_size
=
255 sizeof(struct ltt_block_start_header
)
256 + sizeof(struct ltt_trace_header_0_4
);
258 t
->start_freq
= ltt_get_uint64(LTT_GET_BO(tf
),
259 &vheader
->start_freq
);
260 t
->start_tsc
= ltt_get_uint64(LTT_GET_BO(tf
),
261 &vheader
->start_tsc
);
262 t
->start_monotonic
= ltt_get_uint64(LTT_GET_BO(tf
),
263 &vheader
->start_monotonic
);
264 t
->start_time
= ltt_get_time(LTT_GET_BO(tf
),
265 &vheader
->start_time
);
266 t
->start_time
.tv_nsec
*= 1000; /* microsec to nanosec */
268 t
->start_time_from_tsc
= ltt_time_from_uint64(
269 (double)t
->start_tsc
* 1000000.0 / (double)t
->start_freq
);
274 g_warning("Unsupported trace version : %hhu.%hhu",
275 any
->major_version
, any
->minor_version
);
281 g_warning("Unsupported trace version : %hhu.%hhu",
282 any
->major_version
, any
->minor_version
);
292 /*****************************************************************************
294 * ltt_tracefile_open : open a trace file, construct a LttTracefile
296 * t : the trace containing the tracefile
297 * fileName : path name of the trace file
298 * tf : the tracefile structure
300 * : 0 for success, -1 otherwise.
301 ****************************************************************************/
303 gint
ltt_tracefile_open(LttTrace
*t
, gchar
* fileName
, LttTracefile
*tf
)
305 struct stat lTDFStat
; /* Trace data file status */
306 struct ltt_block_start_header
*header
;
307 int page_size
= getpagesize();
310 tf
->long_name
= g_quark_from_string(fileName
);
312 tf
->fd
= open(fileName
, O_RDONLY
);
314 g_warning("Unable to open input data file %s\n", fileName
);
318 // Get the file's status
319 if(fstat(tf
->fd
, &lTDFStat
) < 0){
320 g_warning("Unable to get the status of the input data file %s\n", fileName
);
324 // Is the file large enough to contain a trace
325 if(lTDFStat
.st_size
<
326 (off_t
)(sizeof(struct ltt_block_start_header
)
327 + sizeof(struct ltt_trace_header_any
))){
328 g_print("The input data file %s does not contain a trace\n", fileName
);
332 /* Temporarily map the buffer start header to get trace information */
333 /* Multiple of pages aligned head */
334 tf
->buffer
.head
= mmap(0,
335 PAGE_ALIGN(sizeof(struct ltt_block_start_header
)
336 + sizeof(struct ltt_trace_header_any
)), PROT_READ
,
337 MAP_PRIVATE
, tf
->fd
, 0);
338 if(tf
->buffer
.head
== MAP_FAILED
) {
339 perror("Error in allocating memory for buffer of tracefile");
342 g_assert( ( (guint
)tf
->buffer
.head
&(8-1) ) == 0); // make sure it's aligned.
344 header
= (struct ltt_block_start_header
*)tf
->buffer
.head
;
346 if(parse_trace_header(header
->trace
, tf
, NULL
)) {
347 g_warning("parse_trace_header error");
351 //store the size of the file
352 tf
->file_size
= lTDFStat
.st_size
;
353 tf
->buf_size
= ltt_get_uint32(LTT_GET_BO(tf
), &header
->buf_size
);
354 tf
->num_blocks
= tf
->file_size
/ tf
->buf_size
;
356 if(munmap(tf
->buffer
.head
,
357 PAGE_ALIGN(sizeof(struct ltt_block_start_header
)
358 + sizeof(struct ltt_trace_header_any
)))) {
359 g_warning("unmap size : %u\n",
360 PAGE_ALIGN(sizeof(struct ltt_block_start_header
)
361 + sizeof(struct ltt_trace_header_any
)));
362 perror("munmap error");
365 tf
->buffer
.head
= NULL
;
367 //read the first block
368 if(map_block(tf
,0)) {
369 perror("Cannot map block for tracefile");
377 if(munmap(tf
->buffer
.head
,
378 PAGE_ALIGN(sizeof(struct ltt_block_start_header
)
379 + sizeof(struct ltt_trace_header_any
)))) {
380 g_warning("unmap size : %u\n",
381 PAGE_ALIGN(sizeof(struct ltt_block_start_header
)
382 + sizeof(struct ltt_trace_header_any
)));
383 perror("munmap error");
392 LttTrace
*ltt_tracefile_get_trace(LttTracefile
*tf
)
398 /*****************************************************************************
399 *Open control and per cpu tracefiles
400 ****************************************************************************/
402 void ltt_tracefile_open_cpu(LttTrace
*t
, gchar
* tracefile_name
)
405 tf
= ltt_tracefile_open(t
,tracefile_name
);
407 t
->per_cpu_tracefile_number
++;
408 g_ptr_array_add(t
->per_cpu_tracefiles
, tf
);
411 gint
ltt_tracefile_open_control(LttTrace
*t
, gchar
* control_name
)
420 tf
= ltt_tracefile_open(t
,control_name
);
422 g_warning("ltt_tracefile_open_control : bad file descriptor");
425 t
->control_tracefile_number
++;
426 g_ptr_array_add(t
->control_tracefiles
,tf
);
428 //parse facilities tracefile to get base_id
429 if(strcmp(&control_name
[strlen(control_name
)-10],"facilities") ==0){
431 if(!ltt_tracefile_read(tf
,&ev
)) return 0; // end of file
433 if(ev
.event_id
== TRACE_FACILITY_LOAD
){
435 fLoad
.name
= (gchar
*)pos
;
436 fLoad
.checksum
= *(LttChecksum
*)(pos
+ strlen(fLoad
.name
));
437 fLoad
.base_code
= *(guint32
*)(pos
+ strlen(fLoad
.name
) + sizeof(LttChecksum
));
439 for(i
=0;i
<t
->facility_number
;i
++){
440 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
,i
);
441 if(strcmp(f
->name
,fLoad
.name
)==0 && fLoad
.checksum
==f
->checksum
){
442 f
->base_id
= fLoad
.base_code
;
446 if(i
==t
->facility_number
) {
447 g_warning("Facility: %s, checksum: %u is not found",
448 fLoad
.name
,(unsigned int)fLoad
.checksum
);
451 }else if(ev
.event_id
== TRACE_BLOCK_START
){
453 }else if(ev
.event_id
== TRACE_BLOCK_END
){
456 g_warning("Not valid facilities trace file");
465 /*****************************************************************************
467 * ltt_tracefile_close: close a trace file,
469 * t : tracefile which will be closed
470 ****************************************************************************/
472 void ltt_tracefile_close(LttTracefile
*t
)
474 int page_size
= getpagesize();
476 if(t
->buffer
.head
!= NULL
)
477 if(munmap(t
->buffer
.head
, PAGE_ALIGN(t
->buf_size
))) {
478 g_warning("unmap size : %u\n",
479 PAGE_ALIGN(t
->buf_size
));
480 perror("munmap error");
488 /*****************************************************************************
489 *Get system information
490 ****************************************************************************/
492 gint
getSystemInfo(LttSystemDescription
* des
, gchar
* pathname
)
499 GMarkupParseContext
* context
;
500 GError
* error
= NULL
;
501 GMarkupParser markup_parser
=
503 parser_start_element
,
506 NULL
, /* passthrough */
510 fd
= g_open(pathname
, O_RDONLY
, 0);
512 g_warning("Can not open file : %s\n", pathname
);
516 iochan
= g_io_channel_unix_new(fd
);
518 context
= g_markup_parse_context_new(&markup_parser
, 0, des
,NULL
);
520 //while(fgets(buf,DIR_NAME_SIZE, fp) != NULL){
521 while(g_io_channel_read_line(iochan
, &buf
, &length
, NULL
, &error
)
522 != G_IO_STATUS_EOF
) {
525 g_warning("Can not read xml file: \n%s\n", error
->message
);
528 if(!g_markup_parse_context_parse(context
, buf
, length
, &error
)){
530 g_warning("Can not parse xml file: \n%s\n", error
->message
);
533 g_markup_parse_context_free(context
);
535 g_io_channel_shutdown(iochan
, FALSE
, &error
); /* No flush */
537 g_warning("Can not close file: \n%s\n", error
->message
);
545 g_markup_parse_context_free(context
);
547 g_io_channel_shutdown(iochan
, FALSE
, &error
); /* No flush */
549 g_warning("Can not close file: \n%s\n", error
->message
);
560 /*****************************************************************************
561 *The following functions get facility/tracefile information
562 ****************************************************************************/
564 gint
getFacilityInfo(LttTrace
*t
, gchar
* eventdefs
)
571 gchar fullname
[DIR_NAME_SIZE
];
572 GError
* error
= NULL
;
574 dir
= g_dir_open(eventdefs
, 0, &error
);
577 g_warning("Can not open directory: %s, %s\n", eventdefs
, error
->message
);
582 while((name
= g_dir_read_name(dir
)) != NULL
){
583 if(!g_pattern_match_simple("*.xml", name
)) continue;
584 strcpy(fullname
,eventdefs
);
585 strcat(fullname
,name
);
586 ltt_facility_open(t
,fullname
);
590 for(j
=0;j
<t
->facility_number
;j
++){
591 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
, j
);
592 for(i
=0; i
<f
->event_number
; i
++){
594 setFieldsOffset(NULL
, et
, NULL
, t
);
601 /*****************************************************************************
602 *A trace is specified as a pathname to the directory containing all the
603 *associated data (control tracefiles, per cpu tracefiles, event
606 *When a trace is closed, all the associated facilities, types and fields
607 *are released as well.
611 /****************************************************************************
612 * get_absolute_pathname
614 * return the unique pathname in the system
616 * MD : Fixed this function so it uses realpath, dealing well with
617 * forgotten cases (.. were not used correctly before).
619 ****************************************************************************/
620 void get_absolute_pathname(const gchar
*pathname
, gchar
* abs_pathname
)
622 abs_pathname
[0] = '\0';
624 if ( realpath (pathname
, abs_pathname
) != NULL
)
628 /* error, return the original path unmodified */
629 strcpy(abs_pathname
, pathname
);
635 /* Search for something like : .*_.*
637 * The left side is the name, the right side is the number.
640 int get_tracefile_name_number(const gchar
*raw_name
,
644 guint raw_name_len
= strlen(raw_name
);
645 gchar char_name
[PATH_MAX
];
651 for(i
=raw_name_len
-1;i
>=0;i
--) {
652 if(raw_name
[i
] == '_') break;
654 if(i
==0) /* Either not found or name length is 0 */
658 cpu_num
= strtol(raw_name
+underscore_pos
+1, &endptr
, 10);
660 if(endptr
== raw_name
+underscore_pos
+1)
661 return -1; /* No digit */
662 if(cpu_num
== LONG_MIN
|| cpu_num
== LONG_MAX
)
663 return -1; /* underflow / overflow */
665 strncpy(char_name
, raw_name
, underscore_pos
);
667 char_name
[underscore_pos
] = '\0';
669 *name
= g_quark_from_string(char_name
);
676 GData
**ltt_trace_get_tracefiles_groups(LttTrace
*trace
)
678 return &trace
->tracefiles
;
682 void compute_tracefile_group(GQuark key_id
,
684 struct compute_tracefile_group_args
*args
)
689 for(i
=0; i
<group
->len
; i
++) {
690 tf
= &g_array_index (group
, LttTracefile
, i
);
692 args
->func(tf
, args
->func_args
);
697 void ltt_tracefile_group_destroy(gpointer data
)
699 GArray
*group
= (GArray
*)data
;
703 for(i
=0; i
<group
->len
; i
++) {
704 tf
= &g_array_index (group
, LttTracefile
, i
);
706 ltt_tracefile_close(tf
);
708 g_array_free(group
, TRUE
);
711 gboolean
ltt_tracefile_group_has_cpu_online(gpointer data
)
713 GArray
*group
= (GArray
*)data
;
717 for(i
=0; i
<group
->len
; i
++) {
718 tf
= &g_array_index (group
, LttTracefile
, i
);
719 if(tf
->cpu_online
) return 1;
725 /* Open each tracefile under a specific directory. Put them in a
726 * GData : permits to access them using their tracefile group pathname.
727 * i.e. access control/modules tracefile group by index :
730 * relative path is the path relative to the trace root
731 * root path is the full path
733 * A tracefile group is simply an array where all the per cpu tracefiles sits.
736 static int open_tracefiles(LttTrace
*trace
, gchar
*root_path
,
737 gchar
*relative_path
)
739 DIR *dir
= opendir(root_path
);
740 struct dirent
*entry
;
741 struct stat stat_buf
;
744 gchar path
[PATH_MAX
];
749 gchar rel_path
[PATH_MAX
];
758 strncpy(path
, root_path
, PATH_MAX
-1);
759 path_len
= strlen(path
);
760 path
[path_len
] = '/';
762 path_ptr
= path
+ path_len
;
764 strncpy(rel_path
, relative_path
, PATH_MAX
-1);
765 rel_path_len
= strlen(rel_path
);
766 rel_path
[rel_path_len
] = '/';
768 rel_path_ptr
= rel_path
+ rel_path_len
;
770 while((entry
= readdir(dir
)) != NULL
) {
772 if(entry
->d_name
[0] == '.') continue;
774 strncpy(path_ptr
, entry
->d_name
, PATH_MAX
- path_len
);
775 strncpy(rel_path_ptr
, entry
->d_name
, PATH_MAX
- rel_path_len
);
777 ret
= stat(path
, &stat_buf
);
783 g_debug("Tracefile file or directory : %s\n", path
);
785 if(strcmp(rel_path
, "/eventdefs") == 0) continue;
787 if(S_ISDIR(stat_buf
.st_mode
)) {
789 g_debug("Entering subdirectory...\n");
790 ret
= open_tracefiles(trace
, path
, rel_path
);
791 if(ret
< 0) continue;
792 } else if(S_ISREG(stat_buf
.st_mode
)) {
797 if(get_tracefile_name_number(rel_path
, &name
, &num
))
798 continue; /* invalid name */
800 g_debug("Opening file.\n");
801 if(ltt_tracefile_open(trace
, path
, &tmp_tf
)) {
802 g_info("Error opening tracefile %s", path
);
804 continue; /* error opening the tracefile : bad magic number ? */
807 g_debug("Tracefile name is %s and number is %u",
808 g_quark_to_string(name
), num
);
810 tmp_tf
.cpu_online
= 1;
811 tmp_tf
.cpu_num
= num
;
814 group
= g_datalist_id_get_data(&trace
->tracefiles
, name
);
816 /* Elements are automatically cleared when the array is allocated.
817 * It makes the cpu_online variable set to 0 : cpu offline, by default.
819 group
= g_array_sized_new (FALSE
, TRUE
, sizeof(LttTracefile
), 10);
820 g_datalist_id_set_data_full(&trace
->tracefiles
, name
,
821 group
, ltt_tracefile_group_destroy
);
824 /* Add the per cpu tracefile to the named group */
825 unsigned int old_len
= group
->len
;
827 group
= g_array_set_size(group
, num
+1);
828 g_array_index (group
, LttTracefile
, num
) = tmp_tf
;
838 /* ltt_get_facility_description
840 * Opens the file corresponding to the requested facility (identified by fac_id
843 * The name searched is : %trace root%/eventdefs/facname_checksum.xml
845 * Returns 0 on success, or 1 on failure.
848 static int ltt_get_facility_description(LttFacility
*f
,
850 LttTracefile
*fac_tf
)
852 char desc_file_name
[PATH_MAX
];
857 text
= g_quark_to_string(t
->pathname
);
858 textlen
= strlen(text
);
860 if(textlen
>= PATH_MAX
) goto name_error
;
861 strcpy(desc_file_name
, text
);
863 text
= "/eventdefs/";
864 textlen
+=strlen(text
);
865 if(textlen
>= PATH_MAX
) goto name_error
;
866 strcat(desc_file_name
, text
);
868 text
= g_quark_to_string(f
->name
);
869 textlen
+=strlen(text
);
870 if(textlen
>= PATH_MAX
) goto name_error
;
871 strcat(desc_file_name
, text
);
874 textlen
+=strlen(text
);
875 if(textlen
>= PATH_MAX
) goto name_error
;
876 strcat(desc_file_name
, text
);
878 err
= snprintf(desc_file_name
+textlen
, PATH_MAX
-textlen
-1,
880 if(err
< 0) goto name_error
;
882 textlen
=strlen(desc_file_name
);
886 textlen
+=strlen(text
);
887 if(textlen
>= PATH_MAX
) goto name_error
;
888 strcat(desc_file_name
, text
);
890 err
= ltt_facility_open(f
, t
, desc_file_name
);
891 if(err
) goto facility_error
;
900 static void ltt_fac_ids_destroy(gpointer data
)
902 GArray
*fac_ids
= (GArray
*)data
;
904 g_array_free(fac_ids
, TRUE
);
908 /* Presumes the tracefile is already seeked at the beginning. It makes sense,
909 * because it must be done just after the opening */
910 static int ltt_process_facility_tracefile(LttTracefile
*tf
)
919 err
= ltt_tracefile_read_seek(tf
);
920 if(err
== EPERM
) goto seek_error
;
921 else if(err
== ERANGE
) break; /* End of tracefile */
923 err
= ltt_tracefile_read_update_event(tf
);
924 if(err
) goto update_error
;
926 /* We are on a facility load/or facility unload/ or heartbeat event */
928 * * facility 0 is hardcoded : this is the core facility. It will be shown
929 * in the facility array though, and is shown as "loaded builtin" in the
931 * It contains event :
933 * 1 : facility unload
934 * 2 : state dump facility load
937 if(tf
->event
.facility_id
!= LTT_FACILITY_CORE
) {
938 /* Should only contain core facility */
939 g_warning("Error in processing facility file %s, "
940 "should not contain facility id %u.", g_quark_to_string(tf
->name
),
941 tf
->event
.facility_id
);
946 struct LttFacilityLoad
*fac_load_data
;
947 struct LttStateDumpFacilityLoad
*fac_state_dump_load_data
;
951 switch((enum ltt_core_events
)tf
->event
.event_id
) {
952 case LTT_EVENT_FACILITY_LOAD
:
953 fac_name
= (char*)(tf
->event
.data
);
954 g_debug("Doing LTT_EVENT_FACILITY_LOAD of facility %s",
957 (struct LttFacilityLoad
*)
958 (tf
->event
.data
+ strlen(fac_name
) + 1);
959 fac
= &g_array_index (tf
->trace
->facilities_by_num
, LttFacility
,
960 ltt_get_uint32(LTT_GET_BO(tf
), &fac_load_data
->id
));
961 /* facility may already exist if trace is paused/unpaused */
962 if(fac
->exists
) continue;
963 fac
->name
= g_quark_from_string(fac_name
);
964 fac
->checksum
= ltt_get_uint32(LTT_GET_BO(tf
),
965 &fac_load_data
->checksum
);
966 fac
->id
= ltt_get_uint32(LTT_GET_BO(tf
), &fac_load_data
->id
);
967 fac
->pointer_size
= ltt_get_uint32(LTT_GET_BO(tf
),
968 &fac_load_data
->pointer_size
);
969 fac
->int_size
= ltt_get_uint32(LTT_GET_BO(tf
),
970 &fac_load_data
->int_size
);
971 fac
->long_size
= ltt_get_uint32(LTT_GET_BO(tf
),
972 &fac_load_data
->long_size
);
973 fac
->size_t_size
= ltt_get_uint32(LTT_GET_BO(tf
),
974 &fac_load_data
->size_t_size
);
975 fac
->alignment
= ltt_get_uint32(LTT_GET_BO(tf
),
976 &fac_load_data
->alignment
);
978 if(ltt_get_facility_description(fac
, tf
->trace
, tf
))
979 continue; /* error opening description */
981 fac
->trace
= tf
->trace
;
983 /* Preset the field offsets */
984 for(i
=0; i
<fac
->events
->len
; i
++){
985 et
= &g_array_index(fac
->events
, LttEventType
, i
);
986 precompute_offsets(tf
, et
);
991 fac_ids
= g_datalist_id_get_data(&tf
->trace
->facilities_by_name
,
993 if(fac_ids
== NULL
) {
994 fac_ids
= g_array_sized_new (FALSE
, TRUE
, sizeof(guint
), 1);
995 g_datalist_id_set_data_full(&tf
->trace
->facilities_by_name
,
997 fac_ids
, ltt_fac_ids_destroy
);
999 g_array_append_val(fac_ids
, fac
->id
);
1002 case LTT_EVENT_FACILITY_UNLOAD
:
1003 g_debug("Doing LTT_EVENT_FACILITY_UNLOAD");
1004 /* We don't care about unload : facilities ID are valid for the whole
1005 * trace. They simply won't be used after the unload. */
1007 case LTT_EVENT_STATE_DUMP_FACILITY_LOAD
:
1008 fac_name
= (char*)(tf
->event
.data
);
1009 g_debug("Doing LTT_EVENT_STATE_DUMP_FACILITY_LOAD of facility %s",
1011 fac_state_dump_load_data
=
1012 (struct LttStateDumpFacilityLoad
*)
1013 (tf
->event
.data
+ strlen(fac_name
) + 1);
1014 fac
= &g_array_index (tf
->trace
->facilities_by_num
, LttFacility
,
1015 ltt_get_uint32(LTT_GET_BO(tf
), &fac_state_dump_load_data
->id
));
1016 /* facility may already exist if trace is paused/unpaused */
1017 if(fac
->exists
) continue;
1018 fac
->name
= g_quark_from_string(fac_name
);
1019 fac
->checksum
= ltt_get_uint32(LTT_GET_BO(tf
),
1020 &fac_state_dump_load_data
->checksum
);
1021 fac
->id
= ltt_get_uint32(LTT_GET_BO(tf
),
1022 &fac_state_dump_load_data
->id
);
1023 fac
->pointer_size
= ltt_get_uint32(LTT_GET_BO(tf
),
1024 &fac_state_dump_load_data
->pointer_size
);
1025 fac
->int_size
= ltt_get_uint32(LTT_GET_BO(tf
),
1026 &fac_state_dump_load_data
->int_size
);
1027 fac
->long_size
= ltt_get_uint32(LTT_GET_BO(tf
),
1028 &fac_state_dump_load_data
->long_size
);
1029 fac
->size_t_size
= ltt_get_uint32(LTT_GET_BO(tf
),
1030 &fac_state_dump_load_data
->size_t_size
);
1031 fac
->alignment
= ltt_get_uint32(LTT_GET_BO(tf
),
1032 &fac_state_dump_load_data
->alignment
);
1033 if(ltt_get_facility_description(fac
, tf
->trace
, tf
))
1034 continue; /* error opening description */
1036 fac
->trace
= tf
->trace
;
1038 /* Preset the field offsets */
1039 for(i
=0; i
<fac
->events
->len
; i
++){
1040 et
= &g_array_index(fac
->events
, LttEventType
, i
);
1041 precompute_offsets(tf
, et
);
1046 fac_ids
= g_datalist_id_get_data(&tf
->trace
->facilities_by_name
,
1048 if(fac_ids
== NULL
) {
1049 fac_ids
= g_array_sized_new (FALSE
, TRUE
, sizeof(guint
), 1);
1050 g_datalist_id_set_data_full(&tf
->trace
->facilities_by_name
,
1052 fac_ids
, ltt_fac_ids_destroy
);
1054 g_array_append_val(fac_ids
, fac
->id
);
1057 case LTT_EVENT_HEARTBEAT
:
1060 g_warning("Error in processing facility file %s, "
1061 "unknown event id %hhu in core facility.",
1062 g_quark_to_string(tf
->name
),
1063 tf
->event
.event_id
);
1065 goto event_id_error
;
1071 /* Error handling */
1076 g_warning("An error occured in facility tracefile parsing");
1081 LttTrace
*ltt_trace_open(const gchar
*pathname
)
1083 gchar abs_path
[PATH_MAX
];
1088 struct ltt_block_start_header
*header
;
1090 struct dirent
*entry
;
1091 guint control_found
= 0;
1092 guint eventdefs_found
= 0;
1093 struct stat stat_buf
;
1094 gchar path
[PATH_MAX
];
1096 t
= g_new(LttTrace
, 1);
1097 if(!t
) goto alloc_error
;
1099 get_absolute_pathname(pathname
, abs_path
);
1100 t
->pathname
= g_quark_from_string(abs_path
);
1102 g_datalist_init(&t
->tracefiles
);
1104 /* Test to see if it looks like a trace */
1105 dir
= opendir(abs_path
);
1110 while((entry
= readdir(dir
)) != NULL
) {
1111 strcpy(path
, abs_path
);
1113 strcat(path
, entry
->d_name
);
1114 ret
= stat(path
, &stat_buf
);
1119 if(S_ISDIR(stat_buf
.st_mode
)) {
1120 if(strcmp(entry
->d_name
, "control") == 0) {
1123 if(strcmp(entry
->d_name
, "eventdefs") == 0) {
1124 eventdefs_found
= 1;
1130 if(!control_found
|| !eventdefs_found
) goto find_error
;
1132 /* Open all the tracefiles */
1133 if(open_tracefiles(t
, abs_path
, "")) {
1134 g_warning("Error opening tracefile %s", abs_path
);
1138 /* Prepare the facilities containers : array and mapping */
1139 /* Array is zeroed : the "exists" field is set to false by default */
1140 t
->facilities_by_num
= g_array_sized_new (FALSE
,
1141 TRUE
, sizeof(LttFacility
),
1143 t
->facilities_by_num
= g_array_set_size(t
->facilities_by_num
, NUM_FACILITIES
);
1145 g_datalist_init(&t
->facilities_by_name
);
1147 /* Parse each trace control/facilitiesN files : get runtime fac. info */
1148 group
= g_datalist_id_get_data(&t
->tracefiles
, LTT_TRACEFILE_NAME_FACILITIES
);
1150 g_error("Trace %s has no facility tracefile", abs_path
);
1152 goto facilities_error
;
1155 /* Get the trace information for the control/facility 0 tracefile */
1156 g_assert(group
->len
> 0);
1157 tf
= &g_array_index (group
, LttTracefile
, 0);
1158 header
= (struct ltt_block_start_header
*)tf
->buffer
.head
;
1159 g_assert(parse_trace_header(header
->trace
,
1162 t
->num_cpu
= group
->len
;
1164 for(i
=0; i
<group
->len
; i
++) {
1165 tf
= &g_array_index (group
, LttTracefile
, i
);
1166 if(ltt_process_facility_tracefile(tf
))
1167 goto facilities_error
;
1172 /* Error handling */
1174 g_datalist_clear(&t
->facilities_by_name
);
1175 g_array_free(t
->facilities_by_num
, TRUE
);
1177 g_datalist_clear(&t
->tracefiles
);
1185 GQuark
ltt_trace_name(const LttTrace
*t
)
1191 /******************************************************************************
1192 * When we copy a trace, we want all the opening actions to happen again :
1193 * the trace will be reopened and totally independant from the original.
1194 * That's why we call ltt_trace_open.
1195 *****************************************************************************/
1196 LttTrace
*ltt_trace_copy(LttTrace
*self
)
1198 return ltt_trace_open(g_quark_to_string(self
->pathname
));
1201 void ltt_trace_close(LttTrace
*t
)
1206 for(i
=0; i
<t
->facilities_by_num
->len
; i
++) {
1207 fac
= &g_array_index (t
->facilities_by_num
, LttFacility
, i
);
1209 ltt_facility_close(fac
);
1212 g_datalist_clear(&t
->facilities_by_name
);
1213 g_array_free(t
->facilities_by_num
, TRUE
);
1214 g_datalist_clear(&t
->tracefiles
);
1219 /*****************************************************************************
1220 *Get the system description of the trace
1221 ****************************************************************************/
1223 LttFacility
*ltt_trace_facility_by_id(LttTrace
*t
, guint8 id
)
1225 g_assert(id
< t
->facilities_by_num
->len
);
1226 return &g_array_index(t
->facilities_by_num
, LttFacility
, id
);
1229 /* ltt_trace_facility_get_by_name
1231 * Returns the GArray of facility indexes. All the fac_ids that matches the
1232 * requested facility name.
1234 * If name is not found, returns NULL.
1236 GArray
*ltt_trace_facility_get_by_name(LttTrace
*t
, GQuark name
)
1238 return g_datalist_id_get_data(&t
->facilities_by_name
, name
);
1241 /*****************************************************************************
1242 * Functions to discover all the event types in the trace
1243 ****************************************************************************/
1246 unsigned ltt_trace_eventtype_number(LttTrace
*t
)
1250 unsigned int num
= t
->facility_number
;
1254 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
, i
);
1255 count
+= f
->event_number
;
1262 //use an iteration on all the trace facilities, and inside iteration on all the
1263 //event types in each facilities instead.
1264 LttEventType
*ltt_trace_eventtype_get(LttTrace
*t
, unsigned evId
)
1266 LttEventType
*event_type
;
1269 f
= ltt_trace_facility_by_id(t
,evId
);
1271 if(unlikely(!f
)) event_type
= NULL
;
1272 else event_type
= f
->events
[evId
- f
->base_id
];
1279 /*****************************************************************************
1280 * ltt_trace_find_tracefile
1282 * Find a tracefile by name and index in the group.
1284 * Returns a pointer to the tracefiles, else NULL.
1285 ****************************************************************************/
1287 LttTracefile
*ltt_trace_find_tracefile(LttTrace
*t
, const gchar
*name
)
1292 /*****************************************************************************
1293 * Get the start time and end time of the trace
1294 ****************************************************************************/
1296 static void ltt_tracefile_time_span_get(LttTracefile
*tf
,
1297 LttTime
*start
, LttTime
*end
)
1301 err
= map_block(tf
, 0);
1303 g_error("Can not map block");
1304 *start
= ltt_time_infinite
;
1306 *start
= tf
->buffer
.begin
.timestamp
;
1308 err
= map_block(tf
, tf
->num_blocks
- 1); /* Last block */
1310 g_error("Can not map block");
1311 *end
= ltt_time_zero
;
1313 *end
= tf
->buffer
.end
.timestamp
;
1316 struct tracefile_time_span_get_args
{
1322 static void group_time_span_get(GQuark name
, gpointer data
, gpointer user_data
)
1324 struct tracefile_time_span_get_args
*args
=
1325 (struct tracefile_time_span_get_args
*)user_data
;
1327 GArray
*group
= (GArray
*)data
;
1333 for(i
=0; i
<group
->len
; i
++) {
1334 tf
= &g_array_index (group
, LttTracefile
, i
);
1335 if(tf
->cpu_online
) {
1336 ltt_tracefile_time_span_get(tf
, &tmp_start
, &tmp_end
);
1337 if(ltt_time_compare(*args
->start
, tmp_start
)>0) *args
->start
= tmp_start
;
1338 if(ltt_time_compare(*args
->end
, tmp_end
)<0) *args
->end
= tmp_end
;
1343 void ltt_trace_time_span_get(LttTrace
*t
, LttTime
*start
, LttTime
*end
)
1345 LttTime min_start
= ltt_time_infinite
;
1346 LttTime max_end
= ltt_time_zero
;
1347 struct tracefile_time_span_get_args args
= { t
, &min_start
, &max_end
};
1349 g_datalist_foreach(&t
->tracefiles
, &group_time_span_get
, &args
);
1351 if(start
!= NULL
) *start
= min_start
;
1352 if(end
!= NULL
) *end
= max_end
;
1357 /*****************************************************************************
1358 *Get the name of a tracefile
1359 ****************************************************************************/
1361 GQuark
ltt_tracefile_name(const LttTracefile
*tf
)
1366 GQuark
ltt_tracefile_long_name(const LttTracefile
*tf
)
1368 return tf
->long_name
;
1373 guint
ltt_tracefile_num(LttTracefile
*tf
)
1378 /*****************************************************************************
1379 * Get the number of blocks in the tracefile
1380 ****************************************************************************/
1382 guint
ltt_tracefile_block_number(LttTracefile
*tf
)
1384 return tf
->num_blocks
;
1388 /* Seek to the first event in a tracefile that has a time equal or greater than
1389 * the time passed in parameter.
1391 * If the time parameter is outside the tracefile time span, seek to the first
1392 * event or if after, return ERANGE.
1394 * If the time parameter is before the first event, we have to seek specially to
1397 * If the time is after the end of the trace, return ERANGE.
1399 * Do a binary search to find the right block, then a sequential search in the
1400 * block to find the event.
1402 * In the special case where the time requested fits inside a block that has no
1403 * event corresponding to the requested time, the first event of the next block
1406 * IMPORTANT NOTE : // FIXME everywhere...
1408 * You MUST NOT do a ltt_tracefile_read right after a ltt_tracefile_seek_time :
1409 * you will jump over an event if you do.
1411 * Return value : 0 : no error, the tf->event can be used
1412 * ERANGE : time if after the last event of the trace
1413 * otherwise : this is an error.
1417 int ltt_tracefile_seek_time(LttTracefile
*tf
, LttTime time
)
1421 unsigned int block_num
, high
, low
;
1423 /* seek at the beginning of trace */
1424 err
= map_block(tf
, 0); /* First block */
1426 g_error("Can not map block");
1430 /* If the time is lower or equal the beginning of the trace,
1431 * go to the first event. */
1432 if(ltt_time_compare(time
, tf
->buffer
.begin
.timestamp
) <= 0) {
1433 ret
= ltt_tracefile_read(tf
);
1434 if(ret
== ERANGE
) goto range
;
1435 else if (ret
) goto fail
;
1436 goto found
; /* There is either no event in the trace or the event points
1437 to the first event in the trace */
1440 err
= map_block(tf
, tf
->num_blocks
- 1); /* Last block */
1442 g_error("Can not map block");
1446 /* If the time is after the end of the trace, return ERANGE. */
1447 if(ltt_time_compare(time
, tf
->buffer
.end
.timestamp
) > 0) {
1451 /* Binary search the block */
1452 high
= tf
->num_blocks
- 1;
1456 block_num
= ((high
-low
) / 2) + low
;
1458 err
= map_block(tf
, block_num
);
1460 g_error("Can not map block");
1464 /* We cannot divide anymore : this is what would happen if the time
1465 * requested was exactly between two consecutive buffers'end and start
1466 * timestamps. This is also what would happend if we didn't deal with out
1467 * of span cases prior in this function. */
1468 /* The event is right in the buffer!
1469 * (or in the next buffer first event) */
1471 ret
= ltt_tracefile_read(tf
);
1472 if(ret
== ERANGE
) goto range
; /* ERANGE or EPERM */
1473 else if(ret
) goto fail
;
1475 if(ltt_time_compare(time
, tf
->event
.event_time
) <= 0)
1479 } else if(ltt_time_compare(time
, tf
->buffer
.begin
.timestamp
) < 0) {
1480 /* go to lower part */
1481 high
= block_num
- 1;
1482 } else if(ltt_time_compare(time
, tf
->buffer
.end
.timestamp
) > 0) {
1483 /* go to higher part */
1484 low
= block_num
+ 1;
1485 } else {/* The event is right in the buffer!
1486 (or in the next buffer first event) */
1488 ret
= ltt_tracefile_read(tf
);
1489 if(ret
== ERANGE
) goto range
; /* ERANGE or EPERM */
1490 else if(ret
) goto fail
;
1492 if(ltt_time_compare(time
, tf
->event
.event_time
) <= 0)
1504 /* Error handling */
1506 g_error("ltt_tracefile_seek_time failed on tracefile %s",
1507 g_quark_to_string(tf
->name
));
1512 int ltt_tracefile_seek_position(LttTracefile
*tf
, const LttEventPosition
*ep
) {
1516 if(ep
->tracefile
!= tf
) {
1520 err
= map_block(tf
, ep
->block
);
1522 g_error("Can not map block");
1526 tf
->event
.offset
= ep
->offset
;
1528 err
= ltt_tracefile_read_update_event(tf
);
1530 err
= ltt_tracefile_read_op(tf
);
1536 g_error("ltt_tracefile_seek_time failed on tracefile %s",
1537 g_quark_to_string(tf
->name
));
1541 /* Calculate the real event time based on the buffer boundaries */
1542 LttTime
ltt_interpolate_time(LttTracefile
*tf
, LttEvent
*event
)
1546 g_assert(tf
->trace
->has_tsc
);
1548 // time = ltt_time_from_uint64(
1549 // cycles_2_ns(tf, (guint64)(tf->buffer.tsc - tf->buffer.begin.cycle_count)));
1550 time
= ltt_time_from_uint64(
1551 (double)(tf
->buffer
.tsc
- tf
->trace
->start_tsc
) * 1000000.0
1552 / (double)tf
->trace
->start_freq
);
1553 //time = ltt_time_add(tf->buffer.begin.timestamp, time);
1554 time
= ltt_time_add(tf
->trace
->start_time_from_tsc
, time
);
1560 /* Get the current event of the tracefile : valid until the next read */
1561 LttEvent
*ltt_tracefile_get_event(LttTracefile
*tf
)
1568 /*****************************************************************************
1570 * ltt_tracefile_read : Read the next event in the tracefile
1575 * Returns 0 if an event can be used in tf->event.
1576 * Returns ERANGE on end of trace. The event in tf->event still can be used
1577 * (if the last block was not empty).
1578 * Returns EPERM on error.
1580 * This function does make the tracefile event structure point to the event
1581 * currently pointed to by the tf->event.
1583 * Note : you must call a ltt_tracefile_seek to the beginning of the trace to
1584 * reinitialize it after an error if you want results to be coherent.
1585 * It would be the case if a end of trace last buffer has no event : the end
1586 * of trace wouldn't be returned, but an error.
1587 * We make the assumption there is at least one event per buffer.
1588 ****************************************************************************/
1590 int ltt_tracefile_read(LttTracefile
*tf
)
1594 err
= ltt_tracefile_read_seek(tf
);
1596 err
= ltt_tracefile_read_update_event(tf
);
1598 err
= ltt_tracefile_read_op(tf
);
1604 int ltt_tracefile_read_seek(LttTracefile
*tf
)
1608 /* Get next buffer until we finally have an event, or end of trace */
1610 err
= ltt_seek_next_event(tf
);
1611 if(unlikely(err
== ENOPROTOOPT
)) {
1615 /* Are we at the end of the buffer ? */
1617 if(unlikely(tf
->buffer
.index
== tf
->num_blocks
-1)){ /* end of trace ? */
1620 /* get next block */
1621 err
= map_block(tf
, tf
->buffer
.index
+ 1);
1623 g_error("Can not map block");
1627 } else break; /* We found an event ! */
1634 /* do specific operation on events */
1635 int ltt_tracefile_read_op(LttTracefile
*tf
)
1641 /* do event specific operation */
1643 /* do something if its an heartbeat event : increment the heartbeat count */
1644 //if(event->facility_id == LTT_FACILITY_CORE)
1645 // if(event->event_id == LTT_EVENT_HEARTBEAT)
1646 // tf->cur_heart_beat_number++;
1652 /* same as ltt_tracefile_read, but does not seek to the next event nor call
1653 * event specific operation. */
1654 int ltt_tracefile_read_update_event(LttTracefile
*tf
)
1660 pos
= tf
->buffer
.head
+ event
->offset
;
1662 /* Read event header */
1664 /* Align the head */
1665 pos
+= ltt_align(pos
, tf
->trace
->arch_size
, tf
->has_alignment
);
1667 if(tf
->trace
->has_tsc
) {
1668 if(tf
->trace
->has_heartbeat
) {
1669 event
->time
.timestamp
= ltt_get_uint32(LTT_GET_BO(tf
),
1671 /* 32 bits -> 64 bits tsc */
1672 /* note : still works for seek and non seek cases. */
1673 if(event
->time
.timestamp
< (0xFFFFFFFFULL
&tf
->buffer
.tsc
)) {
1674 tf
->buffer
.tsc
= ((tf
->buffer
.tsc
&0xFFFFFFFF00000000ULL
)
1676 | (guint64
)event
->time
.timestamp
;
1677 event
->tsc
= tf
->buffer
.tsc
;
1680 tf
->buffer
.tsc
= (tf
->buffer
.tsc
&0xFFFFFFFF00000000ULL
)
1681 | (guint64
)event
->time
.timestamp
;
1682 event
->tsc
= tf
->buffer
.tsc
;
1684 pos
+= sizeof(guint32
);
1686 event
->tsc
= ltt_get_uint64(LTT_GET_BO(tf
), pos
);
1687 tf
->buffer
.tsc
= event
->tsc
;
1688 pos
+= sizeof(guint64
);
1691 event
->event_time
= ltt_interpolate_time(tf
, event
);
1693 event
->time
.delta
.tv_sec
= 0;
1694 event
->time
.delta
.tv_nsec
= ltt_get_uint32(LTT_GET_BO(tf
),
1695 pos
) * NSEC_PER_USEC
;
1697 event
->tsc
= tf
->buffer
.tsc
;
1699 event
->event_time
= ltt_time_add(tf
->buffer
.begin
.timestamp
,
1701 pos
+= sizeof(guint32
);
1704 event
->facility_id
= *(guint8
*)pos
;
1705 pos
+= sizeof(guint8
);
1707 event
->event_id
= *(guint8
*)pos
;
1708 pos
+= sizeof(guint8
);
1710 event
->event_size
= ltt_get_uint16(LTT_GET_BO(tf
), pos
);
1711 pos
+= sizeof(guint16
);
1713 /* Align the head */
1714 pos
+= ltt_align(pos
, tf
->trace
->arch_size
, tf
->has_alignment
);
1718 /* get the data size and update the event fields with the current
1720 ltt_update_event_size(tf
);
1726 /****************************************************************************
1728 * map_block : map a block from the file
1730 * lttdes : ltt trace file
1731 * whichBlock : the block which will be read
1734 * EINVAL : lseek fail
1735 * EIO : can not read from the file
1736 ****************************************************************************/
1738 static gint
map_block(LttTracefile
* tf
, guint block_num
)
1740 int page_size
= getpagesize();
1741 struct ltt_block_start_header
*header
;
1743 g_assert(block_num
< tf
->num_blocks
);
1745 if(tf
->buffer
.head
!= NULL
) {
1746 if(munmap(tf
->buffer
.head
, PAGE_ALIGN(tf
->buf_size
))) {
1747 g_warning("unmap size : %u\n",
1748 PAGE_ALIGN(tf
->buf_size
));
1749 perror("munmap error");
1755 /* Multiple of pages aligned head */
1756 tf
->buffer
.head
= mmap(0,
1757 PAGE_ALIGN(tf
->buf_size
),
1758 PROT_READ
, MAP_PRIVATE
, tf
->fd
,
1759 PAGE_ALIGN((off_t
)tf
->buf_size
* (off_t
)block_num
));
1761 if(tf
->buffer
.head
== MAP_FAILED
) {
1762 perror("Error in allocating memory for buffer of tracefile");
1766 g_assert( ( (guint
)tf
->buffer
.head
&(8-1) ) == 0); // make sure it's aligned.
1769 tf
->buffer
.index
= block_num
;
1771 header
= (struct ltt_block_start_header
*)tf
->buffer
.head
;
1774 tf
->buffer
.begin
.timestamp
= ltt_time_add(
1775 ltt_time_from_uint64(
1776 ltt_get_uint64(LTT_GET_BO(tf
),
1777 &header
->begin
.timestamp
)
1778 - tf
->trace
->start_monotonic
),
1779 tf
->trace
->start_time
);
1781 //g_debug("block %u begin : %lu.%lu", block_num,
1782 // tf->buffer.begin.timestamp.tv_sec, tf->buffer.begin.timestamp.tv_nsec);
1783 tf
->buffer
.begin
.cycle_count
= ltt_get_uint64(LTT_GET_BO(tf
),
1784 &header
->begin
.cycle_count
);
1785 tf
->buffer
.begin
.freq
= ltt_get_uint64(LTT_GET_BO(tf
),
1786 &header
->begin
.freq
);
1787 tf
->buffer
.begin
.timestamp
= ltt_time_add(
1788 ltt_time_from_uint64(
1789 (double)(tf
->buffer
.begin
.cycle_count
1790 - tf
->trace
->start_tsc
) * 1000000.0
1791 / (double)tf
->trace
->start_freq
),
1792 tf
->trace
->start_time_from_tsc
);
1795 tf
->buffer
.end
.timestamp
= ltt_time_add(
1796 ltt_time_from_uint64(
1797 ltt_get_uint64(LTT_GET_BO(tf
),
1798 &header
->end
.timestamp
)
1799 - tf
->trace
->start_monotonic
),
1800 tf
->trace
->start_time
);
1802 //g_debug("block %u end : %lu.%lu", block_num,
1803 // tf->buffer.end.timestamp.tv_sec, tf->buffer.end.timestamp.tv_nsec);
1804 tf
->buffer
.end
.cycle_count
= ltt_get_uint64(LTT_GET_BO(tf
),
1805 &header
->end
.cycle_count
);
1806 tf
->buffer
.end
.freq
= ltt_get_uint64(LTT_GET_BO(tf
),
1808 tf
->buffer
.lost_size
= ltt_get_uint32(LTT_GET_BO(tf
),
1809 &header
->lost_size
);
1810 tf
->buffer
.end
.timestamp
= ltt_time_add(
1811 ltt_time_from_uint64(
1812 (double)(tf
->buffer
.end
.cycle_count
1813 - tf
->trace
->start_tsc
) * 1000000.0
1814 / (double)tf
->trace
->start_freq
),
1815 tf
->trace
->start_time_from_tsc
);
1817 tf
->buffer
.tsc
= tf
->buffer
.begin
.cycle_count
;
1818 tf
->event
.tsc
= tf
->buffer
.tsc
;
1819 tf
->buffer
.freq
= tf
->buffer
.begin
.freq
;
1822 * eventually support variable buffer size : will need a partial pre-read of
1823 * the headers to create an index when we open the trace... eventually. */
1824 g_assert(tf
->buf_size
== ltt_get_uint32(LTT_GET_BO(tf
),
1825 &header
->buf_size
));
1827 /* Now that the buffer is mapped, calculate the time interpolation for the
1830 // tf->buffer.nsecs_per_cycle = calc_nsecs_per_cycle(tf);
1831 //tf->buffer.cyc2ns_scale = calc_nsecs_per_cycle(tf);
1833 /* Make the current event point to the beginning of the buffer :
1834 * it means that the event read must get the first event. */
1835 tf
->event
.tracefile
= tf
;
1836 tf
->event
.block
= block_num
;
1837 tf
->event
.offset
= 0;
1846 /* It will update the fields offsets too */
1847 void ltt_update_event_size(LttTracefile
*tf
)
1851 /* Specific handling of core events : necessary to read the facility control
1853 LttFacility
*f
= ltt_trace_get_facility_by_num(tf
->trace
,
1854 tf
->event
.facility_id
);
1856 if(likely(tf
->event
.facility_id
== LTT_FACILITY_CORE
)) {
1857 switch((enum ltt_core_events
)tf
->event
.event_id
) {
1858 case LTT_EVENT_FACILITY_LOAD
:
1859 size
= strlen((char*)tf
->event
.data
) + 1;
1860 //g_debug("Update Event facility load of facility %s", (char*)tf->event.data);
1861 size
+= sizeof(struct LttFacilityLoad
);
1863 case LTT_EVENT_FACILITY_UNLOAD
:
1864 //g_debug("Update Event facility unload");
1865 size
= sizeof(struct LttFacilityUnload
);
1867 case LTT_EVENT_STATE_DUMP_FACILITY_LOAD
:
1868 size
= strlen((char*)tf
->event
.data
) + 1;
1869 //g_debug("Update Event facility load state dump of facility %s",
1870 // (char*)tf->event.data);
1871 size
+= sizeof(struct LttStateDumpFacilityLoad
);
1873 case LTT_EVENT_HEARTBEAT
:
1874 //g_debug("Update Event heartbeat");
1875 size
= sizeof(TimeHeartbeat
);
1878 g_warning("Error in getting event size : tracefile %s, "
1879 "unknown event id %hhu in core facility.",
1880 g_quark_to_string(tf
->name
),
1881 tf
->event
.event_id
);
1882 goto event_id_error
;
1887 g_error("Unknown facility %hhu (0x%hhx) in tracefile %s",
1888 tf
->event
.facility_id
,
1889 tf
->event
.facility_id
,
1890 g_quark_to_string(tf
->name
));
1891 goto facility_error
;
1894 LttEventType
*event_type
=
1895 ltt_facility_eventtype_get(f
, tf
->event
.event_id
);
1898 g_error("Unknown event id %hhu in facility %s in tracefile %s",
1900 g_quark_to_string(f
->name
),
1901 g_quark_to_string(tf
->name
));
1902 goto event_type_error
;
1905 /* Compute the dynamic offsets */
1906 compute_offsets(tf
, event_type
, &size
, tf
->event
.data
);
1908 //g_debug("Event root field : f.e %hhu.%hhu size %zd",
1909 // tf->event.facility_id,
1910 // tf->event.event_id, size);
1913 tf
->event
.data_size
= size
;
1915 /* Check consistency between kernel and LTTV structure sizes */
1916 g_assert(tf
->event
.data_size
== tf
->event
.event_size
);
1923 tf
->event
.data_size
= 0;
1927 /* Take the tf current event offset and use the event facility id and event id
1928 * to figure out where is the next event offset.
1930 * This is an internal function not aiming at being used elsewhere : it will
1931 * not jump over the current block limits. Please consider using
1932 * ltt_tracefile_read to do this.
1934 * Returns 0 on success
1935 * ERANGE if we are at the end of the buffer.
1936 * ENOPROTOOPT if an error occured when getting the current event size.
1938 static int ltt_seek_next_event(LttTracefile
*tf
)
1943 /* seek over the buffer header if we are at the buffer start */
1944 if(tf
->event
.offset
== 0) {
1945 tf
->event
.offset
+= tf
->buffer_header_size
;
1947 if(tf
->event
.offset
== tf
->buf_size
- tf
->buffer
.lost_size
) {
1954 pos
= tf
->event
.data
;
1956 if(tf
->event
.data_size
< 0) goto error
;
1958 pos
+= (size_t)tf
->event
.data_size
;
1960 tf
->event
.offset
= pos
- tf
->buffer
.head
;
1962 if(tf
->event
.offset
== tf
->buf_size
- tf
->buffer
.lost_size
) {
1966 g_assert(tf
->event
.offset
< tf
->buf_size
- tf
->buffer
.lost_size
);
1972 g_error("Error in ltt_seek_next_event for tracefile %s",
1973 g_quark_to_string(tf
->name
));
1978 /*****************************************************************************
1980 * calc_nsecs_per_cycle : calculate nsecs per cycle for current block
1982 * 1.0 / (freq(khz) *1000) * 1000000000
1985 ****************************************************************************/
1986 /* from timer_tsc.c */
1987 #define CYC2NS_SCALE_FACTOR 10
1988 static guint32
calc_nsecs_per_cycle(LttTracefile
* tf
)
1990 //return 1e6 / (double)tf->buffer.freq;
1991 guint32 cpu_mhz
= tf
->buffer
.freq
/ 1000;
1992 guint32 cyc2ns_scale
= (1000 << CYC2NS_SCALE_FACTOR
)/cpu_mhz
;
1994 return cyc2ns_scale
;
1995 // return 1e6 / (double)tf->buffer.freq;
1998 static guint64
cycles_2_ns(LttTracefile
*tf
, guint64 cycles
)
2000 return (cycles
* tf
->buffer
.cyc2ns_scale
) >> CYC2NS_SCALE_FACTOR
;
2005 void setFieldsOffset(LttTracefile
*tf
, LttEventType
*evT
,void *evD
)
2007 LttField
* rootFld
= evT
->root_field
;
2008 // rootFld->base_address = evD;
2011 rootFld
->field_size
= getFieldtypeSize(tf
, evT
->facility
,
2012 evT
, 0,0,rootFld
, evD
);
2016 /*****************************************************************************
2018 * set_fields_offsets : set the precomputable offset of the fields
2020 * tracefile : opened trace file
2021 * event_type : the event type
2022 ****************************************************************************/
2024 void set_fields_offsets(LttTracefile
*tf
, LttEventType
*event_type
)
2026 LttField
*field
= event_type
->root_field
;
2027 enum field_status fixed_root
= FIELD_FIXED
, fixed_parent
= FIELD_FIXED
;
2030 preset_field_type_size(tf
, event_type
, 0, 0,
2031 &fixed_root
, &fixed_parent
,
2038 /*****************************************************************************
2040 * get_alignment : Get the alignment needed for a field.
2045 * returns : The size on which it must be aligned.
2047 ****************************************************************************/
2048 off_t
get_alignment(LttTracefile
*tf
, LttField
*field
)
2050 type
= &field
->field_type
;
2052 switch(type
->type_class
) {
2054 case LTT_UINT_FIXED
:
2069 /* Align offset on type size */
2070 return field
->field_size
;
2076 g_assert(type
->fields
->len
== 1);
2078 LttField
*child
= &g_array_index(type
->fields
, LttField
, 0);
2079 return get_alignment(tf
, child
);
2083 g_assert(type
->fields
->len
== 2);
2086 LttField
*child
= &g_array_index(type
->fields
, LttField
, 0);
2088 localign
= max(localign
, get_alignment(tf
, child
));
2090 child
= &g_array_index(type
->fields
, LttField
, 1);
2091 localign
= max(localign
, get_alignment(tf
, child
));
2102 for(i
=0; i
<type
->fields
->len
; i
++) {
2103 LttField
*child
= &g_array_index(type
->fields
, LttField
, i
);
2104 localign
= max(localign
, get_alignment(tf
, child
));
2111 g_error("get_alignment : unknown type");
2116 /*****************************************************************************
2118 * field_compute_static_size : Determine the size of fields known by their
2119 * sole definition. Unions, arrays and struct sizes might be known, but
2120 * the parser does not give that information.
2125 ****************************************************************************/
2127 void field_compute_static_size(LttTracefile
*tf
, LttField
*field
)
2129 type
= &field
->field_type
;
2131 switch(type
->type_class
) {
2133 case LTT_UINT_FIXED
:
2152 /* note this : array type size is the number of elements in the array,
2153 * while array field size of the length of the array in bytes */
2154 g_assert(type
->fields
->len
== 1);
2156 LttField
*child
= &g_array_index(type
->fields
, LttField
, 0);
2157 field_compute_static_size(tf
, child
);
2159 if(child
->field_size
!= 0) {
2160 field
->field_size
= type
->size
* child
->field_size
;
2161 field
->dynamic_offsets
= g_array_sized_new(FALSE
, TRUE
,
2162 sizeof(off_t
), type
->size
);
2164 field
->field_size
= 0;
2169 g_assert(type
->fields
->len
== 2);
2172 LttField
*child
= &g_array_index(type
->fields
, LttField
, 1);
2173 field_compute_static_size(tf
, child
);
2174 field
->field_size
= 0;
2176 if(child
->field_size
!= 0) {
2177 field
->dynamic_offsets
= g_array_sized_new(FALSE
, TRUE
,
2178 sizeof(off_t
), SEQUENCE_AVG_ELEMENTS
);
2186 for(i
=0;i
<type
->fields
->len
;i
++) {
2187 LttField
*child
= &g_array_index(type
->fields
, LttField
, i
);
2188 field_compute_static_size(tf
, child
);
2189 if(child
->field_size
!= 0) {
2190 type
->size
+= ltt_align(type
->size
, get_alignment(tf
, child
),
2192 type
->size
+= child
->field_size
;
2194 /* As soon as we find a child with variable size, we have
2195 * a variable size */
2200 field
->field_size
= type
->size
;
2204 g_error("field_static_size : unknown type");
2210 /*****************************************************************************
2212 * precompute_fields_offsets : set the precomputable offset of the fields
2216 * offset : pointer to the current offset, must be incremented
2218 * return : 1 : found a variable length field, stop the processing.
2220 ****************************************************************************/
2223 gint
precompute_fields_offsets(LttTracefile
*tf
, LttField
*field
, off_t
*offset
)
2225 type
= &field
->field_type
;
2227 switch(type
->type_class
) {
2229 case LTT_UINT_FIXED
:
2244 /* Align offset on type size */
2245 *offset
+= ltt_align(*offset
, get_alignment(tf
, field
),
2247 /* remember offset */
2248 field
->offset_root
= *offset
;
2249 field
->fixed_root
= FIELD_FIXED
;
2250 /* Increment offset */
2251 *offset
+= field
->field_size
;
2255 field
->offset_root
= *offset
;
2256 field
->fixed_root
= FIELD_FIXED
;
2260 g_assert(type
->fields
->len
== 1);
2262 LttField
*child
= &g_array_index(type
->fields
, LttField
, 0);
2264 *offset
+= ltt_align(*offset
, get_alignment(tf
, field
),
2267 /* remember offset */
2268 field
->offset_root
= *offset
;
2269 field
->array_offset
= *offset
;
2270 field
->fixed_root
= FIELD_FIXED
;
2272 /* Let the child be variable */
2273 //precompute_fields_offsets(tf, child, offset);
2275 if(field
->field_size
!= 0) {
2276 /* Increment offset */
2277 /* field_size is the array size in bytes */
2278 *offset
+= field
->field_size
;
2286 g_assert(type
->fields
->len
== 2);
2291 *offset
+= ltt_align(*offset
, get_alignment(tf
, field
),
2294 /* remember offset */
2295 field
->offset_root
= *offset
;
2296 field
->fixed_root
= FIELD_FIXED
;
2298 child
= &g_array_index(type
->fields
, LttField
, 0);
2299 ret
= precompute_fields_offsets(tf
, child
, offset
);
2300 g_assert(ret
== 0); /* Seq len cannot have variable len */
2302 child
= &g_array_index(type
->fields
, LttField
, 1);
2303 *offset
+= ltt_align(*offset
, get_alignment(tf
, child
),
2305 field
->array_offset
= *offset
;
2306 /* Set the offset position at position 0 */
2307 ret
= precompute_fields_offsets(tf
, child
, offset
);
2309 /* Cannot precompute fields offsets of sequence members, and has
2310 * variable length. */
2320 *offset
+= ltt_align(*offset
, get_alignment(tf
, field
),
2322 /* remember offset */
2323 field
->offset_root
= *offset
;
2324 field
->fixed_root
= FIELD_FIXED
;
2326 for(i
=0; i
< type
->fields
->len
; i
++) {
2327 child
= &g_array_index(type
->fields
, LttField
, i
);
2328 ret
= precompute_fields_offsets(tf
, child
, offset
);
2341 *offset
+= ltt_align(*offset
, get_alignment(tf
, field
),
2343 /* remember offset */
2344 field
->offset_root
= *offset
;
2345 field
->fixed_root
= FIELD_FIXED
;
2347 for(i
=0; i
< type
->fields
->len
; i
++) {
2348 *offset
= field
->offset_root
;
2349 child
= &g_array_index(type
->fields
, LttField
, i
);
2350 ret
= precompute_fields_offsets(tf
, child
, offset
);
2354 *offset
= field
->offset_root
+ field
->field_size
;
2361 g_error("precompute_fields_offsets : unknown type");
2368 /*****************************************************************************
2370 * precompute_offsets : set the precomputable offset of an event type
2373 * event : event type
2375 ****************************************************************************/
2376 void precompute_offsets(LttTracefile
*tf
, LttEventType
*event
)
2382 /* First, compute the size of fixed size fields. Will determine size for
2383 * arrays, struct and unions, which is not done by the parser */
2384 for(i
=0; i
<event
->fields
->len
; i
++) {
2385 LttField
*field
= &g_array_index(event
->fields
, LttField
, i
);
2386 field_compute_static_size(tf
, field
);
2389 /* Precompute all known offsets */
2390 for(i
=0; i
<event
->fields
->len
; i
++) {
2391 LttField
*field
= &g_array_index(event
->fields
, LttField
, i
);
2392 ret
= precompute_fields_offsets(tf
, field
, &offset
);
2400 /*****************************************************************************
2402 * preset_field_type_size : set the fixed sizes of the field type
2405 * event_type : event type
2406 * offset_root : offset from the root
2407 * offset_parent : offset from the parent
2408 * fixed_root : Do we know a fixed offset to the root ?
2409 * fixed_parent : Do we know a fixed offset to the parent ?
2411 ****************************************************************************/
2415 // preset the fixed size offsets. Calculate them just like genevent-new : an
2416 // increment of a *to value that represents the offset from the start of the
2418 // The preset information is : offsets up to (and including) the first element
2419 // of variable size. All subsequent fields must be flagged "VARIABLE OFFSET".
2421 void preset_field_type_size(LttTracefile
*tf
, LttEventType
*event_type
,
2422 off_t offset_root
, off_t offset_parent
,
2423 enum field_status
*fixed_root
, enum field_status
*fixed_parent
,
2426 enum field_status local_fixed_root
, local_fixed_parent
;
2430 g_assert(field
->fixed_root
== FIELD_UNKNOWN
);
2431 g_assert(field
->fixed_parent
== FIELD_UNKNOWN
);
2432 g_assert(field
->fixed_size
== FIELD_UNKNOWN
);
2434 type
= field
->field_type
;
2436 field
->fixed_root
= *fixed_root
;
2437 if(field
->fixed_root
== FIELD_FIXED
)
2438 field
->offset_root
= offset_root
;
2440 field
->offset_root
= 0;
2442 field
->fixed_parent
= *fixed_parent
;
2443 if(field
->fixed_parent
== FIELD_FIXED
)
2444 field
->offset_parent
= offset_parent
;
2446 field
->offset_parent
= 0;
2448 size_t current_root_offset
;
2449 size_t current_offset
;
2450 enum field_status current_child_status
, final_child_status
;
2453 switch(type
->type_class
) {
2458 field
->field_size
= ltt_type_size(tf
->trace
, type
);
2459 field
->fixed_size
= FIELD_FIXED
;
2462 field
->field_size
= (off_t
)event_type
->facility
->pointer_size
;
2463 field
->fixed_size
= FIELD_FIXED
;
2467 field
->field_size
= (off_t
)event_type
->facility
->long_size
;
2468 field
->fixed_size
= FIELD_FIXED
;
2473 field
->field_size
= (off_t
)event_type
->facility
->size_t_size
;
2474 field
->fixed_size
= FIELD_FIXED
;
2477 local_fixed_root
= FIELD_VARIABLE
;
2478 local_fixed_parent
= FIELD_VARIABLE
;
2479 preset_field_type_size(tf
, event_type
,
2481 &local_fixed_root
, &local_fixed_parent
,
2483 field
->fixed_size
= FIELD_VARIABLE
;
2484 field
->field_size
= 0;
2485 *fixed_root
= FIELD_VARIABLE
;
2486 *fixed_parent
= FIELD_VARIABLE
;
2489 field
->fixed_size
= FIELD_VARIABLE
;
2490 field
->field_size
= 0;
2491 *fixed_root
= FIELD_VARIABLE
;
2492 *fixed_parent
= FIELD_VARIABLE
;
2495 local_fixed_root
= FIELD_VARIABLE
;
2496 local_fixed_parent
= FIELD_VARIABLE
;
2497 preset_field_type_size(tf
, event_type
,
2499 &local_fixed_root
, &local_fixed_parent
,
2501 field
->fixed_size
= field
->child
[0]->fixed_size
;
2502 if(field
->fixed_size
== FIELD_FIXED
) {
2503 field
->field_size
= type
->element_number
* field
->child
[0]->field_size
;
2505 field
->field_size
= 0;
2506 *fixed_root
= FIELD_VARIABLE
;
2507 *fixed_parent
= FIELD_VARIABLE
;
2511 current_root_offset
= field
->offset_root
;
2513 current_child_status
= FIELD_FIXED
;
2514 for(i
=0;i
<type
->element_number
;i
++) {
2515 preset_field_type_size(tf
, event_type
,
2516 current_root_offset
, current_offset
,
2517 fixed_root
, ¤t_child_status
,
2519 if(current_child_status
== FIELD_FIXED
) {
2520 current_root_offset
+= field
->child
[i
]->field_size
;
2521 current_offset
+= field
->child
[i
]->field_size
;
2523 current_root_offset
= 0;
2527 if(current_child_status
!= FIELD_FIXED
) {
2528 *fixed_parent
= current_child_status
;
2529 field
->field_size
= 0;
2530 field
->fixed_size
= current_child_status
;
2532 field
->field_size
= current_offset
;
2533 field
->fixed_size
= FIELD_FIXED
;
2537 current_root_offset
= field
->offset_root
;
2540 final_child_status
= FIELD_FIXED
;
2541 for(i
=0;i
<type
->element_number
;i
++) {
2542 enum field_status current_root_child_status
= FIELD_FIXED
;
2543 enum field_status current_child_status
= FIELD_FIXED
;
2544 preset_field_type_size(tf
, event_type
,
2545 current_root_offset
, current_offset
,
2546 ¤t_root_child_status
, ¤t_child_status
,
2548 if(current_child_status
!= FIELD_FIXED
)
2549 final_child_status
= current_child_status
;
2551 max_size
= max(max_size
, field
->child
[i
]->field_size
);
2553 if(final_child_status
!= FIELD_FIXED
) {
2554 g_error("LTTV does not support variable size fields in unions.");
2555 /* This will stop the application. */
2556 *fixed_root
= final_child_status
;
2557 *fixed_parent
= final_child_status
;
2558 field
->field_size
= 0;
2559 field
->fixed_size
= current_child_status
;
2561 field
->field_size
= max_size
;
2562 field
->fixed_size
= FIELD_FIXED
;
2570 /*****************************************************************************
2572 * check_fields_compatibility : Check for compatibility between two fields :
2573 * do they use the same inner structure ?
2575 * event_type1 : event type
2576 * event_type2 : event type
2579 *Returns : 0 if identical
2581 ****************************************************************************/
2582 // this function checks for equality of field types. Therefore, it does not use
2583 // per se offsets. For instance, an aligned version of a structure is
2584 // compatible with an unaligned version of the same structure.
2585 gint
check_fields_compatibility(LttEventType
*event_type1
,
2586 LttEventType
*event_type2
,
2587 LttField
*field1
, LttField
*field2
)
2589 guint different
= 0;
2591 if(field1
== NULL
) {
2592 if(field2
== NULL
) goto end
;
2597 } else if(field2
== NULL
) {
2602 type1
= field1
->field_type
;
2603 type2
= field2
->field_type
;
2605 if(type1
->type_class
!= type2
->type_class
) {
2609 if(type1
->element_name
!= type2
->element_name
) {
2614 switch(type1
->type_class
) {
2616 case LTT_UINT_FIXED
:
2631 if(field1
->field_size
!= field2
->field_size
)
2638 LttField
*child1
= &g_array_index(type1
->fields
, LttField
, 0);
2639 LttField
*child2
= &g_array_index(type2
->fields
, LttField
, 0);
2641 if(type1
->size
!= type2
->size
)
2643 if(check_fields_compatibility(event_type1
, event_type2
, child1
, child2
))
2649 LttField
*child1
= &g_array_index(type1
->fields
, LttField
, 1);
2650 LttField
*child2
= &g_array_index(type2
->fields
, LttField
, 1);
2652 if(check_fields_compatibility(event_type1
, event_type2
, child1
, child2
))
2662 if(type1
->fields
->len
!= type2
->fields
->len
) {
2667 for(i
=0; i
< type1
->fields
->len
; i
++) {
2668 child1
= &g_array_index(type1
->fields
, LttField
, i
);
2669 child2
= &g_array_index(type2
->fields
, LttField
, i
);
2670 different
= check_fields_compatibility(event_type1
,
2671 event_type2
, child1
, child2
);
2673 if(different
) break;
2679 g_error("precompute_fields_offsets : unknown type");
2688 gint
check_fields_compatibility(LttEventType
*event_type1
,
2689 LttEventType
*event_type2
,
2690 LttField
*field1
, LttField
*field2
)
2692 guint different
= 0;
2697 if(field1
== NULL
) {
2698 if(field2
== NULL
) goto end
;
2703 } else if(field2
== NULL
) {
2708 g_assert(field1
->fixed_root
!= FIELD_UNKNOWN
);
2709 g_assert(field2
->fixed_root
!= FIELD_UNKNOWN
);
2710 g_assert(field1
->fixed_parent
!= FIELD_UNKNOWN
);
2711 g_assert(field2
->fixed_parent
!= FIELD_UNKNOWN
);
2712 g_assert(field1
->fixed_size
!= FIELD_UNKNOWN
);
2713 g_assert(field2
->fixed_size
!= FIELD_UNKNOWN
);
2715 type1
= field1
->field_type
;
2716 type2
= field2
->field_type
;
2718 if(type1
->type_class
!= type2
->type_class
) {
2722 if(type1
->element_name
!= type2
->element_name
) {
2727 switch(type1
->type_class
) {
2737 if(field1
->field_size
!= field2
->field_size
) {
2743 if(type1
->element_number
!= type2
->element_number
) {
2747 for(i
=0;i
<type1
->element_number
;i
++) {
2748 if(type1
->enum_strings
[i
] != type2
->enum_strings
[i
]) {
2755 /* Two elements : size and child */
2756 g_assert(type1
->element_number
!= type2
->element_number
);
2757 for(i
=0;i
<type1
->element_number
;i
++) {
2758 if(check_fields_compatibility(event_type1
, event_type2
,
2759 field1
->child
[0], field2
->child
[0])) {
2768 if(field1
->field_size
!= field2
->field_size
) {
2772 /* Two elements : size and child */
2773 g_assert(type1
->element_number
!= type2
->element_number
);
2774 for(i
=0;i
<type1
->element_number
;i
++) {
2775 if(check_fields_compatibility(event_type1
, event_type2
,
2776 field1
->child
[0], field2
->child
[0])) {
2784 if(type1
->element_number
!= type2
->element_number
) {
2788 for(i
=0;i
<type1
->element_number
;i
++) {
2789 if(check_fields_compatibility(event_type1
, event_type2
,
2790 field1
->child
[0], field2
->child
[0])) {
2803 /*****************************************************************************
2805 * ltt_get_int : get an integer number
2807 * reverse_byte_order: must we reverse the byte order ?
2808 * size : the size of the integer
2809 * ptr : the data pointer
2811 * gint64 : a 64 bits integer
2812 ****************************************************************************/
2814 gint64
ltt_get_int(gboolean reverse_byte_order
, gint size
, void *data
)
2819 case 1: val
= *((gint8
*)data
); break;
2820 case 2: val
= ltt_get_int16(reverse_byte_order
, data
); break;
2821 case 4: val
= ltt_get_int32(reverse_byte_order
, data
); break;
2822 case 8: val
= ltt_get_int64(reverse_byte_order
, data
); break;
2823 default: val
= ltt_get_int64(reverse_byte_order
, data
);
2824 g_critical("get_int : integer size %d unknown", size
);
2831 /*****************************************************************************
2833 * ltt_get_uint : get an unsigned integer number
2835 * reverse_byte_order: must we reverse the byte order ?
2836 * size : the size of the integer
2837 * ptr : the data pointer
2839 * guint64 : a 64 bits unsigned integer
2840 ****************************************************************************/
2842 guint64
ltt_get_uint(gboolean reverse_byte_order
, gint size
, void *data
)
2847 case 1: val
= *((gint8
*)data
); break;
2848 case 2: val
= ltt_get_uint16(reverse_byte_order
, data
); break;
2849 case 4: val
= ltt_get_uint32(reverse_byte_order
, data
); break;
2850 case 8: val
= ltt_get_uint64(reverse_byte_order
, data
); break;
2851 default: val
= ltt_get_uint64(reverse_byte_order
, data
);
2852 g_critical("get_uint : unsigned integer size %d unknown",
2861 /* get the node name of the system */
2863 char * ltt_trace_system_description_node_name (LttSystemDescription
* s
)
2865 return s
->node_name
;
2869 /* get the domain name of the system */
2871 char * ltt_trace_system_description_domain_name (LttSystemDescription
* s
)
2873 return s
->domain_name
;
2877 /* get the description of the system */
2879 char * ltt_trace_system_description_description (LttSystemDescription
* s
)
2881 return s
->description
;
2885 /* get the NTP corrected start time of the trace */
2886 LttTime
ltt_trace_start_time(LttTrace
*t
)
2888 return t
->start_time
;
2891 /* get the monotonic start time of the trace */
2892 LttTime
ltt_trace_start_time_monotonic(LttTrace
*t
)
2894 return t
->start_time_from_tsc
;
2897 LttTracefile
*ltt_tracefile_new()
2899 return g_new(LttTracefile
, 1);
2902 void ltt_tracefile_destroy(LttTracefile
*tf
)
2907 void ltt_tracefile_copy(LttTracefile
*dest
, const LttTracefile
*src
)
2912 /* Before library loading... */
2914 static void __attribute__((constructor
)) init(void)
2916 LTT_FACILITY_NAME_HEARTBEAT
= g_quark_from_string("heartbeat");
2917 LTT_EVENT_NAME_HEARTBEAT
= g_quark_from_string("heartbeat");
2919 LTT_TRACEFILE_NAME_FACILITIES
= g_quark_from_string("/control/facilities");