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 static int open_tracefiles(LttTrace
*trace
, gchar
*root_path
,
108 gchar
*relative_path
);
109 static int ltt_process_facility_tracefile(LttTracefile
*tf
);
110 static void ltt_tracefile_time_span_get(LttTracefile
*tf
,
111 LttTime
*start
, LttTime
*end
);
112 static void group_time_span_get(GQuark name
, gpointer data
, gpointer user_data
);
113 static gint
map_block(LttTracefile
* tf
, guint block_num
);
114 static void ltt_update_event_size(LttTracefile
*tf
);
116 /* Enable event debugging */
117 static int a_event_debug
= 0;
119 void ltt_event_debug(int state
)
121 a_event_debug
= state
;
126 * Return value : 0 success, 1 bad tracefile
128 static int parse_trace_header(void *header
, LttTracefile
*tf
, LttTrace
*t
)
130 guint32
*magic_number
= (guint32
*)header
;
131 struct ltt_trace_header_any
*any
= (struct ltt_trace_header_any
*)header
;
133 if(*magic_number
== LTT_MAGIC_NUMBER
)
135 else if(*magic_number
== LTT_REV_MAGIC_NUMBER
)
137 else /* invalid magic number, bad tracefile ! */
140 /* Get float byte order : might be different from int byte order
141 * (or is set to 0 if the trace has no float (kernel trace)) */
142 tf
->float_word_order
= any
->float_word_order
;
143 tf
->alignment
= any
->alignment
;
144 tf
->has_heartbeat
= any
->has_heartbeat
;
147 t
->arch_type
= ltt_get_uint32(LTT_GET_BO(tf
),
149 t
->arch_variant
= ltt_get_uint32(LTT_GET_BO(tf
),
151 t
->arch_size
= any
->arch_size
;
152 t
->ltt_major_version
= any
->major_version
;
153 t
->ltt_minor_version
= any
->minor_version
;
154 t
->flight_recorder
= any
->flight_recorder
;
155 // t->compact_facilities = NULL;
158 switch(any
->major_version
) {
161 g_warning("Unsupported trace version : %hhu.%hhu",
162 any
->major_version
, any
->minor_version
);
166 switch(any
->minor_version
) {
169 struct ltt_trace_header_1_0
*vheader
=
170 (struct ltt_trace_header_1_0
*)header
;
171 tf
->buffer_header_size
=
172 sizeof(struct ltt_block_start_header
)
173 + sizeof(struct ltt_trace_header_1_0
);
174 tf
->tsc_lsb_truncate
= vheader
->tsc_lsb_truncate
;
175 tf
->tscbits
= vheader
->tscbits
;
176 tf
->tsc_msb_cutoff
= 32 - tf
->tsc_lsb_truncate
- tf
->tscbits
;
177 tf
->compact_event_bits
= 32 - vheader
->compact_data_shift
;
178 tf
->tsc_mask
= ((1ULL << (tf
->tscbits
))-1);
179 tf
->tsc_mask
= tf
->tsc_mask
<< tf
->tsc_lsb_truncate
;
180 tf
->tsc_mask_next_bit
= (1ULL<<(tf
->tscbits
));
181 tf
->tsc_mask_next_bit
= tf
->tsc_mask_next_bit
<< tf
->tsc_lsb_truncate
;
183 t
->start_freq
= ltt_get_uint64(LTT_GET_BO(tf
),
184 &vheader
->start_freq
);
185 t
->freq_scale
= ltt_get_uint32(LTT_GET_BO(tf
),
186 &vheader
->freq_scale
);
188 t
->start_freq
= father_trace
->start_freq
;
189 t
->freq_scale
= father_trace
->freq_scale
;
194 t
->start_tsc
= ltt_get_uint64(LTT_GET_BO(tf
),
195 &vheader
->start_tsc
);
196 t
->start_monotonic
= ltt_get_uint64(LTT_GET_BO(tf
),
197 &vheader
->start_monotonic
);
198 t
->start_time
.tv_sec
= ltt_get_uint64(LTT_GET_BO(tf
),
199 &vheader
->start_time_sec
);
200 t
->start_time
.tv_nsec
= ltt_get_uint64(LTT_GET_BO(tf
),
201 &vheader
->start_time_usec
);
202 t
->start_time
.tv_nsec
*= 1000; /* microsec to nanosec */
204 t
->start_time_from_tsc
= ltt_time_from_uint64(
206 * (1000000000.0 / tf
->trace
->freq_scale
)
207 / (double)t
->start_freq
);
212 g_warning("Unsupported trace version : %hhu.%hhu",
213 any
->major_version
, any
->minor_version
);
218 g_warning("Unsupported trace version : %hhu.%hhu",
219 any
->major_version
, any
->minor_version
);
229 /*****************************************************************************
231 * ltt_tracefile_open : open a trace file, construct a LttTracefile
233 * t : the trace containing the tracefile
234 * fileName : path name of the trace file
235 * tf : the tracefile structure
237 * : 0 for success, -1 otherwise.
238 ****************************************************************************/
240 static gint
ltt_tracefile_open(LttTrace
*t
, gchar
* fileName
, LttTracefile
*tf
)
242 struct stat lTDFStat
; /* Trace data file status */
243 struct ltt_block_start_header
*header
;
244 int page_size
= getpagesize();
247 tf
->long_name
= g_quark_from_string(fileName
);
249 tf
->fd
= open(fileName
, O_RDONLY
);
251 g_warning("Unable to open input data file %s\n", fileName
);
255 // Get the file's status
256 if(fstat(tf
->fd
, &lTDFStat
) < 0){
257 g_warning("Unable to get the status of the input data file %s\n", fileName
);
261 // Is the file large enough to contain a trace
262 if(lTDFStat
.st_size
<
263 (off_t
)(sizeof(struct ltt_block_start_header
)
264 + sizeof(struct ltt_trace_header_any
))){
265 g_print("The input data file %s does not contain a trace\n", fileName
);
269 /* Temporarily map the buffer start header to get trace information */
270 /* Multiple of pages aligned head */
271 tf
->buffer
.head
= mmap(0,
272 PAGE_ALIGN(sizeof(struct ltt_block_start_header
)
273 + sizeof(struct ltt_trace_header_any
)), PROT_READ
,
274 MAP_PRIVATE
, tf
->fd
, 0);
275 if(tf
->buffer
.head
== MAP_FAILED
) {
276 perror("Error in allocating memory for buffer of tracefile");
279 g_assert( ( (gulong
)tf
->buffer
.head
&(8-1) ) == 0); // make sure it's aligned.
281 header
= (struct ltt_block_start_header
*)tf
->buffer
.head
;
283 if(parse_trace_header(header
->trace
, tf
, NULL
)) {
284 g_warning("parse_trace_header error");
288 //store the size of the file
289 tf
->file_size
= lTDFStat
.st_size
;
290 tf
->buf_size
= ltt_get_uint32(LTT_GET_BO(tf
), &header
->buf_size
);
291 tf
->num_blocks
= tf
->file_size
/ tf
->buf_size
;
293 if(munmap(tf
->buffer
.head
,
294 PAGE_ALIGN(sizeof(struct ltt_block_start_header
)
295 + sizeof(struct ltt_trace_header_any
)))) {
296 g_warning("unmap size : %u\n",
297 PAGE_ALIGN(sizeof(struct ltt_block_start_header
)
298 + sizeof(struct ltt_trace_header_any
)));
299 perror("munmap error");
302 tf
->buffer
.head
= NULL
;
304 //read the first block
305 if(map_block(tf
,0)) {
306 perror("Cannot map block for tracefile");
314 if(munmap(tf
->buffer
.head
,
315 PAGE_ALIGN(sizeof(struct ltt_block_start_header
)
316 + sizeof(struct ltt_trace_header_any
)))) {
317 g_warning("unmap size : %u\n",
318 PAGE_ALIGN(sizeof(struct ltt_block_start_header
)
319 + sizeof(struct ltt_trace_header_any
)));
320 perror("munmap error");
330 /*****************************************************************************
331 *Open control and per cpu tracefiles
332 ****************************************************************************/
334 void ltt_tracefile_open_cpu(LttTrace
*t
, gchar
* tracefile_name
)
337 tf
= ltt_tracefile_open(t
,tracefile_name
);
339 t
->per_cpu_tracefile_number
++;
340 g_ptr_array_add(t
->per_cpu_tracefiles
, tf
);
343 gint
ltt_tracefile_open_control(LttTrace
*t
, gchar
* control_name
)
352 tf
= ltt_tracefile_open(t
,control_name
);
354 g_warning("ltt_tracefile_open_control : bad file descriptor");
357 t
->control_tracefile_number
++;
358 g_ptr_array_add(t
->control_tracefiles
,tf
);
360 //parse facilities tracefile to get base_id
361 if(strcmp(&control_name
[strlen(control_name
)-10],"facilities") ==0){
363 if(!ltt_tracefile_read(tf
,&ev
)) return 0; // end of file
365 if(ev
.event_id
== TRACE_FACILITY_LOAD
){
367 fLoad
.name
= (gchar
*)pos
;
368 fLoad
.checksum
= *(LttChecksum
*)(pos
+ strlen(fLoad
.name
));
369 fLoad
.base_code
= *(guint32
*)(pos
+ strlen(fLoad
.name
) + sizeof(LttChecksum
));
371 for(i
=0;i
<t
->facility_number
;i
++){
372 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
,i
);
373 if(strcmp(f
->name
,fLoad
.name
)==0 && fLoad
.checksum
==f
->checksum
){
374 f
->base_id
= fLoad
.base_code
;
378 if(i
==t
->facility_number
) {
379 g_warning("Facility: %s, checksum: %u is not found",
380 fLoad
.name
,(unsigned int)fLoad
.checksum
);
383 }else if(ev
.event_id
== TRACE_BLOCK_START
){
385 }else if(ev
.event_id
== TRACE_BLOCK_END
){
388 g_warning("Not valid facilities trace file");
397 /*****************************************************************************
399 * ltt_tracefile_close: close a trace file,
401 * t : tracefile which will be closed
402 ****************************************************************************/
404 static void ltt_tracefile_close(LttTracefile
*t
)
406 int page_size
= getpagesize();
408 if(t
->buffer
.head
!= NULL
)
409 if(munmap(t
->buffer
.head
, PAGE_ALIGN(t
->buf_size
))) {
410 g_warning("unmap size : %u\n",
411 PAGE_ALIGN(t
->buf_size
));
412 perror("munmap error");
420 /*****************************************************************************
421 *Get system information
422 ****************************************************************************/
424 gint
getSystemInfo(LttSystemDescription
* des
, gchar
* pathname
)
431 GMarkupParseContext
* context
;
432 GError
* error
= NULL
;
433 GMarkupParser markup_parser
=
435 parser_start_element
,
438 NULL
, /* passthrough */
442 fd
= g_open(pathname
, O_RDONLY
, 0);
444 g_warning("Can not open file : %s\n", pathname
);
448 iochan
= g_io_channel_unix_new(fd
);
450 context
= g_markup_parse_context_new(&markup_parser
, 0, des
,NULL
);
452 //while(fgets(buf,DIR_NAME_SIZE, fp) != NULL){
453 while(g_io_channel_read_line(iochan
, &buf
, &length
, NULL
, &error
)
454 != G_IO_STATUS_EOF
) {
457 g_warning("Can not read xml file: \n%s\n", error
->message
);
460 if(!g_markup_parse_context_parse(context
, buf
, length
, &error
)){
462 g_warning("Can not parse xml file: \n%s\n", error
->message
);
465 g_markup_parse_context_free(context
);
467 g_io_channel_shutdown(iochan
, FALSE
, &error
); /* No flush */
469 g_warning("Can not close file: \n%s\n", error
->message
);
477 g_markup_parse_context_free(context
);
479 g_io_channel_shutdown(iochan
, FALSE
, &error
); /* No flush */
481 g_warning("Can not close file: \n%s\n", error
->message
);
492 /*****************************************************************************
493 *The following functions get facility/tracefile information
494 ****************************************************************************/
496 gint
getFacilityInfo(LttTrace
*t
, gchar
* eventdefs
)
503 gchar fullname
[DIR_NAME_SIZE
];
504 GError
* error
= NULL
;
506 dir
= g_dir_open(eventdefs
, 0, &error
);
509 g_warning("Can not open directory: %s, %s\n", eventdefs
, error
->message
);
514 while((name
= g_dir_read_name(dir
)) != NULL
){
515 if(!g_pattern_match_simple("*.xml", name
)) continue;
516 strcpy(fullname
,eventdefs
);
517 strcat(fullname
,name
);
518 ltt_facility_open(t
,fullname
);
522 for(j
=0;j
<t
->facility_number
;j
++){
523 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
, j
);
524 for(i
=0; i
<f
->event_number
; i
++){
526 setFieldsOffset(NULL
, et
, NULL
, t
);
533 /*****************************************************************************
534 *A trace is specified as a pathname to the directory containing all the
535 *associated data (control tracefiles, per cpu tracefiles, event
538 *When a trace is closed, all the associated facilities, types and fields
539 *are released as well.
543 /****************************************************************************
544 * get_absolute_pathname
546 * return the unique pathname in the system
548 * MD : Fixed this function so it uses realpath, dealing well with
549 * forgotten cases (.. were not used correctly before).
551 ****************************************************************************/
552 void get_absolute_pathname(const gchar
*pathname
, gchar
* abs_pathname
)
554 abs_pathname
[0] = '\0';
556 if ( realpath (pathname
, abs_pathname
) != NULL
)
560 /* error, return the original path unmodified */
561 strcpy(abs_pathname
, pathname
);
567 /* Search for something like : .*_.*
569 * The left side is the name, the right side is the number.
572 static int get_tracefile_name_number(gchar
*raw_name
,
579 guint raw_name_len
= strlen(raw_name
);
580 gchar char_name
[PATH_MAX
];
587 for(i
=raw_name_len
-1;i
>=0;i
--) {
588 if(raw_name
[i
] == '_') break;
590 if(i
==-1) { /* Either not found or name length is 0 */
591 /* This is a userspace tracefile */
592 strncpy(char_name
, raw_name
, raw_name_len
);
593 char_name
[raw_name_len
] = '\0';
594 *name
= g_quark_from_string(char_name
);
595 *num
= 0; /* unknown cpu */
596 for(i
=0;i
<raw_name_len
;i
++) {
597 if(raw_name
[i
] == '/') {
602 for(;i
<raw_name_len
;i
++) {
603 if(raw_name
[i
] == '/') {
608 for(;i
<raw_name_len
;i
++) {
609 if(raw_name
[i
] == '-') {
613 if(i
== raw_name_len
) return -1;
615 tmpptr
= &raw_name
[i
];
616 for(;i
<raw_name_len
;i
++) {
617 if(raw_name
[i
] == '.') {
622 *tid
= strtoul(tmpptr
, &endptr
, 10);
624 return -1; /* No digit */
625 if(*tid
== ULONG_MAX
)
626 return -1; /* underflow / overflow */
628 tmpptr
= &raw_name
[i
];
629 for(;i
<raw_name_len
;i
++) {
630 if(raw_name
[i
] == '.') {
635 *pgid
= strtoul(tmpptr
, &endptr
, 10);
637 return -1; /* No digit */
638 if(*pgid
== ULONG_MAX
)
639 return -1; /* underflow / overflow */
641 tmpptr
= &raw_name
[i
];
642 *creation
= strtoull(tmpptr
, &endptr
, 10);
644 return -1; /* No digit */
645 if(*creation
== G_MAXUINT64
)
646 return -1; /* underflow / overflow */
650 cpu_num
= strtol(raw_name
+underscore_pos
+1, &endptr
, 10);
652 if(endptr
== raw_name
+underscore_pos
+1)
653 return -1; /* No digit */
654 if(cpu_num
== LONG_MIN
|| cpu_num
== LONG_MAX
)
655 return -1; /* underflow / overflow */
657 strncpy(char_name
, raw_name
, underscore_pos
);
658 char_name
[underscore_pos
] = '\0';
660 *name
= g_quark_from_string(char_name
);
669 GData
**ltt_trace_get_tracefiles_groups(LttTrace
*trace
)
671 return &trace
->tracefiles
;
675 void compute_tracefile_group(GQuark key_id
,
677 struct compute_tracefile_group_args
*args
)
682 for(i
=0; i
<group
->len
; i
++) {
683 tf
= &g_array_index (group
, LttTracefile
, i
);
685 args
->func(tf
, args
->func_args
);
690 static void ltt_tracefile_group_destroy(gpointer data
)
692 GArray
*group
= (GArray
*)data
;
696 for(i
=0; i
<group
->len
; i
++) {
697 tf
= &g_array_index (group
, LttTracefile
, i
);
699 ltt_tracefile_close(tf
);
701 g_array_free(group
, TRUE
);
704 static gboolean
ltt_tracefile_group_has_cpu_online(gpointer data
)
706 GArray
*group
= (GArray
*)data
;
710 for(i
=0; i
<group
->len
; i
++) {
711 tf
= &g_array_index (group
, LttTracefile
, i
);
719 /* Open each tracefile under a specific directory. Put them in a
720 * GData : permits to access them using their tracefile group pathname.
721 * i.e. access control/modules tracefile group by index :
724 * relative path is the path relative to the trace root
725 * root path is the full path
727 * A tracefile group is simply an array where all the per cpu tracefiles sit.
730 static int open_tracefiles(LttTrace
*trace
, gchar
*root_path
, gchar
*relative_path
)
732 DIR *dir
= opendir(root_path
);
733 struct dirent
*entry
;
734 struct stat stat_buf
;
737 gchar path
[PATH_MAX
];
742 gchar rel_path
[PATH_MAX
];
751 strncpy(path
, root_path
, PATH_MAX
-1);
752 path_len
= strlen(path
);
753 path
[path_len
] = '/';
755 path_ptr
= path
+ path_len
;
757 strncpy(rel_path
, relative_path
, PATH_MAX
-1);
758 rel_path_len
= strlen(rel_path
);
759 rel_path
[rel_path_len
] = '/';
761 rel_path_ptr
= rel_path
+ rel_path_len
;
763 while((entry
= readdir(dir
)) != NULL
) {
765 if(entry
->d_name
[0] == '.') continue;
767 strncpy(path_ptr
, entry
->d_name
, PATH_MAX
- path_len
);
768 strncpy(rel_path_ptr
, entry
->d_name
, PATH_MAX
- rel_path_len
);
770 ret
= stat(path
, &stat_buf
);
776 g_debug("Tracefile file or directory : %s\n", path
);
778 // if(strcmp(rel_path, "/eventdefs") == 0) continue;
780 if(S_ISDIR(stat_buf
.st_mode
)) {
782 g_debug("Entering subdirectory...\n");
783 ret
= open_tracefiles(trace
, path
, rel_path
);
784 if(ret
< 0) continue;
785 } else if(S_ISREG(stat_buf
.st_mode
)) {
794 if(get_tracefile_name_number(rel_path
, &name
, &num
, &tid
, &pgid
, &creation
))
795 continue; /* invalid name */
797 g_debug("Opening file.\n");
798 if(ltt_tracefile_open(trace
, path
, &tmp_tf
)) {
799 g_info("Error opening tracefile %s", path
);
801 continue; /* error opening the tracefile : bad magic number ? */
804 g_debug("Tracefile name is %s and number is %u",
805 g_quark_to_string(name
), num
);
807 tmp_tf
.cpu_online
= 1;
808 tmp_tf
.cpu_num
= num
;
812 tmp_tf
.creation
= creation
;
813 if(tmp_tf
.name
== g_quark_from_string("/compact")
814 || tmp_tf
.name
== g_quark_from_string("/flight-compact"))
818 group
= g_datalist_id_get_data(&trace
->tracefiles
, name
);
820 /* Elements are automatically cleared when the array is allocated.
821 * It makes the cpu_online variable set to 0 : cpu offline, by default.
823 group
= g_array_sized_new (FALSE
, TRUE
, sizeof(LttTracefile
), 10);
824 g_datalist_id_set_data_full(&trace
->tracefiles
, name
,
825 group
, ltt_tracefile_group_destroy
);
828 /* Add the per cpu tracefile to the named group */
829 unsigned int old_len
= group
->len
;
831 group
= g_array_set_size(group
, num
+1);
832 g_array_index (group
, LttTracefile
, num
) = tmp_tf
;
833 g_array_index (group
, LttTracefile
, num
).event
.tracefile
=
834 &g_array_index (group
, LttTracefile
, num
);
844 /* Presumes the tracefile is already seeked at the beginning. It makes sense,
845 * because it must be done just after the opening */
846 static int ltt_process_facility_tracefile(LttTracefile
*tf
)
855 err
= ltt_tracefile_read_seek(tf
);
856 if(err
== EPERM
) goto seek_error
;
857 else if(err
== ERANGE
) break; /* End of tracefile */
859 err
= ltt_tracefile_read_update_event(tf
);
860 if(err
) goto update_error
;
862 /* We are on a facility load/or facility unload/ or heartbeat event */
864 * * facility 0 is hardcoded : this is the core facility. It will be shown
865 * in the facility array though, and is shown as "loaded builtin" in the
867 * It contains event :
869 * 1 : facility unload
870 * 2 : state dump facility load
873 if(tf
->event
.event_id
>= MARKER_CORE_IDS
) {
874 /* Should only contain core facility */
875 g_warning("Error in processing facility file %s, "
876 "should not contain event id %u.", g_quark_to_string(tf
->name
),
883 const char *marker_name
, *format
;
885 guint8 int_size
, long_size
, pointer_size
, size_t_size
, alignment
;
888 switch((enum marker_id
)tf
->event
.event_id
) {
889 case MARKER_ID_SET_MARKER_ID
:
890 marker_name
= pos
= tf
->event
.data
;
891 g_debug("Doing MARKER_ID_SET_MARKER_ID of marker %s", marker_name
);
892 pos
+= strlen(marker_name
) + 1;
893 //remove genevent compatibility
894 //pos += ltt_align((size_t)pos, tf->trace->arch_size, tf->alignment);
895 pos
+= ltt_align((size_t)pos
, sizeof(uint16_t), tf
->alignment
);
896 id
= ltt_get_uint16(LTT_GET_BO(tf
), pos
);
897 g_debug("In MARKER_ID_SET_MARKER_ID of marker %s id %hu",
899 pos
+= sizeof(guint16
);
900 int_size
= *(guint8
*)pos
;
901 pos
+= sizeof(guint8
);
902 long_size
= *(guint8
*)pos
;
903 pos
+= sizeof(guint8
);
904 pointer_size
= *(guint8
*)pos
;
905 pos
+= sizeof(guint8
);
906 size_t_size
= *(guint8
*)pos
;
907 pos
+= sizeof(guint8
);
908 alignment
= *(guint8
*)pos
;
909 pos
+= sizeof(guint8
);
910 marker_id_event(tf
->trace
, g_quark_from_string(marker_name
),
911 id
, int_size
, long_size
,
912 pointer_size
, size_t_size
, alignment
);
914 case MARKER_ID_SET_MARKER_FORMAT
:
915 marker_name
= pos
= tf
->event
.data
;
916 g_debug("Doing MARKER_ID_SET_MARKER_FORMAT of marker %s",
918 pos
+= strlen(marker_name
) + 1;
920 //pos += ltt_align((size_t)pos, tf->trace->arch_size, tf->alignment);
922 pos
+= strlen(format
) + 1;
924 //pos += ltt_align((size_t)pos, tf->trace->arch_size, tf->alignment);
925 marker_format_event(tf
->trace
, g_quark_from_string(marker_name
),
927 /* get information from dictionnary TODO */
929 case MARKER_ID_HEARTBEAT_32
:
930 case MARKER_ID_HEARTBEAT_64
:
933 g_warning("Error in processing facility file %s, "
934 "unknown event id %hhu.",
935 g_quark_to_string(tf
->name
),
948 g_warning("An error occured in facility tracefile parsing");
953 * Open a trace and return its LttTrace handle.
955 * pathname must be the directory of the trace
958 LttTrace
*ltt_trace_open(const gchar
*pathname
)
960 gchar abs_path
[PATH_MAX
];
965 struct ltt_block_start_header
*header
;
967 struct dirent
*entry
;
968 guint control_found
= 0;
969 struct stat stat_buf
;
970 gchar path
[PATH_MAX
];
972 t
= g_new(LttTrace
, 1);
973 if(!t
) goto alloc_error
;
975 get_absolute_pathname(pathname
, abs_path
);
976 t
->pathname
= g_quark_from_string(abs_path
);
978 g_datalist_init(&t
->tracefiles
);
980 /* Test to see if it looks like a trace */
981 dir
= opendir(abs_path
);
986 while((entry
= readdir(dir
)) != NULL
) {
987 strcpy(path
, abs_path
);
989 strcat(path
, entry
->d_name
);
990 ret
= stat(path
, &stat_buf
);
995 if(S_ISDIR(stat_buf
.st_mode
)) {
996 if(strcmp(entry
->d_name
, "control") == 0) {
1003 if(!control_found
) goto find_error
;
1005 /* Open all the tracefiles */
1006 if(open_tracefiles(t
, abs_path
, "")) {
1007 g_warning("Error opening tracefile %s", abs_path
);
1011 /* Parse each trace control/facilitiesN files : get runtime fac. info */
1012 group
= g_datalist_id_get_data(&t
->tracefiles
, LTT_TRACEFILE_NAME_FACILITIES
);
1014 g_error("Trace %s has no facility tracefile", abs_path
);
1016 goto facilities_error
;
1019 /* Get the trace information for the control/facility 0 tracefile */
1020 g_assert(group
->len
> 0);
1021 tf
= &g_array_index (group
, LttTracefile
, 0);
1022 header
= (struct ltt_block_start_header
*)tf
->buffer
.head
;
1023 g_assert(parse_trace_header(header
->trace
,
1026 t
->num_cpu
= group
->len
;
1028 ret
= allocate_marker_data(t
);
1030 g_error("Error in allocating marker data");
1032 for(i
=0; i
<group
->len
; i
++) {
1033 tf
= &g_array_index (group
, LttTracefile
, i
);
1034 if(ltt_process_facility_tracefile(tf
))
1035 goto facilities_error
;
1040 /* Error handling */
1042 destroy_marker_data(t
);
1044 g_datalist_clear(&t
->tracefiles
);
1052 /* Open another, completely independant, instance of a trace.
1054 * A read on this new instance will read the first event of the trace.
1056 * When we copy a trace, we want all the opening actions to happen again :
1057 * the trace will be reopened and totally independant from the original.
1058 * That's why we call ltt_trace_open.
1060 LttTrace
*ltt_trace_copy(LttTrace
*self
)
1062 return ltt_trace_open(g_quark_to_string(self
->pathname
));
1069 void ltt_trace_close(LttTrace
*t
)
1071 g_datalist_clear(&t
->tracefiles
);
1076 /*****************************************************************************
1077 * Get the start time and end time of the trace
1078 ****************************************************************************/
1080 void ltt_tracefile_time_span_get(LttTracefile
*tf
,
1081 LttTime
*start
, LttTime
*end
)
1085 err
= map_block(tf
, 0);
1087 g_error("Can not map block");
1088 *start
= ltt_time_infinite
;
1090 *start
= tf
->buffer
.begin
.timestamp
;
1092 err
= map_block(tf
, tf
->num_blocks
- 1); /* Last block */
1094 g_error("Can not map block");
1095 *end
= ltt_time_zero
;
1097 *end
= tf
->buffer
.end
.timestamp
;
1100 struct tracefile_time_span_get_args
{
1106 static void group_time_span_get(GQuark name
, gpointer data
, gpointer user_data
)
1108 struct tracefile_time_span_get_args
*args
=
1109 (struct tracefile_time_span_get_args
*)user_data
;
1111 GArray
*group
= (GArray
*)data
;
1117 for(i
=0; i
<group
->len
; i
++) {
1118 tf
= &g_array_index (group
, LttTracefile
, i
);
1119 if(tf
->cpu_online
) {
1120 ltt_tracefile_time_span_get(tf
, &tmp_start
, &tmp_end
);
1121 if(ltt_time_compare(*args
->start
, tmp_start
)>0) *args
->start
= tmp_start
;
1122 if(ltt_time_compare(*args
->end
, tmp_end
)<0) *args
->end
= tmp_end
;
1127 /* return the start and end time of a trace */
1129 void ltt_trace_time_span_get(LttTrace
*t
, LttTime
*start
, LttTime
*end
)
1131 LttTime min_start
= ltt_time_infinite
;
1132 LttTime max_end
= ltt_time_zero
;
1133 struct tracefile_time_span_get_args args
= { t
, &min_start
, &max_end
};
1135 g_datalist_foreach(&t
->tracefiles
, &group_time_span_get
, &args
);
1137 if(start
!= NULL
) *start
= min_start
;
1138 if(end
!= NULL
) *end
= max_end
;
1143 /* Seek to the first event in a tracefile that has a time equal or greater than
1144 * the time passed in parameter.
1146 * If the time parameter is outside the tracefile time span, seek to the first
1147 * event or if after, return ERANGE.
1149 * If the time parameter is before the first event, we have to seek specially to
1152 * If the time is after the end of the trace, return ERANGE.
1154 * Do a binary search to find the right block, then a sequential search in the
1155 * block to find the event.
1157 * In the special case where the time requested fits inside a block that has no
1158 * event corresponding to the requested time, the first event of the next block
1161 * IMPORTANT NOTE : // FIXME everywhere...
1163 * You MUST NOT do a ltt_tracefile_read right after a ltt_tracefile_seek_time :
1164 * you will jump over an event if you do.
1166 * Return value : 0 : no error, the tf->event can be used
1167 * ERANGE : time if after the last event of the trace
1168 * otherwise : this is an error.
1172 int ltt_tracefile_seek_time(LttTracefile
*tf
, LttTime time
)
1176 unsigned int block_num
, high
, low
;
1178 /* seek at the beginning of trace */
1179 err
= map_block(tf
, 0); /* First block */
1181 g_error("Can not map block");
1185 /* If the time is lower or equal the beginning of the trace,
1186 * go to the first event. */
1187 if(ltt_time_compare(time
, tf
->buffer
.begin
.timestamp
) <= 0) {
1188 ret
= ltt_tracefile_read(tf
);
1189 if(ret
== ERANGE
) goto range
;
1190 else if (ret
) goto fail
;
1191 goto found
; /* There is either no event in the trace or the event points
1192 to the first event in the trace */
1195 err
= map_block(tf
, tf
->num_blocks
- 1); /* Last block */
1197 g_error("Can not map block");
1201 /* If the time is after the end of the trace, return ERANGE. */
1202 if(ltt_time_compare(time
, tf
->buffer
.end
.timestamp
) > 0) {
1206 /* Binary search the block */
1207 high
= tf
->num_blocks
- 1;
1211 block_num
= ((high
-low
) / 2) + low
;
1213 err
= map_block(tf
, block_num
);
1215 g_error("Can not map block");
1219 /* We cannot divide anymore : this is what would happen if the time
1220 * requested was exactly between two consecutive buffers'end and start
1221 * timestamps. This is also what would happend if we didn't deal with out
1222 * of span cases prior in this function. */
1223 /* The event is right in the buffer!
1224 * (or in the next buffer first event) */
1226 ret
= ltt_tracefile_read(tf
);
1227 if(ret
== ERANGE
) goto range
; /* ERANGE or EPERM */
1228 else if(ret
) goto fail
;
1230 if(ltt_time_compare(time
, tf
->event
.event_time
) <= 0)
1234 } else if(ltt_time_compare(time
, tf
->buffer
.begin
.timestamp
) < 0) {
1235 /* go to lower part */
1236 high
= block_num
- 1;
1237 } else if(ltt_time_compare(time
, tf
->buffer
.end
.timestamp
) > 0) {
1238 /* go to higher part */
1239 low
= block_num
+ 1;
1240 } else {/* The event is right in the buffer!
1241 (or in the next buffer first event) */
1243 ret
= ltt_tracefile_read(tf
);
1244 if(ret
== ERANGE
) goto range
; /* ERANGE or EPERM */
1245 else if(ret
) goto fail
;
1247 if(ltt_time_compare(time
, tf
->event
.event_time
) <= 0)
1259 /* Error handling */
1261 g_error("ltt_tracefile_seek_time failed on tracefile %s",
1262 g_quark_to_string(tf
->name
));
1266 /* Seek to a position indicated by an LttEventPosition
1269 int ltt_tracefile_seek_position(LttTracefile
*tf
, const LttEventPosition
*ep
)
1273 if(ep
->tracefile
!= tf
) {
1277 err
= map_block(tf
, ep
->block
);
1279 g_error("Can not map block");
1283 tf
->event
.offset
= ep
->offset
;
1285 /* Put back the event real tsc */
1286 tf
->event
.tsc
= ep
->tsc
;
1287 tf
->buffer
.tsc
= ep
->tsc
;
1289 err
= ltt_tracefile_read_update_event(tf
);
1292 /* deactivate this, as it does nothing for now
1293 err = ltt_tracefile_read_op(tf);
1300 g_error("ltt_tracefile_seek_time failed on tracefile %s",
1301 g_quark_to_string(tf
->name
));
1305 /* Given a TSC value, return the LttTime (seconds,nanoseconds) it
1309 LttTime
ltt_interpolate_time_from_tsc(LttTracefile
*tf
, guint64 tsc
)
1313 if(tsc
> tf
->trace
->start_tsc
) {
1314 time
= ltt_time_from_uint64(
1315 (double)(tsc
- tf
->trace
->start_tsc
)
1316 * (1000000000.0 / tf
->trace
->freq_scale
)
1317 / (double)tf
->trace
->start_freq
);
1318 time
= ltt_time_add(tf
->trace
->start_time_from_tsc
, time
);
1320 time
= ltt_time_from_uint64(
1321 (double)(tf
->trace
->start_tsc
- tsc
)
1322 * (1000000000.0 / tf
->trace
->freq_scale
)
1323 / (double)tf
->trace
->start_freq
);
1324 time
= ltt_time_sub(tf
->trace
->start_time_from_tsc
, time
);
1329 /* Calculate the real event time based on the buffer boundaries */
1330 LttTime
ltt_interpolate_time(LttTracefile
*tf
, LttEvent
*event
)
1332 return ltt_interpolate_time_from_tsc(tf
, tf
->buffer
.tsc
);
1336 /* Get the current event of the tracefile : valid until the next read */
1337 LttEvent
*ltt_tracefile_get_event(LttTracefile
*tf
)
1344 /*****************************************************************************
1346 * ltt_tracefile_read : Read the next event in the tracefile
1351 * Returns 0 if an event can be used in tf->event.
1352 * Returns ERANGE on end of trace. The event in tf->event still can be used
1353 * (if the last block was not empty).
1354 * Returns EPERM on error.
1356 * This function does make the tracefile event structure point to the event
1357 * currently pointed to by the tf->event.
1359 * Note : you must call a ltt_tracefile_seek to the beginning of the trace to
1360 * reinitialize it after an error if you want results to be coherent.
1361 * It would be the case if a end of trace last buffer has no event : the end
1362 * of trace wouldn't be returned, but an error.
1363 * We make the assumption there is at least one event per buffer.
1364 ****************************************************************************/
1366 int ltt_tracefile_read(LttTracefile
*tf
)
1370 err
= ltt_tracefile_read_seek(tf
);
1372 err
= ltt_tracefile_read_update_event(tf
);
1375 /* deactivate this, as it does nothing for now
1376 err = ltt_tracefile_read_op(tf);
1383 int ltt_tracefile_read_seek(LttTracefile
*tf
)
1387 /* Get next buffer until we finally have an event, or end of trace */
1389 err
= ltt_seek_next_event(tf
);
1390 if(unlikely(err
== ENOPROTOOPT
)) {
1394 /* Are we at the end of the buffer ? */
1396 if(unlikely(tf
->buffer
.index
== tf
->num_blocks
-1)){ /* end of trace ? */
1399 /* get next block */
1400 err
= map_block(tf
, tf
->buffer
.index
+ 1);
1402 g_error("Can not map block");
1406 } else break; /* We found an event ! */
1412 /* do an operation when reading a new event */
1414 /* This function does nothing for now */
1416 int ltt_tracefile_read_op(LttTracefile
*tf
)
1422 /* do event specific operation */
1430 static void print_debug_event_header(LttEvent
*ev
, void *start_pos
, void *end_pos
)
1432 unsigned int offset
= 0;
1435 g_printf("Event header (tracefile %s offset %llx):\n",
1436 g_quark_to_string(ev
->tracefile
->long_name
),
1437 ((uint64_t)ev
->tracefile
->buffer
.index
* ev
->tracefile
->buf_size
)
1438 + (long)start_pos
- (long)ev
->tracefile
->buffer
.head
);
1440 while (offset
< (long)end_pos
- (long)start_pos
) {
1441 g_printf("%8lx", (long)start_pos
- (long)ev
->tracefile
->buffer
.head
+ offset
);
1444 for (i
= 0; i
< 4 ; i
++) {
1445 for (j
= 0; j
< 4; j
++) {
1446 if (offset
+ ((i
* 4) + j
) <
1447 (long)end_pos
- (long)start_pos
)
1449 ((char*)start_pos
)[offset
+ ((i
* 4) + j
)]);
1463 /* same as ltt_tracefile_read, but does not seek to the next event nor call
1464 * event specific operation. */
1465 int ltt_tracefile_read_update_event(LttTracefile
*tf
)
1472 pos
= tf
->buffer
.head
+ event
->offset
;
1474 /* Read event header */
1476 /* Align the head */
1478 pos
+= ltt_align((size_t)pos
, tf
->trace
->arch_size
, tf
->alignment
);
1480 g_assert(tf
->has_heartbeat
);
1481 pos
+= ltt_align((size_t)pos
, sizeof(uint32_t), tf
->alignment
);
1485 if(tf
->has_heartbeat
) {
1486 event
->timestamp
= ltt_get_uint32(LTT_GET_BO(tf
),
1489 /* 32 bits -> 64 bits tsc */
1490 /* note : still works for seek and non seek cases. */
1491 if(event
->timestamp
< (0xFFFFFFFFULL
&tf
->buffer
.tsc
)) {
1492 tf
->buffer
.tsc
= ((tf
->buffer
.tsc
&0xFFFFFFFF00000000ULL
)
1494 | (guint64
)event
->timestamp
;
1495 event
->tsc
= tf
->buffer
.tsc
;
1498 tf
->buffer
.tsc
= (tf
->buffer
.tsc
&0xFFFFFFFF00000000ULL
)
1499 | (guint64
)event
->timestamp
;
1500 event
->tsc
= tf
->buffer
.tsc
;
1501 event
->compact_data
= 0;
1504 /* Compact header */
1505 /* We keep the LSB of the previous timestamp, to make sure
1506 * we never go back */
1507 event
->event_id
= event
->timestamp
>> tf
->tscbits
;
1508 event
->event_id
= event
->event_id
& ((1 << tf
->compact_event_bits
) - 1);
1509 event
->compact_data
= event
->timestamp
>>
1510 (tf
->compact_event_bits
+ tf
->tscbits
);
1511 //printf("tsc bits %u, ev bits %u init data %u\n",
1512 // tf->tscbits, tf->trace->compact_event_bits, event->compact_data);
1513 /* Put the compact data back in original endianness */
1514 event
->compact_data
= ltt_get_uint32(LTT_GET_BO(tf
), &event
->compact_data
);
1515 event
->event_size
= 0xFFFF;
1516 //printf("Found compact event %d\n", event->event_id);
1517 //printf("Compact data %d\n", event->compact_data);
1518 event
->timestamp
= event
->timestamp
<< tf
->tsc_lsb_truncate
;
1519 event
->timestamp
= event
->timestamp
& tf
->tsc_mask
;
1520 //printf("timestamp 0x%lX\n", event->timestamp);
1521 //printf("mask 0x%llX\n", tf->tsc_mask);
1522 //printf("mask_next 0x%llX\n", tf->tsc_mask_next_bit);
1523 //printf("previous tsc 0x%llX\n", tf->buffer.tsc);
1524 //printf("previous tsc&mask 0x%llX\n", tf->tsc_mask&tf->buffer.tsc);
1525 //printf("previous tsc&(~mask) 0x%llX\n", tf->buffer.tsc&(~tf->tsc_mask));
1526 if(event
->timestamp
< (tf
->tsc_mask
&tf
->buffer
.tsc
)) {
1528 tf
->buffer
.tsc
= ((tf
->buffer
.tsc
&(~tf
->tsc_mask
))
1529 + tf
->tsc_mask_next_bit
)
1530 | (guint64
)event
->timestamp
;
1531 event
->tsc
= tf
->buffer
.tsc
;
1533 //printf("no wrap\n");
1535 tf
->buffer
.tsc
= (tf
->buffer
.tsc
&(~tf
->tsc_mask
))
1536 | (guint64
)event
->timestamp
;
1537 event
->tsc
= tf
->buffer
.tsc
;
1539 //printf("current tsc 0x%llX\n", tf->buffer.tsc);
1541 pos
+= sizeof(guint32
);
1543 event
->tsc
= ltt_get_uint64(LTT_GET_BO(tf
), pos
);
1544 tf
->buffer
.tsc
= event
->tsc
;
1545 event
->compact_data
= 0;
1546 pos
+= sizeof(guint64
);
1548 event
->event_time
= ltt_interpolate_time(tf
, event
);
1551 event
->event_id
= ltt_get_uint16(LTT_GET_BO(tf
), pos
);
1552 pos
+= sizeof(guint16
);
1554 event
->event_size
= ltt_get_uint16(LTT_GET_BO(tf
), pos
);
1555 pos
+= sizeof(guint16
);
1558 event
->event_size
= 0xFFFF;
1562 print_debug_event_header(event
, pos_aligned
, pos
);
1564 /* Align the head */
1566 pos
+= ltt_align((size_t)pos
, tf
->trace
->arch_size
, tf
->alignment
);
1570 /* get the data size and update the event fields with the current
1571 * information. Also update the time if a heartbeat_full event is found. */
1572 ltt_update_event_size(tf
);
1578 /****************************************************************************
1580 * map_block : map a block from the file
1582 * lttdes : ltt trace file
1583 * whichBlock : the block which will be read
1586 * EINVAL : lseek fail
1587 * EIO : can not read from the file
1588 ****************************************************************************/
1590 static gint
map_block(LttTracefile
* tf
, guint block_num
)
1592 int page_size
= getpagesize();
1593 struct ltt_block_start_header
*header
;
1595 g_assert(block_num
< tf
->num_blocks
);
1597 if(tf
->buffer
.head
!= NULL
) {
1598 if(munmap(tf
->buffer
.head
, PAGE_ALIGN(tf
->buf_size
))) {
1599 g_warning("unmap size : %u\n",
1600 PAGE_ALIGN(tf
->buf_size
));
1601 perror("munmap error");
1607 /* Multiple of pages aligned head */
1608 tf
->buffer
.head
= mmap(0,
1609 PAGE_ALIGN(tf
->buf_size
),
1610 PROT_READ
, MAP_PRIVATE
, tf
->fd
,
1611 PAGE_ALIGN((off_t
)tf
->buf_size
* (off_t
)block_num
));
1613 if(tf
->buffer
.head
== MAP_FAILED
) {
1614 perror("Error in allocating memory for buffer of tracefile");
1618 g_assert( ( (gulong
)tf
->buffer
.head
&(8-1) ) == 0); // make sure it's aligned.
1621 tf
->buffer
.index
= block_num
;
1623 header
= (struct ltt_block_start_header
*)tf
->buffer
.head
;
1626 tf
->buffer
.begin
.timestamp
= ltt_time_add(
1627 ltt_time_from_uint64(
1628 ltt_get_uint64(LTT_GET_BO(tf
),
1629 &header
->begin
.timestamp
)
1630 - tf
->trace
->start_monotonic
),
1631 tf
->trace
->start_time
);
1633 //g_debug("block %u begin : %lu.%lu", block_num,
1634 // tf->buffer.begin.timestamp.tv_sec, tf->buffer.begin.timestamp.tv_nsec);
1635 tf
->buffer
.begin
.cycle_count
= ltt_get_uint64(LTT_GET_BO(tf
),
1636 &header
->begin
.cycle_count
);
1637 tf
->buffer
.begin
.freq
= ltt_get_uint64(LTT_GET_BO(tf
),
1638 &header
->begin
.freq
);
1639 if(tf
->buffer
.begin
.freq
== 0)
1640 tf
->buffer
.begin
.freq
= tf
->trace
->start_freq
;
1642 tf
->buffer
.begin
.timestamp
= ltt_interpolate_time_from_tsc(tf
,
1643 tf
->buffer
.begin
.cycle_count
);
1646 ltt_time_from_uint64(
1647 (double)(tf
->buffer
.begin
.cycle_count
1648 - tf
->trace
->start_tsc
) * 1000000.0
1649 / (double)tf
->trace
->start_freq
),
1650 tf
->trace
->start_time_from_tsc
);
1654 tf
->buffer
.end
.timestamp
= ltt_time_add(
1655 ltt_time_from_uint64(
1656 ltt_get_uint64(LTT_GET_BO(tf
),
1657 &header
->end
.timestamp
)
1658 - tf
->trace
->start_monotonic
),
1659 tf
->trace
->start_time
);
1661 //g_debug("block %u end : %lu.%lu", block_num,
1662 // tf->buffer.end.timestamp.tv_sec, tf->buffer.end.timestamp.tv_nsec);
1663 tf
->buffer
.end
.cycle_count
= ltt_get_uint64(LTT_GET_BO(tf
),
1664 &header
->end
.cycle_count
);
1665 tf
->buffer
.end
.freq
= ltt_get_uint64(LTT_GET_BO(tf
),
1667 if(tf
->buffer
.end
.freq
== 0)
1668 tf
->buffer
.end
.freq
= tf
->trace
->start_freq
;
1670 tf
->buffer
.lost_size
= ltt_get_uint32(LTT_GET_BO(tf
),
1671 &header
->lost_size
);
1672 tf
->buffer
.end
.timestamp
= ltt_interpolate_time_from_tsc(tf
,
1673 tf
->buffer
.end
.cycle_count
);
1676 ltt_time_from_uint64(
1677 (double)(tf
->buffer
.end
.cycle_count
1678 - tf
->trace
->start_tsc
) * 1000000.0
1679 / (double)tf
->trace
->start_freq
),
1680 tf
->trace
->start_time_from_tsc
);
1682 tf
->buffer
.tsc
= tf
->buffer
.begin
.cycle_count
;
1683 tf
->event
.tsc
= tf
->buffer
.tsc
;
1684 tf
->buffer
.freq
= tf
->buffer
.begin
.freq
;
1687 * eventually support variable buffer size : will need a partial pre-read of
1688 * the headers to create an index when we open the trace... eventually. */
1689 g_assert(tf
->buf_size
== ltt_get_uint32(LTT_GET_BO(tf
),
1690 &header
->buf_size
));
1692 /* Now that the buffer is mapped, calculate the time interpolation for the
1695 // tf->buffer.nsecs_per_cycle = calc_nsecs_per_cycle(tf);
1696 //tf->buffer.cyc2ns_scale = calc_nsecs_per_cycle(tf);
1698 /* Make the current event point to the beginning of the buffer :
1699 * it means that the event read must get the first event. */
1700 tf
->event
.tracefile
= tf
;
1701 tf
->event
.block
= block_num
;
1702 tf
->event
.offset
= 0;
1711 static void print_debug_event_data(LttEvent
*ev
)
1713 unsigned int offset
= 0;
1716 if (!max(ev
->event_size
, ev
->data_size
))
1719 g_printf("Event data (tracefile %s offset %llx):\n",
1720 g_quark_to_string(ev
->tracefile
->long_name
),
1721 ((uint64_t)ev
->tracefile
->buffer
.index
* ev
->tracefile
->buf_size
)
1722 + (long)ev
->data
- (long)ev
->tracefile
->buffer
.head
);
1724 while (offset
< max(ev
->event_size
, ev
->data_size
)) {
1725 g_printf("%8lx", (long)ev
->data
+ offset
1726 - (long)ev
->tracefile
->buffer
.head
);
1729 for (i
= 0; i
< 4 ; i
++) {
1730 for (j
= 0; j
< 4; j
++) {
1731 if (offset
+ ((i
* 4) + j
) < max(ev
->event_size
, ev
->data_size
))
1732 g_printf("%02hhX", ((char*)ev
->data
)[offset
+ ((i
* 4) + j
)]);
1743 for (i
= 0; i
< 4; i
++) {
1744 for (j
= 0; j
< 4; j
++) {
1745 if (offset
+ ((i
* 4) + j
) < max(ev
->event_size
, ev
->data_size
)) {
1746 if (isprint(((char*)ev
->data
)[offset
+ ((i
* 4) + j
)]))
1747 g_printf("%c", ((char*)ev
->data
)[offset
+ ((i
* 4) + j
)]);
1759 /* It will update the fields offsets too */
1760 void ltt_update_event_size(LttTracefile
*tf
)
1764 struct marker_info
*info
;
1766 switch((enum marker_id
)tf
->event
.event_id
) {
1767 case MARKER_ID_SET_MARKER_ID
:
1768 size
= strlen((char*)tf
->event
.data
) + 1;
1769 g_debug("marker %s id set", (char*)tf
->event
.data
);
1770 size
+= ltt_align(size
, sizeof(guint16
), tf
->alignment
);
1771 size
+= sizeof(guint16
);
1772 size
+= sizeof(guint8
);
1773 size
+= sizeof(guint8
);
1774 size
+= sizeof(guint8
);
1775 size
+= sizeof(guint8
);
1776 size
+= sizeof(guint8
);
1778 case MARKER_ID_SET_MARKER_FORMAT
:
1779 g_debug("marker %s format set", (char*)tf
->event
.data
);
1780 size
= strlen((char*)tf
->event
.data
) + 1;
1781 size
+= strlen((char*)tf
->event
.data
+ size
) + 1;
1783 case MARKER_ID_HEARTBEAT_32
:
1784 g_debug("Update Event heartbeat 32 bits");
1786 case MARKER_ID_HEARTBEAT_64
:
1787 g_debug("Update Event heartbeat 64 bits");
1788 tscdata
= (char*)(tf
->event
.data
);
1789 tf
->event
.tsc
= ltt_get_uint64(LTT_GET_BO(tf
), tscdata
);
1790 tf
->buffer
.tsc
= tf
->event
.tsc
;
1791 tf
->event
.event_time
= ltt_interpolate_time(tf
, &tf
->event
);
1792 size
= ltt_align(size
, sizeof(guint64
), tf
->alignment
);
1793 size
+= sizeof(guint64
);
1797 info
= marker_get_info_from_id(tf
->trace
, tf
->event
.event_id
);
1799 if (tf
->event
.event_id
>= MARKER_CORE_IDS
)
1800 g_assert(info
!= NULL
);
1802 /* Do not update field offsets of core markers when initially reading the
1803 * facility tracefile when the infos about these markers do not exist yet.
1805 if (likely(info
&& info
->fields
)) {
1806 if (info
->size
!= -1)
1809 size
= marker_update_fields_offsets(marker_get_info_from_id(tf
->trace
,
1810 tf
->event
.event_id
), tf
->event
.data
);
1813 tf
->event
.data_size
= size
;
1815 /* Check consistency between kernel and LTTV structure sizes */
1816 if(tf
->event
.event_size
== 0xFFFF) {
1817 /* Event size too big to fit in the event size field */
1818 tf
->event
.event_size
= tf
->event
.data_size
;
1822 print_debug_event_data(&tf
->event
);
1824 /* Having a marker load or marker format event out of the facilities
1825 * tracefiles is a serious bug. */
1826 switch((enum marker_id
)tf
->event
.event_id
) {
1827 case MARKER_ID_SET_MARKER_ID
:
1828 case MARKER_ID_SET_MARKER_FORMAT
:
1829 if (tf
->name
!= g_quark_from_string("/control/facilities"))
1830 g_error("Trace inconsistency : metadata event found in data "
1831 "tracefile %s", g_quark_to_string(tf
->long_name
));
1834 if (tf
->event
.data_size
!= tf
->event
.event_size
) {
1835 struct marker_info
*info
= marker_get_info_from_id(tf
->trace
,
1836 tf
->event
.event_id
);
1837 g_error("Kernel/LTTV event size differs for event %s: kernel %u, LTTV %u",
1838 g_quark_to_string(info
->name
),
1839 tf
->event
.event_size
, tf
->event
.data_size
);
1845 /* Take the tf current event offset and use the event facility id and event id
1846 * to figure out where is the next event offset.
1848 * This is an internal function not aiming at being used elsewhere : it will
1849 * not jump over the current block limits. Please consider using
1850 * ltt_tracefile_read to do this.
1852 * Returns 0 on success
1853 * ERANGE if we are at the end of the buffer.
1854 * ENOPROTOOPT if an error occured when getting the current event size.
1856 static int ltt_seek_next_event(LttTracefile
*tf
)
1861 /* seek over the buffer header if we are at the buffer start */
1862 if(tf
->event
.offset
== 0) {
1863 tf
->event
.offset
+= tf
->buffer_header_size
;
1865 if(tf
->event
.offset
== tf
->buf_size
- tf
->buffer
.lost_size
) {
1872 pos
= tf
->event
.data
;
1874 if(tf
->event
.data_size
< 0) goto error
;
1876 pos
+= (size_t)tf
->event
.data_size
;
1878 tf
->event
.offset
= pos
- tf
->buffer
.head
;
1880 if(tf
->event
.offset
== tf
->buf_size
- tf
->buffer
.lost_size
) {
1884 g_assert(tf
->event
.offset
< tf
->buf_size
- tf
->buffer
.lost_size
);
1890 g_error("Error in ltt_seek_next_event for tracefile %s",
1891 g_quark_to_string(tf
->name
));
1896 /*****************************************************************************
1898 * calc_nsecs_per_cycle : calculate nsecs per cycle for current block
1900 * 1.0 / (freq(khz) *1000) * 1000000000
1903 ****************************************************************************/
1904 /* from timer_tsc.c */
1905 #define CYC2NS_SCALE_FACTOR 10
1906 static guint32
calc_nsecs_per_cycle(LttTracefile
* tf
)
1908 //return 1e6 / (double)tf->buffer.freq;
1909 guint32 cpu_mhz
= tf
->buffer
.freq
/ 1000;
1910 guint32 cyc2ns_scale
= (1000 << CYC2NS_SCALE_FACTOR
)/cpu_mhz
;
1912 return cyc2ns_scale
;
1913 // return 1e6 / (double)tf->buffer.freq;
1916 static guint64
cycles_2_ns(LttTracefile
*tf
, guint64 cycles
)
1918 return (cycles
* tf
->buffer
.cyc2ns_scale
) >> CYC2NS_SCALE_FACTOR
;
1923 void setFieldsOffset(LttTracefile
*tf
, LttEventType
*evT
,void *evD
)
1925 LttField
* rootFld
= evT
->root_field
;
1926 // rootFld->base_address = evD;
1929 rootFld
->field_size
= getFieldtypeSize(tf
, evT
->facility
,
1930 evT
, 0,0,rootFld
, evD
);
1934 /*****************************************************************************
1936 * set_fields_offsets : set the precomputable offset of the fields
1938 * tracefile : opened trace file
1939 * event_type : the event type
1940 ****************************************************************************/
1942 void set_fields_offsets(LttTracefile
*tf
, LttEventType
*event_type
)
1944 LttField
*field
= event_type
->root_field
;
1945 enum field_status fixed_root
= FIELD_FIXED
, fixed_parent
= FIELD_FIXED
;
1948 preset_field_type_size(tf
, event_type
, 0, 0,
1949 &fixed_root
, &fixed_parent
,
1956 /*****************************************************************************
1958 * get_alignment : Get the alignment needed for a field.
1962 * returns : The size on which it must be aligned.
1964 ****************************************************************************/
1966 off_t
get_alignment(LttField
*field
)
1968 LttType
*type
= &field
->field_type
;
1970 switch(type
->type_class
) {
1972 case LTT_UINT_FIXED
:
1987 /* Align offset on type size */
1988 g_assert(field
->field_size
!= 0);
1989 return field
->field_size
;
1995 g_assert(type
->fields
->len
== 1);
1997 LttField
*child
= &g_array_index(type
->fields
, LttField
, 0);
1998 return get_alignment(child
);
2002 g_assert(type
->fields
->len
== 2);
2005 LttField
*child
= &g_array_index(type
->fields
, LttField
, 0);
2007 localign
= max(localign
, get_alignment(child
));
2009 child
= &g_array_index(type
->fields
, LttField
, 1);
2010 localign
= max(localign
, get_alignment(child
));
2021 for(i
=0; i
<type
->fields
->len
; i
++) {
2022 LttField
*child
= &g_array_index(type
->fields
, LttField
, i
);
2023 localign
= max(localign
, get_alignment(child
));
2030 g_error("get_alignment : unknown type");
2037 /*****************************************************************************
2039 * field_compute_static_size : Determine the size of fields known by their
2040 * sole definition. Unions, arrays and struct sizes might be known, but
2041 * the parser does not give that information.
2046 ****************************************************************************/
2048 void field_compute_static_size(LttFacility
*fac
, LttField
*field
)
2050 LttType
*type
= &field
->field_type
;
2052 switch(type
->type_class
) {
2054 case LTT_UINT_FIXED
:
2073 /* note this : array type size is the number of elements in the array,
2074 * while array field size of the length of the array in bytes */
2075 g_assert(type
->fields
->len
== 1);
2077 LttField
*child
= &g_array_index(type
->fields
, LttField
, 0);
2078 field_compute_static_size(fac
, child
);
2080 if(child
->field_size
!= 0) {
2081 field
->field_size
= type
->size
* child
->field_size
;
2082 field
->dynamic_offsets
= g_array_sized_new(FALSE
, TRUE
,
2083 sizeof(off_t
), type
->size
);
2085 field
->field_size
= 0;
2090 g_assert(type
->fields
->len
== 2);
2092 off_t local_offset
= 0;
2093 LttField
*child
= &g_array_index(type
->fields
, LttField
, 1);
2094 field_compute_static_size(fac
, child
);
2095 field
->field_size
= 0;
2097 if(child
->field_size
!= 0) {
2098 field
->dynamic_offsets
= g_array_sized_new(FALSE
, TRUE
,
2099 sizeof(off_t
), SEQUENCE_AVG_ELEMENTS
);
2107 for(i
=0;i
<type
->fields
->len
;i
++) {
2108 LttField
*child
= &g_array_index(type
->fields
, LttField
, i
);
2109 field_compute_static_size(fac
, child
);
2110 if(child
->field_size
!= 0) {
2111 type
->size
+= ltt_align(type
->size
, get_alignment(child
),
2113 type
->size
+= child
->field_size
;
2115 /* As soon as we find a child with variable size, we have
2116 * a variable size */
2121 field
->field_size
= type
->size
;
2125 g_error("field_static_size : unknown type");
2132 /*****************************************************************************
2134 * precompute_fields_offsets : set the precomputable offset of the fields
2138 * offset : pointer to the current offset, must be incremented
2140 * return : 1 : found a variable length field, stop the processing.
2142 ****************************************************************************/
2145 gint
precompute_fields_offsets(LttFacility
*fac
, LttField
*field
, off_t
*offset
, gint is_compact
)
2147 LttType
*type
= &field
->field_type
;
2149 if(unlikely(is_compact
)) {
2150 g_assert(field
->field_size
!= 0);
2151 /* FIXME THIS IS A HUUUUUGE hack :
2152 * offset is between the compact_data field in struct LttEvent
2153 * and the address of the field root in the memory map.
2154 * ark. Both will stay at the same addresses while the event
2155 * is readable, so it's ok.
2157 field
->offset_root
= 0;
2158 field
->fixed_root
= FIELD_FIXED
;
2162 switch(type
->type_class
) {
2164 case LTT_UINT_FIXED
:
2179 g_assert(field
->field_size
!= 0);
2180 /* Align offset on type size */
2181 *offset
+= ltt_align(*offset
, get_alignment(field
),
2183 /* remember offset */
2184 field
->offset_root
= *offset
;
2185 field
->fixed_root
= FIELD_FIXED
;
2186 /* Increment offset */
2187 *offset
+= field
->field_size
;
2191 field
->offset_root
= *offset
;
2192 field
->fixed_root
= FIELD_FIXED
;
2196 g_assert(type
->fields
->len
== 1);
2198 LttField
*child
= &g_array_index(type
->fields
, LttField
, 0);
2200 *offset
+= ltt_align(*offset
, get_alignment(field
),
2203 /* remember offset */
2204 field
->offset_root
= *offset
;
2205 field
->array_offset
= *offset
;
2206 field
->fixed_root
= FIELD_FIXED
;
2208 /* Let the child be variable */
2209 //precompute_fields_offsets(tf, child, offset);
2211 if(field
->field_size
!= 0) {
2212 /* Increment offset */
2213 /* field_size is the array size in bytes */
2214 *offset
+= field
->field_size
;
2222 g_assert(type
->fields
->len
== 2);
2227 *offset
+= ltt_align(*offset
, get_alignment(field
),
2230 /* remember offset */
2231 field
->offset_root
= *offset
;
2232 field
->fixed_root
= FIELD_FIXED
;
2234 child
= &g_array_index(type
->fields
, LttField
, 0);
2235 ret
= precompute_fields_offsets(fac
, child
, offset
, is_compact
);
2236 g_assert(ret
== 0); /* Seq len cannot have variable len */
2238 child
= &g_array_index(type
->fields
, LttField
, 1);
2239 *offset
+= ltt_align(*offset
, get_alignment(child
),
2241 field
->array_offset
= *offset
;
2242 /* Let the child be variable. */
2243 //ret = precompute_fields_offsets(fac, child, offset);
2245 /* Cannot precompute fields offsets of sequence members, and has
2246 * variable length. */
2256 *offset
+= ltt_align(*offset
, get_alignment(field
),
2258 /* remember offset */
2259 field
->offset_root
= *offset
;
2260 field
->fixed_root
= FIELD_FIXED
;
2262 for(i
=0; i
< type
->fields
->len
; i
++) {
2263 child
= &g_array_index(type
->fields
, LttField
, i
);
2264 ret
= precompute_fields_offsets(fac
, child
, offset
, is_compact
);
2277 *offset
+= ltt_align(*offset
, get_alignment(field
),
2279 /* remember offset */
2280 field
->offset_root
= *offset
;
2281 field
->fixed_root
= FIELD_FIXED
;
2283 for(i
=0; i
< type
->fields
->len
; i
++) {
2284 *offset
= field
->offset_root
;
2285 child
= &g_array_index(type
->fields
, LttField
, i
);
2286 ret
= precompute_fields_offsets(fac
, child
, offset
, is_compact
);
2290 *offset
= field
->offset_root
+ field
->field_size
;
2297 g_error("precompute_fields_offsets : unknown type");
2306 /*****************************************************************************
2308 * precompute_offsets : set the precomputable offset of an event type
2311 * event : event type
2313 ****************************************************************************/
2314 void precompute_offsets(LttFacility
*fac
, LttEventType
*event
)
2320 /* First, compute the size of fixed size fields. Will determine size for
2321 * arrays, struct and unions, which is not done by the parser */
2322 for(i
=0; i
<event
->fields
->len
; i
++) {
2323 LttField
*field
= &g_array_index(event
->fields
, LttField
, i
);
2324 field_compute_static_size(fac
, field
);
2327 /* Precompute all known offsets */
2328 for(i
=0; i
<event
->fields
->len
; i
++) {
2329 LttField
*field
= &g_array_index(event
->fields
, LttField
, i
);
2330 if(event
->has_compact_data
&& i
== 0)
2331 ret
= precompute_fields_offsets(fac
, field
, &offset
, 1);
2333 ret
= precompute_fields_offsets(fac
, field
, &offset
, 0);
2341 /*****************************************************************************
2343 * preset_field_type_size : set the fixed sizes of the field type
2346 * event_type : event type
2347 * offset_root : offset from the root
2348 * offset_parent : offset from the parent
2349 * fixed_root : Do we know a fixed offset to the root ?
2350 * fixed_parent : Do we know a fixed offset to the parent ?
2352 ****************************************************************************/
2356 // preset the fixed size offsets. Calculate them just like genevent-new : an
2357 // increment of a *to value that represents the offset from the start of the
2359 // The preset information is : offsets up to (and including) the first element
2360 // of variable size. All subsequent fields must be flagged "VARIABLE OFFSET".
2362 void preset_field_type_size(LttTracefile
*tf
, LttEventType
*event_type
,
2363 off_t offset_root
, off_t offset_parent
,
2364 enum field_status
*fixed_root
, enum field_status
*fixed_parent
,
2367 enum field_status local_fixed_root
, local_fixed_parent
;
2371 g_assert(field
->fixed_root
== FIELD_UNKNOWN
);
2372 g_assert(field
->fixed_parent
== FIELD_UNKNOWN
);
2373 g_assert(field
->fixed_size
== FIELD_UNKNOWN
);
2375 type
= field
->field_type
;
2377 field
->fixed_root
= *fixed_root
;
2378 if(field
->fixed_root
== FIELD_FIXED
)
2379 field
->offset_root
= offset_root
;
2381 field
->offset_root
= 0;
2383 field
->fixed_parent
= *fixed_parent
;
2384 if(field
->fixed_parent
== FIELD_FIXED
)
2385 field
->offset_parent
= offset_parent
;
2387 field
->offset_parent
= 0;
2389 size_t current_root_offset
;
2390 size_t current_offset
;
2391 enum field_status current_child_status
, final_child_status
;
2394 switch(type
->type_class
) {
2396 case LTT_UINT_FIXED
:
2405 field
->field_size
= ltt_type_size(tf
->trace
, type
);
2406 field
->fixed_size
= FIELD_FIXED
;
2409 field
->field_size
= (off_t
)event_type
->facility
->pointer_size
;
2410 field
->fixed_size
= FIELD_FIXED
;
2414 field
->field_size
= (off_t
)event_type
->facility
->long_size
;
2415 field
->fixed_size
= FIELD_FIXED
;
2420 field
->field_size
= (off_t
)event_type
->facility
->size_t_size
;
2421 field
->fixed_size
= FIELD_FIXED
;
2424 local_fixed_root
= FIELD_VARIABLE
;
2425 local_fixed_parent
= FIELD_VARIABLE
;
2426 preset_field_type_size(tf
, event_type
,
2428 &local_fixed_root
, &local_fixed_parent
,
2430 field
->fixed_size
= FIELD_VARIABLE
;
2431 field
->field_size
= 0;
2432 *fixed_root
= FIELD_VARIABLE
;
2433 *fixed_parent
= FIELD_VARIABLE
;
2436 field
->fixed_size
= FIELD_VARIABLE
;
2437 field
->field_size
= 0;
2438 *fixed_root
= FIELD_VARIABLE
;
2439 *fixed_parent
= FIELD_VARIABLE
;
2442 local_fixed_root
= FIELD_VARIABLE
;
2443 local_fixed_parent
= FIELD_VARIABLE
;
2444 preset_field_type_size(tf
, event_type
,
2446 &local_fixed_root
, &local_fixed_parent
,
2448 field
->fixed_size
= field
->child
[0]->fixed_size
;
2449 if(field
->fixed_size
== FIELD_FIXED
) {
2450 field
->field_size
= type
->element_number
* field
->child
[0]->field_size
;
2452 field
->field_size
= 0;
2453 *fixed_root
= FIELD_VARIABLE
;
2454 *fixed_parent
= FIELD_VARIABLE
;
2458 current_root_offset
= field
->offset_root
;
2460 current_child_status
= FIELD_FIXED
;
2461 for(i
=0;i
<type
->element_number
;i
++) {
2462 preset_field_type_size(tf
, event_type
,
2463 current_root_offset
, current_offset
,
2464 fixed_root
, ¤t_child_status
,
2466 if(current_child_status
== FIELD_FIXED
) {
2467 current_root_offset
+= field
->child
[i
]->field_size
;
2468 current_offset
+= field
->child
[i
]->field_size
;
2470 current_root_offset
= 0;
2474 if(current_child_status
!= FIELD_FIXED
) {
2475 *fixed_parent
= current_child_status
;
2476 field
->field_size
= 0;
2477 field
->fixed_size
= current_child_status
;
2479 field
->field_size
= current_offset
;
2480 field
->fixed_size
= FIELD_FIXED
;
2484 current_root_offset
= field
->offset_root
;
2487 final_child_status
= FIELD_FIXED
;
2488 for(i
=0;i
<type
->element_number
;i
++) {
2489 enum field_status current_root_child_status
= FIELD_FIXED
;
2490 enum field_status current_child_status
= FIELD_FIXED
;
2491 preset_field_type_size(tf
, event_type
,
2492 current_root_offset
, current_offset
,
2493 ¤t_root_child_status
, ¤t_child_status
,
2495 if(current_child_status
!= FIELD_FIXED
)
2496 final_child_status
= current_child_status
;
2498 max_size
= max(max_size
, field
->child
[i
]->field_size
);
2500 if(final_child_status
!= FIELD_FIXED
) {
2501 g_error("LTTV does not support variable size fields in unions.");
2502 /* This will stop the application. */
2503 *fixed_root
= final_child_status
;
2504 *fixed_parent
= final_child_status
;
2505 field
->field_size
= 0;
2506 field
->fixed_size
= current_child_status
;
2508 field
->field_size
= max_size
;
2509 field
->fixed_size
= FIELD_FIXED
;
2513 g_error("unexpected type NONE");
2520 /*****************************************************************************
2522 * check_fields_compatibility : Check for compatibility between two fields :
2523 * do they use the same inner structure ?
2525 * event_type1 : event type
2526 * event_type2 : event type
2529 *Returns : 0 if identical
2531 ****************************************************************************/
2532 // this function checks for equality of field types. Therefore, it does not use
2533 // per se offsets. For instance, an aligned version of a structure is
2534 // compatible with an unaligned version of the same structure.
2536 gint
check_fields_compatibility(LttEventType
*event_type1
,
2537 LttEventType
*event_type2
,
2538 LttField
*field1
, LttField
*field2
)
2540 guint different
= 0;
2544 if(field1
== NULL
) {
2545 if(field2
== NULL
) goto end
;
2550 } else if(field2
== NULL
) {
2555 type1
= &field1
->field_type
;
2556 type2
= &field2
->field_type
;
2558 if(type1
->type_class
!= type2
->type_class
) {
2562 if(type1
->network
!= type2
->network
) {
2567 switch(type1
->type_class
) {
2569 case LTT_UINT_FIXED
:
2584 if(field1
->field_size
!= field2
->field_size
)
2591 LttField
*child1
= &g_array_index(type1
->fields
, LttField
, 0);
2592 LttField
*child2
= &g_array_index(type2
->fields
, LttField
, 0);
2594 if(type1
->size
!= type2
->size
)
2596 if(check_fields_compatibility(event_type1
, event_type2
, child1
, child2
))
2602 LttField
*child1
= &g_array_index(type1
->fields
, LttField
, 1);
2603 LttField
*child2
= &g_array_index(type2
->fields
, LttField
, 1);
2605 if(check_fields_compatibility(event_type1
, event_type2
, child1
, child2
))
2615 if(type1
->fields
->len
!= type2
->fields
->len
) {
2620 for(i
=0; i
< type1
->fields
->len
; i
++) {
2623 child1
= &g_array_index(type1
->fields
, LttField
, i
);
2624 child2
= &g_array_index(type2
->fields
, LttField
, i
);
2625 different
= check_fields_compatibility(event_type1
,
2626 event_type2
, child1
, child2
);
2628 if(different
) break;
2634 g_error("check_fields_compatibility : unknown type");
2643 gint
check_fields_compatibility(LttEventType
*event_type1
,
2644 LttEventType
*event_type2
,
2645 LttField
*field1
, LttField
*field2
)
2647 guint different
= 0;
2652 if(field1
== NULL
) {
2653 if(field2
== NULL
) goto end
;
2658 } else if(field2
== NULL
) {
2663 g_assert(field1
->fixed_root
!= FIELD_UNKNOWN
);
2664 g_assert(field2
->fixed_root
!= FIELD_UNKNOWN
);
2665 g_assert(field1
->fixed_parent
!= FIELD_UNKNOWN
);
2666 g_assert(field2
->fixed_parent
!= FIELD_UNKNOWN
);
2667 g_assert(field1
->fixed_size
!= FIELD_UNKNOWN
);
2668 g_assert(field2
->fixed_size
!= FIELD_UNKNOWN
);
2670 type1
= field1
->field_type
;
2671 type2
= field2
->field_type
;
2673 if(type1
->type_class
!= type2
->type_class
) {
2677 if(type1
->element_name
!= type2
->element_name
) {
2682 switch(type1
->type_class
) {
2684 case LTT_UINT_FIXED
:
2699 if(field1
->field_size
!= field2
->field_size
) {
2705 if(type1
->element_number
!= type2
->element_number
) {
2709 for(i
=0;i
<type1
->element_number
;i
++) {
2710 if(type1
->enum_strings
[i
] != type2
->enum_strings
[i
]) {
2717 /* Two elements : size and child */
2718 g_assert(type1
->element_number
!= type2
->element_number
);
2719 for(i
=0;i
<type1
->element_number
;i
++) {
2720 if(check_fields_compatibility(event_type1
, event_type2
,
2721 field1
->child
[0], field2
->child
[0])) {
2730 if(field1
->field_size
!= field2
->field_size
) {
2734 /* Two elements : size and child */
2735 g_assert(type1
->element_number
!= type2
->element_number
);
2736 for(i
=0;i
<type1
->element_number
;i
++) {
2737 if(check_fields_compatibility(event_type1
, event_type2
,
2738 field1
->child
[0], field2
->child
[0])) {
2746 if(type1
->element_number
!= type2
->element_number
) {
2750 for(i
=0;i
<type1
->element_number
;i
++) {
2751 if(check_fields_compatibility(event_type1
, event_type2
,
2752 field1
->child
[0], field2
->child
[0])) {
2765 /*****************************************************************************
2767 * ltt_get_int : get an integer number
2769 * reverse_byte_order: must we reverse the byte order ?
2770 * size : the size of the integer
2771 * ptr : the data pointer
2773 * gint64 : a 64 bits integer
2774 ****************************************************************************/
2776 gint64
ltt_get_int(gboolean reverse_byte_order
, gint size
, void *data
)
2781 case 1: val
= *((gint8
*)data
); break;
2782 case 2: val
= ltt_get_int16(reverse_byte_order
, data
); break;
2783 case 4: val
= ltt_get_int32(reverse_byte_order
, data
); break;
2784 case 8: val
= ltt_get_int64(reverse_byte_order
, data
); break;
2785 default: val
= ltt_get_int64(reverse_byte_order
, data
);
2786 g_critical("get_int : integer size %d unknown", size
);
2793 /*****************************************************************************
2795 * ltt_get_uint : get an unsigned integer number
2797 * reverse_byte_order: must we reverse the byte order ?
2798 * size : the size of the integer
2799 * ptr : the data pointer
2801 * guint64 : a 64 bits unsigned integer
2802 ****************************************************************************/
2804 guint64
ltt_get_uint(gboolean reverse_byte_order
, gint size
, void *data
)
2809 case 1: val
= *((gint8
*)data
); break;
2810 case 2: val
= ltt_get_uint16(reverse_byte_order
, data
); break;
2811 case 4: val
= ltt_get_uint32(reverse_byte_order
, data
); break;
2812 case 8: val
= ltt_get_uint64(reverse_byte_order
, data
); break;
2813 default: val
= ltt_get_uint64(reverse_byte_order
, data
);
2814 g_critical("get_uint : unsigned integer size %d unknown",
2823 /* get the node name of the system */
2825 char * ltt_trace_system_description_node_name (LttSystemDescription
* s
)
2827 return s
->node_name
;
2831 /* get the domain name of the system */
2833 char * ltt_trace_system_description_domain_name (LttSystemDescription
* s
)
2835 return s
->domain_name
;
2839 /* get the description of the system */
2841 char * ltt_trace_system_description_description (LttSystemDescription
* s
)
2843 return s
->description
;
2847 /* get the NTP corrected start time of the trace */
2848 LttTime
ltt_trace_start_time(LttTrace
*t
)
2850 return t
->start_time
;
2853 /* get the monotonic start time of the trace */
2854 LttTime
ltt_trace_start_time_monotonic(LttTrace
*t
)
2856 return t
->start_time_from_tsc
;
2859 static LttTracefile
*ltt_tracefile_new()
2862 tf
= g_new(LttTracefile
, 1);
2863 tf
->event
.tracefile
= tf
;
2867 static void ltt_tracefile_destroy(LttTracefile
*tf
)
2872 static void ltt_tracefile_copy(LttTracefile
*dest
, const LttTracefile
*src
)
2877 /* Before library loading... */
2879 static __attribute__((constructor
)) void init(void)
2881 LTT_FACILITY_NAME_HEARTBEAT
= g_quark_from_string("heartbeat");
2882 LTT_EVENT_NAME_HEARTBEAT
= g_quark_from_string("heartbeat");
2883 LTT_EVENT_NAME_HEARTBEAT_FULL
= g_quark_from_string("heartbeat_full");
2885 LTT_TRACEFILE_NAME_FACILITIES
= g_quark_from_string("/control/facilities");