1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Xiangxiu Yang
3 * 2006 Mathieu Desnoyers
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License Version 2.1 as published by the Free Software Foundation.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
24 #include <sys/types.h>
29 #define max(a,b) ((a)>(b)?(a):(b))
33 #define min(a,b) ((a)<(b)?(a):(b))
38 #define LTT_MAGIC_NUMBER 0x00D6B7ED
39 #define LTT_REV_MAGIC_NUMBER 0xEDB7D600
41 #define NSEC_PER_USEC 1000
43 #define LTT_PACKED_STRUCT __attribute__ ((packed))
45 /* Hardcoded facilities */
46 #define LTT_FACILITY_CORE 0
49 #define LTT_GET_BO(t) ((t)->reverse_bo)
51 #define LTT_HAS_FLOAT(t) ((t)->float_word_order!=0)
52 #define LTT_GET_FLOAT_BO(t) \
53 (((t)->float_word_order==__BYTE_ORDER)?0:1)
55 #define SEQUENCE_AVG_ELEMENTS 1000
57 /* Hardcoded core events */
58 enum ltt_core_events
{
59 LTT_EVENT_FACILITY_LOAD
,
60 LTT_EVENT_FACILITY_UNLOAD
,
62 LTT_EVENT_HEARTBEAT_FULL
,
63 LTT_EVENT_STATE_DUMP_FACILITY_LOAD
68 /* enumeration definition */
70 typedef enum _BuildinEvent
{
71 TRACE_FACILITY_LOAD
= 0,
72 TRACE_BLOCK_START
= 17,
74 TRACE_TIME_HEARTBEAT
= 19
78 /* structure definition */
80 typedef struct _FacilityLoad
{
84 } LTT_PACKED_STRUCT FacilityLoad
;
86 typedef struct _BlockStart
{
87 LttTime time
; //Time stamp of this block
88 LttCycleCount cycle_count
; //cycle count of the event
89 guint32 block_id
; //block id
90 } LTT_PACKED_STRUCT BlockStart
;
92 typedef struct _BlockEnd
{
93 LttTime time
; //Time stamp of this block
94 LttCycleCount cycle_count
; //cycle count of the event
95 guint32 block_id
; //block id
96 } LTT_PACKED_STRUCT BlockEnd
;
100 typedef guint8
uint8_t;
101 typedef guint16
uint16_t;
102 typedef guint32
uint32_t;
103 typedef guint64
uint64_t;
105 /* Hardcoded facility load event : this plus an preceding "name" string */
106 struct LttFacilityLoad
{
111 guint32 pointer_size
;
113 guint32 has_alignment
;
116 struct LttFacilityUnload
{
120 struct LttStateDumpFacilityLoad
{
125 guint32 pointer_size
;
127 guint32 has_alignment
;
131 typedef struct _TimeHeartbeat
{
132 } LTT_PACKED_STRUCT TimeHeartbeat
;
134 typedef struct _TimeHeartbeatFull
{
136 } LTT_PACKED_STRUCT TimeHeartbeatFull
;
138 struct ltt_event_header_hb
{
144 struct ltt_event_header_nohb
{
151 /* Block and trace headers */
153 struct ltt_trace_header_any
{
154 uint32_t magic_number
;
156 uint32_t arch_variant
;
157 uint32_t float_word_order
;
159 uint8_t major_version
;
160 uint8_t minor_version
;
161 uint8_t flight_recorder
;
162 uint8_t has_heartbeat
;
163 uint8_t has_alignment
; /* Event header alignment */
167 struct ltt_trace_header_1_0
{
168 uint32_t magic_number
;
170 uint32_t arch_variant
;
171 uint32_t float_word_order
;
173 uint8_t major_version
;
174 uint8_t minor_version
;
175 uint8_t flight_recorder
;
176 uint8_t has_heartbeat
;
177 uint8_t has_alignment
; /* Event header alignment */
178 uint8_t tsc_lsb_truncate
;
183 uint64_t start_monotonic
;
184 uint64_t start_time_sec
;
185 uint64_t start_time_usec
;
189 struct ltt_block_start_header
{
191 uint64_t cycle_count
;
195 uint64_t cycle_count
;
198 uint32_t lost_size
; /* Size unused at the end of the buffer */
199 uint32_t buf_size
; /* The size of this sub-buffer */
200 struct ltt_trace_header_any trace
[0];
205 // LTTV does not care about type names. Everything is a field.
206 // GQuark type_name; //type name if it is a named type
209 LttTypeEnum type_class
; //which type
210 GHashTable
*enum_map
; //maps enum labels to numbers.
211 gint32 highest_value
; //For enum
212 gint32 lowest_value
; //For enum
213 GArray
*fields
; // Array of LttFields, for array, sequence, union, struct.
214 GData
*fields_by_name
;
215 guint network
; // Is the type in network byte order ?
216 //part added by gaby for fmt:
223 struct _LttEventType
{
226 guint index
; //id of the event type within the facility
227 struct marker_info
*info
;
228 GArray
* fields
; //event's fields (LttField)
229 GData
*fields_by_name
;
230 int has_compact_data
; //event header contains compact data (first field)
234 /* Structure LttEvent and LttEventPosition must begin with the _exact_ same
235 * fields in the exact same order. LttEventPosition is a parent of LttEvent. */
238 /* Begin of LttEventPosition fields */
239 LttTracefile
*tracefile
;
244 uint64_t tsc
; /* Current timestamp counter */
246 /* End of LttEventPosition fields */
248 guint32 timestamp
; /* truncated timestamp */
254 void * data
; //event data
256 guint event_size
; //event_size field of the header :
257 //used to verify data_size from facility.
258 uint32_t compact_data
;
260 int count
; //the number of overflow of cycle count
261 gint64 overflow_nsec
; //precalculated nsec for overflows
264 struct _LttEventPosition
{
265 LttTracefile
*tracefile
;
270 uint64_t tsc
; /* Current timestamp counter */
274 enum field_status
{ FIELD_UNKNOWN
, FIELD_VARIABLE
, FIELD_FIXED
};
279 LttType field_type
; //field type
281 off_t offset_root
; //offset from the root
282 enum field_status fixed_root
; //offset fixed according to the root
284 guint field_size
; // size of the field
285 // Only if field type size is set to 0
286 // (it's variable), then the field_size should be
287 // dynamically calculated while reading the trace
288 // and put here. Otherwise, the field_size always
289 // equals the type size.
290 off_t array_offset
; // offset of the beginning of the array (for array
292 GArray
* dynamic_offsets
; // array of offsets calculated dynamically at
293 // each event for sequences and arrays that
294 // contain variable length fields.
301 guint32 checksum
; //checksum of the facility
302 guint32 id
; //id of the facility
306 guint32 pointer_size
;
311 GData
*events_by_name
;
312 // not necessary in LTTV GData *named_types;
314 unsigned char exists
; /* 0 does not exist, 1 exists */
318 typedef struct _LttBuffer
{
324 uint64_t cycle_count
;
325 uint64_t freq
; /* Frequency in khz */
329 uint64_t cycle_count
;
330 uint64_t freq
; /* Frequency in khz */
332 uint32_t lost_size
; /* Size unused at the end of the buffer */
335 uint64_t tsc
; /* Current timestamp counter */
336 uint64_t freq
; /* Frequency in khz */
337 //double nsecs_per_cycle; /* Precalculated from freq */
338 guint32 cyc2ns_scale
;
341 struct _LttTracefile
{
342 gboolean cpu_online
; //is the cpu online ?
343 GQuark long_name
; //tracefile complete filename
344 GQuark name
; //tracefile name
345 guint cpu_num
; //cpu number of the tracefile
346 guint tid
; //Usertrace tid, else 0
347 guint pgid
; //Usertrace pgid, else 0
348 guint64 creation
; //Usertrace creation, else 0
349 LttTrace
* trace
; //trace containing the tracefile
350 int fd
; //file descriptor
351 off_t file_size
; //file size
352 //unsigned block_size; //block_size
353 guint num_blocks
; //number of blocks in the file
354 gboolean reverse_bo
; //must we reverse byte order ?
355 gboolean float_word_order
; //what is the byte order of floats ?
356 size_t has_alignment
; //alignment of events in the tracefile.
357 // 0 or the architecture size in bytes.
359 guint8 has_heartbeat
;
360 size_t buffer_header_size
;
361 int compact
; //compact tracefile ?
362 uint8_t tsc_lsb_truncate
;
364 uint8_t tsc_msb_cutoff
;
366 uint64_t tsc_mask_next_bit
; //next MSB after the mask
369 LttEvent event
; //Event currently accessible in the trace
372 LttBuffer buffer
; //current buffer
373 guint32 buf_size
; /* The size of blocks */
376 //unsigned int count; //the number of overflow of cycle count
377 //double nsec_per_cycle; //Nsec per cycle
378 //TimeHeartbeat * last_heartbeat; //last heartbeat
380 //LttCycleCount cycles_per_nsec_reciprocal; // Optimisation for speed
381 //void * last_event_pos;
383 //LttTime prev_block_end_time; //the end time of previous block
384 //LttTime prev_event_time; //the time of the previous event
385 //LttCycleCount pre_cycle_count; //previous cycle count of the event
389 GQuark pathname
; //the pathname of the trace
390 //LttSystemDescription * system_description;//system description
392 GArray
*facilities_by_num
; /* fac_id as index in array */
393 GData
*facilities_by_name
; /* fac name (GQuark) as index */
394 /* Points to array of fac_id of all the
395 * facilities that has this name. */
399 guint32 arch_variant
;
401 guint8 ltt_major_version
;
402 guint8 ltt_minor_version
;
403 guint8 flight_recorder
;
407 uint64_t start_monotonic
;
409 LttTime start_time_from_tsc
;
410 uint8_t compact_event_bits
;
412 GData
*tracefiles
; //tracefiles groups
413 /* Support for markers */
414 GArray
*markers
; //indexed by marker ID
415 GHashTable
*markers_hash
; //indexed by name hash
418 /* The characteristics of the system on which the trace was obtained
419 is described in a LttSystemDescription structure. */
421 struct _LttSystemDescription
{
427 LttArchEndian endian
;
429 gchar
*kernel_release
;
430 gchar
*kernel_version
;
433 gchar
*hardware_platform
;
434 gchar
*operating_system
;
439 /*****************************************************************************
440 macro for size of some data types
441 *****************************************************************************/
442 // alignment -> dynamic!
444 //#define TIMESTAMP_SIZE sizeof(guint32)
445 //#define EVENT_ID_SIZE sizeof(guint16)
446 //#define EVENT_HEADER_SIZE (TIMESTAMP_SIZE + EVENT_ID_SIZE)
449 off_t
get_alignment(LttField
*field
);
451 /* Calculate the offset needed to align the type.
452 * If has_alignment is 0, alignment is disactivated.
453 * else, the function returns the offset needed to
454 * align align_drift on the has_alignment value (should be
455 * the size of the architecture). */
456 static inline unsigned int ltt_align(size_t align_drift
,
458 size_t has_alignment
)
460 size_t alignment
= min(has_alignment
, size_of_type
);
462 if(!has_alignment
) return 0;
464 g_assert(size_of_type
!= 0);
465 return ((alignment
- align_drift
) & (alignment
-1));
469 #endif /* LTT_PRIVATE_H */