1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2005 Mathieu Desnoyers
4 * Complete rewrite from the original version made by XangXiu Yang.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License Version 2 as
8 * published by the Free Software Foundation;
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
30 #include <sys/types.h>
45 #include "ltt-private.h"
46 #include <ltt/trace.h>
47 #include <ltt/facility.h>
48 #include <ltt/event.h>
50 #include <ltt/ltt-types.h>
53 /* Facility names used in this file */
55 GQuark LTT_FACILITY_NAME_HEARTBEAT
,
56 LTT_EVENT_NAME_HEARTBEAT
;
63 #define __UNUSED__ __attribute__((__unused__))
65 #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
66 #define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format)
70 /* obtain the time of an event */
72 static inline LttTime
getEventTime(LttTracefile
* tf
);
75 /* set the offset of the fields belonging to the event,
76 need the information of the archecture */
77 void setFieldsOffset(LttTracefile
*tf
,LttEventType
*evT
,void *evD
,LttTrace
*t
);
79 /* get the size of the field type according to the archtecture's
80 size and endian type(info of the archecture) */
81 static inline gint
getFieldtypeSize(LttTracefile
* tf
,
82 LttEventType
* evT
, gint offsetRoot
,
83 gint offsetParent
, LttField
*fld
, void *evD
, LttTrace
* t
);
85 /* map a fixed size or a block information from the file (fd) */
86 int map_block(LttTracefile
* tf
, unsigned int block_num
);
88 /* calculate cycles per nsec for current block */
89 void getCyclePerNsec(LttTracefile
* t
);
91 /* go to the next event */
92 static int ltt_seek_next_event(LttTracefile
*tf
);
94 /* Functions to parse system.xml file (using glib xml parser) */
95 static void parser_start_element (GMarkupParseContext __UNUSED__
*context
,
96 const gchar
*element_name
,
97 const gchar
**attribute_names
,
98 const gchar
**attribute_values
,
103 LttSystemDescription
* des
= (LttSystemDescription
* )user_data
;
104 if(strcmp("system", element_name
)){
105 *error
= g_error_new(G_MARKUP_ERROR
,
107 "This is not system.xml file");
111 while(attribute_names
[i
]){
112 if(strcmp("node_name", attribute_names
[i
])==0){
113 des
->node_name
= g_strdup(attribute_values
[i
]);
114 }else if(strcmp("domainname", attribute_names
[i
])==0){
115 des
->domain_name
= g_strdup(attribute_values
[i
]);
116 }else if(strcmp("cpu", attribute_names
[i
])==0){
117 des
->nb_cpu
= atoi(attribute_values
[i
]);
118 }else if(strcmp("arch_size", attribute_names
[i
])==0){
119 if(strcmp(attribute_values
[i
],"LP32") == 0) des
->size
= LTT_LP32
;
120 else if(strcmp(attribute_values
[i
],"ILP32") == 0) des
->size
= LTT_ILP32
;
121 else if(strcmp(attribute_values
[i
],"LP64") == 0) des
->size
= LTT_LP64
;
122 else if(strcmp(attribute_values
[i
],"ILP64") == 0) des
->size
= LTT_ILP64
;
123 else if(strcmp(attribute_values
[i
],"UNKNOWN") == 0) des
->size
= LTT_UNKNOWN
;
124 }else if(strcmp("endian", attribute_names
[i
])==0){
125 if(strcmp(attribute_values
[i
],"LITTLE_ENDIAN") == 0)
126 des
->endian
= LTT_LITTLE_ENDIAN
;
127 else if(strcmp(attribute_values
[i
],"BIG_ENDIAN") == 0)
128 des
->endian
= LTT_BIG_ENDIAN
;
129 }else if(strcmp("kernel_name", attribute_names
[i
])==0){
130 des
->kernel_name
= g_strdup(attribute_values
[i
]);
131 }else if(strcmp("kernel_release", attribute_names
[i
])==0){
132 des
->kernel_release
= g_strdup(attribute_values
[i
]);
133 }else if(strcmp("kernel_version", attribute_names
[i
])==0){
134 des
->kernel_version
= g_strdup(attribute_values
[i
]);
135 }else if(strcmp("machine", attribute_names
[i
])==0){
136 des
->machine
= g_strdup(attribute_values
[i
]);
137 }else if(strcmp("processor", attribute_names
[i
])==0){
138 des
->processor
= g_strdup(attribute_values
[i
]);
139 }else if(strcmp("hardware_platform", attribute_names
[i
])==0){
140 des
->hardware_platform
= g_strdup(attribute_values
[i
]);
141 }else if(strcmp("operating_system", attribute_names
[i
])==0){
142 des
->operating_system
= g_strdup(attribute_values
[i
]);
143 }else if(strcmp("ltt_major_version", attribute_names
[i
])==0){
144 des
->ltt_major_version
= atoi(attribute_values
[i
]);
145 }else if(strcmp("ltt_minor_version", attribute_names
[i
])==0){
146 des
->ltt_minor_version
= atoi(attribute_values
[i
]);
147 }else if(strcmp("ltt_block_size", attribute_names
[i
])==0){
148 des
->ltt_block_size
= atoi(attribute_values
[i
]);
150 *error
= g_error_new(G_MARKUP_ERROR
,
152 "Not a valid attribute");
159 static void parser_characters (GMarkupParseContext __UNUSED__
*context
,
161 gsize __UNUSED__ text_len
,
163 GError __UNUSED__
**error
)
165 LttSystemDescription
* des
= (LttSystemDescription
* )user_data
;
166 des
->description
= g_strdup(text
);
170 /*****************************************************************************
172 * ltt_tracefile_open : open a trace file, construct a LttTracefile
174 * t : the trace containing the tracefile
175 * fileName : path name of the trace file
176 * tf : the tracefile structure
178 * : 0 for success, -1 otherwise.
179 ****************************************************************************/
181 int ltt_tracefile_open(LttTrace
*t
, gchar
* fileName
, LttTracefile
*tf
)
183 struct stat lTDFStat
; /* Trace data file status */
184 struct ltt_block_start_header
*header
;
187 tf
->name
= g_quark_from_string(fileName
);
189 tf
->fd
= g_open(fileName
, O_RDONLY
, 0);
191 g_warning("Unable to open input data file %s\n", fileName
);
195 // Get the file's status
196 if(fstat(tf
->fd
, &lTDFStat
) < 0){
197 g_warning("Unable to get the status of the input data file %s\n", fileName
);
201 // Is the file large enough to contain a trace
202 if(lTDFStat
.st_size
< (off_t
)(sizeof(BlockStart
))){
203 g_print("The input data file %s does not contain a trace\n", fileName
);
207 /* Temporarily map the buffer start header to get trace information */
208 /* Multiple of pages aligned head */
209 tf
->buffer
.head
= mmap(0, sizeof(struct ltt_block_start_header
), PROT_READ
,
211 if(tf
->buffer
== NULL
) {
212 perror("Error in allocating memory for buffer of tracefile %s\n", fileName
);
215 g_assert(tf
->buffer
.head
& (8-1) == 0); // make sure it's aligned.
217 header
= (struct ltt_block_start_header
*)tf
->buffer
.head
;
219 if(header
->traceset
.magic_number
== LTT_MAGIC_NUMBER
)
221 else if(header
->traceset
.magic_number
== LTT_REV_MAGIC_NUMBER
)
223 else /* invalid magic number, bad tracefile ! */
226 //store the size of the file
227 tf
->file_size
= lTDFStat
.st_size
;
228 tf
->block_size
= header
->buf_size
;
229 tf
->block_number
= tf
->file_size
/ tf
->block_size
;
231 vfree(tf
->buffer
.head
);
232 tf
->buffer
.head
= NULL
;
234 //read the first block
235 if(map_block(tf
,0)) {
236 perror("Cannot map block %u for tracefile %s\n", 0, fileName
);
244 munmap(tf
->buffer
.head
, sizeof(struct ltt_block_start_header
));
252 /*****************************************************************************
253 *Open control and per cpu tracefiles
254 ****************************************************************************/
256 void ltt_tracefile_open_cpu(LttTrace
*t
, gchar
* tracefile_name
)
259 tf
= ltt_tracefile_open(t
,tracefile_name
);
261 t
->per_cpu_tracefile_number
++;
262 g_ptr_array_add(t
->per_cpu_tracefiles
, tf
);
265 gint
ltt_tracefile_open_control(LttTrace
*t
, gchar
* control_name
)
274 tf
= ltt_tracefile_open(t
,control_name
);
276 g_warning("ltt_tracefile_open_control : bad file descriptor");
279 t
->control_tracefile_number
++;
280 g_ptr_array_add(t
->control_tracefiles
,tf
);
282 //parse facilities tracefile to get base_id
283 if(strcmp(&control_name
[strlen(control_name
)-10],"facilities") ==0){
285 if(!ltt_tracefile_read(tf
,&ev
)) return 0; // end of file
287 if(ev
.event_id
== TRACE_FACILITY_LOAD
){
289 fLoad
.name
= (gchar
*)pos
;
290 fLoad
.checksum
= *(LttChecksum
*)(pos
+ strlen(fLoad
.name
));
291 fLoad
.base_code
= *(guint32
*)(pos
+ strlen(fLoad
.name
) + sizeof(LttChecksum
));
293 for(i
=0;i
<t
->facility_number
;i
++){
294 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
,i
);
295 if(strcmp(f
->name
,fLoad
.name
)==0 && fLoad
.checksum
==f
->checksum
){
296 f
->base_id
= fLoad
.base_code
;
300 if(i
==t
->facility_number
) {
301 g_warning("Facility: %s, checksum: %u is not found",
302 fLoad
.name
,(unsigned int)fLoad
.checksum
);
305 }else if(ev
.event_id
== TRACE_BLOCK_START
){
307 }else if(ev
.event_id
== TRACE_BLOCK_END
){
310 g_warning("Not valid facilities trace file");
318 /*****************************************************************************
320 * ltt_tracefile_close: close a trace file,
322 * t : tracefile which will be closed
323 ****************************************************************************/
325 void ltt_tracefile_close(LttTracefile
*t
)
327 if(t
->buffer
.head
!= NULL
)
328 munmap(t
->buffer
.head
, t
->buf_size
);
333 /*****************************************************************************
334 *Get system information
335 ****************************************************************************/
336 gint
getSystemInfo(LttSystemDescription
* des
, gchar
* pathname
)
343 GMarkupParseContext
* context
;
344 GError
* error
= NULL
;
345 GMarkupParser markup_parser
=
347 parser_start_element
,
350 NULL
, /* passthrough */
354 fd
= g_open(pathname
, O_RDONLY
, 0);
356 g_warning("Can not open file : %s\n", pathname
);
360 iochan
= g_io_channel_unix_new(fd
);
362 context
= g_markup_parse_context_new(&markup_parser
, 0, des
,NULL
);
364 //while(fgets(buf,DIR_NAME_SIZE, fp) != NULL){
365 while(g_io_channel_read_line(iochan
, &buf
, &length
, NULL
, &error
)
366 != G_IO_STATUS_EOF
) {
369 g_warning("Can not read xml file: \n%s\n", error
->message
);
372 if(!g_markup_parse_context_parse(context
, buf
, length
, &error
)){
374 g_warning("Can not parse xml file: \n%s\n", error
->message
);
377 g_markup_parse_context_free(context
);
379 g_io_channel_shutdown(iochan
, FALSE
, &error
); /* No flush */
381 g_warning("Can not close file: \n%s\n", error
->message
);
389 g_markup_parse_context_free(context
);
391 g_io_channel_shutdown(iochan
, FALSE
, &error
); /* No flush */
393 g_warning("Can not close file: \n%s\n", error
->message
);
403 /*****************************************************************************
404 *The following functions get facility/tracefile information
405 ****************************************************************************/
407 gint
getFacilityInfo(LttTrace
*t
, gchar
* eventdefs
)
414 gchar fullname
[DIR_NAME_SIZE
];
415 GError
* error
= NULL
;
417 dir
= g_dir_open(eventdefs
, 0, &error
);
420 g_warning("Can not open directory: %s, %s\n", eventdefs
, error
->message
);
425 while((name
= g_dir_read_name(dir
)) != NULL
){
426 if(!g_pattern_match_simple("*.xml", name
)) continue;
427 strcpy(fullname
,eventdefs
);
428 strcat(fullname
,name
);
429 ltt_facility_open(t
,fullname
);
433 for(j
=0;j
<t
->facility_number
;j
++){
434 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
, j
);
435 for(i
=0; i
<f
->event_number
; i
++){
437 setFieldsOffset(NULL
, et
, NULL
, t
);
443 /*****************************************************************************
444 *A trace is specified as a pathname to the directory containing all the
445 *associated data (control tracefiles, per cpu tracefiles, event
448 *When a trace is closed, all the associated facilities, types and fields
449 *are released as well.
453 /****************************************************************************
454 * get_absolute_pathname
456 * return the unique pathname in the system
458 * MD : Fixed this function so it uses realpath, dealing well with
459 * forgotten cases (.. were not used correctly before).
461 ****************************************************************************/
462 void get_absolute_pathname(const gchar
*pathname
, gchar
* abs_pathname
)
464 abs_pathname
[0] = '\0';
466 if ( realpath (pathname
, abs_pathname
) != NULL
)
470 /* error, return the original path unmodified */
471 strcpy(abs_pathname
, pathname
);
477 /* Search for something like : .*_.*
479 * The left side is the name, the right side is the number.
482 int get_tracefile_name_number(const gchar
*raw_name
,
486 guint raw_name_len
= strlen(raw_name
);
487 gchar char_name
[PATH_MAX
]
494 for(i
=raw_name_len
-1;i
>=0;i
--) {
495 if(raw_name
[i
] == '_') break;
497 if(i
==0) /* Either not found or name length is 0 */
501 cpu_num
= strtol(raw_name
+underscore_pos
+1, &endptr
, 10);
503 if(endptr
== raw_name
+underscore_pos
+1)
504 return -1; /* No digit */
505 if(cpu_num
== LONG_MIN
|| cpu_num
== LONG_MAX
)
506 return -1; /* underflow / overflow */
508 char_name
= strncpy(char_name
, raw_name
, underscore_pos
);
510 *name
= g_quark_from_string(char_name
);
517 void ltt_tracefile_group_destroy(gpointer data
)
519 GArray
*group
= (GArray
*)data
;
523 for(i
=0; i
<group
->len
; i
++) {
524 tf
= &g_array_index (group
, LttTracefile
, i
);
526 ltt_tracefile_close(tf
);
528 g_array_free(group
, TRUE
);
531 gboolean
ltt_tracefile_group_has_cpu_online(gpointer data
)
533 GArray
*group
= (GArray
*)data
;
537 for(i
=0; i
<group
->len
; i
++) {
538 tf
= &g_array_index (group
, LttTracefile
, i
);
539 if(tf
->cpu_online
) return 1;
545 /* Open each tracefile under a specific directory. Put them in a
546 * GData : permits to access them using their tracefile group pathname.
547 * i.e. access control/modules tracefile group by index :
550 * A tracefile group is simply an array where all the per cpu tracefiles sits.
553 static int open_tracefiles(LttTrace
*trace
, char *root_path
, GData
*tracefiles
)
555 DIR *dir
= opendir(root_path
);
556 struct dirent
*entry
;
557 struct stat stat_buf
;
563 if(channel_dir
== NULL
) {
564 perror(subchannel_name
);
568 strncpy(path
, root_path
, PATH_MAX
-1);
569 path_len
= strlen(path
);
570 path
[path_len
] = '/';
572 path_ptr
= path
+ path_len
;
574 while((entry
= readdir(channel_dir
)) != NULL
) {
576 if(entry
->d_name
[0] == '.') continue;
578 strncpy(path_ptr
, entry
->d_name
, PATH_MAX
- path_len
);
580 ret
= stat(path
, &stat_buf
);
586 g_debug("Tracefile file or directory : %s\n", path
);
588 if(S_ISDIR(stat_buf
.st_mode
)) {
590 g_debug("Entering subdirectory...\n");
591 ret
= open_tracefiles(path
, tracefiles
);
592 if(ret
< 0) continue;
593 } else if(S_ISREG(stat_buf
.st_mode
)) {
594 g_debug("Opening file.\n");
602 if(get_tracefile_name_number(path
, &name
, &num
))
603 continue; /* invalid name */
605 group
= g_datalist_get_data(tracefiles
, name
);
607 /* Elements are automatically cleared when the array is allocated.
608 * It makes the cpu_online variable set to 0 : cpu offline, by default.
610 group
= g_array_sized_new (FALSE
, TRUE
, sizeof(LttTracefile
), 10);
611 g_datalist_set_data_full(tracefiles
, name
,
612 group
, ltt_tracefile_group_destroy
);
614 /* Add the per cpu tracefile to the named group */
615 unsigned int old_len
= group
->len
;
617 group
= g_array_set_size(group
, num
+1);
618 tf
= &g_array_index (group
, LttTracefile
, num
);
620 if(ltt_tracefile_open(trace
, path
, tf
)) {
621 g_info("Error opening tracefile %s", path
);
622 g_array_set_size(group
, old_len
);
624 if(!ltt_tracefile_group_has_cpu_online(group
))
625 g_datalist_remove_data(tracefiles
, name
);
627 continue; /* error opening the tracefile : bad magic number ? */
638 /* ltt_get_facility_description
640 * Opens the trace corresponding to the requested facility (identified by fac_id
643 * The name searched is : %trace root%/eventdefs/facname_checksum.xml
645 * Returns 0 on success, or 1 on failure.
648 static int ltt_get_facility_description(LttFacility
*f
,
651 char desc_file_name
[PATH_MAX
];
656 text
= g_quark_to_string(t
->pathname
);
657 textlen
= strlen(text
);
659 if(textlen
>= PATH_MAX
) goto name_error
;
660 strcpy(desc_file_name
, text
);
662 text
= "/eventdefs/";
663 textlen
+=strlen(text
);
664 if(textlen
>= PATH_MAX
) goto name_error
;
665 strcat(desc_file_name
, text
);
667 text
= g_quark_to_string(f
->name
);
668 textlen
+=strlen(text
);
669 if(textlen
>= PATH_MAX
) goto name_error
;
670 strcat(desc_file_name
, text
);
673 textlen
+=strlen(text
);
674 if(textlen
>= PATH_MAX
) goto name_error
;
675 strcat(desc_file_name
, text
);
677 err
= snprintf(desc_file_name
+textlen
, PATH_MAX
-textlen
-1,
679 if(err
) goto name_error
;
681 textlen
=strlen(desc_file_name
);
684 textlen
+=strlen(text
);
685 if(textlen
>= PATH_MAX
) goto name_error
;
686 strcat(desc_file_name
, text
);
688 err
= ltt_facility_open(f
, t
, desc_file_name
);
689 if(err
) goto facility_error
;
698 static void ltt_tracefile_ids_destroy(gpointer data
)
700 GArray
*fac_ids
= (GArray
*)data
;
704 for(i
=0; i
<group
->len
; i
++) {
705 fac
= &g_array_index (fac_ids
, LttFacility
, i
);
706 ltt_facility_close(fac
);
709 g_array_free(array
, TRUE
);
713 /* Presumes the tracefile is already seeked at the beginning. It makes sense,
714 * because it must be done just after the opening */
715 static int ltt_process_facility_tracefile(LttTracefile
*tf
)
722 err
= ltt_tracefile_read_seek(tf
);
723 if(err
== EPERM
) goto seek_error
;;
724 else if(err
== ERANGE
) break; /* End of tracefile */
726 err
= ltt_tracefile_read_update_event(tf
);
727 if(err
) goto update_error
;
729 /* We are on a facility load/or facility unload/ or heartbeat event */
731 * * facility 0 is hardcoded : this is the core facility. It will be shown
732 * in the facility array though, and is shown as "loaded builtin" in the
734 * It contains event :
736 * 1 : facility unload
737 * 2 : state dump facility load
738 * Facility 1 : (heartbeat)
741 if(tf
->event
.facility_id
> 1) { /* Should only contain core and heartbeat
743 g_warning("Error in processing facility file %s, "
744 "should not contain facility id %u.", g_quark_to_string(tf
->name
),
745 tf
->event
.facility_id
);
748 } else if(tf
->event
.facility_id
== 0) {
751 switch((enum ltt_core_events
)tf
->event
.event_id
) {
752 case LTT_EVENT_FACILITY_LOAD
:
753 struct LttFacilityLoad
*fac_load_data
=
754 (struct LttFacilityLoad
*)tf
->event
.data
;
756 (char*)(tf
->event
.data
+ sizeof(struct LttFacilityLoad
));
757 fac
= &g_array_index (tf
->facilities_by_num
, LttTracefile
,
759 g_assert(fac
->exists
== 0);
760 fac
->name
= g_quark_from_string(fac_name
);
761 fac
->checksum
= ltt_get_uint32(LTT_GET_BO(tf
),
762 fac_load_data
->checksum
);
763 fac
->id
= ltt_get_uint8(LTT_GET_BO(tf
), fac_load_data
->id
);
764 fac
->pointer_size
= ltt_get_uint32(LTT_GET_BO(tf
),
765 fac_load_data
->pointer_size
);
766 fac
->size_t_size
= ltt_get_uin32(LTT_GET_BO(tf
),
767 fac_load_data
->size_t_size
);
768 fac
->alignment
= ltt_get_uint32(LTT_GET_BO(tf
),
769 fac_load_data
->alignment
);
771 if(ltt_get_facility_description(fac
, tf
->trace
))
776 fac_ids
= g_datalist_get_data(tf
->facilities_by_name
, fac
->name
);
777 if(fac_ids
== NULL
) {
778 fac_ids
= g_array_sized_new (FALSE
, TRUE
, sizeof(guint
), 1);
779 g_datalist_set_data_full(tf
->facilities_by_name
, fac
->name
,
780 fac_ids
, ltt_fac_ids_destroy
);
782 g_array_append_val(fac_ids
, fac
->id
);
785 case LTT_EVENT_FACILITY_UNLOAD
:
786 /* We don't care about unload : facilities ID are valid for the whole
787 * trace. They simply won't be used after the unload. */
789 case LTT_EVENT_STATE_DUMP_FACILITY_LOAD
:
790 struct LttFacilityLoad
*fac_load_data
=
791 (struct LttFacilityLoad
*)tf
->event
.data
;
793 (char*)(tf
->event
.data
+ sizeof(struct LttFacilityLoad
));
794 fac
= &g_array_index (tf
->facilities_by_num
, LttTracefile
,
796 g_assert(fac
->exists
== 0);
797 fac
->name
= g_quark_from_string(fac_name
);
798 fac
->checksum
= ltt_get_uint32(LTT_GET_BO(tf
),
799 fac_load_data
->checksum
);
800 fac
->id
= ltt_get_uint8(LTT_GET_BO(tf
), fac_load_data
->id
);
801 fac
->pointer_size
= ltt_get_uint32(LTT_GET_BO(tf
),
802 fac_load_data
->pointer_size
);
803 fac
->size_t_size
= ltt_get_uin32(LTT_GET_BO(tf
),
804 fac_load_data
->size_t_size
);
805 fac
->alignment
= ltt_get_uint32(LTT_GET_BO(tf
),
806 fac_load_data
->alignment
);
809 fac
->named_types_number
;
812 fac_ids
= g_datalist_get_data(tf
->facilities_by_name
, fac
->name
);
813 if(fac_ids
== NULL
) {
814 fac_ids
= g_array_sized_new (FALSE
, TRUE
, sizeof(guint
), 1);
815 g_datalist_set_data_full(tf
->facilities_by_name
, fac
->name
,
816 fac_ids
, ltt_fac_ids_destroy
);
818 g_array_append_val(fac_ids
, fac
->id
);
822 g_warning("Error in processing facility file %s, "
823 "unknown event id %hhu in core facility.",
824 g_quark_to_string(tf
->name
),
829 } else if(tf
->event
.facility_id
== 1) {
831 switch((enum ltt_heartbeat_events
)tf
->event
.event_id
) {
832 case LTT_EVENT_HEARTBEAT
:
835 g_warning("Error in processing facility file %s, "
836 "unknown event id %hhu in heartbeat facility.",
837 g_quark_to_string(tf
->name
),
856 LttTrace
*ltt_trace_open(const gchar
*pathname
)
858 gchar abs_path
[PATH_MAX
];
864 LttTrace
* t
= g_new(LttTrace
, 1);
865 if(!t
) goto alloc_error
;
867 get_absolute_pathname(pathname
, abs_path
);
868 t
->pathname
= g_quark_from_string(abs_path
);
870 /* Open all the tracefiles */
871 g_datalist_init(t
->tracefiles
);
872 if(open_tracefiles(t
, abs_path
, t
->tracefiles
))
875 /* Prepare the facilities containers : array and mapping */
876 /* Array is zeroed : the "exists" field is set to false by default */
877 t
->facilities_by_num
= g_array_sized_new (FALSE
,
878 TRUE
, sizeof(LttFacility
),
880 t
->facilities_by_num
= g_array_set_size(t
->facilities_by_num
, NUM_FACILITIES
);
882 g_datalist_init(t
->tracefiles_by_name
);
884 /* Load trace XML event descriptions */
887 /* Parse each trace control/facilitiesN files : get runtime fac. info */
888 group
= g_datalist_get_data(t
->tracefiles
, LTT_TRACEFILE_NAME_FACILITIES
);
890 g_error("Trace %s has no facility tracefile", abs_path
);
891 goto facilities_error
;
894 for(i
=0; i
<group
->len
; i
++) {
895 tf
= &g_array_index (group
, LttTracefile
, i
);
896 if(ltt_process_facility_tracefile(tf
))
897 goto facilities_error
;
906 g_datalist_free(t
->tracefiles_by_name
);
907 g_array_free(t
->facilities_by_num
, TRUE
);
909 g_datalist_clear(t
->tracefiles
);
916 GQuark
ltt_trace_name(LttTrace
*t
)
922 /******************************************************************************
923 * When we copy a trace, we want all the opening actions to happen again :
924 * the trace will be reopened and totally independant from the original.
925 * That's why we call ltt_trace_open.
926 *****************************************************************************/
927 LttTrace
*ltt_trace_copy(LttTrace
*self
)
929 return ltt_trace_open(self
->pathname
);
933 void ltt_trace_close(LttTrace
*t
)
941 //free system_description
942 g_free(t
->system_description
->description
);
943 g_free(t
->system_description
->node_name
);
944 g_free(t
->system_description
->domain_name
);
945 g_free(t
->system_description
->kernel_name
);
946 g_free(t
->system_description
->kernel_release
);
947 g_free(t
->system_description
->kernel_version
);
948 g_free(t
->system_description
->machine
);
949 g_free(t
->system_description
->processor
);
950 g_free(t
->system_description
->hardware_platform
);
951 g_free(t
->system_description
->operating_system
);
952 g_free(t
->system_description
);
954 //free control_tracefiles
955 for(i
=0;i
<t
->control_tracefile_number
;i
++){
956 tf
= (LttTracefile
*)g_ptr_array_index(t
->control_tracefiles
,i
);
957 ltt_tracefile_close(tf
);
959 g_ptr_array_free(t
->control_tracefiles
, TRUE
);
961 //free per_cpu_tracefiles
962 for(i
=0;i
<t
->per_cpu_tracefile_number
;i
++){
963 tf
= (LttTracefile
*)g_ptr_array_index(t
->per_cpu_tracefiles
,i
);
964 ltt_tracefile_close(tf
);
966 g_ptr_array_free(t
->per_cpu_tracefiles
, TRUE
);
969 for(i
=0;i
<t
->facility_number
;i
++){
970 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
,i
);
971 ltt_facility_close(f
);
973 g_ptr_array_free(t
->facilities
, TRUE
);
981 /*****************************************************************************
982 *Get the system description of the trace
983 ****************************************************************************/
985 LttFacility
*ltt_trace_facility_by_id(LttTrace
*t
, guint8 id
)
987 g_assert(index
< t
->facilities_by_num
->len
);
988 return &g_array_index(t
->facilities_by_num
, LttFacility
, id
);
991 /* ltt_trace_facility_get_by_name
993 * Returns the GArray of facility indexes. All the fac_ids that matches the
994 * requested facility name.
996 * If name is not found, returns NULL.
998 GArray
*ltt_trace_facility_get_by_name(LttTrace
*t
, GQuark name
)
1000 return g_datalist_id_get_data(t
->facilities_by_name
, name
);
1003 /*****************************************************************************
1004 * Functions to discover all the event types in the trace
1005 ****************************************************************************/
1007 unsigned ltt_trace_eventtype_number(LttTrace
*t
)
1011 unsigned int num
= t
->facility_number
;
1015 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
, i
);
1016 count
+= f
->event_number
;
1021 LttEventType
*ltt_trace_eventtype_get(LttTrace
*t
, unsigned evId
)
1023 LttEventType
*event_type
;
1026 f
= ltt_trace_facility_by_id(t
,evId
);
1028 if(unlikely(!f
)) event_type
= NULL
;
1029 else event_type
= f
->events
[evId
- f
->base_id
];
1035 /*****************************************************************************
1036 * ltt_trace_find_tracefile
1038 * Find a tracefile by name and index in the group.
1040 * Returns a pointer to the tracefiles, else NULL.
1041 ****************************************************************************/
1043 LttTracefile
*ltt_trace_find_tracefile(LttTrace
*t
, const gchar
*name
)
1048 /*****************************************************************************
1049 * Get the start time and end time of the trace
1050 ****************************************************************************/
1052 static void ltt_tracefile_time_span_get(LttTracefile
*tf
,
1053 LttTime
*start
, LttTime
*end
)
1055 struct ltt_block_start_header
* header
;
1058 err
= map_block(tf
, 0);
1060 g_error("Can not map block");
1061 *start
= { 0xFFFFFFFF, 0xFFFFFFFF };
1063 *start
= tf
->buffer
.begin
.timestamp
;
1065 err
= map_block(tf
, tf
->num_blocks
- 1); /* Last block */
1067 g_error("Can not map block");
1070 *end
= tf
->buffer
.end
.timestamp
;
1073 struct tracefile_time_span_get_args
{
1079 static void group_time_span_get(GQuark name
, gpointer data
, gpointer user_data
)
1081 struct tracefile_time_span_get_args
*args
=
1082 (struct tracefile_time_span_get_args
*)user_data
;
1084 GArray
*group
= (GArray
*)data
;
1090 for(i
=0; i
<group
->len
; i
++) {
1091 tf
= &g_array_index (group
, LttTracefile
, i
);
1092 if(tf
->cpu_online
) {
1093 ltt_tracefile_time_span_get(tf
, &tmp_start
, &tmp_end
);
1094 if(ltt_time_compare(*args
->start
, tmp_start
)>0) *args
->start
= tmp_start
;
1095 if(ltt_time_compare(*args
->end
, tmp_end
)<0) *args
->end
= tmp_end
;
1100 void ltt_trace_time_span_get(LttTrace
*t
, LttTime
*start
, LttTime
*end
)
1102 LttTime min_start
= { 0xFFFFFFFF, 0xFFFFFFFF };
1103 LttTime max_end
= { 0, 0 };
1104 struct tracefile_time_span_get_args args
= { t
, &min_start
, &max_end
};
1106 g_datalist_foreach(t
->tracefiles
, &group_time_span_get
, &args
);
1108 if(start
!= NULL
) *start
= min_start
;
1109 if(end
!= NULL
) *end
= max_end
;
1114 /*****************************************************************************
1115 *Get the name of a tracefile
1116 ****************************************************************************/
1118 GQuark
ltt_tracefile_name(LttTracefile
*tf
)
1123 /*****************************************************************************
1124 * Get the number of blocks in the tracefile
1125 ****************************************************************************/
1127 guint
ltt_tracefile_block_number(LttTracefile
*tf
)
1129 return tf
->block_number
;
1133 /* Seek to the first event in a tracefile that has a time equal or greater than
1134 * the time passed in parameter.
1136 * If the time parameter is outside the tracefile time span, seek to the first
1137 * or the last event of the tracefile.
1139 * If the time parameter is before the first event, we have to seek specially to
1142 * If the time is after the end of the trace, get the last event.
1144 * Do a binary search to find the right block, then a sequential search in the
1145 * block to find the event.
1147 * In the special case where the time requested fits inside a block that has no
1148 * event corresponding to the requested time, the first event of the next block
1151 * IMPORTANT NOTE : // FIXME everywhere...
1153 * You MUST NOT do a ltt_tracefile_read right after a ltt_tracefile_seek_time :
1154 * you will jump over an event if you do.
1156 * Return value : 0 : no error, the tf->event can be used
1157 * otherwise : this is an error.
1161 int ltt_tracefile_seek_time(LttTracefile
*tf
, LttTime time
)
1165 unsigned int block_num
, high
, low
;
1167 /* seek at the beginning of trace */
1168 err
= map_block(tf
, 0); /* First block */
1170 g_error("Can not map block");
1174 /* If the time is lower or equal the beginning of the trace,
1175 * go to the first event. */
1176 if(ltt_time_compare(time
, tf
->buffer
.start
.timestamp
) <= 0) {
1177 ret
= ltt_tracefile_read(tf
)
1178 goto found
; /* There is either no event in the trace or the event points
1179 to the first event in the trace */
1182 err
= map_block(tf
, tf
->num_blocks
- 1); /* Last block */
1184 g_error("Can not map block");
1188 /* If the time is after the end of the trace, get the last event. */
1189 if(ltt_time_compare(time
, tf
->buffer
.end
.timestamp
) >= 0) {
1190 /* While the ltt_tracefile_read doesn't return ERANGE or EPERM,
1194 ret
= ltt_tracefile_read(tf
);
1195 if(ret
== ERANGE
) goto found
; /* ERANGE or EPERM */
1196 else if(ret
) goto fail
;
1200 /* Binary search the block */
1201 high
= tf
->num_blocks
- 1;
1205 block_num
= ((high
-low
) / 2) + low
;
1207 err
= map_block(tf
, block_num
);
1209 g_error("Can not map block");
1213 /* We cannot divide anymore : this is what would happen if the time
1214 * requested was exactly between two consecutive buffers'end and start
1215 * timestamps. This is also what would happend if we didn't deal with out
1216 * of span cases prior in this function. */
1217 /* The event is right in the buffer!
1218 * (or in the next buffer first event) */
1220 ret
= ltt_tracefile_read(tf
);
1221 if(ret
== ERANGE
) goto found
; /* ERANGE or EPERM */
1222 else if(ret
) goto fail
;
1224 if(ltt_time_compare(time
, tf
->event
.event_time
) >= 0)
1228 } if(ltt_time_compare(time
, tf
->buffer
.start
.timestamp
) < 0) {
1229 /* go to lower part */
1231 } else if(ltt_time_compare(time
, tf
->buffer
.end
.timestamp
) > 0) {
1232 /* go to higher part */
1234 } else {/* The event is right in the buffer!
1235 (or in the next buffer first event) */
1237 ltt_tracefile_read(tf
);
1238 if(ret
== ERANGE
) goto found
; /* ERANGE or EPERM */
1239 else if(ret
) goto fail
;
1241 if(ltt_time_compare(time
, tf
->event
.event_time
) >= 0)
1251 /* Error handling */
1253 g_error("ltt_tracefile_seek_time failed on tracefile %s",
1254 g_quark_to_string(tf
->name
));
1259 int ltt_tracefile_seek_position(LttTracefile
*tf
, const LttEventPosition
*ep
) {
1263 if(ep
->tracefile
!= tf
) {
1267 err
= map_block(tf
, ep
->block
);
1269 g_error("Can not map block");
1273 tf
->event
.offset
= ep
->offset
;
1275 err
= ltt_tracefile_read_update_event(tf
);
1277 err
= ltt_tracefile_read_op(tf
);
1283 g_error("ltt_tracefile_seek_time failed on tracefile %s",
1284 g_quark_to_string(tf
->name
));
1287 /* Calculate the real event time based on the buffer boundaries */
1288 LttTime
ltt_interpolate_time(LttTracefile
*tf
, LttEvent
*event
)
1292 g_assert(t
->trace
->has_tsc
);
1294 time
= ltt_time_from_uint64(
1295 (guint64
)tf
->buffer
.tsc
*tf
->buffer
.nsecs_per_cycle
);
1296 time
= ltt_time_add(tf
->buffer
.begin
.timestamp
, time
);
1301 /*****************************************************************************
1303 * ltt_tracefile_read : Read the next event in the tracefile
1308 * Returns 0 if an event can be used in tf->event.
1309 * Returns ERANGE on end of trace. The event in tf->event still can be used.
1310 * Returns EPERM on error.
1312 * This function does make the tracefile event structure point to the event
1313 * currently pointed to by the tf->event.
1315 * Note : you must call a ltt_tracefile_seek to the beginning of the trace to
1316 * reinitialize it after an error if you want results to be coherent.
1317 * It would be the case if a end of trace last buffer has no event : the end
1318 * of trace wouldn't be returned, but an error.
1319 * We make the assumption there is at least one event per buffer.
1320 ****************************************************************************/
1322 int ltt_tracefile_read(LttTracefile
*tf
)
1326 err
= ltt_tracefile_read_seek(tf
);
1328 err
= ltt_tracefile_read_update_event(tf
);
1330 err
= ltt_tracefile_read_op(tf
);
1336 int ltt_tracefile_read_seek(LttTracefile
*tf
)
1340 /* Get next buffer until we finally have an event, or end of trace */
1342 err
= ltt_seek_next_event(tf
);
1343 if(unlikely(err
== ENOPROTOOPT
)) {
1347 /* Are we at the end of the buffer ? */
1349 if(unlikely(tf
->buffer
.index
== tf
->num_blocks
-1)){ /* end of trace ? */
1352 /* get next block */
1353 err
= map_block(tf
, tf
->buffer
.index
+ 1);
1355 g_error("Can not map block");
1359 } else break; /* We found an event ! */
1366 /* do specific operation on events */
1367 int ltt_tracefile_read_op(LttTracefile
*tf
)
1376 /* do event specific operation */
1378 /* do something if its an heartbeat event : increment the heartbeat count */
1379 if(event
->facility_id
!= 0) { /* except core */
1380 f
= (LttFacility
*)g_ptr_array_index(tf
->trace
->facilities
,
1381 event
->facility_id
);
1382 g_assert(f
!= NULL
);
1384 if(unlikely(ltt_facility_name(f
)
1385 != LTT_FACILITY_NAME_HEARTBEAT
)) {
1386 LttEventType
*et
= ltt_facility_eventtype_get_by_name(f
,
1387 LTT_EVENT_NAME_HEARTBEAT
);
1388 if(et
->id
== event
->event_id
)
1389 t
->cur_heart_beat_number
++;
1397 /* same as ltt_tracefile_read, but does not seek to the next event nor call
1398 * event specific operation. */
1399 int ltt_tracefile_read_update_event(LttTracefile
*tf
)
1407 pos
= event
->offset
;
1409 /* Read event header */
1413 if(tf
->trace
->has_tsc
) {
1414 event
->time
.timestamp
= ltt_get_uint32(LTT_GET_BO(t
),
1416 /* 32 bits -> 64 bits tsc */
1417 /* note : still works for seek and non seek cases. */
1418 if(event
->time
.timestamp
< (0xFFFFFFFFULL
&tf
->buffer
.tsc
)) {
1419 tf
->buffer
.tsc
= ((tf
->buffer
.tsc
&0xFFFFFFFF00000000ULL
)
1421 | (guint64
)event
->time
.timestamp
;
1424 tf
->buffer
.tsc
= (tf
->buffer
.tsc
&0xFFFFFFFF00000000ULL
)
1425 | (guint64
)event
->time
.timestamp
;
1428 event
->event_time
= ltt_interpolate_time(tf
, event
);
1430 pos
+= sizeof(uint32
);
1432 event
->time
.delta
= ltt_get_uint32(LTT_GET_BO(tf
),
1436 event
->event_time
= ltt_time_add(tf
->buffer
.begin
.timestamp
,
1438 pos
+= sizeof(uint32
);
1441 event
->facility_id
= ltt_get_uint8(LTT_GET_BO(tf
),
1443 pos
+= sizeof(uint8
);
1445 event
->event_id
= ltt_get_uint8(LTT_GET_BO(tf
),
1447 pos
+= sizeof(uint8
);
1449 event
->data
= tf
->cur_event_pos
+ EVENT_HEADER_SIZE
;
1457 /****************************************************************************
1459 * map_block : map a block from the file
1461 * lttdes : ltt trace file
1462 * whichBlock : the block which will be read
1465 * EINVAL : lseek fail
1466 * EIO : can not read from the file
1467 ****************************************************************************/
1469 static int map_block(LttTracefile
* tf
, int block_num
)
1471 struct ltt_block_start_header
*header
;
1473 g_assert(block_num
< tf
->num_blocks
);
1475 if(tf
->buffer
.head
!= NULL
)
1476 munmap(tf
->buffer
.head
, tf
->buf_size
);
1478 /* Multiple of pages aligned head */
1479 tf
->buffer
.head
= mmap(0, tf
->block_size
, PROT_READ
, tf
->fd
,
1480 (off_t
)tf
->block_size
* (off_t
)block_num
);
1482 if(tf
->buffer
.head
== NULL
) {
1483 perror("Error in allocating memory for buffer of tracefile %s\n", fileName
);
1486 g_assert(tf
->buffer
.head
& (8-1) == 0); // make sure it's aligned.
1489 tf
->buffer
.index
= block_num
;
1491 header
= (struct ltt_block_start_header
*)tf
->buffer
.head
;
1493 tf
->buffer
.begin
.timestamp
= ltt_get_uint64(LTT_GET_BO(tf
),
1494 header
->begin
.timestamp
)
1496 tf
->buffer
.begin
.cycle_count
= ltt_get_uint64(LTT_GET_BO(tf
),
1497 header
->begin
.cycle_count
);
1498 tf
->buffer
.end
.timestamp
= ltt_get_uint64(LTT_GET_BO(tf
),
1499 header
->end
.timestamp
)
1501 tf
->buffer
.end
.cycle_count
= ltt_get_uint64(LTT_GET_BO(tf
),
1502 header
->end
.cycle_count
);
1503 tf
->buffer
.lost_size
= ltt_get_uint32(LTT_GET_BO(tf
),
1506 tf
->buffer
.tsc
= tf
->buffer
.begin
.cycle_count
;
1509 * eventually support variable buffer size : will need a partial pre-read of
1510 * the headers to create an index when we open the trace... eventually. */
1511 g_assert(tf
->block_size
== ltt_get_uint32(header
->buf_size
));
1513 /* Now that the buffer is mapped, calculate the time interpolation for the
1516 tf
->buffer
.nsecs_per_cycle
= calc_nsecs_per_cycle(&tf
->buffer
);
1518 /* Make the current event point to the beginning of the buffer :
1519 * it means that the event read must get the first event. */
1520 tf
->event
.tracefile
= tf
;
1521 tf
->event
.block
= block_num
;
1522 tf
->event
.offset
= tf
->buffer
.head
;
1531 /* Take the tf current event offset and use the event facility id and event id
1532 * to figure out where is the next event offset.
1534 * This is an internal function not aiming at being used elsewhere : it will
1535 * not jump over the current block limits. Please consider using
1536 * ltt_tracefile_read to do this.
1538 * Returns 0 on success
1539 * ERANGE if we are at the end of the buffer.
1540 * ENOPROTOOPT if an error occured when getting the current event size.
1542 static int ltt_seek_next_event(LttTracefile
*tf
)
1547 /* seek over the buffer header if we are at the buffer start */
1548 if(tf
->event
.offset
== tf
->buffer
.head
) {
1549 tf
->event
.offset
+= sizeof(struct ltt_block_start_header
);
1554 if(tf
->event
.offset
== tf
->buffer
.head
+ tf
->buffer
.lost_size
) {
1559 pos
= tf
->event
.data
;
1561 /* FIXME : do this function. Remember to hardcode the sizes of heartbeat and
1563 pos
+= ltt_facility_get_event_size(tf
->event
.facility_id
, tf
->event
.event_id
);
1564 on error
: goto error
;
1566 tf
->event
.offset
= pos
;
1572 g_error("Error in ltt_seek_next_event for tracefile %s",
1573 g_quark_to_string(tf
->name
));
1578 /*****************************************************************************
1580 * calc_nsecs_per_cycle : calculate nsecs per cycle for current block
1583 ****************************************************************************/
1585 static double calc_nsecs_per_cycle(LttTracefile
* t
)
1587 LttTime lBufTotalTime
; /* Total time for this buffer */
1588 double lBufTotalNSec
; /* Total time for this buffer in nsecs */
1589 LttCycleCount lBufTotalCycle
;/* Total cycles for this buffer */
1591 /* Calculate the total time for this buffer */
1592 lBufTotalTime
= ltt_time_sub(
1593 ltt_get_time(t
->buffer
.end
.timestamp
),
1594 ltt_get_time(t
->buffer
.begin
.timestamp
));
1596 /* Calculate the total cycles for this bufffer */
1597 lBufTotalCycle
= t
->buffer
.end
.cycle_count
;
1598 lBufTotalCycle
-= t
->buffer
.start
.cycle_count
;
1600 /* Convert the total time to double */
1601 lBufTotalNSec
= ltt_time_to_double(lBufTotalTime
);
1603 return lBufTotalNSec
/ (double)lBufTotalCycle
;
1607 /*****************************************************************************
1609 * setFieldsOffset : set offset of the fields
1611 * tracefile : opened trace file
1612 * evT : the event type
1613 * evD : event data, it may be NULL
1614 ****************************************************************************/
1616 void setFieldsOffset(LttTracefile
*tf
,LttEventType
*evT
,void *evD
,LttTrace
* t
)
1618 LttField
* rootFld
= evT
->root_field
;
1619 // rootFld->base_address = evD;
1622 rootFld
->field_size
= getFieldtypeSize(tf
, evT
, 0,0,rootFld
, evD
,t
);
1625 /*****************************************************************************
1627 * getFieldtypeSize: get the size of the field type (primitive type)
1629 * tracefile : opened trace file
1631 * offsetRoot : offset from the root
1632 * offsetParent : offset from the parrent
1634 * evD : event data, it may be NULL
1636 * int : size of the field
1637 ****************************************************************************/
1639 static inline gint
getFieldtypeSize(LttTracefile
* t
,
1640 LttEventType
* evT
, gint offsetRoot
,
1641 gint offsetParent
, LttField
* fld
, void *evD
, LttTrace
*trace
)
1643 gint size
, size1
, element_number
, i
, offset1
, offset2
;
1644 LttType
* type
= fld
->field_type
;
1646 if(unlikely(t
&& evT
->latest_block
==t
->which_block
&&
1647 evT
->latest_event
==t
->which_event
)){
1648 size
= fld
->field_size
;
1649 goto end_getFieldtypeSize
;
1651 /* This likely has been tested with gcov : half of them.. */
1652 if(unlikely(fld
->field_fixed
== 1)){
1654 if(unlikely(fld
== evT
->root_field
)) {
1655 size
= fld
->field_size
;
1656 goto end_getFieldtypeSize
;
1660 /* From gcov profiling : half string, half struct, can we gain something
1661 * from that ? (Mathieu) */
1662 switch(type
->type_class
) {
1664 element_number
= (int) type
->element_number
;
1665 if(fld
->field_fixed
== -1){
1666 size
= getFieldtypeSize(t
, evT
, offsetRoot
,
1667 0,fld
->child
[0], NULL
, trace
);
1668 if(size
== 0){ //has string or sequence
1669 fld
->field_fixed
= 0;
1671 fld
->field_fixed
= 1;
1672 size
*= element_number
;
1674 }else if(fld
->field_fixed
== 0){// has string or sequence
1676 for(i
=0;i
<element_number
;i
++){
1677 size
+= getFieldtypeSize(t
, evT
, offsetRoot
+size
,size
,
1678 fld
->child
[0], evD
+size
, trace
);
1680 }else size
= fld
->field_size
;
1682 fld
->fixed_root
= (offsetRoot
==-1) ? 0 : 1;
1683 fld
->fixed_parent
= (offsetParent
==-1) ? 0 : 1;
1689 size1
= (int) ltt_type_size(trace
, type
);
1690 if(fld
->field_fixed
== -1){
1691 fld
->sequ_number_size
= size1
;
1692 fld
->field_fixed
= 0;
1693 size
= getFieldtypeSize(t
, evT
, offsetRoot
,
1694 0,fld
->child
[0], NULL
, trace
);
1695 fld
->element_size
= size
;
1697 element_number
= getIntNumber(t
->trace
->reverse_byte_order
,size1
,evD
);
1698 type
->element_number
= element_number
;
1699 if(fld
->element_size
> 0){
1700 size
= element_number
* fld
->element_size
;
1701 }else{//sequence has string or sequence
1703 for(i
=0;i
<element_number
;i
++){
1704 size
+= getFieldtypeSize(t
, evT
, offsetRoot
+size
+size1
,size
+size1
,
1705 fld
->child
[0], evD
+size
+size1
, trace
);
1711 fld
->fixed_root
= (offsetRoot
==-1) ? 0 : 1;
1712 fld
->fixed_parent
= (offsetParent
==-1) ? 0 : 1;
1719 if(fld
->field_fixed
== -1){
1720 fld
->field_fixed
= 0;
1722 /* Hope my implementation is faster than strlen (Mathieu) */
1723 char *ptr
=(char*)evD
;
1725 /* from gcov : many many strings are empty, make it the common case.*/
1726 while(unlikely(*ptr
!= '\0')) { size
++; ptr
++; }
1727 //size = ptr - (char*)evD + 1; //include end : '\0'
1729 fld
->fixed_root
= (offsetRoot
==-1) ? 0 : 1;
1730 fld
->fixed_parent
= (offsetParent
==-1) ? 0 : 1;
1735 element_number
= (int) type
->element_number
;
1737 /* tested with gcov */
1738 if(unlikely(fld
->field_fixed
== -1)){
1739 offset1
= offsetRoot
;
1741 for(i
=0;i
<element_number
;i
++){
1742 size1
=getFieldtypeSize(t
, evT
,offset1
,offset2
,
1743 fld
->child
[i
], NULL
, trace
);
1744 if(likely(size1
> 0 && size
>= 0)){
1746 if(likely(offset1
>= 0)) offset1
+= size1
;
1754 if(unlikely(size
== -1)){
1755 fld
->field_fixed
= 0;
1757 }else fld
->field_fixed
= 1;
1758 }else if(likely(fld
->field_fixed
== 0)){
1759 offset1
= offsetRoot
;
1761 for(i
=0;unlikely(i
<element_number
);i
++){
1762 size
=getFieldtypeSize(t
,evT
,offset1
,offset2
,
1763 fld
->child
[i
],evD
+offset2
, trace
);
1768 }else size
= fld
->field_size
;
1769 fld
->fixed_root
= (offsetRoot
==-1) ? 0 : 1;
1770 fld
->fixed_parent
= (offsetParent
==-1) ? 0 : 1;
1774 if(unlikely(fld
->field_fixed
== -1)){
1775 size
= (int) ltt_type_size(trace
, type
);
1776 fld
->field_fixed
= 1;
1777 }else size
= fld
->field_size
;
1779 fld
->fixed_root
= (offsetRoot
==-1) ? 0 : 1;
1780 fld
->fixed_parent
= (offsetParent
==-1) ? 0 : 1;
1786 fld
->offset_root
= offsetRoot
;
1787 fld
->offset_parent
= offsetParent
;
1788 fld
->field_size
= size
;
1790 end_getFieldtypeSize
:
1796 /*****************************************************************************
1798 * getIntNumber : get an integer number
1800 * size : the size of the integer
1801 * evD : the event data
1803 * gint64 : a 64 bits integer
1804 ****************************************************************************/
1806 gint64
getIntNumber(gboolean reverse_byte_order
, int size
, void *evD
)
1811 case 1: i
= *((gint8
*)evD
); break;
1812 case 2: i
= ltt_get_int16(reverse_byte_order
, evD
); break;
1813 case 4: i
= ltt_get_int32(reverse_byte_order
, evD
); break;
1814 case 8: i
= ltt_get_int64(reverse_byte_order
, evD
); break;
1815 default: i
= ltt_get_int64(reverse_byte_order
, evD
);
1816 g_critical("getIntNumber : integer size %d unknown", size
);
1823 /* get the node name of the system */
1825 char * ltt_trace_system_description_node_name (LttSystemDescription
* s
)
1827 return s
->node_name
;
1831 /* get the domain name of the system */
1833 char * ltt_trace_system_description_domain_name (LttSystemDescription
* s
)
1835 return s
->domain_name
;
1839 /* get the description of the system */
1841 char * ltt_trace_system_description_description (LttSystemDescription
* s
)
1843 return s
->description
;
1847 /* get the start time of the trace */
1849 LttTime
ltt_trace_system_description_trace_start_time(LttSystemDescription
*s
)
1851 return s
->trace_start
;
1855 LttTracefile
*ltt_tracefile_new()
1857 return g_new(LttTracefile
, 1);
1860 void ltt_tracefile_destroy(LttTracefile
*tf
)
1865 void ltt_tracefile_copy(LttTracefile
*dest
, const LttTracefile
*src
)
1870 /* Before library loading... */
1872 static void __attribute__((constructor
)) init(void)
1874 LTT_FACILITY_NAME_HEARTBEAT
= g_quark_from_string("heartbeat");
1875 LTT_EVENT_NAME_HEARTBEAT
= g_quark_from_string("heartbeat");
1877 LTT_TRACEFILE_NAME_FACILITIES
= g_quark_from_string("control/facilities");