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>
30 #define max(a,b) ((a)>(b)?(a):(b))
34 #define min(a,b) ((a)<(b)?(a):(b))
39 #define LTT_MAGIC_NUMBER 0x00D6B7ED
40 #define LTT_REV_MAGIC_NUMBER 0xEDB7D600
42 #define NSEC_PER_USEC 1000
44 #define LTT_PACKED_STRUCT __attribute__ ((packed))
46 /* Hardcoded facilities */
47 #define LTT_FACILITY_CORE 0
50 #define LTT_GET_BO(t) ((t)->reverse_bo)
52 #define LTT_HAS_FLOAT(t) ((t)->float_word_order!=0)
53 #define LTT_GET_FLOAT_BO(t) \
54 (((t)->float_word_order==__BYTE_ORDER)?0:1)
56 #define SEQUENCE_AVG_ELEMENTS 1000
58 /* Hardcoded core events */
59 enum ltt_core_events
{
60 LTT_EVENT_FACILITY_LOAD
,
61 LTT_EVENT_FACILITY_UNLOAD
,
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
;
130 typedef struct _TimeHeartbeat
{
131 LttTime time
; //Time stamp of this block
132 uint64_t cycle_count
; //cycle count of the event
133 } LTT_PACKED_STRUCT TimeHeartbeat
;
135 struct ltt_event_header_hb
{
137 unsigned char facility_id
;
138 unsigned char event_id
;
142 struct ltt_event_header_nohb
{
144 unsigned char facility_id
;
145 unsigned char event_id
;
150 /* Block and trace headers */
152 struct ltt_trace_header_any
{
153 uint32_t magic_number
;
155 uint32_t arch_variant
;
156 uint32_t float_word_order
;
158 uint8_t major_version
;
159 uint8_t minor_version
;
160 uint8_t flight_recorder
;
161 uint8_t has_heartbeat
;
162 uint8_t has_alignment
; /* Event header alignment */
167 /* For version 0.3 */
169 struct ltt_trace_header_0_3
{
170 uint32_t magic_number
;
172 uint32_t arch_variant
;
173 uint32_t float_word_order
;
175 uint8_t major_version
;
176 uint8_t minor_version
;
177 uint8_t flight_recorder
;
178 uint8_t has_heartbeat
;
179 uint8_t has_alignment
; /* Event header alignment */
183 /* For version 0.7 */
185 struct ltt_trace_header_0_7
{
186 uint32_t magic_number
;
188 uint32_t arch_variant
;
189 uint32_t float_word_order
;
191 uint8_t major_version
;
192 uint8_t minor_version
;
193 uint8_t flight_recorder
;
194 uint8_t has_heartbeat
;
195 uint8_t has_alignment
; /* Event header alignment */
199 uint64_t start_monotonic
;
200 uint64_t start_time_sec
;
201 uint64_t start_time_usec
;
205 struct ltt_block_start_header
{
207 uint64_t cycle_count
;
211 uint64_t cycle_count
;
214 uint32_t lost_size
; /* Size unused at the end of the buffer */
215 uint32_t buf_size
; /* The size of this sub-buffer */
216 struct ltt_trace_header_any trace
[0];
221 // LTTV does not care about type names. Everything is a field.
222 // GQuark type_name; //type name if it is a named type
225 LttTypeEnum type_class
; //which type
226 GHashTable
*enum_map
; //maps enum labels to numbers.
227 GArray
*fields
; // Array of LttFields, for array, sequence, union, struct.
228 GData
*fields_by_name
;
231 struct _LttEventType
{
234 guint index
; //id of the event type within the facility
235 LttFacility
* facility
; //the facility that contains the event type
236 GArray
* fields
; //event's fields (LttField)
237 GData
*fields_by_name
;
240 /* Structure LttEvent and LttEventPosition must begin with the _exact_ same
241 * fields in the exact same order. LttEventPosition is a parent of LttEvent. */
244 /* Begin of LttEventPosition fields */
245 LttTracefile
*tracefile
;
250 uint64_t tsc
; /* Current timestamp counter */
252 /* End of LttEventPosition fields */
254 guint32 timestamp
; /* truncated timestamp */
256 unsigned char facility_id
; /* facility ID are never reused. */
257 unsigned char event_id
;
261 void * data
; //event data
263 guint event_size
; //event_size field of the header :
264 //used to verify data_size from facility.
266 int count
; //the number of overflow of cycle count
267 gint64 overflow_nsec
; //precalculated nsec for overflows
270 struct _LttEventPosition
{
271 LttTracefile
*tracefile
;
276 uint64_t tsc
; /* Current timestamp counter */
280 enum field_status
{ FIELD_UNKNOWN
, FIELD_VARIABLE
, FIELD_FIXED
};
285 LttType field_type
; //field type
287 off_t offset_root
; //offset from the root
288 enum field_status fixed_root
; //offset fixed according to the root
290 guint field_size
; // size of the field
291 // Only if field type size is set to 0
292 // (it's variable), then the field_size should be
293 // dynamically calculated while reading the trace
294 // and put here. Otherwise, the field_size always
295 // equels the type size.
296 off_t array_offset
; // offset of the beginning of the array (for array
298 GArray
* dynamic_offsets
; // array of offsets calculated dynamically at
299 // each event for sequences and arrays that
300 // contain variable length fields.
306 guint32 checksum
; //checksum of the facility
307 guint32 id
; //id of the facility
311 guint32 pointer_size
;
316 GData
*events_by_name
;
317 // not necessary in LTTV GData *named_types;
319 unsigned char exists
; /* 0 does not exist, 1 exists */
322 typedef struct _LttBuffer
{
328 uint64_t cycle_count
;
329 uint64_t freq
; /* Frequency in khz */
333 uint64_t cycle_count
;
334 uint64_t freq
; /* Frequency in khz */
336 uint32_t lost_size
; /* Size unused at the end of the buffer */
339 uint64_t tsc
; /* Current timestamp counter */
340 uint64_t freq
; /* Frequency in khz */
341 //double nsecs_per_cycle; /* Precalculated from freq */
342 guint32 cyc2ns_scale
;
345 struct _LttTracefile
{
346 gboolean cpu_online
; //is the cpu online ?
347 GQuark long_name
; //tracefile complete filename
348 GQuark name
; //tracefile name
349 guint cpu_num
; //cpu number of the tracefile
350 LttTrace
* trace
; //trace containing the tracefile
351 int fd
; //file descriptor
352 off_t file_size
; //file size
353 //unsigned block_size; //block_size
354 guint num_blocks
; //number of blocks in the file
355 gboolean reverse_bo
; //must we reverse byte order ?
356 gboolean float_word_order
; //what is the byte order of floats ?
357 size_t has_alignment
; //alignment of events in the tracefile.
358 // 0 or the architecture size in bytes.
360 size_t buffer_header_size
;
363 LttEvent event
; //Event currently accessible in the trace
366 LttBuffer buffer
; //current buffer
367 guint32 buf_size
; /* The size of blocks */
370 //unsigned int count; //the number of overflow of cycle count
371 //double nsec_per_cycle; //Nsec per cycle
372 //TimeHeartbeat * last_heartbeat; //last heartbeat
374 //LttCycleCount cycles_per_nsec_reciprocal; // Optimisation for speed
375 //void * last_event_pos;
377 //LttTime prev_block_end_time; //the end time of previous block
378 //LttTime prev_event_time; //the time of the previous event
379 //LttCycleCount pre_cycle_count; //previous cycle count of the event
383 GQuark pathname
; //the pathname of the trace
384 //LttSystemDescription * system_description;//system description
386 GArray
*facilities_by_num
; /* fac_id as index in array */
387 GData
*facilities_by_name
; /* fac name (GQuark) as index */
388 /* Points to array of fac_id of all the
389 * facilities that has this name. */
393 guint32 arch_variant
;
395 guint8 ltt_major_version
;
396 guint8 ltt_minor_version
;
397 guint8 flight_recorder
;
398 guint8 has_heartbeat
;
402 uint64_t start_monotonic
;
404 LttTime start_time_from_tsc
;
406 GData
*tracefiles
; //tracefiles groups
409 /* The characteristics of the system on which the trace was obtained
410 is described in a LttSystemDescription structure. */
412 struct _LttSystemDescription
{
418 LttArchEndian endian
;
420 gchar
*kernel_release
;
421 gchar
*kernel_version
;
424 gchar
*hardware_platform
;
425 gchar
*operating_system
;
430 /*****************************************************************************
431 macro for size of some data types
432 *****************************************************************************/
433 // alignment -> dynamic!
435 //#define TIMESTAMP_SIZE sizeof(guint32)
436 //#define EVENT_ID_SIZE sizeof(guint16)
437 //#define EVENT_HEADER_SIZE (TIMESTAMP_SIZE + EVENT_ID_SIZE)
440 /* Calculate the offset needed to align the type.
441 * If has_alignment is 0, alignment is disactivated.
442 * else, the function returns the offset needed to
443 * align align_drift on the has_alignment value (should be
444 * the size of the architecture). */
445 static inline unsigned int ltt_align(size_t align_drift
,
447 size_t has_alignment
)
449 size_t alignment
= min(has_alignment
, size_of_type
);
451 if(!has_alignment
) return 0;
453 return ((alignment
- align_drift
) & (alignment
-1));
457 #endif /* LTT_PRIVATE_H */