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_HEARTBEAT_FULL
,
64 LTT_EVENT_STATE_DUMP_FACILITY_LOAD
69 /* enumeration definition */
71 typedef enum _BuildinEvent
{
72 TRACE_FACILITY_LOAD
= 0,
73 TRACE_BLOCK_START
= 17,
75 TRACE_TIME_HEARTBEAT
= 19
79 /* structure definition */
81 typedef struct _FacilityLoad
{
85 } LTT_PACKED_STRUCT FacilityLoad
;
87 typedef struct _BlockStart
{
88 LttTime time
; //Time stamp of this block
89 LttCycleCount cycle_count
; //cycle count of the event
90 guint32 block_id
; //block id
91 } LTT_PACKED_STRUCT BlockStart
;
93 typedef struct _BlockEnd
{
94 LttTime time
; //Time stamp of this block
95 LttCycleCount cycle_count
; //cycle count of the event
96 guint32 block_id
; //block id
97 } LTT_PACKED_STRUCT BlockEnd
;
101 typedef guint8
uint8_t;
102 typedef guint16
uint16_t;
103 typedef guint32
uint32_t;
104 typedef guint64
uint64_t;
106 /* Hardcoded facility load event : this plus an preceding "name" string */
107 struct LttFacilityLoad
{
112 guint32 pointer_size
;
114 guint32 has_alignment
;
117 struct LttFacilityUnload
{
121 struct LttStateDumpFacilityLoad
{
126 guint32 pointer_size
;
128 guint32 has_alignment
;
132 typedef struct _TimeHeartbeat
{
133 } LTT_PACKED_STRUCT TimeHeartbeat
;
135 typedef struct _TimeHeartbeatFull
{
137 } LTT_PACKED_STRUCT TimeHeartbeatFull
;
139 struct ltt_event_header_hb
{
141 unsigned char facility_id
;
142 unsigned char event_id
;
146 struct ltt_event_header_nohb
{
148 unsigned char facility_id
;
149 unsigned char event_id
;
154 /* Block and trace headers */
156 struct ltt_trace_header_any
{
157 uint32_t magic_number
;
159 uint32_t arch_variant
;
160 uint32_t float_word_order
;
162 uint8_t major_version
;
163 uint8_t minor_version
;
164 uint8_t flight_recorder
;
165 uint8_t has_heartbeat
;
166 uint8_t has_alignment
; /* Event header alignment */
171 /* For version 0.3 */
173 struct ltt_trace_header_0_3
{
174 uint32_t magic_number
;
176 uint32_t arch_variant
;
177 uint32_t float_word_order
;
179 uint8_t major_version
;
180 uint8_t minor_version
;
181 uint8_t flight_recorder
;
182 uint8_t has_heartbeat
;
183 uint8_t has_alignment
; /* Event header alignment */
187 /* For version 0.7 */
189 struct ltt_trace_header_0_7
{
190 uint32_t magic_number
;
192 uint32_t arch_variant
;
193 uint32_t float_word_order
;
195 uint8_t major_version
;
196 uint8_t minor_version
;
197 uint8_t flight_recorder
;
198 uint8_t has_heartbeat
;
199 uint8_t has_alignment
; /* Event header alignment */
203 uint64_t start_monotonic
;
204 uint64_t start_time_sec
;
205 uint64_t start_time_usec
;
208 /* For version 0.8 */
210 struct ltt_trace_header_0_8
{
211 uint32_t magic_number
;
213 uint32_t arch_variant
;
214 uint32_t float_word_order
;
216 uint8_t major_version
;
217 uint8_t minor_version
;
218 uint8_t flight_recorder
;
219 uint8_t has_heartbeat
;
220 uint8_t has_alignment
; /* Event header alignment */
221 uint8_t tsc_lsb_truncate
;
226 uint64_t start_monotonic
;
227 uint64_t start_time_sec
;
228 uint64_t start_time_usec
;
232 struct ltt_block_start_header
{
234 uint64_t cycle_count
;
238 uint64_t cycle_count
;
241 uint32_t lost_size
; /* Size unused at the end of the buffer */
242 uint32_t buf_size
; /* The size of this sub-buffer */
243 struct ltt_trace_header_any trace
[0];
248 // LTTV does not care about type names. Everything is a field.
249 // GQuark type_name; //type name if it is a named type
252 LttTypeEnum type_class
; //which type
253 GHashTable
*enum_map
; //maps enum labels to numbers.
254 gint32 highest_value
; //For enum
255 gint32 lowest_value
; //For enum
256 GArray
*fields
; // Array of LttFields, for array, sequence, union, struct.
257 GData
*fields_by_name
;
258 guint network
; // Is the type in network byte order ?
261 struct _LttEventType
{
264 guint index
; //id of the event type within the facility
265 LttFacility
* facility
; //the facility that contains the event type
266 GArray
* fields
; //event's fields (LttField)
267 GData
*fields_by_name
;
268 int has_compact_data
; //event header contains compact data (first field)
271 /* Structure LttEvent and LttEventPosition must begin with the _exact_ same
272 * fields in the exact same order. LttEventPosition is a parent of LttEvent. */
275 /* Begin of LttEventPosition fields */
276 LttTracefile
*tracefile
;
281 uint64_t tsc
; /* Current timestamp counter */
283 /* End of LttEventPosition fields */
285 guint32 timestamp
; /* truncated timestamp */
287 unsigned char facility_id
; /* facility ID are never reused. */
288 unsigned char event_id
;
292 void * data
; //event data
294 guint event_size
; //event_size field of the header :
295 //used to verify data_size from facility.
296 uint32_t compact_data
;
298 int count
; //the number of overflow of cycle count
299 gint64 overflow_nsec
; //precalculated nsec for overflows
302 struct _LttEventPosition
{
303 LttTracefile
*tracefile
;
308 uint64_t tsc
; /* Current timestamp counter */
312 enum field_status
{ FIELD_UNKNOWN
, FIELD_VARIABLE
, FIELD_FIXED
};
317 LttType field_type
; //field type
319 off_t offset_root
; //offset from the root
320 enum field_status fixed_root
; //offset fixed according to the root
322 guint field_size
; // size of the field
323 // Only if field type size is set to 0
324 // (it's variable), then the field_size should be
325 // dynamically calculated while reading the trace
326 // and put here. Otherwise, the field_size always
327 // equals the type size.
328 off_t array_offset
; // offset of the beginning of the array (for array
330 GArray
* dynamic_offsets
; // array of offsets calculated dynamically at
331 // each event for sequences and arrays that
332 // contain variable length fields.
338 guint32 checksum
; //checksum of the facility
339 guint32 id
; //id of the facility
343 guint32 pointer_size
;
348 GData
*events_by_name
;
349 // not necessary in LTTV GData *named_types;
351 unsigned char exists
; /* 0 does not exist, 1 exists */
354 typedef struct _LttBuffer
{
360 uint64_t cycle_count
;
361 uint64_t freq
; /* Frequency in khz */
365 uint64_t cycle_count
;
366 uint64_t freq
; /* Frequency in khz */
368 uint32_t lost_size
; /* Size unused at the end of the buffer */
371 uint64_t tsc
; /* Current timestamp counter */
372 uint64_t freq
; /* Frequency in khz */
373 //double nsecs_per_cycle; /* Precalculated from freq */
374 guint32 cyc2ns_scale
;
377 struct _LttTracefile
{
378 gboolean cpu_online
; //is the cpu online ?
379 GQuark long_name
; //tracefile complete filename
380 GQuark name
; //tracefile name
381 guint cpu_num
; //cpu number of the tracefile
382 guint tid
; //Usertrace tid, else 0
383 guint pgid
; //Usertrace pgid, else 0
384 guint64 creation
; //Usertrace creation, else 0
385 LttTrace
* trace
; //trace containing the tracefile
386 int fd
; //file descriptor
387 off_t file_size
; //file size
388 //unsigned block_size; //block_size
389 guint num_blocks
; //number of blocks in the file
390 gboolean reverse_bo
; //must we reverse byte order ?
391 gboolean float_word_order
; //what is the byte order of floats ?
392 size_t has_alignment
; //alignment of events in the tracefile.
393 // 0 or the architecture size in bytes.
395 guint8 has_heartbeat
;
396 size_t buffer_header_size
;
397 int compact
; //compact tracefile ?
398 uint8_t tsc_lsb_truncate
;
400 uint8_t tsc_msb_cutoff
;
402 uint64_t tsc_mask_next_bit
; //next MSB after the mask
405 LttEvent event
; //Event currently accessible in the trace
408 LttBuffer buffer
; //current buffer
409 guint32 buf_size
; /* The size of blocks */
412 //unsigned int count; //the number of overflow of cycle count
413 //double nsec_per_cycle; //Nsec per cycle
414 //TimeHeartbeat * last_heartbeat; //last heartbeat
416 //LttCycleCount cycles_per_nsec_reciprocal; // Optimisation for speed
417 //void * last_event_pos;
419 //LttTime prev_block_end_time; //the end time of previous block
420 //LttTime prev_event_time; //the time of the previous event
421 //LttCycleCount pre_cycle_count; //previous cycle count of the event
425 GQuark pathname
; //the pathname of the trace
426 //LttSystemDescription * system_description;//system description
428 GArray
*facilities_by_num
; /* fac_id as index in array */
429 GData
*facilities_by_name
; /* fac name (GQuark) as index */
430 /* Points to array of fac_id of all the
431 * facilities that has this name. */
435 guint32 arch_variant
;
437 guint8 ltt_major_version
;
438 guint8 ltt_minor_version
;
439 guint8 flight_recorder
;
443 uint64_t start_monotonic
;
445 LttTime start_time_from_tsc
;
446 GArray
*compact_facilities
;
447 uint8_t compact_event_bits
;
449 GData
*tracefiles
; //tracefiles groups
452 /* The characteristics of the system on which the trace was obtained
453 is described in a LttSystemDescription structure. */
455 struct _LttSystemDescription
{
461 LttArchEndian endian
;
463 gchar
*kernel_release
;
464 gchar
*kernel_version
;
467 gchar
*hardware_platform
;
468 gchar
*operating_system
;
473 /*****************************************************************************
474 macro for size of some data types
475 *****************************************************************************/
476 // alignment -> dynamic!
478 //#define TIMESTAMP_SIZE sizeof(guint32)
479 //#define EVENT_ID_SIZE sizeof(guint16)
480 //#define EVENT_HEADER_SIZE (TIMESTAMP_SIZE + EVENT_ID_SIZE)
483 off_t
get_alignment(LttField
*field
);
485 /* Calculate the offset needed to align the type.
486 * If has_alignment is 0, alignment is disactivated.
487 * else, the function returns the offset needed to
488 * align align_drift on the has_alignment value (should be
489 * the size of the architecture). */
490 static inline unsigned int ltt_align(size_t align_drift
,
492 size_t has_alignment
)
494 size_t alignment
= min(has_alignment
, size_of_type
);
496 if(!has_alignment
) return 0;
498 g_assert(size_of_type
!= 0);
499 return ((alignment
- align_drift
) & (alignment
-1));
503 #endif /* LTT_PRIVATE_H */