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 void precompute_offsets(LttFacility
*fac
, LttEventType
*event
);
112 /* Functions to parse system.xml file (using glib xml parser) */
113 static void parser_start_element (GMarkupParseContext __UNUSED__
*context
,
114 const gchar
*element_name
,
115 const gchar
**attribute_names
,
116 const gchar
**attribute_values
,
121 LttSystemDescription
* des
= (LttSystemDescription
* )user_data
;
122 if(strcmp("system", element_name
)){
123 *error
= g_error_new(G_MARKUP_ERROR
,
125 "This is not system.xml file");
129 while(attribute_names
[i
]){
130 if(strcmp("node_name", attribute_names
[i
])==0){
131 des
->node_name
= g_strdup(attribute_values
[i
]);
132 }else if(strcmp("domainname", attribute_names
[i
])==0){
133 des
->domain_name
= g_strdup(attribute_values
[i
]);
134 }else if(strcmp("cpu", attribute_names
[i
])==0){
135 des
->nb_cpu
= atoi(attribute_values
[i
]);
136 }else if(strcmp("arch_size", attribute_names
[i
])==0){
137 if(strcmp(attribute_values
[i
],"LP32") == 0) des
->size
= LTT_LP32
;
138 else if(strcmp(attribute_values
[i
],"ILP32") == 0) des
->size
= LTT_ILP32
;
139 else if(strcmp(attribute_values
[i
],"LP64") == 0) des
->size
= LTT_LP64
;
140 else if(strcmp(attribute_values
[i
],"ILP64") == 0) des
->size
= LTT_ILP64
;
141 else if(strcmp(attribute_values
[i
],"UNKNOWN") == 0) des
->size
= LTT_UNKNOWN
;
142 }else if(strcmp("endian", attribute_names
[i
])==0){
143 if(strcmp(attribute_values
[i
],"LITTLE_ENDIAN") == 0)
144 des
->endian
= LTT_LITTLE_ENDIAN
;
145 else if(strcmp(attribute_values
[i
],"BIG_ENDIAN") == 0)
146 des
->endian
= LTT_BIG_ENDIAN
;
147 }else if(strcmp("kernel_name", attribute_names
[i
])==0){
148 des
->kernel_name
= g_strdup(attribute_values
[i
]);
149 }else if(strcmp("kernel_release", attribute_names
[i
])==0){
150 des
->kernel_release
= g_strdup(attribute_values
[i
]);
151 }else if(strcmp("kernel_version", attribute_names
[i
])==0){
152 des
->kernel_version
= g_strdup(attribute_values
[i
]);
153 }else if(strcmp("machine", attribute_names
[i
])==0){
154 des
->machine
= g_strdup(attribute_values
[i
]);
155 }else if(strcmp("processor", attribute_names
[i
])==0){
156 des
->processor
= g_strdup(attribute_values
[i
]);
157 }else if(strcmp("hardware_platform", attribute_names
[i
])==0){
158 des
->hardware_platform
= g_strdup(attribute_values
[i
]);
159 }else if(strcmp("operating_system", attribute_names
[i
])==0){
160 des
->operating_system
= g_strdup(attribute_values
[i
]);
161 }else if(strcmp("ltt_major_version", attribute_names
[i
])==0){
162 des
->ltt_major_version
= atoi(attribute_values
[i
]);
163 }else if(strcmp("ltt_minor_version", attribute_names
[i
])==0){
164 des
->ltt_minor_version
= atoi(attribute_values
[i
]);
165 }else if(strcmp("ltt_block_size", attribute_names
[i
])==0){
166 des
->ltt_block_size
= atoi(attribute_values
[i
]);
168 *error
= g_error_new(G_MARKUP_ERROR
,
170 "Not a valid attribute");
177 static void parser_characters (GMarkupParseContext __UNUSED__
*context
,
179 gsize __UNUSED__ text_len
,
181 GError __UNUSED__
**error
)
183 LttSystemDescription
* des
= (LttSystemDescription
* )user_data
;
184 des
->description
= g_strdup(text
);
189 LttFacility
*ltt_trace_get_facility_by_num(LttTrace
*t
,
192 g_assert(num
< t
->facilities_by_num
->len
);
194 return &g_array_index(t
->facilities_by_num
, LttFacility
, num
);
198 guint
ltt_trace_get_num_cpu(LttTrace
*t
)
206 * Return value : 0 success, 1 bad tracefile
208 int parse_trace_header(void *header
, LttTracefile
*tf
, LttTrace
*t
)
210 guint32
*magic_number
= (guint32
*)header
;
211 struct ltt_trace_header_any
*any
= (struct ltt_trace_header_any
*)header
;
213 if(*magic_number
== LTT_MAGIC_NUMBER
)
215 else if(*magic_number
== LTT_REV_MAGIC_NUMBER
)
217 else /* invalid magic number, bad tracefile ! */
220 /* Get float byte order : might be different from int byte order
221 * (or is set to 0 if the trace has no float (kernel trace)) */
222 tf
->float_word_order
= any
->float_word_order
;
223 tf
->has_alignment
= any
->has_alignment
;
226 t
->arch_type
= ltt_get_uint32(LTT_GET_BO(tf
),
228 t
->arch_variant
= ltt_get_uint32(LTT_GET_BO(tf
),
230 t
->arch_size
= any
->arch_size
;
231 t
->ltt_major_version
= any
->major_version
;
232 t
->ltt_minor_version
= any
->minor_version
;
233 t
->flight_recorder
= any
->flight_recorder
;
234 t
->has_heartbeat
= any
->has_heartbeat
;
235 t
->has_tsc
= any
->has_tsc
;
239 switch(any
->major_version
) {
242 switch(any
->minor_version
) {
245 tf
->buffer_header_size
=
246 sizeof(struct ltt_block_start_header
)
247 + sizeof(struct ltt_trace_header_0_3
);
248 g_warning("Unsupported trace version : %hhu.%hhu",
249 any
->major_version
, any
->minor_version
);
255 struct ltt_trace_header_0_6
*vheader
=
256 (struct ltt_trace_header_0_6
*)header
;
257 tf
->buffer_header_size
=
258 sizeof(struct ltt_block_start_header
)
259 + sizeof(struct ltt_trace_header_0_6
);
261 t
->start_freq
= ltt_get_uint64(LTT_GET_BO(tf
),
262 &vheader
->start_freq
);
263 t
->start_tsc
= ltt_get_uint64(LTT_GET_BO(tf
),
264 &vheader
->start_tsc
);
265 t
->start_monotonic
= ltt_get_uint64(LTT_GET_BO(tf
),
266 &vheader
->start_monotonic
);
267 t
->start_time
.tv_sec
= ltt_get_uint64(LTT_GET_BO(tf
),
268 &vheader
->start_time_sec
);
269 t
->start_time
.tv_nsec
= ltt_get_uint64(LTT_GET_BO(tf
),
270 &vheader
->start_time_usec
);
271 t
->start_time
.tv_nsec
*= 1000; /* microsec to nanosec */
273 t
->start_time_from_tsc
= ltt_time_from_uint64(
274 (double)t
->start_tsc
* 1000000.0 / (double)t
->start_freq
);
279 g_warning("Unsupported trace version : %hhu.%hhu",
280 any
->major_version
, any
->minor_version
);
286 g_warning("Unsupported trace version : %hhu.%hhu",
287 any
->major_version
, any
->minor_version
);
297 /*****************************************************************************
299 * ltt_tracefile_open : open a trace file, construct a LttTracefile
301 * t : the trace containing the tracefile
302 * fileName : path name of the trace file
303 * tf : the tracefile structure
305 * : 0 for success, -1 otherwise.
306 ****************************************************************************/
308 gint
ltt_tracefile_open(LttTrace
*t
, gchar
* fileName
, LttTracefile
*tf
)
310 struct stat lTDFStat
; /* Trace data file status */
311 struct ltt_block_start_header
*header
;
312 int page_size
= getpagesize();
315 tf
->long_name
= g_quark_from_string(fileName
);
317 tf
->fd
= open(fileName
, O_RDONLY
);
319 g_warning("Unable to open input data file %s\n", fileName
);
323 // Get the file's status
324 if(fstat(tf
->fd
, &lTDFStat
) < 0){
325 g_warning("Unable to get the status of the input data file %s\n", fileName
);
329 // Is the file large enough to contain a trace
330 if(lTDFStat
.st_size
<
331 (off_t
)(sizeof(struct ltt_block_start_header
)
332 + sizeof(struct ltt_trace_header_any
))){
333 g_print("The input data file %s does not contain a trace\n", fileName
);
337 /* Temporarily map the buffer start header to get trace information */
338 /* Multiple of pages aligned head */
339 tf
->buffer
.head
= mmap(0,
340 PAGE_ALIGN(sizeof(struct ltt_block_start_header
)
341 + sizeof(struct ltt_trace_header_any
)), PROT_READ
,
342 MAP_PRIVATE
, tf
->fd
, 0);
343 if(tf
->buffer
.head
== MAP_FAILED
) {
344 perror("Error in allocating memory for buffer of tracefile");
347 g_assert( ( (guint
)tf
->buffer
.head
&(8-1) ) == 0); // make sure it's aligned.
349 header
= (struct ltt_block_start_header
*)tf
->buffer
.head
;
351 if(parse_trace_header(header
->trace
, tf
, NULL
)) {
352 g_warning("parse_trace_header error");
356 //store the size of the file
357 tf
->file_size
= lTDFStat
.st_size
;
358 tf
->buf_size
= ltt_get_uint32(LTT_GET_BO(tf
), &header
->buf_size
);
359 tf
->num_blocks
= tf
->file_size
/ tf
->buf_size
;
361 if(munmap(tf
->buffer
.head
,
362 PAGE_ALIGN(sizeof(struct ltt_block_start_header
)
363 + sizeof(struct ltt_trace_header_any
)))) {
364 g_warning("unmap size : %u\n",
365 PAGE_ALIGN(sizeof(struct ltt_block_start_header
)
366 + sizeof(struct ltt_trace_header_any
)));
367 perror("munmap error");
370 tf
->buffer
.head
= NULL
;
372 //read the first block
373 if(map_block(tf
,0)) {
374 perror("Cannot map block for tracefile");
382 if(munmap(tf
->buffer
.head
,
383 PAGE_ALIGN(sizeof(struct ltt_block_start_header
)
384 + sizeof(struct ltt_trace_header_any
)))) {
385 g_warning("unmap size : %u\n",
386 PAGE_ALIGN(sizeof(struct ltt_block_start_header
)
387 + sizeof(struct ltt_trace_header_any
)));
388 perror("munmap error");
397 LttTrace
*ltt_tracefile_get_trace(LttTracefile
*tf
)
403 /*****************************************************************************
404 *Open control and per cpu tracefiles
405 ****************************************************************************/
407 void ltt_tracefile_open_cpu(LttTrace
*t
, gchar
* tracefile_name
)
410 tf
= ltt_tracefile_open(t
,tracefile_name
);
412 t
->per_cpu_tracefile_number
++;
413 g_ptr_array_add(t
->per_cpu_tracefiles
, tf
);
416 gint
ltt_tracefile_open_control(LttTrace
*t
, gchar
* control_name
)
425 tf
= ltt_tracefile_open(t
,control_name
);
427 g_warning("ltt_tracefile_open_control : bad file descriptor");
430 t
->control_tracefile_number
++;
431 g_ptr_array_add(t
->control_tracefiles
,tf
);
433 //parse facilities tracefile to get base_id
434 if(strcmp(&control_name
[strlen(control_name
)-10],"facilities") ==0){
436 if(!ltt_tracefile_read(tf
,&ev
)) return 0; // end of file
438 if(ev
.event_id
== TRACE_FACILITY_LOAD
){
440 fLoad
.name
= (gchar
*)pos
;
441 fLoad
.checksum
= *(LttChecksum
*)(pos
+ strlen(fLoad
.name
));
442 fLoad
.base_code
= *(guint32
*)(pos
+ strlen(fLoad
.name
) + sizeof(LttChecksum
));
444 for(i
=0;i
<t
->facility_number
;i
++){
445 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
,i
);
446 if(strcmp(f
->name
,fLoad
.name
)==0 && fLoad
.checksum
==f
->checksum
){
447 f
->base_id
= fLoad
.base_code
;
451 if(i
==t
->facility_number
) {
452 g_warning("Facility: %s, checksum: %u is not found",
453 fLoad
.name
,(unsigned int)fLoad
.checksum
);
456 }else if(ev
.event_id
== TRACE_BLOCK_START
){
458 }else if(ev
.event_id
== TRACE_BLOCK_END
){
461 g_warning("Not valid facilities trace file");
470 /*****************************************************************************
472 * ltt_tracefile_close: close a trace file,
474 * t : tracefile which will be closed
475 ****************************************************************************/
477 void ltt_tracefile_close(LttTracefile
*t
)
479 int page_size
= getpagesize();
481 if(t
->buffer
.head
!= NULL
)
482 if(munmap(t
->buffer
.head
, PAGE_ALIGN(t
->buf_size
))) {
483 g_warning("unmap size : %u\n",
484 PAGE_ALIGN(t
->buf_size
));
485 perror("munmap error");
493 /*****************************************************************************
494 *Get system information
495 ****************************************************************************/
497 gint
getSystemInfo(LttSystemDescription
* des
, gchar
* pathname
)
504 GMarkupParseContext
* context
;
505 GError
* error
= NULL
;
506 GMarkupParser markup_parser
=
508 parser_start_element
,
511 NULL
, /* passthrough */
515 fd
= g_open(pathname
, O_RDONLY
, 0);
517 g_warning("Can not open file : %s\n", pathname
);
521 iochan
= g_io_channel_unix_new(fd
);
523 context
= g_markup_parse_context_new(&markup_parser
, 0, des
,NULL
);
525 //while(fgets(buf,DIR_NAME_SIZE, fp) != NULL){
526 while(g_io_channel_read_line(iochan
, &buf
, &length
, NULL
, &error
)
527 != G_IO_STATUS_EOF
) {
530 g_warning("Can not read xml file: \n%s\n", error
->message
);
533 if(!g_markup_parse_context_parse(context
, buf
, length
, &error
)){
535 g_warning("Can not parse xml file: \n%s\n", error
->message
);
538 g_markup_parse_context_free(context
);
540 g_io_channel_shutdown(iochan
, FALSE
, &error
); /* No flush */
542 g_warning("Can not close file: \n%s\n", error
->message
);
550 g_markup_parse_context_free(context
);
552 g_io_channel_shutdown(iochan
, FALSE
, &error
); /* No flush */
554 g_warning("Can not close file: \n%s\n", error
->message
);
565 /*****************************************************************************
566 *The following functions get facility/tracefile information
567 ****************************************************************************/
569 gint
getFacilityInfo(LttTrace
*t
, gchar
* eventdefs
)
576 gchar fullname
[DIR_NAME_SIZE
];
577 GError
* error
= NULL
;
579 dir
= g_dir_open(eventdefs
, 0, &error
);
582 g_warning("Can not open directory: %s, %s\n", eventdefs
, error
->message
);
587 while((name
= g_dir_read_name(dir
)) != NULL
){
588 if(!g_pattern_match_simple("*.xml", name
)) continue;
589 strcpy(fullname
,eventdefs
);
590 strcat(fullname
,name
);
591 ltt_facility_open(t
,fullname
);
595 for(j
=0;j
<t
->facility_number
;j
++){
596 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
, j
);
597 for(i
=0; i
<f
->event_number
; i
++){
599 setFieldsOffset(NULL
, et
, NULL
, t
);
606 /*****************************************************************************
607 *A trace is specified as a pathname to the directory containing all the
608 *associated data (control tracefiles, per cpu tracefiles, event
611 *When a trace is closed, all the associated facilities, types and fields
612 *are released as well.
616 /****************************************************************************
617 * get_absolute_pathname
619 * return the unique pathname in the system
621 * MD : Fixed this function so it uses realpath, dealing well with
622 * forgotten cases (.. were not used correctly before).
624 ****************************************************************************/
625 void get_absolute_pathname(const gchar
*pathname
, gchar
* abs_pathname
)
627 abs_pathname
[0] = '\0';
629 if ( realpath (pathname
, abs_pathname
) != NULL
)
633 /* error, return the original path unmodified */
634 strcpy(abs_pathname
, pathname
);
640 /* Search for something like : .*_.*
642 * The left side is the name, the right side is the number.
645 int get_tracefile_name_number(const gchar
*raw_name
,
649 guint raw_name_len
= strlen(raw_name
);
650 gchar char_name
[PATH_MAX
];
656 for(i
=raw_name_len
-1;i
>=0;i
--) {
657 if(raw_name
[i
] == '_') break;
659 if(i
==0) /* Either not found or name length is 0 */
663 cpu_num
= strtol(raw_name
+underscore_pos
+1, &endptr
, 10);
665 if(endptr
== raw_name
+underscore_pos
+1)
666 return -1; /* No digit */
667 if(cpu_num
== LONG_MIN
|| cpu_num
== LONG_MAX
)
668 return -1; /* underflow / overflow */
670 strncpy(char_name
, raw_name
, underscore_pos
);
672 char_name
[underscore_pos
] = '\0';
674 *name
= g_quark_from_string(char_name
);
681 GData
**ltt_trace_get_tracefiles_groups(LttTrace
*trace
)
683 return &trace
->tracefiles
;
687 void compute_tracefile_group(GQuark key_id
,
689 struct compute_tracefile_group_args
*args
)
694 for(i
=0; i
<group
->len
; i
++) {
695 tf
= &g_array_index (group
, LttTracefile
, i
);
697 args
->func(tf
, args
->func_args
);
702 void ltt_tracefile_group_destroy(gpointer data
)
704 GArray
*group
= (GArray
*)data
;
708 for(i
=0; i
<group
->len
; i
++) {
709 tf
= &g_array_index (group
, LttTracefile
, i
);
711 ltt_tracefile_close(tf
);
713 g_array_free(group
, TRUE
);
716 gboolean
ltt_tracefile_group_has_cpu_online(gpointer data
)
718 GArray
*group
= (GArray
*)data
;
722 for(i
=0; i
<group
->len
; i
++) {
723 tf
= &g_array_index (group
, LttTracefile
, i
);
724 if(tf
->cpu_online
) return 1;
730 /* Open each tracefile under a specific directory. Put them in a
731 * GData : permits to access them using their tracefile group pathname.
732 * i.e. access control/modules tracefile group by index :
735 * relative path is the path relative to the trace root
736 * root path is the full path
738 * A tracefile group is simply an array where all the per cpu tracefiles sits.
741 static int open_tracefiles(LttTrace
*trace
, gchar
*root_path
,
742 gchar
*relative_path
)
744 DIR *dir
= opendir(root_path
);
745 struct dirent
*entry
;
746 struct stat stat_buf
;
749 gchar path
[PATH_MAX
];
754 gchar rel_path
[PATH_MAX
];
763 strncpy(path
, root_path
, PATH_MAX
-1);
764 path_len
= strlen(path
);
765 path
[path_len
] = '/';
767 path_ptr
= path
+ path_len
;
769 strncpy(rel_path
, relative_path
, PATH_MAX
-1);
770 rel_path_len
= strlen(rel_path
);
771 rel_path
[rel_path_len
] = '/';
773 rel_path_ptr
= rel_path
+ rel_path_len
;
775 while((entry
= readdir(dir
)) != NULL
) {
777 if(entry
->d_name
[0] == '.') continue;
779 strncpy(path_ptr
, entry
->d_name
, PATH_MAX
- path_len
);
780 strncpy(rel_path_ptr
, entry
->d_name
, PATH_MAX
- rel_path_len
);
782 ret
= stat(path
, &stat_buf
);
788 g_debug("Tracefile file or directory : %s\n", path
);
790 if(strcmp(rel_path
, "/eventdefs") == 0) continue;
792 if(S_ISDIR(stat_buf
.st_mode
)) {
794 g_debug("Entering subdirectory...\n");
795 ret
= open_tracefiles(trace
, path
, rel_path
);
796 if(ret
< 0) continue;
797 } else if(S_ISREG(stat_buf
.st_mode
)) {
802 if(get_tracefile_name_number(rel_path
, &name
, &num
))
803 continue; /* invalid name */
805 g_debug("Opening file.\n");
806 if(ltt_tracefile_open(trace
, path
, &tmp_tf
)) {
807 g_info("Error opening tracefile %s", path
);
809 continue; /* error opening the tracefile : bad magic number ? */
812 g_debug("Tracefile name is %s and number is %u",
813 g_quark_to_string(name
), num
);
815 tmp_tf
.cpu_online
= 1;
816 tmp_tf
.cpu_num
= num
;
819 group
= g_datalist_id_get_data(&trace
->tracefiles
, name
);
821 /* Elements are automatically cleared when the array is allocated.
822 * It makes the cpu_online variable set to 0 : cpu offline, by default.
824 group
= g_array_sized_new (FALSE
, TRUE
, sizeof(LttTracefile
), 10);
825 g_datalist_id_set_data_full(&trace
->tracefiles
, name
,
826 group
, ltt_tracefile_group_destroy
);
829 /* Add the per cpu tracefile to the named group */
830 unsigned int old_len
= group
->len
;
832 group
= g_array_set_size(group
, num
+1);
833 g_array_index (group
, LttTracefile
, num
) = tmp_tf
;
843 /* ltt_get_facility_description
845 * Opens the file corresponding to the requested facility (identified by fac_id
848 * The name searched is : %trace root%/eventdefs/facname_checksum.xml
850 * Returns 0 on success, or 1 on failure.
853 static int ltt_get_facility_description(LttFacility
*f
,
855 LttTracefile
*fac_tf
)
857 char desc_file_name
[PATH_MAX
];
864 text
= g_quark_to_string(t
->pathname
);
865 textlen
= strlen(text
);
867 if(textlen
>= PATH_MAX
) goto name_error
;
868 strcpy(desc_file_name
, text
);
870 text
= "/eventdefs/";
871 textlen
+=strlen(text
);
872 if(textlen
>= PATH_MAX
) goto name_error
;
873 strcat(desc_file_name
, text
);
875 text
= g_quark_to_string(f
->name
);
876 fac_name_len
= strlen(text
);
877 textlen
+=fac_name_len
;
878 if(textlen
>= PATH_MAX
) goto name_error
;
879 strcat(desc_file_name
, text
);
881 /* arch specific facilities are named like this : name_arch */
882 if(fac_name_len
+1 < sizeof("_arch"))
885 if(!strcmp(&text
[fac_name_len
+1-sizeof("_arch")], "_arch"))
893 textlen
+=strlen(text
);
894 if(textlen
>= PATH_MAX
) goto name_error
;
895 strcat(desc_file_name
, text
);
897 err
= snprintf(desc_file_name
+textlen
, PATH_MAX
-textlen
-1,
899 if(err
< 0) goto name_error
;
901 textlen
=strlen(desc_file_name
);
906 switch(t
->arch_type
) {
907 case LTT_ARCH_TYPE_I386
:
910 case LTT_ARCH_TYPE_PPC
:
913 case LTT_ARCH_TYPE_SH
:
916 case LTT_ARCH_TYPE_S390
:
919 case LTT_ARCH_TYPE_MIPS
:
922 case LTT_ARCH_TYPE_ARM
:
924 case LTT_ARCH_TYPE_PPC64
:
926 case LTT_ARCH_TYPE_X86_64
:
930 g_error("Trace from unsupported architecture.");
932 textlen
+=strlen(text
);
933 if(textlen
>= PATH_MAX
) goto name_error
;
934 strcat(desc_file_name
, text
);
938 textlen
+=strlen(text
);
939 if(textlen
>= PATH_MAX
) goto name_error
;
940 strcat(desc_file_name
, text
);
942 err
= ltt_facility_open(f
, t
, desc_file_name
);
943 if(err
) goto facility_error
;
952 static void ltt_fac_ids_destroy(gpointer data
)
954 GArray
*fac_ids
= (GArray
*)data
;
956 g_array_free(fac_ids
, TRUE
);
960 /* Presumes the tracefile is already seeked at the beginning. It makes sense,
961 * because it must be done just after the opening */
962 static int ltt_process_facility_tracefile(LttTracefile
*tf
)
971 err
= ltt_tracefile_read_seek(tf
);
972 if(err
== EPERM
) goto seek_error
;
973 else if(err
== ERANGE
) break; /* End of tracefile */
975 err
= ltt_tracefile_read_update_event(tf
);
976 if(err
) goto update_error
;
978 /* We are on a facility load/or facility unload/ or heartbeat event */
980 * * facility 0 is hardcoded : this is the core facility. It will be shown
981 * in the facility array though, and is shown as "loaded builtin" in the
983 * It contains event :
985 * 1 : facility unload
986 * 2 : state dump facility load
989 if(tf
->event
.facility_id
!= LTT_FACILITY_CORE
) {
990 /* Should only contain core facility */
991 g_warning("Error in processing facility file %s, "
992 "should not contain facility id %u.", g_quark_to_string(tf
->name
),
993 tf
->event
.facility_id
);
998 struct LttFacilityLoad
*fac_load_data
;
999 struct LttStateDumpFacilityLoad
*fac_state_dump_load_data
;
1004 switch((enum ltt_core_events
)tf
->event
.event_id
) {
1005 case LTT_EVENT_FACILITY_LOAD
:
1006 fac_name
= (char*)(tf
->event
.data
);
1007 g_debug("Doing LTT_EVENT_FACILITY_LOAD of facility %s",
1009 pos
= (tf
->event
.data
+ strlen(fac_name
) + 1);
1010 pos
+= ltt_align((size_t)pos
, sizeof(guint32
), tf
->has_alignment
);
1011 fac_load_data
= (struct LttFacilityLoad
*)pos
;
1013 fac
= &g_array_index (tf
->trace
->facilities_by_num
, LttFacility
,
1014 ltt_get_uint32(LTT_GET_BO(tf
), &fac_load_data
->id
));
1015 /* facility may already exist if trace is paused/unpaused */
1016 if(fac
->exists
) continue;
1017 fac
->name
= g_quark_from_string(fac_name
);
1018 fac
->checksum
= ltt_get_uint32(LTT_GET_BO(tf
),
1019 &fac_load_data
->checksum
);
1020 fac
->id
= ltt_get_uint32(LTT_GET_BO(tf
), &fac_load_data
->id
);
1021 fac
->pointer_size
= ltt_get_uint32(LTT_GET_BO(tf
),
1022 &fac_load_data
->pointer_size
);
1023 fac
->int_size
= ltt_get_uint32(LTT_GET_BO(tf
),
1024 &fac_load_data
->int_size
);
1025 fac
->long_size
= ltt_get_uint32(LTT_GET_BO(tf
),
1026 &fac_load_data
->long_size
);
1027 fac
->size_t_size
= ltt_get_uint32(LTT_GET_BO(tf
),
1028 &fac_load_data
->size_t_size
);
1029 fac
->alignment
= ltt_get_uint32(LTT_GET_BO(tf
),
1030 &fac_load_data
->has_alignment
);
1032 if(ltt_get_facility_description(fac
, tf
->trace
, tf
))
1033 continue; /* error opening description */
1035 fac
->trace
= tf
->trace
;
1037 /* Preset the field offsets */
1038 for(i
=0; i
<fac
->events
->len
; i
++){
1039 et
= &g_array_index(fac
->events
, LttEventType
, i
);
1040 precompute_offsets(fac
, et
);
1045 fac_ids
= g_datalist_id_get_data(&tf
->trace
->facilities_by_name
,
1047 if(fac_ids
== NULL
) {
1048 fac_ids
= g_array_sized_new (FALSE
, TRUE
, sizeof(guint
), 1);
1049 g_datalist_id_set_data_full(&tf
->trace
->facilities_by_name
,
1051 fac_ids
, ltt_fac_ids_destroy
);
1053 g_array_append_val(fac_ids
, fac
->id
);
1056 case LTT_EVENT_FACILITY_UNLOAD
:
1057 g_debug("Doing LTT_EVENT_FACILITY_UNLOAD");
1058 /* We don't care about unload : facilities ID are valid for the whole
1059 * trace. They simply won't be used after the unload. */
1061 case LTT_EVENT_STATE_DUMP_FACILITY_LOAD
:
1062 fac_name
= (char*)(tf
->event
.data
);
1063 g_debug("Doing LTT_EVENT_STATE_DUMP_FACILITY_LOAD of facility %s",
1065 pos
= (tf
->event
.data
+ strlen(fac_name
) + 1);
1066 pos
+= ltt_align((size_t)pos
, sizeof(guint32
), tf
->has_alignment
);
1067 fac_state_dump_load_data
= (struct LttStateDumpFacilityLoad
*)pos
;
1069 fac
= &g_array_index (tf
->trace
->facilities_by_num
, LttFacility
,
1070 ltt_get_uint32(LTT_GET_BO(tf
), &fac_state_dump_load_data
->id
));
1071 /* facility may already exist if trace is paused/unpaused */
1072 if(fac
->exists
) continue;
1073 fac
->name
= g_quark_from_string(fac_name
);
1074 fac
->checksum
= ltt_get_uint32(LTT_GET_BO(tf
),
1075 &fac_state_dump_load_data
->checksum
);
1076 fac
->id
= ltt_get_uint32(LTT_GET_BO(tf
),
1077 &fac_state_dump_load_data
->id
);
1078 fac
->pointer_size
= ltt_get_uint32(LTT_GET_BO(tf
),
1079 &fac_state_dump_load_data
->pointer_size
);
1080 fac
->int_size
= ltt_get_uint32(LTT_GET_BO(tf
),
1081 &fac_state_dump_load_data
->int_size
);
1082 fac
->long_size
= ltt_get_uint32(LTT_GET_BO(tf
),
1083 &fac_state_dump_load_data
->long_size
);
1084 fac
->size_t_size
= ltt_get_uint32(LTT_GET_BO(tf
),
1085 &fac_state_dump_load_data
->size_t_size
);
1086 fac
->alignment
= ltt_get_uint32(LTT_GET_BO(tf
),
1087 &fac_state_dump_load_data
->has_alignment
);
1088 if(ltt_get_facility_description(fac
, tf
->trace
, tf
))
1089 continue; /* error opening description */
1091 fac
->trace
= tf
->trace
;
1093 /* Preset the field offsets */
1094 for(i
=0; i
<fac
->events
->len
; i
++){
1095 et
= &g_array_index(fac
->events
, LttEventType
, i
);
1096 precompute_offsets(fac
, et
);
1101 fac_ids
= g_datalist_id_get_data(&tf
->trace
->facilities_by_name
,
1103 if(fac_ids
== NULL
) {
1104 fac_ids
= g_array_sized_new (FALSE
, TRUE
, sizeof(guint
), 1);
1105 g_datalist_id_set_data_full(&tf
->trace
->facilities_by_name
,
1107 fac_ids
, ltt_fac_ids_destroy
);
1109 g_array_append_val(fac_ids
, fac
->id
);
1112 case LTT_EVENT_HEARTBEAT
:
1115 g_warning("Error in processing facility file %s, "
1116 "unknown event id %hhu in core facility.",
1117 g_quark_to_string(tf
->name
),
1118 tf
->event
.event_id
);
1120 goto event_id_error
;
1126 /* Error handling */
1131 g_warning("An error occured in facility tracefile parsing");
1136 LttTrace
*ltt_trace_open(const gchar
*pathname
)
1138 gchar abs_path
[PATH_MAX
];
1143 struct ltt_block_start_header
*header
;
1145 struct dirent
*entry
;
1146 guint control_found
= 0;
1147 guint eventdefs_found
= 0;
1148 struct stat stat_buf
;
1149 gchar path
[PATH_MAX
];
1151 t
= g_new(LttTrace
, 1);
1152 if(!t
) goto alloc_error
;
1154 get_absolute_pathname(pathname
, abs_path
);
1155 t
->pathname
= g_quark_from_string(abs_path
);
1157 g_datalist_init(&t
->tracefiles
);
1159 /* Test to see if it looks like a trace */
1160 dir
= opendir(abs_path
);
1165 while((entry
= readdir(dir
)) != NULL
) {
1166 strcpy(path
, abs_path
);
1168 strcat(path
, entry
->d_name
);
1169 ret
= stat(path
, &stat_buf
);
1174 if(S_ISDIR(stat_buf
.st_mode
)) {
1175 if(strcmp(entry
->d_name
, "control") == 0) {
1178 if(strcmp(entry
->d_name
, "eventdefs") == 0) {
1179 eventdefs_found
= 1;
1185 if(!control_found
|| !eventdefs_found
) goto find_error
;
1187 /* Open all the tracefiles */
1188 if(open_tracefiles(t
, abs_path
, "")) {
1189 g_warning("Error opening tracefile %s", abs_path
);
1193 /* Prepare the facilities containers : array and mapping */
1194 /* Array is zeroed : the "exists" field is set to false by default */
1195 t
->facilities_by_num
= g_array_sized_new (FALSE
,
1196 TRUE
, sizeof(LttFacility
),
1198 t
->facilities_by_num
= g_array_set_size(t
->facilities_by_num
, NUM_FACILITIES
);
1200 g_datalist_init(&t
->facilities_by_name
);
1202 /* Parse each trace control/facilitiesN files : get runtime fac. info */
1203 group
= g_datalist_id_get_data(&t
->tracefiles
, LTT_TRACEFILE_NAME_FACILITIES
);
1205 g_error("Trace %s has no facility tracefile", abs_path
);
1207 goto facilities_error
;
1210 /* Get the trace information for the control/facility 0 tracefile */
1211 g_assert(group
->len
> 0);
1212 tf
= &g_array_index (group
, LttTracefile
, 0);
1213 header
= (struct ltt_block_start_header
*)tf
->buffer
.head
;
1214 g_assert(parse_trace_header(header
->trace
,
1217 t
->num_cpu
= group
->len
;
1219 for(i
=0; i
<group
->len
; i
++) {
1220 tf
= &g_array_index (group
, LttTracefile
, i
);
1221 if(ltt_process_facility_tracefile(tf
))
1222 goto facilities_error
;
1227 /* Error handling */
1229 g_datalist_clear(&t
->facilities_by_name
);
1230 g_array_free(t
->facilities_by_num
, TRUE
);
1232 g_datalist_clear(&t
->tracefiles
);
1240 GQuark
ltt_trace_name(const LttTrace
*t
)
1246 /******************************************************************************
1247 * When we copy a trace, we want all the opening actions to happen again :
1248 * the trace will be reopened and totally independant from the original.
1249 * That's why we call ltt_trace_open.
1250 *****************************************************************************/
1251 LttTrace
*ltt_trace_copy(LttTrace
*self
)
1253 return ltt_trace_open(g_quark_to_string(self
->pathname
));
1256 void ltt_trace_close(LttTrace
*t
)
1261 for(i
=0; i
<t
->facilities_by_num
->len
; i
++) {
1262 fac
= &g_array_index (t
->facilities_by_num
, LttFacility
, i
);
1264 ltt_facility_close(fac
);
1267 g_datalist_clear(&t
->facilities_by_name
);
1268 g_array_free(t
->facilities_by_num
, TRUE
);
1269 g_datalist_clear(&t
->tracefiles
);
1274 /*****************************************************************************
1275 *Get the system description of the trace
1276 ****************************************************************************/
1278 LttFacility
*ltt_trace_facility_by_id(LttTrace
*t
, guint8 id
)
1280 g_assert(id
< t
->facilities_by_num
->len
);
1281 return &g_array_index(t
->facilities_by_num
, LttFacility
, id
);
1284 /* ltt_trace_facility_get_by_name
1286 * Returns the GArray of facility indexes. All the fac_ids that matches the
1287 * requested facility name.
1289 * If name is not found, returns NULL.
1291 GArray
*ltt_trace_facility_get_by_name(LttTrace
*t
, GQuark name
)
1293 return g_datalist_id_get_data(&t
->facilities_by_name
, name
);
1296 /*****************************************************************************
1297 * Functions to discover all the event types in the trace
1298 ****************************************************************************/
1301 unsigned ltt_trace_eventtype_number(LttTrace
*t
)
1305 unsigned int num
= t
->facility_number
;
1309 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
, i
);
1310 count
+= f
->event_number
;
1317 //use an iteration on all the trace facilities, and inside iteration on all the
1318 //event types in each facilities instead.
1319 LttEventType
*ltt_trace_eventtype_get(LttTrace
*t
, unsigned evId
)
1321 LttEventType
*event_type
;
1324 f
= ltt_trace_facility_by_id(t
,evId
);
1326 if(unlikely(!f
)) event_type
= NULL
;
1327 else event_type
= f
->events
[evId
- f
->base_id
];
1334 /*****************************************************************************
1335 * ltt_trace_find_tracefile
1337 * Find a tracefile by name and index in the group.
1339 * Returns a pointer to the tracefiles, else NULL.
1340 ****************************************************************************/
1342 LttTracefile
*ltt_trace_find_tracefile(LttTrace
*t
, const gchar
*name
)
1347 /*****************************************************************************
1348 * Get the start time and end time of the trace
1349 ****************************************************************************/
1351 static void ltt_tracefile_time_span_get(LttTracefile
*tf
,
1352 LttTime
*start
, LttTime
*end
)
1356 err
= map_block(tf
, 0);
1358 g_error("Can not map block");
1359 *start
= ltt_time_infinite
;
1361 *start
= tf
->buffer
.begin
.timestamp
;
1363 err
= map_block(tf
, tf
->num_blocks
- 1); /* Last block */
1365 g_error("Can not map block");
1366 *end
= ltt_time_zero
;
1368 *end
= tf
->buffer
.end
.timestamp
;
1371 struct tracefile_time_span_get_args
{
1377 static void group_time_span_get(GQuark name
, gpointer data
, gpointer user_data
)
1379 struct tracefile_time_span_get_args
*args
=
1380 (struct tracefile_time_span_get_args
*)user_data
;
1382 GArray
*group
= (GArray
*)data
;
1388 for(i
=0; i
<group
->len
; i
++) {
1389 tf
= &g_array_index (group
, LttTracefile
, i
);
1390 if(tf
->cpu_online
) {
1391 ltt_tracefile_time_span_get(tf
, &tmp_start
, &tmp_end
);
1392 if(ltt_time_compare(*args
->start
, tmp_start
)>0) *args
->start
= tmp_start
;
1393 if(ltt_time_compare(*args
->end
, tmp_end
)<0) *args
->end
= tmp_end
;
1398 void ltt_trace_time_span_get(LttTrace
*t
, LttTime
*start
, LttTime
*end
)
1400 LttTime min_start
= ltt_time_infinite
;
1401 LttTime max_end
= ltt_time_zero
;
1402 struct tracefile_time_span_get_args args
= { t
, &min_start
, &max_end
};
1404 g_datalist_foreach(&t
->tracefiles
, &group_time_span_get
, &args
);
1406 if(start
!= NULL
) *start
= min_start
;
1407 if(end
!= NULL
) *end
= max_end
;
1412 /*****************************************************************************
1413 *Get the name of a tracefile
1414 ****************************************************************************/
1416 GQuark
ltt_tracefile_name(const LttTracefile
*tf
)
1421 GQuark
ltt_tracefile_long_name(const LttTracefile
*tf
)
1423 return tf
->long_name
;
1428 guint
ltt_tracefile_num(LttTracefile
*tf
)
1433 /*****************************************************************************
1434 * Get the number of blocks in the tracefile
1435 ****************************************************************************/
1437 guint
ltt_tracefile_block_number(LttTracefile
*tf
)
1439 return tf
->num_blocks
;
1443 /* Seek to the first event in a tracefile that has a time equal or greater than
1444 * the time passed in parameter.
1446 * If the time parameter is outside the tracefile time span, seek to the first
1447 * event or if after, return ERANGE.
1449 * If the time parameter is before the first event, we have to seek specially to
1452 * If the time is after the end of the trace, return ERANGE.
1454 * Do a binary search to find the right block, then a sequential search in the
1455 * block to find the event.
1457 * In the special case where the time requested fits inside a block that has no
1458 * event corresponding to the requested time, the first event of the next block
1461 * IMPORTANT NOTE : // FIXME everywhere...
1463 * You MUST NOT do a ltt_tracefile_read right after a ltt_tracefile_seek_time :
1464 * you will jump over an event if you do.
1466 * Return value : 0 : no error, the tf->event can be used
1467 * ERANGE : time if after the last event of the trace
1468 * otherwise : this is an error.
1472 int ltt_tracefile_seek_time(LttTracefile
*tf
, LttTime time
)
1476 unsigned int block_num
, high
, low
;
1478 /* seek at the beginning of trace */
1479 err
= map_block(tf
, 0); /* First block */
1481 g_error("Can not map block");
1485 /* If the time is lower or equal the beginning of the trace,
1486 * go to the first event. */
1487 if(ltt_time_compare(time
, tf
->buffer
.begin
.timestamp
) <= 0) {
1488 ret
= ltt_tracefile_read(tf
);
1489 if(ret
== ERANGE
) goto range
;
1490 else if (ret
) goto fail
;
1491 goto found
; /* There is either no event in the trace or the event points
1492 to the first event in the trace */
1495 err
= map_block(tf
, tf
->num_blocks
- 1); /* Last block */
1497 g_error("Can not map block");
1501 /* If the time is after the end of the trace, return ERANGE. */
1502 if(ltt_time_compare(time
, tf
->buffer
.end
.timestamp
) > 0) {
1506 /* Binary search the block */
1507 high
= tf
->num_blocks
- 1;
1511 block_num
= ((high
-low
) / 2) + low
;
1513 err
= map_block(tf
, block_num
);
1515 g_error("Can not map block");
1519 /* We cannot divide anymore : this is what would happen if the time
1520 * requested was exactly between two consecutive buffers'end and start
1521 * timestamps. This is also what would happend if we didn't deal with out
1522 * of span cases prior in this function. */
1523 /* The event is right in the buffer!
1524 * (or in the next buffer first event) */
1526 ret
= ltt_tracefile_read(tf
);
1527 if(ret
== ERANGE
) goto range
; /* ERANGE or EPERM */
1528 else if(ret
) goto fail
;
1530 if(ltt_time_compare(time
, tf
->event
.event_time
) <= 0)
1534 } else if(ltt_time_compare(time
, tf
->buffer
.begin
.timestamp
) < 0) {
1535 /* go to lower part */
1536 high
= block_num
- 1;
1537 } else if(ltt_time_compare(time
, tf
->buffer
.end
.timestamp
) > 0) {
1538 /* go to higher part */
1539 low
= block_num
+ 1;
1540 } else {/* The event is right in the buffer!
1541 (or in the next buffer first event) */
1543 ret
= ltt_tracefile_read(tf
);
1544 if(ret
== ERANGE
) goto range
; /* ERANGE or EPERM */
1545 else if(ret
) goto fail
;
1547 if(ltt_time_compare(time
, tf
->event
.event_time
) <= 0)
1559 /* Error handling */
1561 g_error("ltt_tracefile_seek_time failed on tracefile %s",
1562 g_quark_to_string(tf
->name
));
1567 int ltt_tracefile_seek_position(LttTracefile
*tf
, const LttEventPosition
*ep
) {
1571 if(ep
->tracefile
!= tf
) {
1575 err
= map_block(tf
, ep
->block
);
1577 g_error("Can not map block");
1581 tf
->event
.offset
= ep
->offset
;
1583 err
= ltt_tracefile_read_update_event(tf
);
1585 err
= ltt_tracefile_read_op(tf
);
1591 g_error("ltt_tracefile_seek_time failed on tracefile %s",
1592 g_quark_to_string(tf
->name
));
1596 /* Calculate the real event time based on the buffer boundaries */
1597 LttTime
ltt_interpolate_time(LttTracefile
*tf
, LttEvent
*event
)
1601 g_assert(tf
->trace
->has_tsc
);
1603 // time = ltt_time_from_uint64(
1604 // cycles_2_ns(tf, (guint64)(tf->buffer.tsc - tf->buffer.begin.cycle_count)));
1605 time
= ltt_time_from_uint64(
1606 (double)(tf
->buffer
.tsc
- tf
->trace
->start_tsc
) * 1000000.0
1607 / (double)tf
->trace
->start_freq
);
1608 //time = ltt_time_add(tf->buffer.begin.timestamp, time);
1609 time
= ltt_time_add(tf
->trace
->start_time_from_tsc
, time
);
1615 /* Get the current event of the tracefile : valid until the next read */
1616 LttEvent
*ltt_tracefile_get_event(LttTracefile
*tf
)
1623 /*****************************************************************************
1625 * ltt_tracefile_read : Read the next event in the tracefile
1630 * Returns 0 if an event can be used in tf->event.
1631 * Returns ERANGE on end of trace. The event in tf->event still can be used
1632 * (if the last block was not empty).
1633 * Returns EPERM on error.
1635 * This function does make the tracefile event structure point to the event
1636 * currently pointed to by the tf->event.
1638 * Note : you must call a ltt_tracefile_seek to the beginning of the trace to
1639 * reinitialize it after an error if you want results to be coherent.
1640 * It would be the case if a end of trace last buffer has no event : the end
1641 * of trace wouldn't be returned, but an error.
1642 * We make the assumption there is at least one event per buffer.
1643 ****************************************************************************/
1645 int ltt_tracefile_read(LttTracefile
*tf
)
1649 err
= ltt_tracefile_read_seek(tf
);
1651 err
= ltt_tracefile_read_update_event(tf
);
1653 err
= ltt_tracefile_read_op(tf
);
1659 int ltt_tracefile_read_seek(LttTracefile
*tf
)
1663 /* Get next buffer until we finally have an event, or end of trace */
1665 err
= ltt_seek_next_event(tf
);
1666 if(unlikely(err
== ENOPROTOOPT
)) {
1670 /* Are we at the end of the buffer ? */
1672 if(unlikely(tf
->buffer
.index
== tf
->num_blocks
-1)){ /* end of trace ? */
1675 /* get next block */
1676 err
= map_block(tf
, tf
->buffer
.index
+ 1);
1678 g_error("Can not map block");
1682 } else break; /* We found an event ! */
1689 /* do specific operation on events */
1690 int ltt_tracefile_read_op(LttTracefile
*tf
)
1696 /* do event specific operation */
1698 /* do something if its an heartbeat event : increment the heartbeat count */
1699 //if(event->facility_id == LTT_FACILITY_CORE)
1700 // if(event->event_id == LTT_EVENT_HEARTBEAT)
1701 // tf->cur_heart_beat_number++;
1707 /* same as ltt_tracefile_read, but does not seek to the next event nor call
1708 * event specific operation. */
1709 int ltt_tracefile_read_update_event(LttTracefile
*tf
)
1715 pos
= tf
->buffer
.head
+ event
->offset
;
1717 /* Read event header */
1719 /* Align the head */
1720 pos
+= ltt_align((size_t)pos
, tf
->trace
->arch_size
, tf
->has_alignment
);
1722 if(tf
->trace
->has_tsc
) {
1723 if(tf
->trace
->has_heartbeat
) {
1724 event
->time
.timestamp
= ltt_get_uint32(LTT_GET_BO(tf
),
1726 /* 32 bits -> 64 bits tsc */
1727 /* note : still works for seek and non seek cases. */
1728 if(event
->time
.timestamp
< (0xFFFFFFFFULL
&tf
->buffer
.tsc
)) {
1729 tf
->buffer
.tsc
= ((tf
->buffer
.tsc
&0xFFFFFFFF00000000ULL
)
1731 | (guint64
)event
->time
.timestamp
;
1732 event
->tsc
= tf
->buffer
.tsc
;
1735 tf
->buffer
.tsc
= (tf
->buffer
.tsc
&0xFFFFFFFF00000000ULL
)
1736 | (guint64
)event
->time
.timestamp
;
1737 event
->tsc
= tf
->buffer
.tsc
;
1739 pos
+= sizeof(guint32
);
1741 event
->tsc
= ltt_get_uint64(LTT_GET_BO(tf
), pos
);
1742 tf
->buffer
.tsc
= event
->tsc
;
1743 pos
+= sizeof(guint64
);
1746 event
->event_time
= ltt_interpolate_time(tf
, event
);
1748 event
->time
.delta
.tv_sec
= 0;
1749 event
->time
.delta
.tv_nsec
= ltt_get_uint32(LTT_GET_BO(tf
),
1750 pos
) * NSEC_PER_USEC
;
1752 event
->tsc
= tf
->buffer
.tsc
;
1754 event
->event_time
= ltt_time_add(tf
->buffer
.begin
.timestamp
,
1756 pos
+= sizeof(guint32
);
1759 event
->facility_id
= *(guint8
*)pos
;
1760 pos
+= sizeof(guint8
);
1762 event
->event_id
= *(guint8
*)pos
;
1763 pos
+= sizeof(guint8
);
1765 event
->event_size
= ltt_get_uint16(LTT_GET_BO(tf
), pos
);
1766 pos
+= sizeof(guint16
);
1768 /* Align the head */
1769 pos
+= ltt_align((size_t)pos
, tf
->trace
->arch_size
, tf
->has_alignment
);
1773 /* get the data size and update the event fields with the current
1775 ltt_update_event_size(tf
);
1781 /****************************************************************************
1783 * map_block : map a block from the file
1785 * lttdes : ltt trace file
1786 * whichBlock : the block which will be read
1789 * EINVAL : lseek fail
1790 * EIO : can not read from the file
1791 ****************************************************************************/
1793 static gint
map_block(LttTracefile
* tf
, guint block_num
)
1795 int page_size
= getpagesize();
1796 struct ltt_block_start_header
*header
;
1798 g_assert(block_num
< tf
->num_blocks
);
1800 if(tf
->buffer
.head
!= NULL
) {
1801 if(munmap(tf
->buffer
.head
, PAGE_ALIGN(tf
->buf_size
))) {
1802 g_warning("unmap size : %u\n",
1803 PAGE_ALIGN(tf
->buf_size
));
1804 perror("munmap error");
1810 /* Multiple of pages aligned head */
1811 tf
->buffer
.head
= mmap(0,
1812 PAGE_ALIGN(tf
->buf_size
),
1813 PROT_READ
, MAP_PRIVATE
, tf
->fd
,
1814 PAGE_ALIGN((off_t
)tf
->buf_size
* (off_t
)block_num
));
1816 if(tf
->buffer
.head
== MAP_FAILED
) {
1817 perror("Error in allocating memory for buffer of tracefile");
1821 g_assert( ( (guint
)tf
->buffer
.head
&(8-1) ) == 0); // make sure it's aligned.
1824 tf
->buffer
.index
= block_num
;
1826 header
= (struct ltt_block_start_header
*)tf
->buffer
.head
;
1829 tf
->buffer
.begin
.timestamp
= ltt_time_add(
1830 ltt_time_from_uint64(
1831 ltt_get_uint64(LTT_GET_BO(tf
),
1832 &header
->begin
.timestamp
)
1833 - tf
->trace
->start_monotonic
),
1834 tf
->trace
->start_time
);
1836 //g_debug("block %u begin : %lu.%lu", block_num,
1837 // tf->buffer.begin.timestamp.tv_sec, tf->buffer.begin.timestamp.tv_nsec);
1838 tf
->buffer
.begin
.cycle_count
= ltt_get_uint64(LTT_GET_BO(tf
),
1839 &header
->begin
.cycle_count
);
1840 tf
->buffer
.begin
.freq
= ltt_get_uint64(LTT_GET_BO(tf
),
1841 &header
->begin
.freq
);
1842 tf
->buffer
.begin
.timestamp
= ltt_time_add(
1843 ltt_time_from_uint64(
1844 (double)(tf
->buffer
.begin
.cycle_count
1845 - tf
->trace
->start_tsc
) * 1000000.0
1846 / (double)tf
->trace
->start_freq
),
1847 tf
->trace
->start_time_from_tsc
);
1850 tf
->buffer
.end
.timestamp
= ltt_time_add(
1851 ltt_time_from_uint64(
1852 ltt_get_uint64(LTT_GET_BO(tf
),
1853 &header
->end
.timestamp
)
1854 - tf
->trace
->start_monotonic
),
1855 tf
->trace
->start_time
);
1857 //g_debug("block %u end : %lu.%lu", block_num,
1858 // tf->buffer.end.timestamp.tv_sec, tf->buffer.end.timestamp.tv_nsec);
1859 tf
->buffer
.end
.cycle_count
= ltt_get_uint64(LTT_GET_BO(tf
),
1860 &header
->end
.cycle_count
);
1861 tf
->buffer
.end
.freq
= ltt_get_uint64(LTT_GET_BO(tf
),
1863 tf
->buffer
.lost_size
= ltt_get_uint32(LTT_GET_BO(tf
),
1864 &header
->lost_size
);
1865 tf
->buffer
.end
.timestamp
= ltt_time_add(
1866 ltt_time_from_uint64(
1867 (double)(tf
->buffer
.end
.cycle_count
1868 - tf
->trace
->start_tsc
) * 1000000.0
1869 / (double)tf
->trace
->start_freq
),
1870 tf
->trace
->start_time_from_tsc
);
1872 tf
->buffer
.tsc
= tf
->buffer
.begin
.cycle_count
;
1873 tf
->event
.tsc
= tf
->buffer
.tsc
;
1874 tf
->buffer
.freq
= tf
->buffer
.begin
.freq
;
1877 * eventually support variable buffer size : will need a partial pre-read of
1878 * the headers to create an index when we open the trace... eventually. */
1879 g_assert(tf
->buf_size
== ltt_get_uint32(LTT_GET_BO(tf
),
1880 &header
->buf_size
));
1882 /* Now that the buffer is mapped, calculate the time interpolation for the
1885 // tf->buffer.nsecs_per_cycle = calc_nsecs_per_cycle(tf);
1886 //tf->buffer.cyc2ns_scale = calc_nsecs_per_cycle(tf);
1888 /* Make the current event point to the beginning of the buffer :
1889 * it means that the event read must get the first event. */
1890 tf
->event
.tracefile
= tf
;
1891 tf
->event
.block
= block_num
;
1892 tf
->event
.offset
= 0;
1901 /* It will update the fields offsets too */
1902 void ltt_update_event_size(LttTracefile
*tf
)
1906 /* Specific handling of core events : necessary to read the facility control
1908 LttFacility
*f
= ltt_trace_get_facility_by_num(tf
->trace
,
1909 tf
->event
.facility_id
);
1911 if(likely(tf
->event
.facility_id
== LTT_FACILITY_CORE
)) {
1912 switch((enum ltt_core_events
)tf
->event
.event_id
) {
1913 case LTT_EVENT_FACILITY_LOAD
:
1914 size
= strlen((char*)tf
->event
.data
) + 1;
1915 //g_debug("Update Event facility load of facility %s", (char*)tf->event.data);
1916 size
+= ltt_align(size
, sizeof(guint32
), tf
->has_alignment
);
1917 size
+= sizeof(struct LttFacilityLoad
);
1919 case LTT_EVENT_FACILITY_UNLOAD
:
1920 //g_debug("Update Event facility unload");
1921 size
= sizeof(struct LttFacilityUnload
);
1923 case LTT_EVENT_STATE_DUMP_FACILITY_LOAD
:
1924 size
= strlen((char*)tf
->event
.data
) + 1;
1925 size
+= ltt_align(size
, sizeof(guint32
), tf
->has_alignment
);
1926 //g_debug("Update Event facility load state dump of facility %s",
1927 // (char*)tf->event.data);
1928 size
+= sizeof(struct LttStateDumpFacilityLoad
);
1930 case LTT_EVENT_HEARTBEAT
:
1931 //g_debug("Update Event heartbeat");
1932 size
= sizeof(TimeHeartbeat
);
1935 g_warning("Error in getting event size : tracefile %s, "
1936 "unknown event id %hhu in core facility.",
1937 g_quark_to_string(tf
->name
),
1938 tf
->event
.event_id
);
1939 goto event_id_error
;
1944 g_error("Unknown facility %hhu (0x%hhx) in tracefile %s",
1945 tf
->event
.facility_id
,
1946 tf
->event
.facility_id
,
1947 g_quark_to_string(tf
->name
));
1948 goto facility_error
;
1951 LttEventType
*event_type
=
1952 ltt_facility_eventtype_get(f
, tf
->event
.event_id
);
1955 g_error("Unknown event id %hhu in facility %s in tracefile %s",
1957 g_quark_to_string(f
->name
),
1958 g_quark_to_string(tf
->name
));
1959 goto event_type_error
;
1962 /* Compute the dynamic offsets */
1963 compute_offsets(tf
, f
, event_type
, &size
, tf
->event
.data
);
1965 //g_debug("Event root field : f.e %hhu.%hhu size %zd",
1966 // tf->event.facility_id,
1967 // tf->event.event_id, size);
1970 tf
->event
.data_size
= size
;
1972 /* Check consistency between kernel and LTTV structure sizes */
1973 g_assert(tf
->event
.data_size
== tf
->event
.event_size
);
1980 tf
->event
.data_size
= 0;
1984 /* Take the tf current event offset and use the event facility id and event id
1985 * to figure out where is the next event offset.
1987 * This is an internal function not aiming at being used elsewhere : it will
1988 * not jump over the current block limits. Please consider using
1989 * ltt_tracefile_read to do this.
1991 * Returns 0 on success
1992 * ERANGE if we are at the end of the buffer.
1993 * ENOPROTOOPT if an error occured when getting the current event size.
1995 static int ltt_seek_next_event(LttTracefile
*tf
)
2000 /* seek over the buffer header if we are at the buffer start */
2001 if(tf
->event
.offset
== 0) {
2002 tf
->event
.offset
+= tf
->buffer_header_size
;
2004 if(tf
->event
.offset
== tf
->buf_size
- tf
->buffer
.lost_size
) {
2011 pos
= tf
->event
.data
;
2013 if(tf
->event
.data_size
< 0) goto error
;
2015 pos
+= (size_t)tf
->event
.data_size
;
2017 tf
->event
.offset
= pos
- tf
->buffer
.head
;
2019 if(tf
->event
.offset
== tf
->buf_size
- tf
->buffer
.lost_size
) {
2023 g_assert(tf
->event
.offset
< tf
->buf_size
- tf
->buffer
.lost_size
);
2029 g_error("Error in ltt_seek_next_event for tracefile %s",
2030 g_quark_to_string(tf
->name
));
2035 /*****************************************************************************
2037 * calc_nsecs_per_cycle : calculate nsecs per cycle for current block
2039 * 1.0 / (freq(khz) *1000) * 1000000000
2042 ****************************************************************************/
2043 /* from timer_tsc.c */
2044 #define CYC2NS_SCALE_FACTOR 10
2045 static guint32
calc_nsecs_per_cycle(LttTracefile
* tf
)
2047 //return 1e6 / (double)tf->buffer.freq;
2048 guint32 cpu_mhz
= tf
->buffer
.freq
/ 1000;
2049 guint32 cyc2ns_scale
= (1000 << CYC2NS_SCALE_FACTOR
)/cpu_mhz
;
2051 return cyc2ns_scale
;
2052 // return 1e6 / (double)tf->buffer.freq;
2055 static guint64
cycles_2_ns(LttTracefile
*tf
, guint64 cycles
)
2057 return (cycles
* tf
->buffer
.cyc2ns_scale
) >> CYC2NS_SCALE_FACTOR
;
2062 void setFieldsOffset(LttTracefile
*tf
, LttEventType
*evT
,void *evD
)
2064 LttField
* rootFld
= evT
->root_field
;
2065 // rootFld->base_address = evD;
2068 rootFld
->field_size
= getFieldtypeSize(tf
, evT
->facility
,
2069 evT
, 0,0,rootFld
, evD
);
2073 /*****************************************************************************
2075 * set_fields_offsets : set the precomputable offset of the fields
2077 * tracefile : opened trace file
2078 * event_type : the event type
2079 ****************************************************************************/
2081 void set_fields_offsets(LttTracefile
*tf
, LttEventType
*event_type
)
2083 LttField
*field
= event_type
->root_field
;
2084 enum field_status fixed_root
= FIELD_FIXED
, fixed_parent
= FIELD_FIXED
;
2087 preset_field_type_size(tf
, event_type
, 0, 0,
2088 &fixed_root
, &fixed_parent
,
2095 /*****************************************************************************
2097 * get_alignment : Get the alignment needed for a field.
2101 * returns : The size on which it must be aligned.
2103 ****************************************************************************/
2104 off_t
get_alignment(LttField
*field
)
2106 LttType
*type
= &field
->field_type
;
2108 switch(type
->type_class
) {
2110 case LTT_UINT_FIXED
:
2125 /* Align offset on type size */
2126 return field
->field_size
;
2132 g_assert(type
->fields
->len
== 1);
2134 LttField
*child
= &g_array_index(type
->fields
, LttField
, 0);
2135 return get_alignment(child
);
2139 g_assert(type
->fields
->len
== 2);
2142 LttField
*child
= &g_array_index(type
->fields
, LttField
, 0);
2144 localign
= max(localign
, get_alignment(child
));
2146 child
= &g_array_index(type
->fields
, LttField
, 1);
2147 localign
= max(localign
, get_alignment(child
));
2158 for(i
=0; i
<type
->fields
->len
; i
++) {
2159 LttField
*child
= &g_array_index(type
->fields
, LttField
, i
);
2160 localign
= max(localign
, get_alignment(child
));
2167 g_error("get_alignment : unknown type");
2172 /*****************************************************************************
2174 * field_compute_static_size : Determine the size of fields known by their
2175 * sole definition. Unions, arrays and struct sizes might be known, but
2176 * the parser does not give that information.
2181 ****************************************************************************/
2183 void field_compute_static_size(LttFacility
*fac
, LttField
*field
)
2185 LttType
*type
= &field
->field_type
;
2187 switch(type
->type_class
) {
2189 case LTT_UINT_FIXED
:
2208 /* note this : array type size is the number of elements in the array,
2209 * while array field size of the length of the array in bytes */
2210 g_assert(type
->fields
->len
== 1);
2212 LttField
*child
= &g_array_index(type
->fields
, LttField
, 0);
2213 field_compute_static_size(fac
, child
);
2215 if(child
->field_size
!= 0) {
2216 field
->field_size
= type
->size
* child
->field_size
;
2217 field
->dynamic_offsets
= g_array_sized_new(FALSE
, TRUE
,
2218 sizeof(off_t
), type
->size
);
2220 field
->field_size
= 0;
2225 g_assert(type
->fields
->len
== 2);
2227 off_t local_offset
= 0;
2228 LttField
*child
= &g_array_index(type
->fields
, LttField
, 1);
2229 field_compute_static_size(fac
, child
);
2230 field
->field_size
= 0;
2232 if(child
->field_size
!= 0) {
2233 field
->dynamic_offsets
= g_array_sized_new(FALSE
, TRUE
,
2234 sizeof(off_t
), SEQUENCE_AVG_ELEMENTS
);
2242 for(i
=0;i
<type
->fields
->len
;i
++) {
2243 LttField
*child
= &g_array_index(type
->fields
, LttField
, i
);
2244 field_compute_static_size(fac
, child
);
2245 if(child
->field_size
!= 0) {
2246 type
->size
+= ltt_align(type
->size
, get_alignment(child
),
2248 type
->size
+= child
->field_size
;
2250 /* As soon as we find a child with variable size, we have
2251 * a variable size */
2256 field
->field_size
= type
->size
;
2260 g_error("field_static_size : unknown type");
2267 /*****************************************************************************
2269 * precompute_fields_offsets : set the precomputable offset of the fields
2273 * offset : pointer to the current offset, must be incremented
2275 * return : 1 : found a variable length field, stop the processing.
2277 ****************************************************************************/
2280 gint
precompute_fields_offsets(LttFacility
*fac
, LttField
*field
, off_t
*offset
)
2282 LttType
*type
= &field
->field_type
;
2284 switch(type
->type_class
) {
2286 case LTT_UINT_FIXED
:
2301 g_assert(field
->field_size
!= 0);
2302 /* Align offset on type size */
2303 *offset
+= ltt_align(*offset
, get_alignment(field
),
2305 /* remember offset */
2306 field
->offset_root
= *offset
;
2307 field
->fixed_root
= FIELD_FIXED
;
2308 /* Increment offset */
2309 *offset
+= field
->field_size
;
2313 field
->offset_root
= *offset
;
2314 field
->fixed_root
= FIELD_FIXED
;
2318 g_assert(type
->fields
->len
== 1);
2320 LttField
*child
= &g_array_index(type
->fields
, LttField
, 0);
2322 *offset
+= ltt_align(*offset
, get_alignment(field
),
2325 /* remember offset */
2326 field
->offset_root
= *offset
;
2327 field
->array_offset
= *offset
;
2328 field
->fixed_root
= FIELD_FIXED
;
2330 /* Let the child be variable */
2331 //precompute_fields_offsets(tf, child, offset);
2333 if(field
->field_size
!= 0) {
2334 /* Increment offset */
2335 /* field_size is the array size in bytes */
2336 *offset
+= field
->field_size
;
2344 g_assert(type
->fields
->len
== 2);
2349 *offset
+= ltt_align(*offset
, get_alignment(field
),
2352 /* remember offset */
2353 field
->offset_root
= *offset
;
2354 field
->fixed_root
= FIELD_FIXED
;
2356 child
= &g_array_index(type
->fields
, LttField
, 0);
2357 ret
= precompute_fields_offsets(fac
, child
, offset
);
2358 g_assert(ret
== 0); /* Seq len cannot have variable len */
2360 child
= &g_array_index(type
->fields
, LttField
, 1);
2361 *offset
+= ltt_align(*offset
, get_alignment(child
),
2363 field
->array_offset
= *offset
;
2364 /* Let the child be variable. */
2365 //ret = precompute_fields_offsets(fac, child, offset);
2367 /* Cannot precompute fields offsets of sequence members, and has
2368 * variable length. */
2378 *offset
+= ltt_align(*offset
, get_alignment(field
),
2380 /* remember offset */
2381 field
->offset_root
= *offset
;
2382 field
->fixed_root
= FIELD_FIXED
;
2384 for(i
=0; i
< type
->fields
->len
; i
++) {
2385 child
= &g_array_index(type
->fields
, LttField
, i
);
2386 ret
= precompute_fields_offsets(fac
, child
, offset
);
2399 *offset
+= ltt_align(*offset
, get_alignment(field
),
2401 /* remember offset */
2402 field
->offset_root
= *offset
;
2403 field
->fixed_root
= FIELD_FIXED
;
2405 for(i
=0; i
< type
->fields
->len
; i
++) {
2406 *offset
= field
->offset_root
;
2407 child
= &g_array_index(type
->fields
, LttField
, i
);
2408 ret
= precompute_fields_offsets(fac
, child
, offset
);
2412 *offset
= field
->offset_root
+ field
->field_size
;
2419 g_error("precompute_fields_offsets : unknown type");
2426 /*****************************************************************************
2428 * precompute_offsets : set the precomputable offset of an event type
2431 * event : event type
2433 ****************************************************************************/
2434 void precompute_offsets(LttFacility
*fac
, LttEventType
*event
)
2440 /* First, compute the size of fixed size fields. Will determine size for
2441 * arrays, struct and unions, which is not done by the parser */
2442 for(i
=0; i
<event
->fields
->len
; i
++) {
2443 LttField
*field
= &g_array_index(event
->fields
, LttField
, i
);
2444 field_compute_static_size(fac
, field
);
2447 /* Precompute all known offsets */
2448 for(i
=0; i
<event
->fields
->len
; i
++) {
2449 LttField
*field
= &g_array_index(event
->fields
, LttField
, i
);
2450 ret
= precompute_fields_offsets(fac
, field
, &offset
);
2458 /*****************************************************************************
2460 * preset_field_type_size : set the fixed sizes of the field type
2463 * event_type : event type
2464 * offset_root : offset from the root
2465 * offset_parent : offset from the parent
2466 * fixed_root : Do we know a fixed offset to the root ?
2467 * fixed_parent : Do we know a fixed offset to the parent ?
2469 ****************************************************************************/
2473 // preset the fixed size offsets. Calculate them just like genevent-new : an
2474 // increment of a *to value that represents the offset from the start of the
2476 // The preset information is : offsets up to (and including) the first element
2477 // of variable size. All subsequent fields must be flagged "VARIABLE OFFSET".
2479 void preset_field_type_size(LttTracefile
*tf
, LttEventType
*event_type
,
2480 off_t offset_root
, off_t offset_parent
,
2481 enum field_status
*fixed_root
, enum field_status
*fixed_parent
,
2484 enum field_status local_fixed_root
, local_fixed_parent
;
2488 g_assert(field
->fixed_root
== FIELD_UNKNOWN
);
2489 g_assert(field
->fixed_parent
== FIELD_UNKNOWN
);
2490 g_assert(field
->fixed_size
== FIELD_UNKNOWN
);
2492 type
= field
->field_type
;
2494 field
->fixed_root
= *fixed_root
;
2495 if(field
->fixed_root
== FIELD_FIXED
)
2496 field
->offset_root
= offset_root
;
2498 field
->offset_root
= 0;
2500 field
->fixed_parent
= *fixed_parent
;
2501 if(field
->fixed_parent
== FIELD_FIXED
)
2502 field
->offset_parent
= offset_parent
;
2504 field
->offset_parent
= 0;
2506 size_t current_root_offset
;
2507 size_t current_offset
;
2508 enum field_status current_child_status
, final_child_status
;
2511 switch(type
->type_class
) {
2516 field
->field_size
= ltt_type_size(tf
->trace
, type
);
2517 field
->fixed_size
= FIELD_FIXED
;
2520 field
->field_size
= (off_t
)event_type
->facility
->pointer_size
;
2521 field
->fixed_size
= FIELD_FIXED
;
2525 field
->field_size
= (off_t
)event_type
->facility
->long_size
;
2526 field
->fixed_size
= FIELD_FIXED
;
2531 field
->field_size
= (off_t
)event_type
->facility
->size_t_size
;
2532 field
->fixed_size
= FIELD_FIXED
;
2535 local_fixed_root
= FIELD_VARIABLE
;
2536 local_fixed_parent
= FIELD_VARIABLE
;
2537 preset_field_type_size(tf
, event_type
,
2539 &local_fixed_root
, &local_fixed_parent
,
2541 field
->fixed_size
= FIELD_VARIABLE
;
2542 field
->field_size
= 0;
2543 *fixed_root
= FIELD_VARIABLE
;
2544 *fixed_parent
= FIELD_VARIABLE
;
2547 field
->fixed_size
= FIELD_VARIABLE
;
2548 field
->field_size
= 0;
2549 *fixed_root
= FIELD_VARIABLE
;
2550 *fixed_parent
= FIELD_VARIABLE
;
2553 local_fixed_root
= FIELD_VARIABLE
;
2554 local_fixed_parent
= FIELD_VARIABLE
;
2555 preset_field_type_size(tf
, event_type
,
2557 &local_fixed_root
, &local_fixed_parent
,
2559 field
->fixed_size
= field
->child
[0]->fixed_size
;
2560 if(field
->fixed_size
== FIELD_FIXED
) {
2561 field
->field_size
= type
->element_number
* field
->child
[0]->field_size
;
2563 field
->field_size
= 0;
2564 *fixed_root
= FIELD_VARIABLE
;
2565 *fixed_parent
= FIELD_VARIABLE
;
2569 current_root_offset
= field
->offset_root
;
2571 current_child_status
= FIELD_FIXED
;
2572 for(i
=0;i
<type
->element_number
;i
++) {
2573 preset_field_type_size(tf
, event_type
,
2574 current_root_offset
, current_offset
,
2575 fixed_root
, ¤t_child_status
,
2577 if(current_child_status
== FIELD_FIXED
) {
2578 current_root_offset
+= field
->child
[i
]->field_size
;
2579 current_offset
+= field
->child
[i
]->field_size
;
2581 current_root_offset
= 0;
2585 if(current_child_status
!= FIELD_FIXED
) {
2586 *fixed_parent
= current_child_status
;
2587 field
->field_size
= 0;
2588 field
->fixed_size
= current_child_status
;
2590 field
->field_size
= current_offset
;
2591 field
->fixed_size
= FIELD_FIXED
;
2595 current_root_offset
= field
->offset_root
;
2598 final_child_status
= FIELD_FIXED
;
2599 for(i
=0;i
<type
->element_number
;i
++) {
2600 enum field_status current_root_child_status
= FIELD_FIXED
;
2601 enum field_status current_child_status
= FIELD_FIXED
;
2602 preset_field_type_size(tf
, event_type
,
2603 current_root_offset
, current_offset
,
2604 ¤t_root_child_status
, ¤t_child_status
,
2606 if(current_child_status
!= FIELD_FIXED
)
2607 final_child_status
= current_child_status
;
2609 max_size
= max(max_size
, field
->child
[i
]->field_size
);
2611 if(final_child_status
!= FIELD_FIXED
) {
2612 g_error("LTTV does not support variable size fields in unions.");
2613 /* This will stop the application. */
2614 *fixed_root
= final_child_status
;
2615 *fixed_parent
= final_child_status
;
2616 field
->field_size
= 0;
2617 field
->fixed_size
= current_child_status
;
2619 field
->field_size
= max_size
;
2620 field
->fixed_size
= FIELD_FIXED
;
2628 /*****************************************************************************
2630 * check_fields_compatibility : Check for compatibility between two fields :
2631 * do they use the same inner structure ?
2633 * event_type1 : event type
2634 * event_type2 : event type
2637 *Returns : 0 if identical
2639 ****************************************************************************/
2640 // this function checks for equality of field types. Therefore, it does not use
2641 // per se offsets. For instance, an aligned version of a structure is
2642 // compatible with an unaligned version of the same structure.
2643 gint
check_fields_compatibility(LttEventType
*event_type1
,
2644 LttEventType
*event_type2
,
2645 LttField
*field1
, LttField
*field2
)
2647 guint different
= 0;
2651 if(field1
== NULL
) {
2652 if(field2
== NULL
) goto end
;
2657 } else if(field2
== NULL
) {
2662 type1
= &field1
->field_type
;
2663 type2
= &field2
->field_type
;
2665 if(type1
->type_class
!= type2
->type_class
) {
2670 switch(type1
->type_class
) {
2672 case LTT_UINT_FIXED
:
2687 if(field1
->field_size
!= field2
->field_size
)
2694 LttField
*child1
= &g_array_index(type1
->fields
, LttField
, 0);
2695 LttField
*child2
= &g_array_index(type2
->fields
, LttField
, 0);
2697 if(type1
->size
!= type2
->size
)
2699 if(check_fields_compatibility(event_type1
, event_type2
, child1
, child2
))
2705 LttField
*child1
= &g_array_index(type1
->fields
, LttField
, 1);
2706 LttField
*child2
= &g_array_index(type2
->fields
, LttField
, 1);
2708 if(check_fields_compatibility(event_type1
, event_type2
, child1
, child2
))
2718 if(type1
->fields
->len
!= type2
->fields
->len
) {
2723 for(i
=0; i
< type1
->fields
->len
; i
++) {
2726 child1
= &g_array_index(type1
->fields
, LttField
, i
);
2727 child2
= &g_array_index(type2
->fields
, LttField
, i
);
2728 different
= check_fields_compatibility(event_type1
,
2729 event_type2
, child1
, child2
);
2731 if(different
) break;
2737 g_error("precompute_fields_offsets : unknown type");
2746 gint
check_fields_compatibility(LttEventType
*event_type1
,
2747 LttEventType
*event_type2
,
2748 LttField
*field1
, LttField
*field2
)
2750 guint different
= 0;
2755 if(field1
== NULL
) {
2756 if(field2
== NULL
) goto end
;
2761 } else if(field2
== NULL
) {
2766 g_assert(field1
->fixed_root
!= FIELD_UNKNOWN
);
2767 g_assert(field2
->fixed_root
!= FIELD_UNKNOWN
);
2768 g_assert(field1
->fixed_parent
!= FIELD_UNKNOWN
);
2769 g_assert(field2
->fixed_parent
!= FIELD_UNKNOWN
);
2770 g_assert(field1
->fixed_size
!= FIELD_UNKNOWN
);
2771 g_assert(field2
->fixed_size
!= FIELD_UNKNOWN
);
2773 type1
= field1
->field_type
;
2774 type2
= field2
->field_type
;
2776 if(type1
->type_class
!= type2
->type_class
) {
2780 if(type1
->element_name
!= type2
->element_name
) {
2785 switch(type1
->type_class
) {
2795 if(field1
->field_size
!= field2
->field_size
) {
2801 if(type1
->element_number
!= type2
->element_number
) {
2805 for(i
=0;i
<type1
->element_number
;i
++) {
2806 if(type1
->enum_strings
[i
] != type2
->enum_strings
[i
]) {
2813 /* Two elements : size and child */
2814 g_assert(type1
->element_number
!= type2
->element_number
);
2815 for(i
=0;i
<type1
->element_number
;i
++) {
2816 if(check_fields_compatibility(event_type1
, event_type2
,
2817 field1
->child
[0], field2
->child
[0])) {
2826 if(field1
->field_size
!= field2
->field_size
) {
2830 /* Two elements : size and child */
2831 g_assert(type1
->element_number
!= type2
->element_number
);
2832 for(i
=0;i
<type1
->element_number
;i
++) {
2833 if(check_fields_compatibility(event_type1
, event_type2
,
2834 field1
->child
[0], field2
->child
[0])) {
2842 if(type1
->element_number
!= type2
->element_number
) {
2846 for(i
=0;i
<type1
->element_number
;i
++) {
2847 if(check_fields_compatibility(event_type1
, event_type2
,
2848 field1
->child
[0], field2
->child
[0])) {
2861 /*****************************************************************************
2863 * ltt_get_int : get an integer number
2865 * reverse_byte_order: must we reverse the byte order ?
2866 * size : the size of the integer
2867 * ptr : the data pointer
2869 * gint64 : a 64 bits integer
2870 ****************************************************************************/
2872 gint64
ltt_get_int(gboolean reverse_byte_order
, gint size
, void *data
)
2877 case 1: val
= *((gint8
*)data
); break;
2878 case 2: val
= ltt_get_int16(reverse_byte_order
, data
); break;
2879 case 4: val
= ltt_get_int32(reverse_byte_order
, data
); break;
2880 case 8: val
= ltt_get_int64(reverse_byte_order
, data
); break;
2881 default: val
= ltt_get_int64(reverse_byte_order
, data
);
2882 g_critical("get_int : integer size %d unknown", size
);
2889 /*****************************************************************************
2891 * ltt_get_uint : get an unsigned integer number
2893 * reverse_byte_order: must we reverse the byte order ?
2894 * size : the size of the integer
2895 * ptr : the data pointer
2897 * guint64 : a 64 bits unsigned integer
2898 ****************************************************************************/
2900 guint64
ltt_get_uint(gboolean reverse_byte_order
, gint size
, void *data
)
2905 case 1: val
= *((gint8
*)data
); break;
2906 case 2: val
= ltt_get_uint16(reverse_byte_order
, data
); break;
2907 case 4: val
= ltt_get_uint32(reverse_byte_order
, data
); break;
2908 case 8: val
= ltt_get_uint64(reverse_byte_order
, data
); break;
2909 default: val
= ltt_get_uint64(reverse_byte_order
, data
);
2910 g_critical("get_uint : unsigned integer size %d unknown",
2919 /* get the node name of the system */
2921 char * ltt_trace_system_description_node_name (LttSystemDescription
* s
)
2923 return s
->node_name
;
2927 /* get the domain name of the system */
2929 char * ltt_trace_system_description_domain_name (LttSystemDescription
* s
)
2931 return s
->domain_name
;
2935 /* get the description of the system */
2937 char * ltt_trace_system_description_description (LttSystemDescription
* s
)
2939 return s
->description
;
2943 /* get the NTP corrected start time of the trace */
2944 LttTime
ltt_trace_start_time(LttTrace
*t
)
2946 return t
->start_time
;
2949 /* get the monotonic start time of the trace */
2950 LttTime
ltt_trace_start_time_monotonic(LttTrace
*t
)
2952 return t
->start_time_from_tsc
;
2955 LttTracefile
*ltt_tracefile_new()
2957 return g_new(LttTracefile
, 1);
2960 void ltt_tracefile_destroy(LttTracefile
*tf
)
2965 void ltt_tracefile_copy(LttTracefile
*dest
, const LttTracefile
*src
)
2970 /* Before library loading... */
2972 static void __attribute__((constructor
)) init(void)
2974 LTT_FACILITY_NAME_HEARTBEAT
= g_quark_from_string("heartbeat");
2975 LTT_EVENT_NAME_HEARTBEAT
= g_quark_from_string("heartbeat");
2977 LTT_TRACEFILE_NAME_FACILITIES
= g_quark_from_string("/control/facilities");