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(LttTracefile
*tf
, 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_4
*vheader
=
256 (struct ltt_trace_header_0_4
*)header
;
257 tf
->buffer_header_size
=
258 sizeof(struct ltt_block_start_header
)
259 + sizeof(struct ltt_trace_header_0_4
);
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
= ltt_get_time(LTT_GET_BO(tf
),
268 &vheader
->start_time
);
269 t
->start_time
.tv_nsec
*= 1000; /* microsec to nanosec */
271 t
->start_time_from_tsc
= ltt_time_from_uint64(
272 (double)t
->start_tsc
* 1000000.0 / (double)t
->start_freq
);
278 struct ltt_trace_header_0_5
*vheader
=
279 (struct ltt_trace_header_0_5
*)header
;
280 tf
->buffer_header_size
=
281 sizeof(struct ltt_block_start_header
)
282 + sizeof(struct ltt_trace_header_0_5
);
284 t
->start_freq
= ltt_get_uint64(LTT_GET_BO(tf
),
285 &vheader
->start_freq
);
286 t
->start_tsc
= ltt_get_uint64(LTT_GET_BO(tf
),
287 &vheader
->start_tsc
);
288 t
->start_monotonic
= ltt_get_uint64(LTT_GET_BO(tf
),
289 &vheader
->start_monotonic
);
290 t
->start_time
.tv_sec
= ltt_get_uint64(LTT_GET_BO(tf
),
291 &vheader
->start_time_sec
);
292 t
->start_time
.tv_nsec
= ltt_get_uint64(LTT_GET_BO(tf
),
293 &vheader
->start_time_usec
);
294 t
->start_time
.tv_nsec
*= 1000; /* microsec to nanosec */
296 t
->start_time_from_tsc
= ltt_time_from_uint64(
297 (double)t
->start_tsc
* 1000000.0 / (double)t
->start_freq
);
302 g_warning("Unsupported trace version : %hhu.%hhu",
303 any
->major_version
, any
->minor_version
);
309 g_warning("Unsupported trace version : %hhu.%hhu",
310 any
->major_version
, any
->minor_version
);
320 /*****************************************************************************
322 * ltt_tracefile_open : open a trace file, construct a LttTracefile
324 * t : the trace containing the tracefile
325 * fileName : path name of the trace file
326 * tf : the tracefile structure
328 * : 0 for success, -1 otherwise.
329 ****************************************************************************/
331 gint
ltt_tracefile_open(LttTrace
*t
, gchar
* fileName
, LttTracefile
*tf
)
333 struct stat lTDFStat
; /* Trace data file status */
334 struct ltt_block_start_header
*header
;
335 int page_size
= getpagesize();
338 tf
->long_name
= g_quark_from_string(fileName
);
340 tf
->fd
= open(fileName
, O_RDONLY
);
342 g_warning("Unable to open input data file %s\n", fileName
);
346 // Get the file's status
347 if(fstat(tf
->fd
, &lTDFStat
) < 0){
348 g_warning("Unable to get the status of the input data file %s\n", fileName
);
352 // Is the file large enough to contain a trace
353 if(lTDFStat
.st_size
<
354 (off_t
)(sizeof(struct ltt_block_start_header
)
355 + sizeof(struct ltt_trace_header_any
))){
356 g_print("The input data file %s does not contain a trace\n", fileName
);
360 /* Temporarily map the buffer start header to get trace information */
361 /* Multiple of pages aligned head */
362 tf
->buffer
.head
= mmap(0,
363 PAGE_ALIGN(sizeof(struct ltt_block_start_header
)
364 + sizeof(struct ltt_trace_header_any
)), PROT_READ
,
365 MAP_PRIVATE
, tf
->fd
, 0);
366 if(tf
->buffer
.head
== MAP_FAILED
) {
367 perror("Error in allocating memory for buffer of tracefile");
370 g_assert( ( (guint
)tf
->buffer
.head
&(8-1) ) == 0); // make sure it's aligned.
372 header
= (struct ltt_block_start_header
*)tf
->buffer
.head
;
374 if(parse_trace_header(header
->trace
, tf
, NULL
)) {
375 g_warning("parse_trace_header error");
379 //store the size of the file
380 tf
->file_size
= lTDFStat
.st_size
;
381 tf
->buf_size
= ltt_get_uint32(LTT_GET_BO(tf
), &header
->buf_size
);
382 tf
->num_blocks
= tf
->file_size
/ tf
->buf_size
;
384 if(munmap(tf
->buffer
.head
,
385 PAGE_ALIGN(sizeof(struct ltt_block_start_header
)
386 + sizeof(struct ltt_trace_header_any
)))) {
387 g_warning("unmap size : %u\n",
388 PAGE_ALIGN(sizeof(struct ltt_block_start_header
)
389 + sizeof(struct ltt_trace_header_any
)));
390 perror("munmap error");
393 tf
->buffer
.head
= NULL
;
395 //read the first block
396 if(map_block(tf
,0)) {
397 perror("Cannot map block for tracefile");
405 if(munmap(tf
->buffer
.head
,
406 PAGE_ALIGN(sizeof(struct ltt_block_start_header
)
407 + sizeof(struct ltt_trace_header_any
)))) {
408 g_warning("unmap size : %u\n",
409 PAGE_ALIGN(sizeof(struct ltt_block_start_header
)
410 + sizeof(struct ltt_trace_header_any
)));
411 perror("munmap error");
420 LttTrace
*ltt_tracefile_get_trace(LttTracefile
*tf
)
426 /*****************************************************************************
427 *Open control and per cpu tracefiles
428 ****************************************************************************/
430 void ltt_tracefile_open_cpu(LttTrace
*t
, gchar
* tracefile_name
)
433 tf
= ltt_tracefile_open(t
,tracefile_name
);
435 t
->per_cpu_tracefile_number
++;
436 g_ptr_array_add(t
->per_cpu_tracefiles
, tf
);
439 gint
ltt_tracefile_open_control(LttTrace
*t
, gchar
* control_name
)
448 tf
= ltt_tracefile_open(t
,control_name
);
450 g_warning("ltt_tracefile_open_control : bad file descriptor");
453 t
->control_tracefile_number
++;
454 g_ptr_array_add(t
->control_tracefiles
,tf
);
456 //parse facilities tracefile to get base_id
457 if(strcmp(&control_name
[strlen(control_name
)-10],"facilities") ==0){
459 if(!ltt_tracefile_read(tf
,&ev
)) return 0; // end of file
461 if(ev
.event_id
== TRACE_FACILITY_LOAD
){
463 fLoad
.name
= (gchar
*)pos
;
464 fLoad
.checksum
= *(LttChecksum
*)(pos
+ strlen(fLoad
.name
));
465 fLoad
.base_code
= *(guint32
*)(pos
+ strlen(fLoad
.name
) + sizeof(LttChecksum
));
467 for(i
=0;i
<t
->facility_number
;i
++){
468 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
,i
);
469 if(strcmp(f
->name
,fLoad
.name
)==0 && fLoad
.checksum
==f
->checksum
){
470 f
->base_id
= fLoad
.base_code
;
474 if(i
==t
->facility_number
) {
475 g_warning("Facility: %s, checksum: %u is not found",
476 fLoad
.name
,(unsigned int)fLoad
.checksum
);
479 }else if(ev
.event_id
== TRACE_BLOCK_START
){
481 }else if(ev
.event_id
== TRACE_BLOCK_END
){
484 g_warning("Not valid facilities trace file");
493 /*****************************************************************************
495 * ltt_tracefile_close: close a trace file,
497 * t : tracefile which will be closed
498 ****************************************************************************/
500 void ltt_tracefile_close(LttTracefile
*t
)
502 int page_size
= getpagesize();
504 if(t
->buffer
.head
!= NULL
)
505 if(munmap(t
->buffer
.head
, PAGE_ALIGN(t
->buf_size
))) {
506 g_warning("unmap size : %u\n",
507 PAGE_ALIGN(t
->buf_size
));
508 perror("munmap error");
516 /*****************************************************************************
517 *Get system information
518 ****************************************************************************/
520 gint
getSystemInfo(LttSystemDescription
* des
, gchar
* pathname
)
527 GMarkupParseContext
* context
;
528 GError
* error
= NULL
;
529 GMarkupParser markup_parser
=
531 parser_start_element
,
534 NULL
, /* passthrough */
538 fd
= g_open(pathname
, O_RDONLY
, 0);
540 g_warning("Can not open file : %s\n", pathname
);
544 iochan
= g_io_channel_unix_new(fd
);
546 context
= g_markup_parse_context_new(&markup_parser
, 0, des
,NULL
);
548 //while(fgets(buf,DIR_NAME_SIZE, fp) != NULL){
549 while(g_io_channel_read_line(iochan
, &buf
, &length
, NULL
, &error
)
550 != G_IO_STATUS_EOF
) {
553 g_warning("Can not read xml file: \n%s\n", error
->message
);
556 if(!g_markup_parse_context_parse(context
, buf
, length
, &error
)){
558 g_warning("Can not parse xml file: \n%s\n", error
->message
);
561 g_markup_parse_context_free(context
);
563 g_io_channel_shutdown(iochan
, FALSE
, &error
); /* No flush */
565 g_warning("Can not close file: \n%s\n", error
->message
);
573 g_markup_parse_context_free(context
);
575 g_io_channel_shutdown(iochan
, FALSE
, &error
); /* No flush */
577 g_warning("Can not close file: \n%s\n", error
->message
);
588 /*****************************************************************************
589 *The following functions get facility/tracefile information
590 ****************************************************************************/
592 gint
getFacilityInfo(LttTrace
*t
, gchar
* eventdefs
)
599 gchar fullname
[DIR_NAME_SIZE
];
600 GError
* error
= NULL
;
602 dir
= g_dir_open(eventdefs
, 0, &error
);
605 g_warning("Can not open directory: %s, %s\n", eventdefs
, error
->message
);
610 while((name
= g_dir_read_name(dir
)) != NULL
){
611 if(!g_pattern_match_simple("*.xml", name
)) continue;
612 strcpy(fullname
,eventdefs
);
613 strcat(fullname
,name
);
614 ltt_facility_open(t
,fullname
);
618 for(j
=0;j
<t
->facility_number
;j
++){
619 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
, j
);
620 for(i
=0; i
<f
->event_number
; i
++){
622 setFieldsOffset(NULL
, et
, NULL
, t
);
629 /*****************************************************************************
630 *A trace is specified as a pathname to the directory containing all the
631 *associated data (control tracefiles, per cpu tracefiles, event
634 *When a trace is closed, all the associated facilities, types and fields
635 *are released as well.
639 /****************************************************************************
640 * get_absolute_pathname
642 * return the unique pathname in the system
644 * MD : Fixed this function so it uses realpath, dealing well with
645 * forgotten cases (.. were not used correctly before).
647 ****************************************************************************/
648 void get_absolute_pathname(const gchar
*pathname
, gchar
* abs_pathname
)
650 abs_pathname
[0] = '\0';
652 if ( realpath (pathname
, abs_pathname
) != NULL
)
656 /* error, return the original path unmodified */
657 strcpy(abs_pathname
, pathname
);
663 /* Search for something like : .*_.*
665 * The left side is the name, the right side is the number.
668 int get_tracefile_name_number(const gchar
*raw_name
,
672 guint raw_name_len
= strlen(raw_name
);
673 gchar char_name
[PATH_MAX
];
679 for(i
=raw_name_len
-1;i
>=0;i
--) {
680 if(raw_name
[i
] == '_') break;
682 if(i
==0) /* Either not found or name length is 0 */
686 cpu_num
= strtol(raw_name
+underscore_pos
+1, &endptr
, 10);
688 if(endptr
== raw_name
+underscore_pos
+1)
689 return -1; /* No digit */
690 if(cpu_num
== LONG_MIN
|| cpu_num
== LONG_MAX
)
691 return -1; /* underflow / overflow */
693 strncpy(char_name
, raw_name
, underscore_pos
);
695 char_name
[underscore_pos
] = '\0';
697 *name
= g_quark_from_string(char_name
);
704 GData
**ltt_trace_get_tracefiles_groups(LttTrace
*trace
)
706 return &trace
->tracefiles
;
710 void compute_tracefile_group(GQuark key_id
,
712 struct compute_tracefile_group_args
*args
)
717 for(i
=0; i
<group
->len
; i
++) {
718 tf
= &g_array_index (group
, LttTracefile
, i
);
720 args
->func(tf
, args
->func_args
);
725 void ltt_tracefile_group_destroy(gpointer data
)
727 GArray
*group
= (GArray
*)data
;
731 for(i
=0; i
<group
->len
; i
++) {
732 tf
= &g_array_index (group
, LttTracefile
, i
);
734 ltt_tracefile_close(tf
);
736 g_array_free(group
, TRUE
);
739 gboolean
ltt_tracefile_group_has_cpu_online(gpointer data
)
741 GArray
*group
= (GArray
*)data
;
745 for(i
=0; i
<group
->len
; i
++) {
746 tf
= &g_array_index (group
, LttTracefile
, i
);
747 if(tf
->cpu_online
) return 1;
753 /* Open each tracefile under a specific directory. Put them in a
754 * GData : permits to access them using their tracefile group pathname.
755 * i.e. access control/modules tracefile group by index :
758 * relative path is the path relative to the trace root
759 * root path is the full path
761 * A tracefile group is simply an array where all the per cpu tracefiles sits.
764 static int open_tracefiles(LttTrace
*trace
, gchar
*root_path
,
765 gchar
*relative_path
)
767 DIR *dir
= opendir(root_path
);
768 struct dirent
*entry
;
769 struct stat stat_buf
;
772 gchar path
[PATH_MAX
];
777 gchar rel_path
[PATH_MAX
];
786 strncpy(path
, root_path
, PATH_MAX
-1);
787 path_len
= strlen(path
);
788 path
[path_len
] = '/';
790 path_ptr
= path
+ path_len
;
792 strncpy(rel_path
, relative_path
, PATH_MAX
-1);
793 rel_path_len
= strlen(rel_path
);
794 rel_path
[rel_path_len
] = '/';
796 rel_path_ptr
= rel_path
+ rel_path_len
;
798 while((entry
= readdir(dir
)) != NULL
) {
800 if(entry
->d_name
[0] == '.') continue;
802 strncpy(path_ptr
, entry
->d_name
, PATH_MAX
- path_len
);
803 strncpy(rel_path_ptr
, entry
->d_name
, PATH_MAX
- rel_path_len
);
805 ret
= stat(path
, &stat_buf
);
811 g_debug("Tracefile file or directory : %s\n", path
);
813 if(strcmp(rel_path
, "/eventdefs") == 0) continue;
815 if(S_ISDIR(stat_buf
.st_mode
)) {
817 g_debug("Entering subdirectory...\n");
818 ret
= open_tracefiles(trace
, path
, rel_path
);
819 if(ret
< 0) continue;
820 } else if(S_ISREG(stat_buf
.st_mode
)) {
825 if(get_tracefile_name_number(rel_path
, &name
, &num
))
826 continue; /* invalid name */
828 g_debug("Opening file.\n");
829 if(ltt_tracefile_open(trace
, path
, &tmp_tf
)) {
830 g_info("Error opening tracefile %s", path
);
832 continue; /* error opening the tracefile : bad magic number ? */
835 g_debug("Tracefile name is %s and number is %u",
836 g_quark_to_string(name
), num
);
838 tmp_tf
.cpu_online
= 1;
839 tmp_tf
.cpu_num
= num
;
842 group
= g_datalist_id_get_data(&trace
->tracefiles
, name
);
844 /* Elements are automatically cleared when the array is allocated.
845 * It makes the cpu_online variable set to 0 : cpu offline, by default.
847 group
= g_array_sized_new (FALSE
, TRUE
, sizeof(LttTracefile
), 10);
848 g_datalist_id_set_data_full(&trace
->tracefiles
, name
,
849 group
, ltt_tracefile_group_destroy
);
852 /* Add the per cpu tracefile to the named group */
853 unsigned int old_len
= group
->len
;
855 group
= g_array_set_size(group
, num
+1);
856 g_array_index (group
, LttTracefile
, num
) = tmp_tf
;
866 /* ltt_get_facility_description
868 * Opens the file corresponding to the requested facility (identified by fac_id
871 * The name searched is : %trace root%/eventdefs/facname_checksum.xml
873 * Returns 0 on success, or 1 on failure.
876 static int ltt_get_facility_description(LttFacility
*f
,
878 LttTracefile
*fac_tf
)
880 char desc_file_name
[PATH_MAX
];
885 text
= g_quark_to_string(t
->pathname
);
886 textlen
= strlen(text
);
888 if(textlen
>= PATH_MAX
) goto name_error
;
889 strcpy(desc_file_name
, text
);
891 text
= "/eventdefs/";
892 textlen
+=strlen(text
);
893 if(textlen
>= PATH_MAX
) goto name_error
;
894 strcat(desc_file_name
, text
);
896 text
= g_quark_to_string(f
->name
);
897 textlen
+=strlen(text
);
898 if(textlen
>= PATH_MAX
) goto name_error
;
899 strcat(desc_file_name
, text
);
902 textlen
+=strlen(text
);
903 if(textlen
>= PATH_MAX
) goto name_error
;
904 strcat(desc_file_name
, text
);
906 err
= snprintf(desc_file_name
+textlen
, PATH_MAX
-textlen
-1,
908 if(err
< 0) goto name_error
;
910 textlen
=strlen(desc_file_name
);
914 textlen
+=strlen(text
);
915 if(textlen
>= PATH_MAX
) goto name_error
;
916 strcat(desc_file_name
, text
);
918 err
= ltt_facility_open(f
, t
, desc_file_name
);
919 if(err
) goto facility_error
;
928 static void ltt_fac_ids_destroy(gpointer data
)
930 GArray
*fac_ids
= (GArray
*)data
;
932 g_array_free(fac_ids
, TRUE
);
936 /* Presumes the tracefile is already seeked at the beginning. It makes sense,
937 * because it must be done just after the opening */
938 static int ltt_process_facility_tracefile(LttTracefile
*tf
)
947 err
= ltt_tracefile_read_seek(tf
);
948 if(err
== EPERM
) goto seek_error
;
949 else if(err
== ERANGE
) break; /* End of tracefile */
951 err
= ltt_tracefile_read_update_event(tf
);
952 if(err
) goto update_error
;
954 /* We are on a facility load/or facility unload/ or heartbeat event */
956 * * facility 0 is hardcoded : this is the core facility. It will be shown
957 * in the facility array though, and is shown as "loaded builtin" in the
959 * It contains event :
961 * 1 : facility unload
962 * 2 : state dump facility load
965 if(tf
->event
.facility_id
!= LTT_FACILITY_CORE
) {
966 /* Should only contain core facility */
967 g_warning("Error in processing facility file %s, "
968 "should not contain facility id %u.", g_quark_to_string(tf
->name
),
969 tf
->event
.facility_id
);
974 struct LttFacilityLoad
*fac_load_data
;
975 struct LttStateDumpFacilityLoad
*fac_state_dump_load_data
;
979 switch((enum ltt_core_events
)tf
->event
.event_id
) {
980 case LTT_EVENT_FACILITY_LOAD
:
981 fac_name
= (char*)(tf
->event
.data
);
982 g_debug("Doing LTT_EVENT_FACILITY_LOAD of facility %s",
985 (struct LttFacilityLoad
*)
986 (tf
->event
.data
+ strlen(fac_name
) + 1);
987 fac
= &g_array_index (tf
->trace
->facilities_by_num
, LttFacility
,
988 ltt_get_uint32(LTT_GET_BO(tf
), &fac_load_data
->id
));
989 /* facility may already exist if trace is paused/unpaused */
990 if(fac
->exists
) continue;
991 fac
->name
= g_quark_from_string(fac_name
);
992 fac
->checksum
= ltt_get_uint32(LTT_GET_BO(tf
),
993 &fac_load_data
->checksum
);
994 fac
->id
= ltt_get_uint32(LTT_GET_BO(tf
), &fac_load_data
->id
);
995 fac
->pointer_size
= ltt_get_uint32(LTT_GET_BO(tf
),
996 &fac_load_data
->pointer_size
);
997 fac
->int_size
= ltt_get_uint32(LTT_GET_BO(tf
),
998 &fac_load_data
->int_size
);
999 fac
->long_size
= ltt_get_uint32(LTT_GET_BO(tf
),
1000 &fac_load_data
->long_size
);
1001 fac
->size_t_size
= ltt_get_uint32(LTT_GET_BO(tf
),
1002 &fac_load_data
->size_t_size
);
1003 fac
->alignment
= ltt_get_uint32(LTT_GET_BO(tf
),
1004 &fac_load_data
->has_alignment
);
1006 if(ltt_get_facility_description(fac
, tf
->trace
, tf
))
1007 continue; /* error opening description */
1009 fac
->trace
= tf
->trace
;
1011 /* Preset the field offsets */
1012 for(i
=0; i
<fac
->events
->len
; i
++){
1013 et
= &g_array_index(fac
->events
, LttEventType
, i
);
1014 precompute_offsets(tf
, et
);
1019 fac_ids
= g_datalist_id_get_data(&tf
->trace
->facilities_by_name
,
1021 if(fac_ids
== NULL
) {
1022 fac_ids
= g_array_sized_new (FALSE
, TRUE
, sizeof(guint
), 1);
1023 g_datalist_id_set_data_full(&tf
->trace
->facilities_by_name
,
1025 fac_ids
, ltt_fac_ids_destroy
);
1027 g_array_append_val(fac_ids
, fac
->id
);
1030 case LTT_EVENT_FACILITY_UNLOAD
:
1031 g_debug("Doing LTT_EVENT_FACILITY_UNLOAD");
1032 /* We don't care about unload : facilities ID are valid for the whole
1033 * trace. They simply won't be used after the unload. */
1035 case LTT_EVENT_STATE_DUMP_FACILITY_LOAD
:
1036 fac_name
= (char*)(tf
->event
.data
);
1037 g_debug("Doing LTT_EVENT_STATE_DUMP_FACILITY_LOAD of facility %s",
1039 fac_state_dump_load_data
=
1040 (struct LttStateDumpFacilityLoad
*)
1041 (tf
->event
.data
+ strlen(fac_name
) + 1);
1042 fac
= &g_array_index (tf
->trace
->facilities_by_num
, LttFacility
,
1043 ltt_get_uint32(LTT_GET_BO(tf
), &fac_state_dump_load_data
->id
));
1044 /* facility may already exist if trace is paused/unpaused */
1045 if(fac
->exists
) continue;
1046 fac
->name
= g_quark_from_string(fac_name
);
1047 fac
->checksum
= ltt_get_uint32(LTT_GET_BO(tf
),
1048 &fac_state_dump_load_data
->checksum
);
1049 fac
->id
= ltt_get_uint32(LTT_GET_BO(tf
),
1050 &fac_state_dump_load_data
->id
);
1051 fac
->pointer_size
= ltt_get_uint32(LTT_GET_BO(tf
),
1052 &fac_state_dump_load_data
->pointer_size
);
1053 fac
->int_size
= ltt_get_uint32(LTT_GET_BO(tf
),
1054 &fac_state_dump_load_data
->int_size
);
1055 fac
->long_size
= ltt_get_uint32(LTT_GET_BO(tf
),
1056 &fac_state_dump_load_data
->long_size
);
1057 fac
->size_t_size
= ltt_get_uint32(LTT_GET_BO(tf
),
1058 &fac_state_dump_load_data
->size_t_size
);
1059 fac
->alignment
= ltt_get_uint32(LTT_GET_BO(tf
),
1060 &fac_state_dump_load_data
->has_alignment
);
1061 if(ltt_get_facility_description(fac
, tf
->trace
, tf
))
1062 continue; /* error opening description */
1064 fac
->trace
= tf
->trace
;
1066 /* Preset the field offsets */
1067 for(i
=0; i
<fac
->events
->len
; i
++){
1068 et
= &g_array_index(fac
->events
, LttEventType
, i
);
1069 precompute_offsets(tf
, et
);
1074 fac_ids
= g_datalist_id_get_data(&tf
->trace
->facilities_by_name
,
1076 if(fac_ids
== NULL
) {
1077 fac_ids
= g_array_sized_new (FALSE
, TRUE
, sizeof(guint
), 1);
1078 g_datalist_id_set_data_full(&tf
->trace
->facilities_by_name
,
1080 fac_ids
, ltt_fac_ids_destroy
);
1082 g_array_append_val(fac_ids
, fac
->id
);
1085 case LTT_EVENT_HEARTBEAT
:
1088 g_warning("Error in processing facility file %s, "
1089 "unknown event id %hhu in core facility.",
1090 g_quark_to_string(tf
->name
),
1091 tf
->event
.event_id
);
1093 goto event_id_error
;
1099 /* Error handling */
1104 g_warning("An error occured in facility tracefile parsing");
1109 LttTrace
*ltt_trace_open(const gchar
*pathname
)
1111 gchar abs_path
[PATH_MAX
];
1116 struct ltt_block_start_header
*header
;
1118 struct dirent
*entry
;
1119 guint control_found
= 0;
1120 guint eventdefs_found
= 0;
1121 struct stat stat_buf
;
1122 gchar path
[PATH_MAX
];
1124 t
= g_new(LttTrace
, 1);
1125 if(!t
) goto alloc_error
;
1127 get_absolute_pathname(pathname
, abs_path
);
1128 t
->pathname
= g_quark_from_string(abs_path
);
1130 g_datalist_init(&t
->tracefiles
);
1132 /* Test to see if it looks like a trace */
1133 dir
= opendir(abs_path
);
1138 while((entry
= readdir(dir
)) != NULL
) {
1139 strcpy(path
, abs_path
);
1141 strcat(path
, entry
->d_name
);
1142 ret
= stat(path
, &stat_buf
);
1147 if(S_ISDIR(stat_buf
.st_mode
)) {
1148 if(strcmp(entry
->d_name
, "control") == 0) {
1151 if(strcmp(entry
->d_name
, "eventdefs") == 0) {
1152 eventdefs_found
= 1;
1158 if(!control_found
|| !eventdefs_found
) goto find_error
;
1160 /* Open all the tracefiles */
1161 if(open_tracefiles(t
, abs_path
, "")) {
1162 g_warning("Error opening tracefile %s", abs_path
);
1166 /* Prepare the facilities containers : array and mapping */
1167 /* Array is zeroed : the "exists" field is set to false by default */
1168 t
->facilities_by_num
= g_array_sized_new (FALSE
,
1169 TRUE
, sizeof(LttFacility
),
1171 t
->facilities_by_num
= g_array_set_size(t
->facilities_by_num
, NUM_FACILITIES
);
1173 g_datalist_init(&t
->facilities_by_name
);
1175 /* Parse each trace control/facilitiesN files : get runtime fac. info */
1176 group
= g_datalist_id_get_data(&t
->tracefiles
, LTT_TRACEFILE_NAME_FACILITIES
);
1178 g_error("Trace %s has no facility tracefile", abs_path
);
1180 goto facilities_error
;
1183 /* Get the trace information for the control/facility 0 tracefile */
1184 g_assert(group
->len
> 0);
1185 tf
= &g_array_index (group
, LttTracefile
, 0);
1186 header
= (struct ltt_block_start_header
*)tf
->buffer
.head
;
1187 g_assert(parse_trace_header(header
->trace
,
1190 t
->num_cpu
= group
->len
;
1192 for(i
=0; i
<group
->len
; i
++) {
1193 tf
= &g_array_index (group
, LttTracefile
, i
);
1194 if(ltt_process_facility_tracefile(tf
))
1195 goto facilities_error
;
1200 /* Error handling */
1202 g_datalist_clear(&t
->facilities_by_name
);
1203 g_array_free(t
->facilities_by_num
, TRUE
);
1205 g_datalist_clear(&t
->tracefiles
);
1213 GQuark
ltt_trace_name(const LttTrace
*t
)
1219 /******************************************************************************
1220 * When we copy a trace, we want all the opening actions to happen again :
1221 * the trace will be reopened and totally independant from the original.
1222 * That's why we call ltt_trace_open.
1223 *****************************************************************************/
1224 LttTrace
*ltt_trace_copy(LttTrace
*self
)
1226 return ltt_trace_open(g_quark_to_string(self
->pathname
));
1229 void ltt_trace_close(LttTrace
*t
)
1234 for(i
=0; i
<t
->facilities_by_num
->len
; i
++) {
1235 fac
= &g_array_index (t
->facilities_by_num
, LttFacility
, i
);
1237 ltt_facility_close(fac
);
1240 g_datalist_clear(&t
->facilities_by_name
);
1241 g_array_free(t
->facilities_by_num
, TRUE
);
1242 g_datalist_clear(&t
->tracefiles
);
1247 /*****************************************************************************
1248 *Get the system description of the trace
1249 ****************************************************************************/
1251 LttFacility
*ltt_trace_facility_by_id(LttTrace
*t
, guint8 id
)
1253 g_assert(id
< t
->facilities_by_num
->len
);
1254 return &g_array_index(t
->facilities_by_num
, LttFacility
, id
);
1257 /* ltt_trace_facility_get_by_name
1259 * Returns the GArray of facility indexes. All the fac_ids that matches the
1260 * requested facility name.
1262 * If name is not found, returns NULL.
1264 GArray
*ltt_trace_facility_get_by_name(LttTrace
*t
, GQuark name
)
1266 return g_datalist_id_get_data(&t
->facilities_by_name
, name
);
1269 /*****************************************************************************
1270 * Functions to discover all the event types in the trace
1271 ****************************************************************************/
1274 unsigned ltt_trace_eventtype_number(LttTrace
*t
)
1278 unsigned int num
= t
->facility_number
;
1282 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
, i
);
1283 count
+= f
->event_number
;
1290 //use an iteration on all the trace facilities, and inside iteration on all the
1291 //event types in each facilities instead.
1292 LttEventType
*ltt_trace_eventtype_get(LttTrace
*t
, unsigned evId
)
1294 LttEventType
*event_type
;
1297 f
= ltt_trace_facility_by_id(t
,evId
);
1299 if(unlikely(!f
)) event_type
= NULL
;
1300 else event_type
= f
->events
[evId
- f
->base_id
];
1307 /*****************************************************************************
1308 * ltt_trace_find_tracefile
1310 * Find a tracefile by name and index in the group.
1312 * Returns a pointer to the tracefiles, else NULL.
1313 ****************************************************************************/
1315 LttTracefile
*ltt_trace_find_tracefile(LttTrace
*t
, const gchar
*name
)
1320 /*****************************************************************************
1321 * Get the start time and end time of the trace
1322 ****************************************************************************/
1324 static void ltt_tracefile_time_span_get(LttTracefile
*tf
,
1325 LttTime
*start
, LttTime
*end
)
1329 err
= map_block(tf
, 0);
1331 g_error("Can not map block");
1332 *start
= ltt_time_infinite
;
1334 *start
= tf
->buffer
.begin
.timestamp
;
1336 err
= map_block(tf
, tf
->num_blocks
- 1); /* Last block */
1338 g_error("Can not map block");
1339 *end
= ltt_time_zero
;
1341 *end
= tf
->buffer
.end
.timestamp
;
1344 struct tracefile_time_span_get_args
{
1350 static void group_time_span_get(GQuark name
, gpointer data
, gpointer user_data
)
1352 struct tracefile_time_span_get_args
*args
=
1353 (struct tracefile_time_span_get_args
*)user_data
;
1355 GArray
*group
= (GArray
*)data
;
1361 for(i
=0; i
<group
->len
; i
++) {
1362 tf
= &g_array_index (group
, LttTracefile
, i
);
1363 if(tf
->cpu_online
) {
1364 ltt_tracefile_time_span_get(tf
, &tmp_start
, &tmp_end
);
1365 if(ltt_time_compare(*args
->start
, tmp_start
)>0) *args
->start
= tmp_start
;
1366 if(ltt_time_compare(*args
->end
, tmp_end
)<0) *args
->end
= tmp_end
;
1371 void ltt_trace_time_span_get(LttTrace
*t
, LttTime
*start
, LttTime
*end
)
1373 LttTime min_start
= ltt_time_infinite
;
1374 LttTime max_end
= ltt_time_zero
;
1375 struct tracefile_time_span_get_args args
= { t
, &min_start
, &max_end
};
1377 g_datalist_foreach(&t
->tracefiles
, &group_time_span_get
, &args
);
1379 if(start
!= NULL
) *start
= min_start
;
1380 if(end
!= NULL
) *end
= max_end
;
1385 /*****************************************************************************
1386 *Get the name of a tracefile
1387 ****************************************************************************/
1389 GQuark
ltt_tracefile_name(const LttTracefile
*tf
)
1394 GQuark
ltt_tracefile_long_name(const LttTracefile
*tf
)
1396 return tf
->long_name
;
1401 guint
ltt_tracefile_num(LttTracefile
*tf
)
1406 /*****************************************************************************
1407 * Get the number of blocks in the tracefile
1408 ****************************************************************************/
1410 guint
ltt_tracefile_block_number(LttTracefile
*tf
)
1412 return tf
->num_blocks
;
1416 /* Seek to the first event in a tracefile that has a time equal or greater than
1417 * the time passed in parameter.
1419 * If the time parameter is outside the tracefile time span, seek to the first
1420 * event or if after, return ERANGE.
1422 * If the time parameter is before the first event, we have to seek specially to
1425 * If the time is after the end of the trace, return ERANGE.
1427 * Do a binary search to find the right block, then a sequential search in the
1428 * block to find the event.
1430 * In the special case where the time requested fits inside a block that has no
1431 * event corresponding to the requested time, the first event of the next block
1434 * IMPORTANT NOTE : // FIXME everywhere...
1436 * You MUST NOT do a ltt_tracefile_read right after a ltt_tracefile_seek_time :
1437 * you will jump over an event if you do.
1439 * Return value : 0 : no error, the tf->event can be used
1440 * ERANGE : time if after the last event of the trace
1441 * otherwise : this is an error.
1445 int ltt_tracefile_seek_time(LttTracefile
*tf
, LttTime time
)
1449 unsigned int block_num
, high
, low
;
1451 /* seek at the beginning of trace */
1452 err
= map_block(tf
, 0); /* First block */
1454 g_error("Can not map block");
1458 /* If the time is lower or equal the beginning of the trace,
1459 * go to the first event. */
1460 if(ltt_time_compare(time
, tf
->buffer
.begin
.timestamp
) <= 0) {
1461 ret
= ltt_tracefile_read(tf
);
1462 if(ret
== ERANGE
) goto range
;
1463 else if (ret
) goto fail
;
1464 goto found
; /* There is either no event in the trace or the event points
1465 to the first event in the trace */
1468 err
= map_block(tf
, tf
->num_blocks
- 1); /* Last block */
1470 g_error("Can not map block");
1474 /* If the time is after the end of the trace, return ERANGE. */
1475 if(ltt_time_compare(time
, tf
->buffer
.end
.timestamp
) > 0) {
1479 /* Binary search the block */
1480 high
= tf
->num_blocks
- 1;
1484 block_num
= ((high
-low
) / 2) + low
;
1486 err
= map_block(tf
, block_num
);
1488 g_error("Can not map block");
1492 /* We cannot divide anymore : this is what would happen if the time
1493 * requested was exactly between two consecutive buffers'end and start
1494 * timestamps. This is also what would happend if we didn't deal with out
1495 * of span cases prior in this function. */
1496 /* The event is right in the buffer!
1497 * (or in the next buffer first event) */
1499 ret
= ltt_tracefile_read(tf
);
1500 if(ret
== ERANGE
) goto range
; /* ERANGE or EPERM */
1501 else if(ret
) goto fail
;
1503 if(ltt_time_compare(time
, tf
->event
.event_time
) <= 0)
1507 } else if(ltt_time_compare(time
, tf
->buffer
.begin
.timestamp
) < 0) {
1508 /* go to lower part */
1509 high
= block_num
- 1;
1510 } else if(ltt_time_compare(time
, tf
->buffer
.end
.timestamp
) > 0) {
1511 /* go to higher part */
1512 low
= block_num
+ 1;
1513 } else {/* The event is right in the buffer!
1514 (or in the next buffer first event) */
1516 ret
= ltt_tracefile_read(tf
);
1517 if(ret
== ERANGE
) goto range
; /* ERANGE or EPERM */
1518 else if(ret
) goto fail
;
1520 if(ltt_time_compare(time
, tf
->event
.event_time
) <= 0)
1532 /* Error handling */
1534 g_error("ltt_tracefile_seek_time failed on tracefile %s",
1535 g_quark_to_string(tf
->name
));
1540 int ltt_tracefile_seek_position(LttTracefile
*tf
, const LttEventPosition
*ep
) {
1544 if(ep
->tracefile
!= tf
) {
1548 err
= map_block(tf
, ep
->block
);
1550 g_error("Can not map block");
1554 tf
->event
.offset
= ep
->offset
;
1556 err
= ltt_tracefile_read_update_event(tf
);
1558 err
= ltt_tracefile_read_op(tf
);
1564 g_error("ltt_tracefile_seek_time failed on tracefile %s",
1565 g_quark_to_string(tf
->name
));
1569 /* Calculate the real event time based on the buffer boundaries */
1570 LttTime
ltt_interpolate_time(LttTracefile
*tf
, LttEvent
*event
)
1574 g_assert(tf
->trace
->has_tsc
);
1576 // time = ltt_time_from_uint64(
1577 // cycles_2_ns(tf, (guint64)(tf->buffer.tsc - tf->buffer.begin.cycle_count)));
1578 time
= ltt_time_from_uint64(
1579 (double)(tf
->buffer
.tsc
- tf
->trace
->start_tsc
) * 1000000.0
1580 / (double)tf
->trace
->start_freq
);
1581 //time = ltt_time_add(tf->buffer.begin.timestamp, time);
1582 time
= ltt_time_add(tf
->trace
->start_time_from_tsc
, time
);
1588 /* Get the current event of the tracefile : valid until the next read */
1589 LttEvent
*ltt_tracefile_get_event(LttTracefile
*tf
)
1596 /*****************************************************************************
1598 * ltt_tracefile_read : Read the next event in the tracefile
1603 * Returns 0 if an event can be used in tf->event.
1604 * Returns ERANGE on end of trace. The event in tf->event still can be used
1605 * (if the last block was not empty).
1606 * Returns EPERM on error.
1608 * This function does make the tracefile event structure point to the event
1609 * currently pointed to by the tf->event.
1611 * Note : you must call a ltt_tracefile_seek to the beginning of the trace to
1612 * reinitialize it after an error if you want results to be coherent.
1613 * It would be the case if a end of trace last buffer has no event : the end
1614 * of trace wouldn't be returned, but an error.
1615 * We make the assumption there is at least one event per buffer.
1616 ****************************************************************************/
1618 int ltt_tracefile_read(LttTracefile
*tf
)
1622 err
= ltt_tracefile_read_seek(tf
);
1624 err
= ltt_tracefile_read_update_event(tf
);
1626 err
= ltt_tracefile_read_op(tf
);
1632 int ltt_tracefile_read_seek(LttTracefile
*tf
)
1636 /* Get next buffer until we finally have an event, or end of trace */
1638 err
= ltt_seek_next_event(tf
);
1639 if(unlikely(err
== ENOPROTOOPT
)) {
1643 /* Are we at the end of the buffer ? */
1645 if(unlikely(tf
->buffer
.index
== tf
->num_blocks
-1)){ /* end of trace ? */
1648 /* get next block */
1649 err
= map_block(tf
, tf
->buffer
.index
+ 1);
1651 g_error("Can not map block");
1655 } else break; /* We found an event ! */
1662 /* do specific operation on events */
1663 int ltt_tracefile_read_op(LttTracefile
*tf
)
1669 /* do event specific operation */
1671 /* do something if its an heartbeat event : increment the heartbeat count */
1672 //if(event->facility_id == LTT_FACILITY_CORE)
1673 // if(event->event_id == LTT_EVENT_HEARTBEAT)
1674 // tf->cur_heart_beat_number++;
1680 /* same as ltt_tracefile_read, but does not seek to the next event nor call
1681 * event specific operation. */
1682 int ltt_tracefile_read_update_event(LttTracefile
*tf
)
1688 pos
= tf
->buffer
.head
+ event
->offset
;
1690 /* Read event header */
1692 /* Align the head */
1693 pos
+= ltt_align((size_t)pos
, tf
->trace
->arch_size
, tf
->has_alignment
);
1695 if(tf
->trace
->has_tsc
) {
1696 if(tf
->trace
->has_heartbeat
) {
1697 event
->time
.timestamp
= ltt_get_uint32(LTT_GET_BO(tf
),
1699 /* 32 bits -> 64 bits tsc */
1700 /* note : still works for seek and non seek cases. */
1701 if(event
->time
.timestamp
< (0xFFFFFFFFULL
&tf
->buffer
.tsc
)) {
1702 tf
->buffer
.tsc
= ((tf
->buffer
.tsc
&0xFFFFFFFF00000000ULL
)
1704 | (guint64
)event
->time
.timestamp
;
1705 event
->tsc
= tf
->buffer
.tsc
;
1708 tf
->buffer
.tsc
= (tf
->buffer
.tsc
&0xFFFFFFFF00000000ULL
)
1709 | (guint64
)event
->time
.timestamp
;
1710 event
->tsc
= tf
->buffer
.tsc
;
1712 pos
+= sizeof(guint32
);
1714 event
->tsc
= ltt_get_uint64(LTT_GET_BO(tf
), pos
);
1715 tf
->buffer
.tsc
= event
->tsc
;
1716 pos
+= sizeof(guint64
);
1719 event
->event_time
= ltt_interpolate_time(tf
, event
);
1721 event
->time
.delta
.tv_sec
= 0;
1722 event
->time
.delta
.tv_nsec
= ltt_get_uint32(LTT_GET_BO(tf
),
1723 pos
) * NSEC_PER_USEC
;
1725 event
->tsc
= tf
->buffer
.tsc
;
1727 event
->event_time
= ltt_time_add(tf
->buffer
.begin
.timestamp
,
1729 pos
+= sizeof(guint32
);
1732 event
->facility_id
= *(guint8
*)pos
;
1733 pos
+= sizeof(guint8
);
1735 event
->event_id
= *(guint8
*)pos
;
1736 pos
+= sizeof(guint8
);
1738 event
->event_size
= ltt_get_uint16(LTT_GET_BO(tf
), pos
);
1739 pos
+= sizeof(guint16
);
1741 /* Align the head */
1742 pos
+= ltt_align((size_t)pos
, tf
->trace
->arch_size
, tf
->has_alignment
);
1746 /* get the data size and update the event fields with the current
1748 ltt_update_event_size(tf
);
1754 /****************************************************************************
1756 * map_block : map a block from the file
1758 * lttdes : ltt trace file
1759 * whichBlock : the block which will be read
1762 * EINVAL : lseek fail
1763 * EIO : can not read from the file
1764 ****************************************************************************/
1766 static gint
map_block(LttTracefile
* tf
, guint block_num
)
1768 int page_size
= getpagesize();
1769 struct ltt_block_start_header
*header
;
1771 g_assert(block_num
< tf
->num_blocks
);
1773 if(tf
->buffer
.head
!= NULL
) {
1774 if(munmap(tf
->buffer
.head
, PAGE_ALIGN(tf
->buf_size
))) {
1775 g_warning("unmap size : %u\n",
1776 PAGE_ALIGN(tf
->buf_size
));
1777 perror("munmap error");
1783 /* Multiple of pages aligned head */
1784 tf
->buffer
.head
= mmap(0,
1785 PAGE_ALIGN(tf
->buf_size
),
1786 PROT_READ
, MAP_PRIVATE
, tf
->fd
,
1787 PAGE_ALIGN((off_t
)tf
->buf_size
* (off_t
)block_num
));
1789 if(tf
->buffer
.head
== MAP_FAILED
) {
1790 perror("Error in allocating memory for buffer of tracefile");
1794 g_assert( ( (guint
)tf
->buffer
.head
&(8-1) ) == 0); // make sure it's aligned.
1797 tf
->buffer
.index
= block_num
;
1799 header
= (struct ltt_block_start_header
*)tf
->buffer
.head
;
1802 tf
->buffer
.begin
.timestamp
= ltt_time_add(
1803 ltt_time_from_uint64(
1804 ltt_get_uint64(LTT_GET_BO(tf
),
1805 &header
->begin
.timestamp
)
1806 - tf
->trace
->start_monotonic
),
1807 tf
->trace
->start_time
);
1809 //g_debug("block %u begin : %lu.%lu", block_num,
1810 // tf->buffer.begin.timestamp.tv_sec, tf->buffer.begin.timestamp.tv_nsec);
1811 tf
->buffer
.begin
.cycle_count
= ltt_get_uint64(LTT_GET_BO(tf
),
1812 &header
->begin
.cycle_count
);
1813 tf
->buffer
.begin
.freq
= ltt_get_uint64(LTT_GET_BO(tf
),
1814 &header
->begin
.freq
);
1815 tf
->buffer
.begin
.timestamp
= ltt_time_add(
1816 ltt_time_from_uint64(
1817 (double)(tf
->buffer
.begin
.cycle_count
1818 - tf
->trace
->start_tsc
) * 1000000.0
1819 / (double)tf
->trace
->start_freq
),
1820 tf
->trace
->start_time_from_tsc
);
1823 tf
->buffer
.end
.timestamp
= ltt_time_add(
1824 ltt_time_from_uint64(
1825 ltt_get_uint64(LTT_GET_BO(tf
),
1826 &header
->end
.timestamp
)
1827 - tf
->trace
->start_monotonic
),
1828 tf
->trace
->start_time
);
1830 //g_debug("block %u end : %lu.%lu", block_num,
1831 // tf->buffer.end.timestamp.tv_sec, tf->buffer.end.timestamp.tv_nsec);
1832 tf
->buffer
.end
.cycle_count
= ltt_get_uint64(LTT_GET_BO(tf
),
1833 &header
->end
.cycle_count
);
1834 tf
->buffer
.end
.freq
= ltt_get_uint64(LTT_GET_BO(tf
),
1836 tf
->buffer
.lost_size
= ltt_get_uint32(LTT_GET_BO(tf
),
1837 &header
->lost_size
);
1838 tf
->buffer
.end
.timestamp
= ltt_time_add(
1839 ltt_time_from_uint64(
1840 (double)(tf
->buffer
.end
.cycle_count
1841 - tf
->trace
->start_tsc
) * 1000000.0
1842 / (double)tf
->trace
->start_freq
),
1843 tf
->trace
->start_time_from_tsc
);
1845 tf
->buffer
.tsc
= tf
->buffer
.begin
.cycle_count
;
1846 tf
->event
.tsc
= tf
->buffer
.tsc
;
1847 tf
->buffer
.freq
= tf
->buffer
.begin
.freq
;
1850 * eventually support variable buffer size : will need a partial pre-read of
1851 * the headers to create an index when we open the trace... eventually. */
1852 g_assert(tf
->buf_size
== ltt_get_uint32(LTT_GET_BO(tf
),
1853 &header
->buf_size
));
1855 /* Now that the buffer is mapped, calculate the time interpolation for the
1858 // tf->buffer.nsecs_per_cycle = calc_nsecs_per_cycle(tf);
1859 //tf->buffer.cyc2ns_scale = calc_nsecs_per_cycle(tf);
1861 /* Make the current event point to the beginning of the buffer :
1862 * it means that the event read must get the first event. */
1863 tf
->event
.tracefile
= tf
;
1864 tf
->event
.block
= block_num
;
1865 tf
->event
.offset
= 0;
1874 /* It will update the fields offsets too */
1875 void ltt_update_event_size(LttTracefile
*tf
)
1879 /* Specific handling of core events : necessary to read the facility control
1881 LttFacility
*f
= ltt_trace_get_facility_by_num(tf
->trace
,
1882 tf
->event
.facility_id
);
1884 if(likely(tf
->event
.facility_id
== LTT_FACILITY_CORE
)) {
1885 switch((enum ltt_core_events
)tf
->event
.event_id
) {
1886 case LTT_EVENT_FACILITY_LOAD
:
1887 size
= strlen((char*)tf
->event
.data
) + 1;
1888 //g_debug("Update Event facility load of facility %s", (char*)tf->event.data);
1889 size
+= sizeof(struct LttFacilityLoad
);
1891 case LTT_EVENT_FACILITY_UNLOAD
:
1892 //g_debug("Update Event facility unload");
1893 size
= sizeof(struct LttFacilityUnload
);
1895 case LTT_EVENT_STATE_DUMP_FACILITY_LOAD
:
1896 size
= strlen((char*)tf
->event
.data
) + 1;
1897 //g_debug("Update Event facility load state dump of facility %s",
1898 // (char*)tf->event.data);
1899 size
+= sizeof(struct LttStateDumpFacilityLoad
);
1901 case LTT_EVENT_HEARTBEAT
:
1902 //g_debug("Update Event heartbeat");
1903 size
= sizeof(TimeHeartbeat
);
1906 g_warning("Error in getting event size : tracefile %s, "
1907 "unknown event id %hhu in core facility.",
1908 g_quark_to_string(tf
->name
),
1909 tf
->event
.event_id
);
1910 goto event_id_error
;
1915 g_error("Unknown facility %hhu (0x%hhx) in tracefile %s",
1916 tf
->event
.facility_id
,
1917 tf
->event
.facility_id
,
1918 g_quark_to_string(tf
->name
));
1919 goto facility_error
;
1922 LttEventType
*event_type
=
1923 ltt_facility_eventtype_get(f
, tf
->event
.event_id
);
1926 g_error("Unknown event id %hhu in facility %s in tracefile %s",
1928 g_quark_to_string(f
->name
),
1929 g_quark_to_string(tf
->name
));
1930 goto event_type_error
;
1933 /* Compute the dynamic offsets */
1934 compute_offsets(tf
, event_type
, &size
, tf
->event
.data
);
1936 //g_debug("Event root field : f.e %hhu.%hhu size %zd",
1937 // tf->event.facility_id,
1938 // tf->event.event_id, size);
1941 tf
->event
.data_size
= size
;
1943 /* Check consistency between kernel and LTTV structure sizes */
1944 g_assert(tf
->event
.data_size
== tf
->event
.event_size
);
1951 tf
->event
.data_size
= 0;
1955 /* Take the tf current event offset and use the event facility id and event id
1956 * to figure out where is the next event offset.
1958 * This is an internal function not aiming at being used elsewhere : it will
1959 * not jump over the current block limits. Please consider using
1960 * ltt_tracefile_read to do this.
1962 * Returns 0 on success
1963 * ERANGE if we are at the end of the buffer.
1964 * ENOPROTOOPT if an error occured when getting the current event size.
1966 static int ltt_seek_next_event(LttTracefile
*tf
)
1971 /* seek over the buffer header if we are at the buffer start */
1972 if(tf
->event
.offset
== 0) {
1973 tf
->event
.offset
+= tf
->buffer_header_size
;
1975 if(tf
->event
.offset
== tf
->buf_size
- tf
->buffer
.lost_size
) {
1982 pos
= tf
->event
.data
;
1984 if(tf
->event
.data_size
< 0) goto error
;
1986 pos
+= (size_t)tf
->event
.data_size
;
1988 tf
->event
.offset
= pos
- tf
->buffer
.head
;
1990 if(tf
->event
.offset
== tf
->buf_size
- tf
->buffer
.lost_size
) {
1994 g_assert(tf
->event
.offset
< tf
->buf_size
- tf
->buffer
.lost_size
);
2000 g_error("Error in ltt_seek_next_event for tracefile %s",
2001 g_quark_to_string(tf
->name
));
2006 /*****************************************************************************
2008 * calc_nsecs_per_cycle : calculate nsecs per cycle for current block
2010 * 1.0 / (freq(khz) *1000) * 1000000000
2013 ****************************************************************************/
2014 /* from timer_tsc.c */
2015 #define CYC2NS_SCALE_FACTOR 10
2016 static guint32
calc_nsecs_per_cycle(LttTracefile
* tf
)
2018 //return 1e6 / (double)tf->buffer.freq;
2019 guint32 cpu_mhz
= tf
->buffer
.freq
/ 1000;
2020 guint32 cyc2ns_scale
= (1000 << CYC2NS_SCALE_FACTOR
)/cpu_mhz
;
2022 return cyc2ns_scale
;
2023 // return 1e6 / (double)tf->buffer.freq;
2026 static guint64
cycles_2_ns(LttTracefile
*tf
, guint64 cycles
)
2028 return (cycles
* tf
->buffer
.cyc2ns_scale
) >> CYC2NS_SCALE_FACTOR
;
2033 void setFieldsOffset(LttTracefile
*tf
, LttEventType
*evT
,void *evD
)
2035 LttField
* rootFld
= evT
->root_field
;
2036 // rootFld->base_address = evD;
2039 rootFld
->field_size
= getFieldtypeSize(tf
, evT
->facility
,
2040 evT
, 0,0,rootFld
, evD
);
2044 /*****************************************************************************
2046 * set_fields_offsets : set the precomputable offset of the fields
2048 * tracefile : opened trace file
2049 * event_type : the event type
2050 ****************************************************************************/
2052 void set_fields_offsets(LttTracefile
*tf
, LttEventType
*event_type
)
2054 LttField
*field
= event_type
->root_field
;
2055 enum field_status fixed_root
= FIELD_FIXED
, fixed_parent
= FIELD_FIXED
;
2058 preset_field_type_size(tf
, event_type
, 0, 0,
2059 &fixed_root
, &fixed_parent
,
2066 /*****************************************************************************
2068 * get_alignment : Get the alignment needed for a field.
2073 * returns : The size on which it must be aligned.
2075 ****************************************************************************/
2076 off_t
get_alignment(LttTracefile
*tf
, LttField
*field
)
2078 LttType
*type
= &field
->field_type
;
2080 switch(type
->type_class
) {
2082 case LTT_UINT_FIXED
:
2097 /* Align offset on type size */
2098 return field
->field_size
;
2104 g_assert(type
->fields
->len
== 1);
2106 LttField
*child
= &g_array_index(type
->fields
, LttField
, 0);
2107 return get_alignment(tf
, child
);
2111 g_assert(type
->fields
->len
== 2);
2114 LttField
*child
= &g_array_index(type
->fields
, LttField
, 0);
2116 localign
= max(localign
, get_alignment(tf
, child
));
2118 child
= &g_array_index(type
->fields
, LttField
, 1);
2119 localign
= max(localign
, get_alignment(tf
, child
));
2130 for(i
=0; i
<type
->fields
->len
; i
++) {
2131 LttField
*child
= &g_array_index(type
->fields
, LttField
, i
);
2132 localign
= max(localign
, get_alignment(tf
, child
));
2139 g_error("get_alignment : unknown type");
2144 /*****************************************************************************
2146 * field_compute_static_size : Determine the size of fields known by their
2147 * sole definition. Unions, arrays and struct sizes might be known, but
2148 * the parser does not give that information.
2153 ****************************************************************************/
2155 void field_compute_static_size(LttTracefile
*tf
, LttField
*field
)
2157 LttType
*type
= &field
->field_type
;
2159 switch(type
->type_class
) {
2161 case LTT_UINT_FIXED
:
2180 /* note this : array type size is the number of elements in the array,
2181 * while array field size of the length of the array in bytes */
2182 g_assert(type
->fields
->len
== 1);
2184 LttField
*child
= &g_array_index(type
->fields
, LttField
, 0);
2185 field_compute_static_size(tf
, child
);
2187 if(child
->field_size
!= 0) {
2188 field
->field_size
= type
->size
* child
->field_size
;
2189 field
->dynamic_offsets
= g_array_sized_new(FALSE
, TRUE
,
2190 sizeof(off_t
), type
->size
);
2192 field
->field_size
= 0;
2197 g_assert(type
->fields
->len
== 2);
2199 off_t local_offset
= 0;
2200 LttField
*child
= &g_array_index(type
->fields
, LttField
, 1);
2201 field_compute_static_size(tf
, child
);
2202 field
->field_size
= 0;
2204 if(child
->field_size
!= 0) {
2205 field
->dynamic_offsets
= g_array_sized_new(FALSE
, TRUE
,
2206 sizeof(off_t
), SEQUENCE_AVG_ELEMENTS
);
2214 for(i
=0;i
<type
->fields
->len
;i
++) {
2215 LttField
*child
= &g_array_index(type
->fields
, LttField
, i
);
2216 field_compute_static_size(tf
, child
);
2217 if(child
->field_size
!= 0) {
2218 type
->size
+= ltt_align(type
->size
, get_alignment(tf
, child
),
2220 type
->size
+= child
->field_size
;
2222 /* As soon as we find a child with variable size, we have
2223 * a variable size */
2228 field
->field_size
= type
->size
;
2232 g_error("field_static_size : unknown type");
2239 /*****************************************************************************
2241 * precompute_fields_offsets : set the precomputable offset of the fields
2245 * offset : pointer to the current offset, must be incremented
2247 * return : 1 : found a variable length field, stop the processing.
2249 ****************************************************************************/
2252 gint
precompute_fields_offsets(LttTracefile
*tf
, LttField
*field
, off_t
*offset
)
2254 LttType
*type
= &field
->field_type
;
2256 switch(type
->type_class
) {
2258 case LTT_UINT_FIXED
:
2273 /* Align offset on type size */
2274 *offset
+= ltt_align(*offset
, get_alignment(tf
, field
),
2276 /* remember offset */
2277 field
->offset_root
= *offset
;
2278 field
->fixed_root
= FIELD_FIXED
;
2279 /* Increment offset */
2280 *offset
+= field
->field_size
;
2284 field
->offset_root
= *offset
;
2285 field
->fixed_root
= FIELD_FIXED
;
2289 g_assert(type
->fields
->len
== 1);
2291 LttField
*child
= &g_array_index(type
->fields
, LttField
, 0);
2293 *offset
+= ltt_align(*offset
, get_alignment(tf
, field
),
2296 /* remember offset */
2297 field
->offset_root
= *offset
;
2298 field
->array_offset
= *offset
;
2299 field
->fixed_root
= FIELD_FIXED
;
2301 /* Let the child be variable */
2302 //precompute_fields_offsets(tf, child, offset);
2304 if(field
->field_size
!= 0) {
2305 /* Increment offset */
2306 /* field_size is the array size in bytes */
2307 *offset
+= field
->field_size
;
2315 g_assert(type
->fields
->len
== 2);
2320 *offset
+= ltt_align(*offset
, get_alignment(tf
, field
),
2323 /* remember offset */
2324 field
->offset_root
= *offset
;
2325 field
->fixed_root
= FIELD_FIXED
;
2327 child
= &g_array_index(type
->fields
, LttField
, 0);
2328 ret
= precompute_fields_offsets(tf
, child
, offset
);
2329 g_assert(ret
== 0); /* Seq len cannot have variable len */
2331 child
= &g_array_index(type
->fields
, LttField
, 1);
2332 *offset
+= ltt_align(*offset
, get_alignment(tf
, child
),
2334 field
->array_offset
= *offset
;
2335 /* Set the offset position at position 0 */
2336 ret
= precompute_fields_offsets(tf
, child
, offset
);
2338 /* Cannot precompute fields offsets of sequence members, and has
2339 * variable length. */
2349 *offset
+= ltt_align(*offset
, get_alignment(tf
, field
),
2351 /* remember offset */
2352 field
->offset_root
= *offset
;
2353 field
->fixed_root
= FIELD_FIXED
;
2355 for(i
=0; i
< type
->fields
->len
; i
++) {
2356 child
= &g_array_index(type
->fields
, LttField
, i
);
2357 ret
= precompute_fields_offsets(tf
, child
, offset
);
2370 *offset
+= ltt_align(*offset
, get_alignment(tf
, field
),
2372 /* remember offset */
2373 field
->offset_root
= *offset
;
2374 field
->fixed_root
= FIELD_FIXED
;
2376 for(i
=0; i
< type
->fields
->len
; i
++) {
2377 *offset
= field
->offset_root
;
2378 child
= &g_array_index(type
->fields
, LttField
, i
);
2379 ret
= precompute_fields_offsets(tf
, child
, offset
);
2383 *offset
= field
->offset_root
+ field
->field_size
;
2390 g_error("precompute_fields_offsets : unknown type");
2397 /*****************************************************************************
2399 * precompute_offsets : set the precomputable offset of an event type
2402 * event : event type
2404 ****************************************************************************/
2405 void precompute_offsets(LttTracefile
*tf
, LttEventType
*event
)
2411 /* First, compute the size of fixed size fields. Will determine size for
2412 * arrays, struct and unions, which is not done by the parser */
2413 for(i
=0; i
<event
->fields
->len
; i
++) {
2414 LttField
*field
= &g_array_index(event
->fields
, LttField
, i
);
2415 field_compute_static_size(tf
, field
);
2418 /* Precompute all known offsets */
2419 for(i
=0; i
<event
->fields
->len
; i
++) {
2420 LttField
*field
= &g_array_index(event
->fields
, LttField
, i
);
2421 ret
= precompute_fields_offsets(tf
, field
, &offset
);
2429 /*****************************************************************************
2431 * preset_field_type_size : set the fixed sizes of the field type
2434 * event_type : event type
2435 * offset_root : offset from the root
2436 * offset_parent : offset from the parent
2437 * fixed_root : Do we know a fixed offset to the root ?
2438 * fixed_parent : Do we know a fixed offset to the parent ?
2440 ****************************************************************************/
2444 // preset the fixed size offsets. Calculate them just like genevent-new : an
2445 // increment of a *to value that represents the offset from the start of the
2447 // The preset information is : offsets up to (and including) the first element
2448 // of variable size. All subsequent fields must be flagged "VARIABLE OFFSET".
2450 void preset_field_type_size(LttTracefile
*tf
, LttEventType
*event_type
,
2451 off_t offset_root
, off_t offset_parent
,
2452 enum field_status
*fixed_root
, enum field_status
*fixed_parent
,
2455 enum field_status local_fixed_root
, local_fixed_parent
;
2459 g_assert(field
->fixed_root
== FIELD_UNKNOWN
);
2460 g_assert(field
->fixed_parent
== FIELD_UNKNOWN
);
2461 g_assert(field
->fixed_size
== FIELD_UNKNOWN
);
2463 type
= field
->field_type
;
2465 field
->fixed_root
= *fixed_root
;
2466 if(field
->fixed_root
== FIELD_FIXED
)
2467 field
->offset_root
= offset_root
;
2469 field
->offset_root
= 0;
2471 field
->fixed_parent
= *fixed_parent
;
2472 if(field
->fixed_parent
== FIELD_FIXED
)
2473 field
->offset_parent
= offset_parent
;
2475 field
->offset_parent
= 0;
2477 size_t current_root_offset
;
2478 size_t current_offset
;
2479 enum field_status current_child_status
, final_child_status
;
2482 switch(type
->type_class
) {
2487 field
->field_size
= ltt_type_size(tf
->trace
, type
);
2488 field
->fixed_size
= FIELD_FIXED
;
2491 field
->field_size
= (off_t
)event_type
->facility
->pointer_size
;
2492 field
->fixed_size
= FIELD_FIXED
;
2496 field
->field_size
= (off_t
)event_type
->facility
->long_size
;
2497 field
->fixed_size
= FIELD_FIXED
;
2502 field
->field_size
= (off_t
)event_type
->facility
->size_t_size
;
2503 field
->fixed_size
= FIELD_FIXED
;
2506 local_fixed_root
= FIELD_VARIABLE
;
2507 local_fixed_parent
= FIELD_VARIABLE
;
2508 preset_field_type_size(tf
, event_type
,
2510 &local_fixed_root
, &local_fixed_parent
,
2512 field
->fixed_size
= FIELD_VARIABLE
;
2513 field
->field_size
= 0;
2514 *fixed_root
= FIELD_VARIABLE
;
2515 *fixed_parent
= FIELD_VARIABLE
;
2518 field
->fixed_size
= FIELD_VARIABLE
;
2519 field
->field_size
= 0;
2520 *fixed_root
= FIELD_VARIABLE
;
2521 *fixed_parent
= FIELD_VARIABLE
;
2524 local_fixed_root
= FIELD_VARIABLE
;
2525 local_fixed_parent
= FIELD_VARIABLE
;
2526 preset_field_type_size(tf
, event_type
,
2528 &local_fixed_root
, &local_fixed_parent
,
2530 field
->fixed_size
= field
->child
[0]->fixed_size
;
2531 if(field
->fixed_size
== FIELD_FIXED
) {
2532 field
->field_size
= type
->element_number
* field
->child
[0]->field_size
;
2534 field
->field_size
= 0;
2535 *fixed_root
= FIELD_VARIABLE
;
2536 *fixed_parent
= FIELD_VARIABLE
;
2540 current_root_offset
= field
->offset_root
;
2542 current_child_status
= FIELD_FIXED
;
2543 for(i
=0;i
<type
->element_number
;i
++) {
2544 preset_field_type_size(tf
, event_type
,
2545 current_root_offset
, current_offset
,
2546 fixed_root
, ¤t_child_status
,
2548 if(current_child_status
== FIELD_FIXED
) {
2549 current_root_offset
+= field
->child
[i
]->field_size
;
2550 current_offset
+= field
->child
[i
]->field_size
;
2552 current_root_offset
= 0;
2556 if(current_child_status
!= FIELD_FIXED
) {
2557 *fixed_parent
= current_child_status
;
2558 field
->field_size
= 0;
2559 field
->fixed_size
= current_child_status
;
2561 field
->field_size
= current_offset
;
2562 field
->fixed_size
= FIELD_FIXED
;
2566 current_root_offset
= field
->offset_root
;
2569 final_child_status
= FIELD_FIXED
;
2570 for(i
=0;i
<type
->element_number
;i
++) {
2571 enum field_status current_root_child_status
= FIELD_FIXED
;
2572 enum field_status current_child_status
= FIELD_FIXED
;
2573 preset_field_type_size(tf
, event_type
,
2574 current_root_offset
, current_offset
,
2575 ¤t_root_child_status
, ¤t_child_status
,
2577 if(current_child_status
!= FIELD_FIXED
)
2578 final_child_status
= current_child_status
;
2580 max_size
= max(max_size
, field
->child
[i
]->field_size
);
2582 if(final_child_status
!= FIELD_FIXED
) {
2583 g_error("LTTV does not support variable size fields in unions.");
2584 /* This will stop the application. */
2585 *fixed_root
= final_child_status
;
2586 *fixed_parent
= final_child_status
;
2587 field
->field_size
= 0;
2588 field
->fixed_size
= current_child_status
;
2590 field
->field_size
= max_size
;
2591 field
->fixed_size
= FIELD_FIXED
;
2599 /*****************************************************************************
2601 * check_fields_compatibility : Check for compatibility between two fields :
2602 * do they use the same inner structure ?
2604 * event_type1 : event type
2605 * event_type2 : event type
2608 *Returns : 0 if identical
2610 ****************************************************************************/
2611 // this function checks for equality of field types. Therefore, it does not use
2612 // per se offsets. For instance, an aligned version of a structure is
2613 // compatible with an unaligned version of the same structure.
2614 gint
check_fields_compatibility(LttEventType
*event_type1
,
2615 LttEventType
*event_type2
,
2616 LttField
*field1
, LttField
*field2
)
2618 guint different
= 0;
2622 if(field1
== NULL
) {
2623 if(field2
== NULL
) goto end
;
2628 } else if(field2
== NULL
) {
2633 type1
= &field1
->field_type
;
2634 type2
= &field2
->field_type
;
2636 if(type1
->type_class
!= type2
->type_class
) {
2641 switch(type1
->type_class
) {
2643 case LTT_UINT_FIXED
:
2658 if(field1
->field_size
!= field2
->field_size
)
2665 LttField
*child1
= &g_array_index(type1
->fields
, LttField
, 0);
2666 LttField
*child2
= &g_array_index(type2
->fields
, LttField
, 0);
2668 if(type1
->size
!= type2
->size
)
2670 if(check_fields_compatibility(event_type1
, event_type2
, child1
, child2
))
2676 LttField
*child1
= &g_array_index(type1
->fields
, LttField
, 1);
2677 LttField
*child2
= &g_array_index(type2
->fields
, LttField
, 1);
2679 if(check_fields_compatibility(event_type1
, event_type2
, child1
, child2
))
2689 if(type1
->fields
->len
!= type2
->fields
->len
) {
2694 for(i
=0; i
< type1
->fields
->len
; i
++) {
2697 child1
= &g_array_index(type1
->fields
, LttField
, i
);
2698 child2
= &g_array_index(type2
->fields
, LttField
, i
);
2699 different
= check_fields_compatibility(event_type1
,
2700 event_type2
, child1
, child2
);
2702 if(different
) break;
2708 g_error("precompute_fields_offsets : unknown type");
2717 gint
check_fields_compatibility(LttEventType
*event_type1
,
2718 LttEventType
*event_type2
,
2719 LttField
*field1
, LttField
*field2
)
2721 guint different
= 0;
2726 if(field1
== NULL
) {
2727 if(field2
== NULL
) goto end
;
2732 } else if(field2
== NULL
) {
2737 g_assert(field1
->fixed_root
!= FIELD_UNKNOWN
);
2738 g_assert(field2
->fixed_root
!= FIELD_UNKNOWN
);
2739 g_assert(field1
->fixed_parent
!= FIELD_UNKNOWN
);
2740 g_assert(field2
->fixed_parent
!= FIELD_UNKNOWN
);
2741 g_assert(field1
->fixed_size
!= FIELD_UNKNOWN
);
2742 g_assert(field2
->fixed_size
!= FIELD_UNKNOWN
);
2744 type1
= field1
->field_type
;
2745 type2
= field2
->field_type
;
2747 if(type1
->type_class
!= type2
->type_class
) {
2751 if(type1
->element_name
!= type2
->element_name
) {
2756 switch(type1
->type_class
) {
2766 if(field1
->field_size
!= field2
->field_size
) {
2772 if(type1
->element_number
!= type2
->element_number
) {
2776 for(i
=0;i
<type1
->element_number
;i
++) {
2777 if(type1
->enum_strings
[i
] != type2
->enum_strings
[i
]) {
2784 /* Two elements : size and child */
2785 g_assert(type1
->element_number
!= type2
->element_number
);
2786 for(i
=0;i
<type1
->element_number
;i
++) {
2787 if(check_fields_compatibility(event_type1
, event_type2
,
2788 field1
->child
[0], field2
->child
[0])) {
2797 if(field1
->field_size
!= field2
->field_size
) {
2801 /* Two elements : size and child */
2802 g_assert(type1
->element_number
!= type2
->element_number
);
2803 for(i
=0;i
<type1
->element_number
;i
++) {
2804 if(check_fields_compatibility(event_type1
, event_type2
,
2805 field1
->child
[0], field2
->child
[0])) {
2813 if(type1
->element_number
!= type2
->element_number
) {
2817 for(i
=0;i
<type1
->element_number
;i
++) {
2818 if(check_fields_compatibility(event_type1
, event_type2
,
2819 field1
->child
[0], field2
->child
[0])) {
2832 /*****************************************************************************
2834 * ltt_get_int : get an integer number
2836 * reverse_byte_order: must we reverse the byte order ?
2837 * size : the size of the integer
2838 * ptr : the data pointer
2840 * gint64 : a 64 bits integer
2841 ****************************************************************************/
2843 gint64
ltt_get_int(gboolean reverse_byte_order
, gint size
, void *data
)
2848 case 1: val
= *((gint8
*)data
); break;
2849 case 2: val
= ltt_get_int16(reverse_byte_order
, data
); break;
2850 case 4: val
= ltt_get_int32(reverse_byte_order
, data
); break;
2851 case 8: val
= ltt_get_int64(reverse_byte_order
, data
); break;
2852 default: val
= ltt_get_int64(reverse_byte_order
, data
);
2853 g_critical("get_int : integer size %d unknown", size
);
2860 /*****************************************************************************
2862 * ltt_get_uint : get an unsigned integer number
2864 * reverse_byte_order: must we reverse the byte order ?
2865 * size : the size of the integer
2866 * ptr : the data pointer
2868 * guint64 : a 64 bits unsigned integer
2869 ****************************************************************************/
2871 guint64
ltt_get_uint(gboolean reverse_byte_order
, gint size
, void *data
)
2876 case 1: val
= *((gint8
*)data
); break;
2877 case 2: val
= ltt_get_uint16(reverse_byte_order
, data
); break;
2878 case 4: val
= ltt_get_uint32(reverse_byte_order
, data
); break;
2879 case 8: val
= ltt_get_uint64(reverse_byte_order
, data
); break;
2880 default: val
= ltt_get_uint64(reverse_byte_order
, data
);
2881 g_critical("get_uint : unsigned integer size %d unknown",
2890 /* get the node name of the system */
2892 char * ltt_trace_system_description_node_name (LttSystemDescription
* s
)
2894 return s
->node_name
;
2898 /* get the domain name of the system */
2900 char * ltt_trace_system_description_domain_name (LttSystemDescription
* s
)
2902 return s
->domain_name
;
2906 /* get the description of the system */
2908 char * ltt_trace_system_description_description (LttSystemDescription
* s
)
2910 return s
->description
;
2914 /* get the NTP corrected start time of the trace */
2915 LttTime
ltt_trace_start_time(LttTrace
*t
)
2917 return t
->start_time
;
2920 /* get the monotonic start time of the trace */
2921 LttTime
ltt_trace_start_time_monotonic(LttTrace
*t
)
2923 return t
->start_time_from_tsc
;
2926 LttTracefile
*ltt_tracefile_new()
2928 return g_new(LttTracefile
, 1);
2931 void ltt_tracefile_destroy(LttTracefile
*tf
)
2936 void ltt_tracefile_copy(LttTracefile
*dest
, const LttTracefile
*src
)
2941 /* Before library loading... */
2943 static void __attribute__((constructor
)) init(void)
2945 LTT_FACILITY_NAME_HEARTBEAT
= g_quark_from_string("heartbeat");
2946 LTT_EVENT_NAME_HEARTBEAT
= g_quark_from_string("heartbeat");
2948 LTT_TRACEFILE_NAME_FACILITIES
= g_quark_from_string("/control/facilities");