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 library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License Version 2.1 as published by the Free Software Foundation.
10 * This library 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 GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
30 #include <sys/types.h>
45 #include "ltt-private.h"
46 #include <ltt/trace.h>
47 #include <ltt/event.h>
48 #include <ltt/ltt-types.h>
49 #include <ltt/marker.h>
51 /* Facility names used in this file */
53 GQuark LTT_FACILITY_NAME_HEARTBEAT
,
54 LTT_EVENT_NAME_HEARTBEAT
,
55 LTT_EVENT_NAME_HEARTBEAT_FULL
;
56 GQuark LTT_TRACEFILE_NAME_FACILITIES
;
63 #define __UNUSED__ __attribute__((__unused__))
65 #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
68 #define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format)
73 /* Those macros must be called from within a function where page_size is a known
75 #define PAGE_MASK (~(page_size-1))
76 #define PAGE_ALIGN(addr) (((addr)+page_size-1)&PAGE_MASK)
78 LttTrace
*father_trace
= NULL
;
80 /* set the offset of the fields belonging to the event,
81 need the information of the archecture */
82 //void set_fields_offsets(LttTracefile *tf, LttEventType *event_type);
83 //size_t get_fields_offsets(LttTracefile *tf, LttEventType *event_type, void *data);
85 /* get the size of the field type according to
86 * The facility size information. */
88 static inline void preset_field_type_size(LttTracefile
*tf
,
89 LttEventType
*event_type
,
90 off_t offset_root
, off_t offset_parent
,
91 enum field_status
*fixed_root
, enum field_status
*fixed_parent
,
95 /* map a fixed size or a block information from the file (fd) */
96 static gint
map_block(LttTracefile
* tf
, guint block_num
);
98 /* calculate nsec per cycles for current block */
100 static guint32
calc_nsecs_per_cycle(LttTracefile
* t
);
101 static guint64
cycles_2_ns(LttTracefile
*tf
, guint64 cycles
);
104 /* go to the next event */
105 static int ltt_seek_next_event(LttTracefile
*tf
);
107 //void ltt_update_event_size(LttTracefile *tf);
109 static int open_tracefiles(LttTrace
*trace
, gchar
*root_path
,
110 gchar
*relative_path
);
111 static int ltt_process_facility_tracefile(LttTracefile
*tf
);
112 static void ltt_tracefile_time_span_get(LttTracefile
*tf
,
113 LttTime
*start
, LttTime
*end
);
114 static void group_time_span_get(GQuark name
, gpointer data
, gpointer user_data
);
115 static gint
map_block(LttTracefile
* tf
, guint block_num
);
116 static int ltt_seek_next_event(LttTracefile
*tf
);
117 static void __attribute__((constructor
)) init(void);
118 static void ltt_update_event_size(LttTracefile
*tf
);
120 /* Enable event debugging */
121 static int a_event_debug
= 0;
123 void ltt_event_debug(int state
)
125 a_event_debug
= state
;
128 guint
ltt_trace_get_num_cpu(LttTrace
*t
)
136 * Return value : 0 success, 1 bad tracefile
138 int parse_trace_header(void *header
, LttTracefile
*tf
, LttTrace
*t
)
140 guint32
*magic_number
= (guint32
*)header
;
141 struct ltt_trace_header_any
*any
= (struct ltt_trace_header_any
*)header
;
143 if(*magic_number
== LTT_MAGIC_NUMBER
)
145 else if(*magic_number
== LTT_REV_MAGIC_NUMBER
)
147 else /* invalid magic number, bad tracefile ! */
150 /* Get float byte order : might be different from int byte order
151 * (or is set to 0 if the trace has no float (kernel trace)) */
152 tf
->float_word_order
= any
->float_word_order
;
153 tf
->alignment
= any
->alignment
;
154 tf
->has_heartbeat
= any
->has_heartbeat
;
157 t
->arch_type
= ltt_get_uint32(LTT_GET_BO(tf
),
159 t
->arch_variant
= ltt_get_uint32(LTT_GET_BO(tf
),
161 t
->arch_size
= any
->arch_size
;
162 t
->ltt_major_version
= any
->major_version
;
163 t
->ltt_minor_version
= any
->minor_version
;
164 t
->flight_recorder
= any
->flight_recorder
;
165 // t->compact_facilities = NULL;
168 switch(any
->major_version
) {
171 g_warning("Unsupported trace version : %hhu.%hhu",
172 any
->major_version
, any
->minor_version
);
176 switch(any
->minor_version
) {
179 struct ltt_trace_header_1_0
*vheader
=
180 (struct ltt_trace_header_1_0
*)header
;
181 tf
->buffer_header_size
=
182 sizeof(struct ltt_block_start_header
)
183 + sizeof(struct ltt_trace_header_1_0
);
184 tf
->tsc_lsb_truncate
= vheader
->tsc_lsb_truncate
;
185 tf
->tscbits
= vheader
->tscbits
;
186 tf
->tsc_msb_cutoff
= 32 - tf
->tsc_lsb_truncate
- tf
->tscbits
;
187 tf
->compact_event_bits
= 32 - vheader
->compact_data_shift
;
188 tf
->tsc_mask
= ((1ULL << (tf
->tscbits
))-1);
189 tf
->tsc_mask
= tf
->tsc_mask
<< tf
->tsc_lsb_truncate
;
190 tf
->tsc_mask_next_bit
= (1ULL<<(tf
->tscbits
));
191 tf
->tsc_mask_next_bit
= tf
->tsc_mask_next_bit
<< tf
->tsc_lsb_truncate
;
193 t
->start_freq
= ltt_get_uint64(LTT_GET_BO(tf
),
194 &vheader
->start_freq
);
195 t
->freq_scale
= ltt_get_uint32(LTT_GET_BO(tf
),
196 &vheader
->freq_scale
);
198 t
->start_freq
= father_trace
->start_freq
;
199 t
->freq_scale
= father_trace
->freq_scale
;
204 t
->start_tsc
= ltt_get_uint64(LTT_GET_BO(tf
),
205 &vheader
->start_tsc
);
206 t
->start_monotonic
= ltt_get_uint64(LTT_GET_BO(tf
),
207 &vheader
->start_monotonic
);
208 t
->start_time
.tv_sec
= ltt_get_uint64(LTT_GET_BO(tf
),
209 &vheader
->start_time_sec
);
210 t
->start_time
.tv_nsec
= ltt_get_uint64(LTT_GET_BO(tf
),
211 &vheader
->start_time_usec
);
212 t
->start_time
.tv_nsec
*= 1000; /* microsec to nanosec */
214 t
->start_time_from_tsc
= ltt_time_from_uint64(
216 * (1000000000.0 / tf
->trace
->freq_scale
)
217 / (double)t
->start_freq
);
222 g_warning("Unsupported trace version : %hhu.%hhu",
223 any
->major_version
, any
->minor_version
);
228 g_warning("Unsupported trace version : %hhu.%hhu",
229 any
->major_version
, any
->minor_version
);
239 /*****************************************************************************
241 * ltt_tracefile_open : open a trace file, construct a LttTracefile
243 * t : the trace containing the tracefile
244 * fileName : path name of the trace file
245 * tf : the tracefile structure
247 * : 0 for success, -1 otherwise.
248 ****************************************************************************/
250 gint
ltt_tracefile_open(LttTrace
*t
, gchar
* fileName
, LttTracefile
*tf
)
252 struct stat lTDFStat
; /* Trace data file status */
253 struct ltt_block_start_header
*header
;
254 int page_size
= getpagesize();
257 tf
->long_name
= g_quark_from_string(fileName
);
259 tf
->fd
= open(fileName
, O_RDONLY
);
261 g_warning("Unable to open input data file %s\n", fileName
);
265 // Get the file's status
266 if(fstat(tf
->fd
, &lTDFStat
) < 0){
267 g_warning("Unable to get the status of the input data file %s\n", fileName
);
271 // Is the file large enough to contain a trace
272 if(lTDFStat
.st_size
<
273 (off_t
)(sizeof(struct ltt_block_start_header
)
274 + sizeof(struct ltt_trace_header_any
))){
275 g_print("The input data file %s does not contain a trace\n", fileName
);
279 /* Temporarily map the buffer start header to get trace information */
280 /* Multiple of pages aligned head */
281 tf
->buffer
.head
= mmap(0,
282 PAGE_ALIGN(sizeof(struct ltt_block_start_header
)
283 + sizeof(struct ltt_trace_header_any
)), PROT_READ
,
284 MAP_PRIVATE
, tf
->fd
, 0);
285 if(tf
->buffer
.head
== MAP_FAILED
) {
286 perror("Error in allocating memory for buffer of tracefile");
289 g_assert( ( (gulong
)tf
->buffer
.head
&(8-1) ) == 0); // make sure it's aligned.
291 header
= (struct ltt_block_start_header
*)tf
->buffer
.head
;
293 if(parse_trace_header(header
->trace
, tf
, NULL
)) {
294 g_warning("parse_trace_header error");
298 //store the size of the file
299 tf
->file_size
= lTDFStat
.st_size
;
300 tf
->buf_size
= ltt_get_uint32(LTT_GET_BO(tf
), &header
->buf_size
);
301 tf
->num_blocks
= tf
->file_size
/ tf
->buf_size
;
303 if(munmap(tf
->buffer
.head
,
304 PAGE_ALIGN(sizeof(struct ltt_block_start_header
)
305 + sizeof(struct ltt_trace_header_any
)))) {
306 g_warning("unmap size : %u\n",
307 PAGE_ALIGN(sizeof(struct ltt_block_start_header
)
308 + sizeof(struct ltt_trace_header_any
)));
309 perror("munmap error");
312 tf
->buffer
.head
= NULL
;
314 //read the first block
315 if(map_block(tf
,0)) {
316 perror("Cannot map block for tracefile");
324 if(munmap(tf
->buffer
.head
,
325 PAGE_ALIGN(sizeof(struct ltt_block_start_header
)
326 + sizeof(struct ltt_trace_header_any
)))) {
327 g_warning("unmap size : %u\n",
328 PAGE_ALIGN(sizeof(struct ltt_block_start_header
)
329 + sizeof(struct ltt_trace_header_any
)));
330 perror("munmap error");
339 LttTrace
*ltt_tracefile_get_trace(LttTracefile
*tf
)
345 /*****************************************************************************
346 *Open control and per cpu tracefiles
347 ****************************************************************************/
349 void ltt_tracefile_open_cpu(LttTrace
*t
, gchar
* tracefile_name
)
352 tf
= ltt_tracefile_open(t
,tracefile_name
);
354 t
->per_cpu_tracefile_number
++;
355 g_ptr_array_add(t
->per_cpu_tracefiles
, tf
);
358 gint
ltt_tracefile_open_control(LttTrace
*t
, gchar
* control_name
)
367 tf
= ltt_tracefile_open(t
,control_name
);
369 g_warning("ltt_tracefile_open_control : bad file descriptor");
372 t
->control_tracefile_number
++;
373 g_ptr_array_add(t
->control_tracefiles
,tf
);
375 //parse facilities tracefile to get base_id
376 if(strcmp(&control_name
[strlen(control_name
)-10],"facilities") ==0){
378 if(!ltt_tracefile_read(tf
,&ev
)) return 0; // end of file
380 if(ev
.event_id
== TRACE_FACILITY_LOAD
){
382 fLoad
.name
= (gchar
*)pos
;
383 fLoad
.checksum
= *(LttChecksum
*)(pos
+ strlen(fLoad
.name
));
384 fLoad
.base_code
= *(guint32
*)(pos
+ strlen(fLoad
.name
) + sizeof(LttChecksum
));
386 for(i
=0;i
<t
->facility_number
;i
++){
387 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
,i
);
388 if(strcmp(f
->name
,fLoad
.name
)==0 && fLoad
.checksum
==f
->checksum
){
389 f
->base_id
= fLoad
.base_code
;
393 if(i
==t
->facility_number
) {
394 g_warning("Facility: %s, checksum: %u is not found",
395 fLoad
.name
,(unsigned int)fLoad
.checksum
);
398 }else if(ev
.event_id
== TRACE_BLOCK_START
){
400 }else if(ev
.event_id
== TRACE_BLOCK_END
){
403 g_warning("Not valid facilities trace file");
412 /*****************************************************************************
414 * ltt_tracefile_close: close a trace file,
416 * t : tracefile which will be closed
417 ****************************************************************************/
419 void ltt_tracefile_close(LttTracefile
*t
)
421 int page_size
= getpagesize();
423 if(t
->buffer
.head
!= NULL
)
424 if(munmap(t
->buffer
.head
, PAGE_ALIGN(t
->buf_size
))) {
425 g_warning("unmap size : %u\n",
426 PAGE_ALIGN(t
->buf_size
));
427 perror("munmap error");
435 /*****************************************************************************
436 *Get system information
437 ****************************************************************************/
439 gint
getSystemInfo(LttSystemDescription
* des
, gchar
* pathname
)
446 GMarkupParseContext
* context
;
447 GError
* error
= NULL
;
448 GMarkupParser markup_parser
=
450 parser_start_element
,
453 NULL
, /* passthrough */
457 fd
= g_open(pathname
, O_RDONLY
, 0);
459 g_warning("Can not open file : %s\n", pathname
);
463 iochan
= g_io_channel_unix_new(fd
);
465 context
= g_markup_parse_context_new(&markup_parser
, 0, des
,NULL
);
467 //while(fgets(buf,DIR_NAME_SIZE, fp) != NULL){
468 while(g_io_channel_read_line(iochan
, &buf
, &length
, NULL
, &error
)
469 != G_IO_STATUS_EOF
) {
472 g_warning("Can not read xml file: \n%s\n", error
->message
);
475 if(!g_markup_parse_context_parse(context
, buf
, length
, &error
)){
477 g_warning("Can not parse xml file: \n%s\n", error
->message
);
480 g_markup_parse_context_free(context
);
482 g_io_channel_shutdown(iochan
, FALSE
, &error
); /* No flush */
484 g_warning("Can not close file: \n%s\n", error
->message
);
492 g_markup_parse_context_free(context
);
494 g_io_channel_shutdown(iochan
, FALSE
, &error
); /* No flush */
496 g_warning("Can not close file: \n%s\n", error
->message
);
507 /*****************************************************************************
508 *The following functions get facility/tracefile information
509 ****************************************************************************/
511 gint
getFacilityInfo(LttTrace
*t
, gchar
* eventdefs
)
518 gchar fullname
[DIR_NAME_SIZE
];
519 GError
* error
= NULL
;
521 dir
= g_dir_open(eventdefs
, 0, &error
);
524 g_warning("Can not open directory: %s, %s\n", eventdefs
, error
->message
);
529 while((name
= g_dir_read_name(dir
)) != NULL
){
530 if(!g_pattern_match_simple("*.xml", name
)) continue;
531 strcpy(fullname
,eventdefs
);
532 strcat(fullname
,name
);
533 ltt_facility_open(t
,fullname
);
537 for(j
=0;j
<t
->facility_number
;j
++){
538 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
, j
);
539 for(i
=0; i
<f
->event_number
; i
++){
541 setFieldsOffset(NULL
, et
, NULL
, t
);
548 /*****************************************************************************
549 *A trace is specified as a pathname to the directory containing all the
550 *associated data (control tracefiles, per cpu tracefiles, event
553 *When a trace is closed, all the associated facilities, types and fields
554 *are released as well.
558 /****************************************************************************
559 * get_absolute_pathname
561 * return the unique pathname in the system
563 * MD : Fixed this function so it uses realpath, dealing well with
564 * forgotten cases (.. were not used correctly before).
566 ****************************************************************************/
567 void get_absolute_pathname(const gchar
*pathname
, gchar
* abs_pathname
)
569 abs_pathname
[0] = '\0';
571 if ( realpath (pathname
, abs_pathname
) != NULL
)
575 /* error, return the original path unmodified */
576 strcpy(abs_pathname
, pathname
);
582 /* Search for something like : .*_.*
584 * The left side is the name, the right side is the number.
587 int get_tracefile_name_number(gchar
*raw_name
,
594 guint raw_name_len
= strlen(raw_name
);
595 gchar char_name
[PATH_MAX
];
602 for(i
=raw_name_len
-1;i
>=0;i
--) {
603 if(raw_name
[i
] == '_') break;
605 if(i
==-1) { /* Either not found or name length is 0 */
606 /* This is a userspace tracefile */
607 strncpy(char_name
, raw_name
, raw_name_len
);
608 char_name
[raw_name_len
] = '\0';
609 *name
= g_quark_from_string(char_name
);
610 *num
= 0; /* unknown cpu */
611 for(i
=0;i
<raw_name_len
;i
++) {
612 if(raw_name
[i
] == '/') {
617 for(;i
<raw_name_len
;i
++) {
618 if(raw_name
[i
] == '/') {
623 for(;i
<raw_name_len
;i
++) {
624 if(raw_name
[i
] == '-') {
628 if(i
== raw_name_len
) return -1;
630 tmpptr
= &raw_name
[i
];
631 for(;i
<raw_name_len
;i
++) {
632 if(raw_name
[i
] == '.') {
637 *tid
= strtoul(tmpptr
, &endptr
, 10);
639 return -1; /* No digit */
640 if(*tid
== ULONG_MAX
)
641 return -1; /* underflow / overflow */
643 tmpptr
= &raw_name
[i
];
644 for(;i
<raw_name_len
;i
++) {
645 if(raw_name
[i
] == '.') {
650 *pgid
= strtoul(tmpptr
, &endptr
, 10);
652 return -1; /* No digit */
653 if(*pgid
== ULONG_MAX
)
654 return -1; /* underflow / overflow */
656 tmpptr
= &raw_name
[i
];
657 *creation
= strtoull(tmpptr
, &endptr
, 10);
659 return -1; /* No digit */
660 if(*creation
== G_MAXUINT64
)
661 return -1; /* underflow / overflow */
665 cpu_num
= strtol(raw_name
+underscore_pos
+1, &endptr
, 10);
667 if(endptr
== raw_name
+underscore_pos
+1)
668 return -1; /* No digit */
669 if(cpu_num
== LONG_MIN
|| cpu_num
== LONG_MAX
)
670 return -1; /* underflow / overflow */
672 strncpy(char_name
, raw_name
, underscore_pos
);
673 char_name
[underscore_pos
] = '\0';
675 *name
= g_quark_from_string(char_name
);
684 GData
**ltt_trace_get_tracefiles_groups(LttTrace
*trace
)
686 return &trace
->tracefiles
;
690 void compute_tracefile_group(GQuark key_id
,
692 struct compute_tracefile_group_args
*args
)
697 for(i
=0; i
<group
->len
; i
++) {
698 tf
= &g_array_index (group
, LttTracefile
, i
);
700 args
->func(tf
, args
->func_args
);
705 void ltt_tracefile_group_destroy(gpointer data
)
707 GArray
*group
= (GArray
*)data
;
711 for(i
=0; i
<group
->len
; i
++) {
712 tf
= &g_array_index (group
, LttTracefile
, i
);
714 ltt_tracefile_close(tf
);
716 g_array_free(group
, TRUE
);
719 gboolean
ltt_tracefile_group_has_cpu_online(gpointer data
)
721 GArray
*group
= (GArray
*)data
;
725 for(i
=0; i
<group
->len
; i
++) {
726 tf
= &g_array_index (group
, LttTracefile
, i
);
734 /* Open each tracefile under a specific directory. Put them in a
735 * GData : permits to access them using their tracefile group pathname.
736 * i.e. access control/modules tracefile group by index :
739 * relative path is the path relative to the trace root
740 * root path is the full path
742 * A tracefile group is simply an array where all the per cpu tracefiles sit.
745 int open_tracefiles(LttTrace
*trace
, gchar
*root_path
, gchar
*relative_path
)
747 DIR *dir
= opendir(root_path
);
748 struct dirent
*entry
;
749 struct stat stat_buf
;
752 gchar path
[PATH_MAX
];
757 gchar rel_path
[PATH_MAX
];
766 strncpy(path
, root_path
, PATH_MAX
-1);
767 path_len
= strlen(path
);
768 path
[path_len
] = '/';
770 path_ptr
= path
+ path_len
;
772 strncpy(rel_path
, relative_path
, PATH_MAX
-1);
773 rel_path_len
= strlen(rel_path
);
774 rel_path
[rel_path_len
] = '/';
776 rel_path_ptr
= rel_path
+ rel_path_len
;
778 while((entry
= readdir(dir
)) != NULL
) {
780 if(entry
->d_name
[0] == '.') continue;
782 strncpy(path_ptr
, entry
->d_name
, PATH_MAX
- path_len
);
783 strncpy(rel_path_ptr
, entry
->d_name
, PATH_MAX
- rel_path_len
);
785 ret
= stat(path
, &stat_buf
);
791 g_debug("Tracefile file or directory : %s\n", path
);
793 // if(strcmp(rel_path, "/eventdefs") == 0) continue;
795 if(S_ISDIR(stat_buf
.st_mode
)) {
797 g_debug("Entering subdirectory...\n");
798 ret
= open_tracefiles(trace
, path
, rel_path
);
799 if(ret
< 0) continue;
800 } else if(S_ISREG(stat_buf
.st_mode
)) {
809 if(get_tracefile_name_number(rel_path
, &name
, &num
, &tid
, &pgid
, &creation
))
810 continue; /* invalid name */
812 g_debug("Opening file.\n");
813 if(ltt_tracefile_open(trace
, path
, &tmp_tf
)) {
814 g_info("Error opening tracefile %s", path
);
816 continue; /* error opening the tracefile : bad magic number ? */
819 g_debug("Tracefile name is %s and number is %u",
820 g_quark_to_string(name
), num
);
822 tmp_tf
.cpu_online
= 1;
823 tmp_tf
.cpu_num
= num
;
827 tmp_tf
.creation
= creation
;
828 if(tmp_tf
.name
== g_quark_from_string("/compact")
829 || tmp_tf
.name
== g_quark_from_string("/flight-compact"))
833 group
= g_datalist_id_get_data(&trace
->tracefiles
, name
);
835 /* Elements are automatically cleared when the array is allocated.
836 * It makes the cpu_online variable set to 0 : cpu offline, by default.
838 group
= g_array_sized_new (FALSE
, TRUE
, sizeof(LttTracefile
), 10);
839 g_datalist_id_set_data_full(&trace
->tracefiles
, name
,
840 group
, ltt_tracefile_group_destroy
);
843 /* Add the per cpu tracefile to the named group */
844 unsigned int old_len
= group
->len
;
846 group
= g_array_set_size(group
, num
+1);
847 g_array_index (group
, LttTracefile
, num
) = tmp_tf
;
848 g_array_index (group
, LttTracefile
, num
).event
.tracefile
=
849 &g_array_index (group
, LttTracefile
, num
);
859 /* Presumes the tracefile is already seeked at the beginning. It makes sense,
860 * because it must be done just after the opening */
861 int ltt_process_facility_tracefile(LttTracefile
*tf
)
870 err
= ltt_tracefile_read_seek(tf
);
871 if(err
== EPERM
) goto seek_error
;
872 else if(err
== ERANGE
) break; /* End of tracefile */
874 err
= ltt_tracefile_read_update_event(tf
);
875 if(err
) goto update_error
;
877 /* We are on a facility load/or facility unload/ or heartbeat event */
879 * * facility 0 is hardcoded : this is the core facility. It will be shown
880 * in the facility array though, and is shown as "loaded builtin" in the
882 * It contains event :
884 * 1 : facility unload
885 * 2 : state dump facility load
888 if(tf
->event
.event_id
>= MARKER_CORE_IDS
) {
889 /* Should only contain core facility */
890 g_warning("Error in processing facility file %s, "
891 "should not contain event id %u.", g_quark_to_string(tf
->name
),
898 const char *marker_name
, *format
;
900 guint8 int_size
, long_size
, pointer_size
, size_t_size
, alignment
;
903 switch((enum marker_id
)tf
->event
.event_id
) {
904 case MARKER_ID_SET_MARKER_ID
:
905 marker_name
= pos
= tf
->event
.data
;
906 g_debug("Doing MARKER_ID_SET_MARKER_ID of marker %s", marker_name
);
907 pos
+= strlen(marker_name
) + 1;
908 //remove genevent compatibility
909 //pos += ltt_align((size_t)pos, tf->trace->arch_size, tf->alignment);
910 pos
+= ltt_align((size_t)pos
, sizeof(uint16_t), tf
->alignment
);
911 id
= ltt_get_uint16(LTT_GET_BO(tf
), pos
);
912 g_debug("In MARKER_ID_SET_MARKER_ID of marker %s id %hu",
914 pos
+= sizeof(guint16
);
915 int_size
= *(guint8
*)pos
;
916 pos
+= sizeof(guint8
);
917 long_size
= *(guint8
*)pos
;
918 pos
+= sizeof(guint8
);
919 pointer_size
= *(guint8
*)pos
;
920 pos
+= sizeof(guint8
);
921 size_t_size
= *(guint8
*)pos
;
922 pos
+= sizeof(guint8
);
923 alignment
= *(guint8
*)pos
;
924 pos
+= sizeof(guint8
);
925 marker_id_event(tf
->trace
, g_quark_from_string(marker_name
),
926 id
, int_size
, long_size
,
927 pointer_size
, size_t_size
, alignment
);
929 case MARKER_ID_SET_MARKER_FORMAT
:
930 marker_name
= pos
= tf
->event
.data
;
931 g_debug("Doing MARKER_ID_SET_MARKER_FORMAT of marker %s",
933 pos
+= strlen(marker_name
) + 1;
935 //pos += ltt_align((size_t)pos, tf->trace->arch_size, tf->alignment);
937 pos
+= strlen(format
) + 1;
939 //pos += ltt_align((size_t)pos, tf->trace->arch_size, tf->alignment);
940 marker_format_event(tf
->trace
, g_quark_from_string(marker_name
),
942 /* get information from dictionnary TODO */
944 case MARKER_ID_HEARTBEAT_32
:
945 case MARKER_ID_HEARTBEAT_64
:
948 g_warning("Error in processing facility file %s, "
949 "unknown event id %hhu.",
950 g_quark_to_string(tf
->name
),
963 g_warning("An error occured in facility tracefile parsing");
968 LttTrace
*ltt_trace_open(const gchar
*pathname
)
970 gchar abs_path
[PATH_MAX
];
975 struct ltt_block_start_header
*header
;
977 struct dirent
*entry
;
978 guint control_found
= 0;
979 struct stat stat_buf
;
980 gchar path
[PATH_MAX
];
982 t
= g_new(LttTrace
, 1);
983 if(!t
) goto alloc_error
;
985 get_absolute_pathname(pathname
, abs_path
);
986 t
->pathname
= g_quark_from_string(abs_path
);
988 g_datalist_init(&t
->tracefiles
);
990 /* Test to see if it looks like a trace */
991 dir
= opendir(abs_path
);
996 while((entry
= readdir(dir
)) != NULL
) {
997 strcpy(path
, abs_path
);
999 strcat(path
, entry
->d_name
);
1000 ret
= stat(path
, &stat_buf
);
1005 if(S_ISDIR(stat_buf
.st_mode
)) {
1006 if(strcmp(entry
->d_name
, "control") == 0) {
1013 if(!control_found
) goto find_error
;
1015 /* Open all the tracefiles */
1016 if(open_tracefiles(t
, abs_path
, "")) {
1017 g_warning("Error opening tracefile %s", abs_path
);
1021 /* Parse each trace control/facilitiesN files : get runtime fac. info */
1022 group
= g_datalist_id_get_data(&t
->tracefiles
, LTT_TRACEFILE_NAME_FACILITIES
);
1024 g_error("Trace %s has no facility tracefile", abs_path
);
1026 goto facilities_error
;
1029 /* Get the trace information for the control/facility 0 tracefile */
1030 g_assert(group
->len
> 0);
1031 tf
= &g_array_index (group
, LttTracefile
, 0);
1032 header
= (struct ltt_block_start_header
*)tf
->buffer
.head
;
1033 g_assert(parse_trace_header(header
->trace
,
1036 t
->num_cpu
= group
->len
;
1038 ret
= allocate_marker_data(t
);
1040 g_error("Error in allocating marker data");
1042 for(i
=0; i
<group
->len
; i
++) {
1043 tf
= &g_array_index (group
, LttTracefile
, i
);
1044 if(ltt_process_facility_tracefile(tf
))
1045 goto facilities_error
;
1050 /* Error handling */
1052 destroy_marker_data(t
);
1054 g_datalist_clear(&t
->tracefiles
);
1062 GQuark
ltt_trace_name(const LttTrace
*t
)
1068 /******************************************************************************
1069 * When we copy a trace, we want all the opening actions to happen again :
1070 * the trace will be reopened and totally independant from the original.
1071 * That's why we call ltt_trace_open.
1072 *****************************************************************************/
1073 LttTrace
*ltt_trace_copy(LttTrace
*self
)
1075 return ltt_trace_open(g_quark_to_string(self
->pathname
));
1078 void ltt_trace_close(LttTrace
*t
)
1080 g_datalist_clear(&t
->tracefiles
);
1085 /*****************************************************************************
1086 * Get the start time and end time of the trace
1087 ****************************************************************************/
1089 void ltt_tracefile_time_span_get(LttTracefile
*tf
,
1090 LttTime
*start
, LttTime
*end
)
1094 err
= map_block(tf
, 0);
1096 g_error("Can not map block");
1097 *start
= ltt_time_infinite
;
1099 *start
= tf
->buffer
.begin
.timestamp
;
1101 err
= map_block(tf
, tf
->num_blocks
- 1); /* Last block */
1103 g_error("Can not map block");
1104 *end
= ltt_time_zero
;
1106 *end
= tf
->buffer
.end
.timestamp
;
1109 struct tracefile_time_span_get_args
{
1115 void group_time_span_get(GQuark name
, gpointer data
, gpointer user_data
)
1117 struct tracefile_time_span_get_args
*args
=
1118 (struct tracefile_time_span_get_args
*)user_data
;
1120 GArray
*group
= (GArray
*)data
;
1126 for(i
=0; i
<group
->len
; i
++) {
1127 tf
= &g_array_index (group
, LttTracefile
, i
);
1128 if(tf
->cpu_online
) {
1129 ltt_tracefile_time_span_get(tf
, &tmp_start
, &tmp_end
);
1130 if(ltt_time_compare(*args
->start
, tmp_start
)>0) *args
->start
= tmp_start
;
1131 if(ltt_time_compare(*args
->end
, tmp_end
)<0) *args
->end
= tmp_end
;
1136 void ltt_trace_time_span_get(LttTrace
*t
, LttTime
*start
, LttTime
*end
)
1138 LttTime min_start
= ltt_time_infinite
;
1139 LttTime max_end
= ltt_time_zero
;
1140 struct tracefile_time_span_get_args args
= { t
, &min_start
, &max_end
};
1142 g_datalist_foreach(&t
->tracefiles
, &group_time_span_get
, &args
);
1144 if(start
!= NULL
) *start
= min_start
;
1145 if(end
!= NULL
) *end
= max_end
;
1150 /*****************************************************************************
1151 *Get the name of a tracefile
1152 ****************************************************************************/
1154 GQuark
ltt_tracefile_name(const LttTracefile
*tf
)
1159 GQuark
ltt_tracefile_long_name(const LttTracefile
*tf
)
1161 return tf
->long_name
;
1166 guint
ltt_tracefile_cpu(LttTracefile
*tf
)
1171 guint
ltt_tracefile_tid(LttTracefile
*tf
)
1176 guint
ltt_tracefile_pgid(LttTracefile
*tf
)
1181 guint64
ltt_tracefile_creation(LttTracefile
*tf
)
1183 return tf
->creation
;
1185 /*****************************************************************************
1186 * Get the number of blocks in the tracefile
1187 ****************************************************************************/
1189 guint
ltt_tracefile_block_number(LttTracefile
*tf
)
1191 return tf
->num_blocks
;
1195 /* Seek to the first event in a tracefile that has a time equal or greater than
1196 * the time passed in parameter.
1198 * If the time parameter is outside the tracefile time span, seek to the first
1199 * event or if after, return ERANGE.
1201 * If the time parameter is before the first event, we have to seek specially to
1204 * If the time is after the end of the trace, return ERANGE.
1206 * Do a binary search to find the right block, then a sequential search in the
1207 * block to find the event.
1209 * In the special case where the time requested fits inside a block that has no
1210 * event corresponding to the requested time, the first event of the next block
1213 * IMPORTANT NOTE : // FIXME everywhere...
1215 * You MUST NOT do a ltt_tracefile_read right after a ltt_tracefile_seek_time :
1216 * you will jump over an event if you do.
1218 * Return value : 0 : no error, the tf->event can be used
1219 * ERANGE : time if after the last event of the trace
1220 * otherwise : this is an error.
1224 int ltt_tracefile_seek_time(LttTracefile
*tf
, LttTime time
)
1228 unsigned int block_num
, high
, low
;
1230 /* seek at the beginning of trace */
1231 err
= map_block(tf
, 0); /* First block */
1233 g_error("Can not map block");
1237 /* If the time is lower or equal the beginning of the trace,
1238 * go to the first event. */
1239 if(ltt_time_compare(time
, tf
->buffer
.begin
.timestamp
) <= 0) {
1240 ret
= ltt_tracefile_read(tf
);
1241 if(ret
== ERANGE
) goto range
;
1242 else if (ret
) goto fail
;
1243 goto found
; /* There is either no event in the trace or the event points
1244 to the first event in the trace */
1247 err
= map_block(tf
, tf
->num_blocks
- 1); /* Last block */
1249 g_error("Can not map block");
1253 /* If the time is after the end of the trace, return ERANGE. */
1254 if(ltt_time_compare(time
, tf
->buffer
.end
.timestamp
) > 0) {
1258 /* Binary search the block */
1259 high
= tf
->num_blocks
- 1;
1263 block_num
= ((high
-low
) / 2) + low
;
1265 err
= map_block(tf
, block_num
);
1267 g_error("Can not map block");
1271 /* We cannot divide anymore : this is what would happen if the time
1272 * requested was exactly between two consecutive buffers'end and start
1273 * timestamps. This is also what would happend if we didn't deal with out
1274 * of span cases prior in this function. */
1275 /* The event is right in the buffer!
1276 * (or in the next buffer first event) */
1278 ret
= ltt_tracefile_read(tf
);
1279 if(ret
== ERANGE
) goto range
; /* ERANGE or EPERM */
1280 else if(ret
) goto fail
;
1282 if(ltt_time_compare(time
, tf
->event
.event_time
) <= 0)
1286 } else if(ltt_time_compare(time
, tf
->buffer
.begin
.timestamp
) < 0) {
1287 /* go to lower part */
1288 high
= block_num
- 1;
1289 } else if(ltt_time_compare(time
, tf
->buffer
.end
.timestamp
) > 0) {
1290 /* go to higher part */
1291 low
= block_num
+ 1;
1292 } else {/* The event is right in the buffer!
1293 (or in the next buffer first event) */
1295 ret
= ltt_tracefile_read(tf
);
1296 if(ret
== ERANGE
) goto range
; /* ERANGE or EPERM */
1297 else if(ret
) goto fail
;
1299 if(ltt_time_compare(time
, tf
->event
.event_time
) <= 0)
1311 /* Error handling */
1313 g_error("ltt_tracefile_seek_time failed on tracefile %s",
1314 g_quark_to_string(tf
->name
));
1319 int ltt_tracefile_seek_position(LttTracefile
*tf
, const LttEventPosition
*ep
) {
1323 if(ep
->tracefile
!= tf
) {
1327 err
= map_block(tf
, ep
->block
);
1329 g_error("Can not map block");
1333 tf
->event
.offset
= ep
->offset
;
1335 /* Put back the event real tsc */
1336 tf
->event
.tsc
= ep
->tsc
;
1337 tf
->buffer
.tsc
= ep
->tsc
;
1339 err
= ltt_tracefile_read_update_event(tf
);
1341 err
= ltt_tracefile_read_op(tf
);
1347 g_error("ltt_tracefile_seek_time failed on tracefile %s",
1348 g_quark_to_string(tf
->name
));
1352 LttTime
ltt_interpolate_time_from_tsc(LttTracefile
*tf
, guint64 tsc
)
1356 if(tsc
> tf
->trace
->start_tsc
) {
1357 time
= ltt_time_from_uint64(
1358 (double)(tsc
- tf
->trace
->start_tsc
)
1359 * (1000000000.0 / tf
->trace
->freq_scale
)
1360 / (double)tf
->trace
->start_freq
);
1361 time
= ltt_time_add(tf
->trace
->start_time_from_tsc
, time
);
1363 time
= ltt_time_from_uint64(
1364 (double)(tf
->trace
->start_tsc
- tsc
)
1365 * (1000000000.0 / tf
->trace
->freq_scale
)
1366 / (double)tf
->trace
->start_freq
);
1367 time
= ltt_time_sub(tf
->trace
->start_time_from_tsc
, time
);
1372 /* Calculate the real event time based on the buffer boundaries */
1373 LttTime
ltt_interpolate_time(LttTracefile
*tf
, LttEvent
*event
)
1375 return ltt_interpolate_time_from_tsc(tf
, tf
->buffer
.tsc
);
1379 /* Get the current event of the tracefile : valid until the next read */
1380 LttEvent
*ltt_tracefile_get_event(LttTracefile
*tf
)
1387 /*****************************************************************************
1389 * ltt_tracefile_read : Read the next event in the tracefile
1394 * Returns 0 if an event can be used in tf->event.
1395 * Returns ERANGE on end of trace. The event in tf->event still can be used
1396 * (if the last block was not empty).
1397 * Returns EPERM on error.
1399 * This function does make the tracefile event structure point to the event
1400 * currently pointed to by the tf->event.
1402 * Note : you must call a ltt_tracefile_seek to the beginning of the trace to
1403 * reinitialize it after an error if you want results to be coherent.
1404 * It would be the case if a end of trace last buffer has no event : the end
1405 * of trace wouldn't be returned, but an error.
1406 * We make the assumption there is at least one event per buffer.
1407 ****************************************************************************/
1409 int ltt_tracefile_read(LttTracefile
*tf
)
1413 err
= ltt_tracefile_read_seek(tf
);
1415 err
= ltt_tracefile_read_update_event(tf
);
1417 err
= ltt_tracefile_read_op(tf
);
1423 int ltt_tracefile_read_seek(LttTracefile
*tf
)
1427 /* Get next buffer until we finally have an event, or end of trace */
1429 err
= ltt_seek_next_event(tf
);
1430 if(unlikely(err
== ENOPROTOOPT
)) {
1434 /* Are we at the end of the buffer ? */
1436 if(unlikely(tf
->buffer
.index
== tf
->num_blocks
-1)){ /* end of trace ? */
1439 /* get next block */
1440 err
= map_block(tf
, tf
->buffer
.index
+ 1);
1442 g_error("Can not map block");
1446 } else break; /* We found an event ! */
1453 /* do specific operation on events */
1454 int ltt_tracefile_read_op(LttTracefile
*tf
)
1460 /* do event specific operation */
1462 /* do something if its an heartbeat event : increment the heartbeat count */
1463 //if(event->facility_id == LTT_FACILITY_CORE)
1464 // if(event->event_id == LTT_EVENT_HEARTBEAT)
1465 // tf->cur_heart_beat_number++;
1470 static void print_debug_event_header(LttEvent
*ev
, void *start_pos
, void *end_pos
)
1472 unsigned int offset
= 0;
1475 g_printf("Event header (tracefile %s offset %llx):\n",
1476 g_quark_to_string(ev
->tracefile
->long_name
),
1477 ((uint64_t)ev
->tracefile
->buffer
.index
* ev
->tracefile
->buf_size
)
1478 + (long)start_pos
- (long)ev
->tracefile
->buffer
.head
);
1480 while (offset
< (long)end_pos
- (long)start_pos
) {
1481 g_printf("%8lx", (long)start_pos
- (long)ev
->tracefile
->buffer
.head
+ offset
);
1484 for (i
= 0; i
< 4 ; i
++) {
1485 for (j
= 0; j
< 4; j
++) {
1486 if (offset
+ ((i
* 4) + j
) <
1487 (long)end_pos
- (long)start_pos
)
1489 ((char*)start_pos
)[offset
+ ((i
* 4) + j
)]);
1503 /* same as ltt_tracefile_read, but does not seek to the next event nor call
1504 * event specific operation. */
1505 int ltt_tracefile_read_update_event(LttTracefile
*tf
)
1512 pos
= tf
->buffer
.head
+ event
->offset
;
1514 /* Read event header */
1516 /* Align the head */
1518 pos
+= ltt_align((size_t)pos
, tf
->trace
->arch_size
, tf
->alignment
);
1520 g_assert(tf
->has_heartbeat
);
1521 pos
+= ltt_align((size_t)pos
, sizeof(uint32_t), tf
->alignment
);
1525 if(tf
->has_heartbeat
) {
1526 event
->timestamp
= ltt_get_uint32(LTT_GET_BO(tf
),
1529 /* 32 bits -> 64 bits tsc */
1530 /* note : still works for seek and non seek cases. */
1531 if(event
->timestamp
< (0xFFFFFFFFULL
&tf
->buffer
.tsc
)) {
1532 tf
->buffer
.tsc
= ((tf
->buffer
.tsc
&0xFFFFFFFF00000000ULL
)
1534 | (guint64
)event
->timestamp
;
1535 event
->tsc
= tf
->buffer
.tsc
;
1538 tf
->buffer
.tsc
= (tf
->buffer
.tsc
&0xFFFFFFFF00000000ULL
)
1539 | (guint64
)event
->timestamp
;
1540 event
->tsc
= tf
->buffer
.tsc
;
1541 event
->compact_data
= 0;
1544 /* Compact header */
1545 /* We keep the LSB of the previous timestamp, to make sure
1546 * we never go back */
1547 event
->event_id
= event
->timestamp
>> tf
->tscbits
;
1548 event
->event_id
= event
->event_id
& ((1 << tf
->compact_event_bits
) - 1);
1549 event
->compact_data
= event
->timestamp
>>
1550 (tf
->compact_event_bits
+ tf
->tscbits
);
1551 //printf("tsc bits %u, ev bits %u init data %u\n",
1552 // tf->tscbits, tf->trace->compact_event_bits, event->compact_data);
1553 /* Put the compact data back in original endianness */
1554 event
->compact_data
= ltt_get_uint32(LTT_GET_BO(tf
), &event
->compact_data
);
1555 event
->event_size
= 0xFFFF;
1556 //printf("Found compact event %d\n", event->event_id);
1557 //printf("Compact data %d\n", event->compact_data);
1558 event
->timestamp
= event
->timestamp
<< tf
->tsc_lsb_truncate
;
1559 event
->timestamp
= event
->timestamp
& tf
->tsc_mask
;
1560 //printf("timestamp 0x%lX\n", event->timestamp);
1561 //printf("mask 0x%llX\n", tf->tsc_mask);
1562 //printf("mask_next 0x%llX\n", tf->tsc_mask_next_bit);
1563 //printf("previous tsc 0x%llX\n", tf->buffer.tsc);
1564 //printf("previous tsc&mask 0x%llX\n", tf->tsc_mask&tf->buffer.tsc);
1565 //printf("previous tsc&(~mask) 0x%llX\n", tf->buffer.tsc&(~tf->tsc_mask));
1566 if(event
->timestamp
< (tf
->tsc_mask
&tf
->buffer
.tsc
)) {
1568 tf
->buffer
.tsc
= ((tf
->buffer
.tsc
&(~tf
->tsc_mask
))
1569 + tf
->tsc_mask_next_bit
)
1570 | (guint64
)event
->timestamp
;
1571 event
->tsc
= tf
->buffer
.tsc
;
1573 //printf("no wrap\n");
1575 tf
->buffer
.tsc
= (tf
->buffer
.tsc
&(~tf
->tsc_mask
))
1576 | (guint64
)event
->timestamp
;
1577 event
->tsc
= tf
->buffer
.tsc
;
1579 //printf("current tsc 0x%llX\n", tf->buffer.tsc);
1581 pos
+= sizeof(guint32
);
1583 event
->tsc
= ltt_get_uint64(LTT_GET_BO(tf
), pos
);
1584 tf
->buffer
.tsc
= event
->tsc
;
1585 event
->compact_data
= 0;
1586 pos
+= sizeof(guint64
);
1588 event
->event_time
= ltt_interpolate_time(tf
, event
);
1591 event
->event_id
= ltt_get_uint16(LTT_GET_BO(tf
), pos
);
1592 pos
+= sizeof(guint16
);
1594 event
->event_size
= ltt_get_uint16(LTT_GET_BO(tf
), pos
);
1595 pos
+= sizeof(guint16
);
1598 event
->event_size
= 0xFFFF;
1602 print_debug_event_header(event
, pos_aligned
, pos
);
1604 /* Align the head */
1606 pos
+= ltt_align((size_t)pos
, tf
->trace
->arch_size
, tf
->alignment
);
1610 /* get the data size and update the event fields with the current
1611 * information. Also update the time if a heartbeat_full event is found. */
1612 ltt_update_event_size(tf
);
1618 /****************************************************************************
1620 * map_block : map a block from the file
1622 * lttdes : ltt trace file
1623 * whichBlock : the block which will be read
1626 * EINVAL : lseek fail
1627 * EIO : can not read from the file
1628 ****************************************************************************/
1630 gint
map_block(LttTracefile
* tf
, guint block_num
)
1632 int page_size
= getpagesize();
1633 struct ltt_block_start_header
*header
;
1635 g_assert(block_num
< tf
->num_blocks
);
1637 if(tf
->buffer
.head
!= NULL
) {
1638 if(munmap(tf
->buffer
.head
, PAGE_ALIGN(tf
->buf_size
))) {
1639 g_warning("unmap size : %u\n",
1640 PAGE_ALIGN(tf
->buf_size
));
1641 perror("munmap error");
1647 /* Multiple of pages aligned head */
1648 tf
->buffer
.head
= mmap(0,
1649 PAGE_ALIGN(tf
->buf_size
),
1650 PROT_READ
, MAP_PRIVATE
, tf
->fd
,
1651 PAGE_ALIGN((off_t
)tf
->buf_size
* (off_t
)block_num
));
1653 if(tf
->buffer
.head
== MAP_FAILED
) {
1654 perror("Error in allocating memory for buffer of tracefile");
1658 g_assert( ( (gulong
)tf
->buffer
.head
&(8-1) ) == 0); // make sure it's aligned.
1661 tf
->buffer
.index
= block_num
;
1663 header
= (struct ltt_block_start_header
*)tf
->buffer
.head
;
1666 tf
->buffer
.begin
.timestamp
= ltt_time_add(
1667 ltt_time_from_uint64(
1668 ltt_get_uint64(LTT_GET_BO(tf
),
1669 &header
->begin
.timestamp
)
1670 - tf
->trace
->start_monotonic
),
1671 tf
->trace
->start_time
);
1673 //g_debug("block %u begin : %lu.%lu", block_num,
1674 // tf->buffer.begin.timestamp.tv_sec, tf->buffer.begin.timestamp.tv_nsec);
1675 tf
->buffer
.begin
.cycle_count
= ltt_get_uint64(LTT_GET_BO(tf
),
1676 &header
->begin
.cycle_count
);
1677 tf
->buffer
.begin
.freq
= ltt_get_uint64(LTT_GET_BO(tf
),
1678 &header
->begin
.freq
);
1679 if(tf
->buffer
.begin
.freq
== 0)
1680 tf
->buffer
.begin
.freq
= tf
->trace
->start_freq
;
1682 tf
->buffer
.begin
.timestamp
= ltt_interpolate_time_from_tsc(tf
,
1683 tf
->buffer
.begin
.cycle_count
);
1686 ltt_time_from_uint64(
1687 (double)(tf
->buffer
.begin
.cycle_count
1688 - tf
->trace
->start_tsc
) * 1000000.0
1689 / (double)tf
->trace
->start_freq
),
1690 tf
->trace
->start_time_from_tsc
);
1694 tf
->buffer
.end
.timestamp
= ltt_time_add(
1695 ltt_time_from_uint64(
1696 ltt_get_uint64(LTT_GET_BO(tf
),
1697 &header
->end
.timestamp
)
1698 - tf
->trace
->start_monotonic
),
1699 tf
->trace
->start_time
);
1701 //g_debug("block %u end : %lu.%lu", block_num,
1702 // tf->buffer.end.timestamp.tv_sec, tf->buffer.end.timestamp.tv_nsec);
1703 tf
->buffer
.end
.cycle_count
= ltt_get_uint64(LTT_GET_BO(tf
),
1704 &header
->end
.cycle_count
);
1705 tf
->buffer
.end
.freq
= ltt_get_uint64(LTT_GET_BO(tf
),
1707 if(tf
->buffer
.end
.freq
== 0)
1708 tf
->buffer
.end
.freq
= tf
->trace
->start_freq
;
1710 tf
->buffer
.lost_size
= ltt_get_uint32(LTT_GET_BO(tf
),
1711 &header
->lost_size
);
1712 tf
->buffer
.end
.timestamp
= ltt_interpolate_time_from_tsc(tf
,
1713 tf
->buffer
.end
.cycle_count
);
1716 ltt_time_from_uint64(
1717 (double)(tf
->buffer
.end
.cycle_count
1718 - tf
->trace
->start_tsc
) * 1000000.0
1719 / (double)tf
->trace
->start_freq
),
1720 tf
->trace
->start_time_from_tsc
);
1722 tf
->buffer
.tsc
= tf
->buffer
.begin
.cycle_count
;
1723 tf
->event
.tsc
= tf
->buffer
.tsc
;
1724 tf
->buffer
.freq
= tf
->buffer
.begin
.freq
;
1727 * eventually support variable buffer size : will need a partial pre-read of
1728 * the headers to create an index when we open the trace... eventually. */
1729 g_assert(tf
->buf_size
== ltt_get_uint32(LTT_GET_BO(tf
),
1730 &header
->buf_size
));
1732 /* Now that the buffer is mapped, calculate the time interpolation for the
1735 // tf->buffer.nsecs_per_cycle = calc_nsecs_per_cycle(tf);
1736 //tf->buffer.cyc2ns_scale = calc_nsecs_per_cycle(tf);
1738 /* Make the current event point to the beginning of the buffer :
1739 * it means that the event read must get the first event. */
1740 tf
->event
.tracefile
= tf
;
1741 tf
->event
.block
= block_num
;
1742 tf
->event
.offset
= 0;
1751 static void print_debug_event_data(LttEvent
*ev
)
1753 unsigned int offset
= 0;
1756 if (!max(ev
->event_size
, ev
->data_size
))
1759 g_printf("Event data (tracefile %s offset %llx):\n",
1760 g_quark_to_string(ev
->tracefile
->long_name
),
1761 ((uint64_t)ev
->tracefile
->buffer
.index
* ev
->tracefile
->buf_size
)
1762 + (long)ev
->data
- (long)ev
->tracefile
->buffer
.head
);
1764 while (offset
< max(ev
->event_size
, ev
->data_size
)) {
1765 g_printf("%8lx", (long)ev
->data
+ offset
1766 - (long)ev
->tracefile
->buffer
.head
);
1769 for (i
= 0; i
< 4 ; i
++) {
1770 for (j
= 0; j
< 4; j
++) {
1771 if (offset
+ ((i
* 4) + j
) < max(ev
->event_size
, ev
->data_size
))
1772 g_printf("%02hhX", ((char*)ev
->data
)[offset
+ ((i
* 4) + j
)]);
1783 for (i
= 0; i
< 4; i
++) {
1784 for (j
= 0; j
< 4; j
++) {
1785 if (offset
+ ((i
* 4) + j
) < max(ev
->event_size
, ev
->data_size
)) {
1786 if (isprint(((char*)ev
->data
)[offset
+ ((i
* 4) + j
)]))
1787 g_printf("%c", ((char*)ev
->data
)[offset
+ ((i
* 4) + j
)]);
1799 /* It will update the fields offsets too */
1800 void ltt_update_event_size(LttTracefile
*tf
)
1804 struct marker_info
*info
;
1806 switch((enum marker_id
)tf
->event
.event_id
) {
1807 case MARKER_ID_SET_MARKER_ID
:
1808 size
= strlen((char*)tf
->event
.data
) + 1;
1809 g_debug("marker %s id set", (char*)tf
->event
.data
);
1810 size
+= ltt_align(size
, sizeof(guint16
), tf
->alignment
);
1811 size
+= sizeof(guint16
);
1812 size
+= sizeof(guint8
);
1813 size
+= sizeof(guint8
);
1814 size
+= sizeof(guint8
);
1815 size
+= sizeof(guint8
);
1816 size
+= sizeof(guint8
);
1818 case MARKER_ID_SET_MARKER_FORMAT
:
1819 g_debug("marker %s format set", (char*)tf
->event
.data
);
1820 size
= strlen((char*)tf
->event
.data
) + 1;
1821 size
+= strlen((char*)tf
->event
.data
+ size
) + 1;
1823 case MARKER_ID_HEARTBEAT_32
:
1824 g_debug("Update Event heartbeat 32 bits");
1826 case MARKER_ID_HEARTBEAT_64
:
1827 g_debug("Update Event heartbeat 64 bits");
1828 tscdata
= (char*)(tf
->event
.data
);
1829 tf
->event
.tsc
= ltt_get_uint64(LTT_GET_BO(tf
), tscdata
);
1830 tf
->buffer
.tsc
= tf
->event
.tsc
;
1831 tf
->event
.event_time
= ltt_interpolate_time(tf
, &tf
->event
);
1832 size
= ltt_align(size
, sizeof(guint64
), tf
->alignment
);
1833 size
+= sizeof(guint64
);
1837 info
= marker_get_info_from_id(tf
->trace
, tf
->event
.event_id
);
1839 if (tf
->event
.event_id
>= MARKER_CORE_IDS
)
1840 g_assert(info
!= NULL
);
1842 /* Do not update field offsets of core markers when initially reading the
1843 * facility tracefile when the infos about these markers do not exist yet.
1845 if (likely(info
&& info
->fields
)) {
1846 if (info
->size
!= -1)
1849 size
= marker_update_fields_offsets(marker_get_info_from_id(tf
->trace
,
1850 tf
->event
.event_id
), tf
->event
.data
);
1853 tf
->event
.data_size
= size
;
1855 /* Check consistency between kernel and LTTV structure sizes */
1856 if(tf
->event
.event_size
== 0xFFFF) {
1857 /* Event size too big to fit in the event size field */
1858 tf
->event
.event_size
= tf
->event
.data_size
;
1862 print_debug_event_data(&tf
->event
);
1864 /* Having a marker load or marker format event out of the facilities
1865 * tracefiles is a serious bug. */
1866 switch((enum marker_id
)tf
->event
.event_id
) {
1867 case MARKER_ID_SET_MARKER_ID
:
1868 case MARKER_ID_SET_MARKER_FORMAT
:
1869 if (tf
->name
!= g_quark_from_string("/control/facilities"))
1870 g_error("Trace inconsistency : metadata event found in data "
1871 "tracefile %s", g_quark_to_string(tf
->long_name
));
1874 if (tf
->event
.data_size
!= tf
->event
.event_size
) {
1875 struct marker_info
*info
= marker_get_info_from_id(tf
->trace
,
1876 tf
->event
.event_id
);
1877 g_error("Kernel/LTTV event size differs for event %s: kernel %u, LTTV %u",
1878 g_quark_to_string(info
->name
),
1879 tf
->event
.event_size
, tf
->event
.data_size
);
1885 /* Take the tf current event offset and use the event facility id and event id
1886 * to figure out where is the next event offset.
1888 * This is an internal function not aiming at being used elsewhere : it will
1889 * not jump over the current block limits. Please consider using
1890 * ltt_tracefile_read to do this.
1892 * Returns 0 on success
1893 * ERANGE if we are at the end of the buffer.
1894 * ENOPROTOOPT if an error occured when getting the current event size.
1896 int ltt_seek_next_event(LttTracefile
*tf
)
1901 /* seek over the buffer header if we are at the buffer start */
1902 if(tf
->event
.offset
== 0) {
1903 tf
->event
.offset
+= tf
->buffer_header_size
;
1905 if(tf
->event
.offset
== tf
->buf_size
- tf
->buffer
.lost_size
) {
1912 pos
= tf
->event
.data
;
1914 if(tf
->event
.data_size
< 0) goto error
;
1916 pos
+= (size_t)tf
->event
.data_size
;
1918 tf
->event
.offset
= pos
- tf
->buffer
.head
;
1920 if(tf
->event
.offset
== tf
->buf_size
- tf
->buffer
.lost_size
) {
1924 g_assert(tf
->event
.offset
< tf
->buf_size
- tf
->buffer
.lost_size
);
1930 g_error("Error in ltt_seek_next_event for tracefile %s",
1931 g_quark_to_string(tf
->name
));
1936 /*****************************************************************************
1938 * calc_nsecs_per_cycle : calculate nsecs per cycle for current block
1940 * 1.0 / (freq(khz) *1000) * 1000000000
1943 ****************************************************************************/
1944 /* from timer_tsc.c */
1945 #define CYC2NS_SCALE_FACTOR 10
1946 static guint32
calc_nsecs_per_cycle(LttTracefile
* tf
)
1948 //return 1e6 / (double)tf->buffer.freq;
1949 guint32 cpu_mhz
= tf
->buffer
.freq
/ 1000;
1950 guint32 cyc2ns_scale
= (1000 << CYC2NS_SCALE_FACTOR
)/cpu_mhz
;
1952 return cyc2ns_scale
;
1953 // return 1e6 / (double)tf->buffer.freq;
1956 static guint64
cycles_2_ns(LttTracefile
*tf
, guint64 cycles
)
1958 return (cycles
* tf
->buffer
.cyc2ns_scale
) >> CYC2NS_SCALE_FACTOR
;
1963 void setFieldsOffset(LttTracefile
*tf
, LttEventType
*evT
,void *evD
)
1965 LttField
* rootFld
= evT
->root_field
;
1966 // rootFld->base_address = evD;
1969 rootFld
->field_size
= getFieldtypeSize(tf
, evT
->facility
,
1970 evT
, 0,0,rootFld
, evD
);
1974 /*****************************************************************************
1976 * set_fields_offsets : set the precomputable offset of the fields
1978 * tracefile : opened trace file
1979 * event_type : the event type
1980 ****************************************************************************/
1982 void set_fields_offsets(LttTracefile
*tf
, LttEventType
*event_type
)
1984 LttField
*field
= event_type
->root_field
;
1985 enum field_status fixed_root
= FIELD_FIXED
, fixed_parent
= FIELD_FIXED
;
1988 preset_field_type_size(tf
, event_type
, 0, 0,
1989 &fixed_root
, &fixed_parent
,
1996 /*****************************************************************************
1998 * get_alignment : Get the alignment needed for a field.
2002 * returns : The size on which it must be aligned.
2004 ****************************************************************************/
2006 off_t
get_alignment(LttField
*field
)
2008 LttType
*type
= &field
->field_type
;
2010 switch(type
->type_class
) {
2012 case LTT_UINT_FIXED
:
2027 /* Align offset on type size */
2028 g_assert(field
->field_size
!= 0);
2029 return field
->field_size
;
2035 g_assert(type
->fields
->len
== 1);
2037 LttField
*child
= &g_array_index(type
->fields
, LttField
, 0);
2038 return get_alignment(child
);
2042 g_assert(type
->fields
->len
== 2);
2045 LttField
*child
= &g_array_index(type
->fields
, LttField
, 0);
2047 localign
= max(localign
, get_alignment(child
));
2049 child
= &g_array_index(type
->fields
, LttField
, 1);
2050 localign
= max(localign
, get_alignment(child
));
2061 for(i
=0; i
<type
->fields
->len
; i
++) {
2062 LttField
*child
= &g_array_index(type
->fields
, LttField
, i
);
2063 localign
= max(localign
, get_alignment(child
));
2070 g_error("get_alignment : unknown type");
2077 /*****************************************************************************
2079 * field_compute_static_size : Determine the size of fields known by their
2080 * sole definition. Unions, arrays and struct sizes might be known, but
2081 * the parser does not give that information.
2086 ****************************************************************************/
2088 void field_compute_static_size(LttFacility
*fac
, LttField
*field
)
2090 LttType
*type
= &field
->field_type
;
2092 switch(type
->type_class
) {
2094 case LTT_UINT_FIXED
:
2113 /* note this : array type size is the number of elements in the array,
2114 * while array field size of the length of the array in bytes */
2115 g_assert(type
->fields
->len
== 1);
2117 LttField
*child
= &g_array_index(type
->fields
, LttField
, 0);
2118 field_compute_static_size(fac
, child
);
2120 if(child
->field_size
!= 0) {
2121 field
->field_size
= type
->size
* child
->field_size
;
2122 field
->dynamic_offsets
= g_array_sized_new(FALSE
, TRUE
,
2123 sizeof(off_t
), type
->size
);
2125 field
->field_size
= 0;
2130 g_assert(type
->fields
->len
== 2);
2132 off_t local_offset
= 0;
2133 LttField
*child
= &g_array_index(type
->fields
, LttField
, 1);
2134 field_compute_static_size(fac
, child
);
2135 field
->field_size
= 0;
2137 if(child
->field_size
!= 0) {
2138 field
->dynamic_offsets
= g_array_sized_new(FALSE
, TRUE
,
2139 sizeof(off_t
), SEQUENCE_AVG_ELEMENTS
);
2147 for(i
=0;i
<type
->fields
->len
;i
++) {
2148 LttField
*child
= &g_array_index(type
->fields
, LttField
, i
);
2149 field_compute_static_size(fac
, child
);
2150 if(child
->field_size
!= 0) {
2151 type
->size
+= ltt_align(type
->size
, get_alignment(child
),
2153 type
->size
+= child
->field_size
;
2155 /* As soon as we find a child with variable size, we have
2156 * a variable size */
2161 field
->field_size
= type
->size
;
2165 g_error("field_static_size : unknown type");
2172 /*****************************************************************************
2174 * precompute_fields_offsets : set the precomputable offset of the fields
2178 * offset : pointer to the current offset, must be incremented
2180 * return : 1 : found a variable length field, stop the processing.
2182 ****************************************************************************/
2185 gint
precompute_fields_offsets(LttFacility
*fac
, LttField
*field
, off_t
*offset
, gint is_compact
)
2187 LttType
*type
= &field
->field_type
;
2189 if(unlikely(is_compact
)) {
2190 g_assert(field
->field_size
!= 0);
2191 /* FIXME THIS IS A HUUUUUGE hack :
2192 * offset is between the compact_data field in struct LttEvent
2193 * and the address of the field root in the memory map.
2194 * ark. Both will stay at the same addresses while the event
2195 * is readable, so it's ok.
2197 field
->offset_root
= 0;
2198 field
->fixed_root
= FIELD_FIXED
;
2202 switch(type
->type_class
) {
2204 case LTT_UINT_FIXED
:
2219 g_assert(field
->field_size
!= 0);
2220 /* Align offset on type size */
2221 *offset
+= ltt_align(*offset
, get_alignment(field
),
2223 /* remember offset */
2224 field
->offset_root
= *offset
;
2225 field
->fixed_root
= FIELD_FIXED
;
2226 /* Increment offset */
2227 *offset
+= field
->field_size
;
2231 field
->offset_root
= *offset
;
2232 field
->fixed_root
= FIELD_FIXED
;
2236 g_assert(type
->fields
->len
== 1);
2238 LttField
*child
= &g_array_index(type
->fields
, LttField
, 0);
2240 *offset
+= ltt_align(*offset
, get_alignment(field
),
2243 /* remember offset */
2244 field
->offset_root
= *offset
;
2245 field
->array_offset
= *offset
;
2246 field
->fixed_root
= FIELD_FIXED
;
2248 /* Let the child be variable */
2249 //precompute_fields_offsets(tf, child, offset);
2251 if(field
->field_size
!= 0) {
2252 /* Increment offset */
2253 /* field_size is the array size in bytes */
2254 *offset
+= field
->field_size
;
2262 g_assert(type
->fields
->len
== 2);
2267 *offset
+= ltt_align(*offset
, get_alignment(field
),
2270 /* remember offset */
2271 field
->offset_root
= *offset
;
2272 field
->fixed_root
= FIELD_FIXED
;
2274 child
= &g_array_index(type
->fields
, LttField
, 0);
2275 ret
= precompute_fields_offsets(fac
, child
, offset
, is_compact
);
2276 g_assert(ret
== 0); /* Seq len cannot have variable len */
2278 child
= &g_array_index(type
->fields
, LttField
, 1);
2279 *offset
+= ltt_align(*offset
, get_alignment(child
),
2281 field
->array_offset
= *offset
;
2282 /* Let the child be variable. */
2283 //ret = precompute_fields_offsets(fac, child, offset);
2285 /* Cannot precompute fields offsets of sequence members, and has
2286 * variable length. */
2296 *offset
+= ltt_align(*offset
, get_alignment(field
),
2298 /* remember offset */
2299 field
->offset_root
= *offset
;
2300 field
->fixed_root
= FIELD_FIXED
;
2302 for(i
=0; i
< type
->fields
->len
; i
++) {
2303 child
= &g_array_index(type
->fields
, LttField
, i
);
2304 ret
= precompute_fields_offsets(fac
, child
, offset
, is_compact
);
2317 *offset
+= ltt_align(*offset
, get_alignment(field
),
2319 /* remember offset */
2320 field
->offset_root
= *offset
;
2321 field
->fixed_root
= FIELD_FIXED
;
2323 for(i
=0; i
< type
->fields
->len
; i
++) {
2324 *offset
= field
->offset_root
;
2325 child
= &g_array_index(type
->fields
, LttField
, i
);
2326 ret
= precompute_fields_offsets(fac
, child
, offset
, is_compact
);
2330 *offset
= field
->offset_root
+ field
->field_size
;
2337 g_error("precompute_fields_offsets : unknown type");
2346 /*****************************************************************************
2348 * precompute_offsets : set the precomputable offset of an event type
2351 * event : event type
2353 ****************************************************************************/
2354 void precompute_offsets(LttFacility
*fac
, LttEventType
*event
)
2360 /* First, compute the size of fixed size fields. Will determine size for
2361 * arrays, struct and unions, which is not done by the parser */
2362 for(i
=0; i
<event
->fields
->len
; i
++) {
2363 LttField
*field
= &g_array_index(event
->fields
, LttField
, i
);
2364 field_compute_static_size(fac
, field
);
2367 /* Precompute all known offsets */
2368 for(i
=0; i
<event
->fields
->len
; i
++) {
2369 LttField
*field
= &g_array_index(event
->fields
, LttField
, i
);
2370 if(event
->has_compact_data
&& i
== 0)
2371 ret
= precompute_fields_offsets(fac
, field
, &offset
, 1);
2373 ret
= precompute_fields_offsets(fac
, field
, &offset
, 0);
2381 /*****************************************************************************
2383 * preset_field_type_size : set the fixed sizes of the field type
2386 * event_type : event type
2387 * offset_root : offset from the root
2388 * offset_parent : offset from the parent
2389 * fixed_root : Do we know a fixed offset to the root ?
2390 * fixed_parent : Do we know a fixed offset to the parent ?
2392 ****************************************************************************/
2396 // preset the fixed size offsets. Calculate them just like genevent-new : an
2397 // increment of a *to value that represents the offset from the start of the
2399 // The preset information is : offsets up to (and including) the first element
2400 // of variable size. All subsequent fields must be flagged "VARIABLE OFFSET".
2402 void preset_field_type_size(LttTracefile
*tf
, LttEventType
*event_type
,
2403 off_t offset_root
, off_t offset_parent
,
2404 enum field_status
*fixed_root
, enum field_status
*fixed_parent
,
2407 enum field_status local_fixed_root
, local_fixed_parent
;
2411 g_assert(field
->fixed_root
== FIELD_UNKNOWN
);
2412 g_assert(field
->fixed_parent
== FIELD_UNKNOWN
);
2413 g_assert(field
->fixed_size
== FIELD_UNKNOWN
);
2415 type
= field
->field_type
;
2417 field
->fixed_root
= *fixed_root
;
2418 if(field
->fixed_root
== FIELD_FIXED
)
2419 field
->offset_root
= offset_root
;
2421 field
->offset_root
= 0;
2423 field
->fixed_parent
= *fixed_parent
;
2424 if(field
->fixed_parent
== FIELD_FIXED
)
2425 field
->offset_parent
= offset_parent
;
2427 field
->offset_parent
= 0;
2429 size_t current_root_offset
;
2430 size_t current_offset
;
2431 enum field_status current_child_status
, final_child_status
;
2434 switch(type
->type_class
) {
2436 case LTT_UINT_FIXED
:
2445 field
->field_size
= ltt_type_size(tf
->trace
, type
);
2446 field
->fixed_size
= FIELD_FIXED
;
2449 field
->field_size
= (off_t
)event_type
->facility
->pointer_size
;
2450 field
->fixed_size
= FIELD_FIXED
;
2454 field
->field_size
= (off_t
)event_type
->facility
->long_size
;
2455 field
->fixed_size
= FIELD_FIXED
;
2460 field
->field_size
= (off_t
)event_type
->facility
->size_t_size
;
2461 field
->fixed_size
= FIELD_FIXED
;
2464 local_fixed_root
= FIELD_VARIABLE
;
2465 local_fixed_parent
= FIELD_VARIABLE
;
2466 preset_field_type_size(tf
, event_type
,
2468 &local_fixed_root
, &local_fixed_parent
,
2470 field
->fixed_size
= FIELD_VARIABLE
;
2471 field
->field_size
= 0;
2472 *fixed_root
= FIELD_VARIABLE
;
2473 *fixed_parent
= FIELD_VARIABLE
;
2476 field
->fixed_size
= FIELD_VARIABLE
;
2477 field
->field_size
= 0;
2478 *fixed_root
= FIELD_VARIABLE
;
2479 *fixed_parent
= FIELD_VARIABLE
;
2482 local_fixed_root
= FIELD_VARIABLE
;
2483 local_fixed_parent
= FIELD_VARIABLE
;
2484 preset_field_type_size(tf
, event_type
,
2486 &local_fixed_root
, &local_fixed_parent
,
2488 field
->fixed_size
= field
->child
[0]->fixed_size
;
2489 if(field
->fixed_size
== FIELD_FIXED
) {
2490 field
->field_size
= type
->element_number
* field
->child
[0]->field_size
;
2492 field
->field_size
= 0;
2493 *fixed_root
= FIELD_VARIABLE
;
2494 *fixed_parent
= FIELD_VARIABLE
;
2498 current_root_offset
= field
->offset_root
;
2500 current_child_status
= FIELD_FIXED
;
2501 for(i
=0;i
<type
->element_number
;i
++) {
2502 preset_field_type_size(tf
, event_type
,
2503 current_root_offset
, current_offset
,
2504 fixed_root
, ¤t_child_status
,
2506 if(current_child_status
== FIELD_FIXED
) {
2507 current_root_offset
+= field
->child
[i
]->field_size
;
2508 current_offset
+= field
->child
[i
]->field_size
;
2510 current_root_offset
= 0;
2514 if(current_child_status
!= FIELD_FIXED
) {
2515 *fixed_parent
= current_child_status
;
2516 field
->field_size
= 0;
2517 field
->fixed_size
= current_child_status
;
2519 field
->field_size
= current_offset
;
2520 field
->fixed_size
= FIELD_FIXED
;
2524 current_root_offset
= field
->offset_root
;
2527 final_child_status
= FIELD_FIXED
;
2528 for(i
=0;i
<type
->element_number
;i
++) {
2529 enum field_status current_root_child_status
= FIELD_FIXED
;
2530 enum field_status current_child_status
= FIELD_FIXED
;
2531 preset_field_type_size(tf
, event_type
,
2532 current_root_offset
, current_offset
,
2533 ¤t_root_child_status
, ¤t_child_status
,
2535 if(current_child_status
!= FIELD_FIXED
)
2536 final_child_status
= current_child_status
;
2538 max_size
= max(max_size
, field
->child
[i
]->field_size
);
2540 if(final_child_status
!= FIELD_FIXED
) {
2541 g_error("LTTV does not support variable size fields in unions.");
2542 /* This will stop the application. */
2543 *fixed_root
= final_child_status
;
2544 *fixed_parent
= final_child_status
;
2545 field
->field_size
= 0;
2546 field
->fixed_size
= current_child_status
;
2548 field
->field_size
= max_size
;
2549 field
->fixed_size
= FIELD_FIXED
;
2553 g_error("unexpected type NONE");
2560 /*****************************************************************************
2562 * check_fields_compatibility : Check for compatibility between two fields :
2563 * do they use the same inner structure ?
2565 * event_type1 : event type
2566 * event_type2 : event type
2569 *Returns : 0 if identical
2571 ****************************************************************************/
2572 // this function checks for equality of field types. Therefore, it does not use
2573 // per se offsets. For instance, an aligned version of a structure is
2574 // compatible with an unaligned version of the same structure.
2576 gint
check_fields_compatibility(LttEventType
*event_type1
,
2577 LttEventType
*event_type2
,
2578 LttField
*field1
, LttField
*field2
)
2580 guint different
= 0;
2584 if(field1
== NULL
) {
2585 if(field2
== NULL
) goto end
;
2590 } else if(field2
== NULL
) {
2595 type1
= &field1
->field_type
;
2596 type2
= &field2
->field_type
;
2598 if(type1
->type_class
!= type2
->type_class
) {
2602 if(type1
->network
!= type2
->network
) {
2607 switch(type1
->type_class
) {
2609 case LTT_UINT_FIXED
:
2624 if(field1
->field_size
!= field2
->field_size
)
2631 LttField
*child1
= &g_array_index(type1
->fields
, LttField
, 0);
2632 LttField
*child2
= &g_array_index(type2
->fields
, LttField
, 0);
2634 if(type1
->size
!= type2
->size
)
2636 if(check_fields_compatibility(event_type1
, event_type2
, child1
, child2
))
2642 LttField
*child1
= &g_array_index(type1
->fields
, LttField
, 1);
2643 LttField
*child2
= &g_array_index(type2
->fields
, LttField
, 1);
2645 if(check_fields_compatibility(event_type1
, event_type2
, child1
, child2
))
2655 if(type1
->fields
->len
!= type2
->fields
->len
) {
2660 for(i
=0; i
< type1
->fields
->len
; i
++) {
2663 child1
= &g_array_index(type1
->fields
, LttField
, i
);
2664 child2
= &g_array_index(type2
->fields
, LttField
, i
);
2665 different
= check_fields_compatibility(event_type1
,
2666 event_type2
, child1
, child2
);
2668 if(different
) break;
2674 g_error("check_fields_compatibility : unknown type");
2683 gint
check_fields_compatibility(LttEventType
*event_type1
,
2684 LttEventType
*event_type2
,
2685 LttField
*field1
, LttField
*field2
)
2687 guint different
= 0;
2692 if(field1
== NULL
) {
2693 if(field2
== NULL
) goto end
;
2698 } else if(field2
== NULL
) {
2703 g_assert(field1
->fixed_root
!= FIELD_UNKNOWN
);
2704 g_assert(field2
->fixed_root
!= FIELD_UNKNOWN
);
2705 g_assert(field1
->fixed_parent
!= FIELD_UNKNOWN
);
2706 g_assert(field2
->fixed_parent
!= FIELD_UNKNOWN
);
2707 g_assert(field1
->fixed_size
!= FIELD_UNKNOWN
);
2708 g_assert(field2
->fixed_size
!= FIELD_UNKNOWN
);
2710 type1
= field1
->field_type
;
2711 type2
= field2
->field_type
;
2713 if(type1
->type_class
!= type2
->type_class
) {
2717 if(type1
->element_name
!= type2
->element_name
) {
2722 switch(type1
->type_class
) {
2724 case LTT_UINT_FIXED
:
2739 if(field1
->field_size
!= field2
->field_size
) {
2745 if(type1
->element_number
!= type2
->element_number
) {
2749 for(i
=0;i
<type1
->element_number
;i
++) {
2750 if(type1
->enum_strings
[i
] != type2
->enum_strings
[i
]) {
2757 /* Two elements : size and child */
2758 g_assert(type1
->element_number
!= type2
->element_number
);
2759 for(i
=0;i
<type1
->element_number
;i
++) {
2760 if(check_fields_compatibility(event_type1
, event_type2
,
2761 field1
->child
[0], field2
->child
[0])) {
2770 if(field1
->field_size
!= field2
->field_size
) {
2774 /* Two elements : size and child */
2775 g_assert(type1
->element_number
!= type2
->element_number
);
2776 for(i
=0;i
<type1
->element_number
;i
++) {
2777 if(check_fields_compatibility(event_type1
, event_type2
,
2778 field1
->child
[0], field2
->child
[0])) {
2786 if(type1
->element_number
!= type2
->element_number
) {
2790 for(i
=0;i
<type1
->element_number
;i
++) {
2791 if(check_fields_compatibility(event_type1
, event_type2
,
2792 field1
->child
[0], field2
->child
[0])) {
2805 /*****************************************************************************
2807 * ltt_get_int : get an integer number
2809 * reverse_byte_order: must we reverse the byte order ?
2810 * size : the size of the integer
2811 * ptr : the data pointer
2813 * gint64 : a 64 bits integer
2814 ****************************************************************************/
2816 gint64
ltt_get_int(gboolean reverse_byte_order
, gint size
, void *data
)
2821 case 1: val
= *((gint8
*)data
); break;
2822 case 2: val
= ltt_get_int16(reverse_byte_order
, data
); break;
2823 case 4: val
= ltt_get_int32(reverse_byte_order
, data
); break;
2824 case 8: val
= ltt_get_int64(reverse_byte_order
, data
); break;
2825 default: val
= ltt_get_int64(reverse_byte_order
, data
);
2826 g_critical("get_int : integer size %d unknown", size
);
2833 /*****************************************************************************
2835 * ltt_get_uint : get an unsigned integer number
2837 * reverse_byte_order: must we reverse the byte order ?
2838 * size : the size of the integer
2839 * ptr : the data pointer
2841 * guint64 : a 64 bits unsigned integer
2842 ****************************************************************************/
2844 guint64
ltt_get_uint(gboolean reverse_byte_order
, gint size
, void *data
)
2849 case 1: val
= *((gint8
*)data
); break;
2850 case 2: val
= ltt_get_uint16(reverse_byte_order
, data
); break;
2851 case 4: val
= ltt_get_uint32(reverse_byte_order
, data
); break;
2852 case 8: val
= ltt_get_uint64(reverse_byte_order
, data
); break;
2853 default: val
= ltt_get_uint64(reverse_byte_order
, data
);
2854 g_critical("get_uint : unsigned integer size %d unknown",
2863 /* get the node name of the system */
2865 char * ltt_trace_system_description_node_name (LttSystemDescription
* s
)
2867 return s
->node_name
;
2871 /* get the domain name of the system */
2873 char * ltt_trace_system_description_domain_name (LttSystemDescription
* s
)
2875 return s
->domain_name
;
2879 /* get the description of the system */
2881 char * ltt_trace_system_description_description (LttSystemDescription
* s
)
2883 return s
->description
;
2887 /* get the NTP corrected start time of the trace */
2888 LttTime
ltt_trace_start_time(LttTrace
*t
)
2890 return t
->start_time
;
2893 /* get the monotonic start time of the trace */
2894 LttTime
ltt_trace_start_time_monotonic(LttTrace
*t
)
2896 return t
->start_time_from_tsc
;
2899 LttTracefile
*ltt_tracefile_new()
2902 tf
= g_new(LttTracefile
, 1);
2903 tf
->event
.tracefile
= tf
;
2907 void ltt_tracefile_destroy(LttTracefile
*tf
)
2912 void ltt_tracefile_copy(LttTracefile
*dest
, const LttTracefile
*src
)
2917 /* Before library loading... */
2921 LTT_FACILITY_NAME_HEARTBEAT
= g_quark_from_string("heartbeat");
2922 LTT_EVENT_NAME_HEARTBEAT
= g_quark_from_string("heartbeat");
2923 LTT_EVENT_NAME_HEARTBEAT_FULL
= g_quark_from_string("heartbeat_full");
2925 LTT_TRACEFILE_NAME_FACILITIES
= g_quark_from_string("/control/facilities");