1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Xiangxiu Yang
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation;
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
23 #include <sys/types.h>
28 #define max(a,b) ((a)>(b)?(a):(b))
32 #define LTT_MAGIC_NUMBER 0x00D6B7ED
33 #define LTT_REV_MAGIC_NUMBER 0xEDB7D600
35 #define NSEC_PER_USEC 1000
37 #define LTT_PACKED_STRUCT __attribute__ ((packed))
39 /* Hardcoded facilities */
40 #define LTT_FACILITY_CORE 0
42 /* Hardcoded core events */
43 enum ltt_core_events
{
44 LTT_EVENT_FACILITY_LOAD
,
45 LTT_EVENT_FACILITY_UNLOAD
,
46 LTT_EVENT_STATE_DUMP_FACILITY_LOAD
,
52 /* enumeration definition */
54 typedef enum _BuildinEvent
{
55 TRACE_FACILITY_LOAD
= 0,
56 TRACE_BLOCK_START
= 17,
58 TRACE_TIME_HEARTBEAT
= 19
62 /* structure definition */
64 typedef struct _FacilityLoad
{
68 } LTT_PACKED_STRUCT FacilityLoad
;
70 typedef struct _BlockStart
{
71 LttTime time
; //Time stamp of this block
72 LttCycleCount cycle_count
; //cycle count of the event
73 guint32 block_id
; //block id
74 } LTT_PACKED_STRUCT BlockStart
;
76 typedef struct _BlockEnd
{
77 LttTime time
; //Time stamp of this block
78 LttCycleCount cycle_count
; //cycle count of the event
79 guint32 block_id
; //block id
80 } LTT_PACKED_STRUCT BlockEnd
;
84 typedef guint8
uint8_t;
85 typedef guint16
uint16_t;
86 typedef guint32
uint32_t;
87 typedef guint64
uint64_t;
89 /* Hardcoded facility load event : this plus an following "name" string */
90 struct LttFacilityLoad
{
99 struct LttFacilityUnload
{
103 struct LttStateDumpFacilityLoad
{
107 guint32 pointer_size
;
114 typedef struct _TimeHeartbeat
{
115 LttTime time
; //Time stamp of this block
116 uint64_t cycle_count
; //cycle count of the event
117 } LTT_PACKED_STRUCT TimeHeartbeat
;
119 struct ltt_event_header_hb
{
121 unsigned char facility_id
;
122 unsigned char event_id
;
124 } __attribute((aligned(8)));
126 struct ltt_event_header_nohb
{
128 unsigned char facility_id
;
129 unsigned char event_id
;
131 } __attribute((aligned(8)));
133 struct ltt_trace_header
{
134 uint32_t magic_number
;
136 uint32_t arch_variant
;
138 //uint32_t system_type;
139 uint8_t major_version
;
140 uint8_t minor_version
;
141 uint8_t flight_recorder
;
142 uint8_t has_heartbeat
;
143 uint8_t has_alignment
; /* Event header alignment */
145 } __attribute((aligned(8)));
148 struct ltt_block_start_header
{
150 struct timeval timestamp
;
151 uint64_t cycle_count
;
154 struct timeval timestamp
;
155 uint64_t cycle_count
;
157 uint32_t lost_size
; /* Size unused at the end of the buffer */
158 uint32_t buf_size
; /* The size of this sub-buffer */
159 struct ltt_trace_header trace
;
160 } __attribute((aligned(8)));
164 GQuark type_name
; //type name if it is a named type
165 GQuark element_name
; //elements name of the struct
168 LttTypeEnum type_class
; //which type
169 GQuark
* enum_strings
; //for enum labels
170 struct _LttType
** element_type
; //for array, sequence and struct
171 unsigned element_number
; //the number of elements
172 //for enum, array, sequence and structure
175 struct _LttEventType
{
178 guint index
; //id of the event type within the facility
179 LttFacility
* facility
; //the facility that contains the event type
180 LttField
* root_field
; //root field
183 /* Structure LttEvent and LttEventPosition must begin with the _exact_ same
184 * fields in the exact same order. LttEventPosition is a parent of LttEvent. */
187 /* Begin of LttEventPosition fields */
188 LttTracefile
*tracefile
;
193 uint64_t tsc
; /* Current timestamp counter */
195 /* End of LttEventPosition fields */
197 union { /* choice by trace has_tsc */
198 guint32 timestamp
; /* truncated timestamp */
202 unsigned char facility_id
; /* facility ID are never reused. */
203 unsigned char event_id
;
207 void * data
; //event data
210 int count
; //the number of overflow of cycle count
211 gint64 overflow_nsec
; //precalculated nsec for overflows
214 struct _LttEventPosition
{
215 LttTracefile
*tracefile
;
220 uint64_t tsc
; /* Current timestamp counter */
224 enum field_status
{ FIELD_UNKNOWN
, FIELD_VARIABLE
, FIELD_FIXED
};
227 //guint field_pos; //field position within its parent
228 LttType
* field_type
; //field type, if it is root field
229 //then it must be struct type
231 off_t offset_root
; //offset from the root, -1:uninitialized
232 enum field_status fixed_root
; //offset fixed according to the root
233 //-1:uninitialized, 0:unfixed, 1:fixed
234 off_t offset_parent
; //offset from the parent,-1:uninitialized
235 enum field_status fixed_parent
; //offset fixed according to its parent
236 //-1:uninitialized, 0:unfixed, 1:fixed
237 // void * base_address; //base address of the field ????
239 guint field_size
; // //>0: size of the field,
241 // //-1: uninitialize
242 enum field_status fixed_size
;
245 gint sequ_number_size
; //the size of unsigned used to save the
246 //number of elements in the sequence
248 gint element_size
; //the element size of the sequence
249 //int field_fixed; //0: field has string or sequence
250 //1: field has no string or sequenc
253 struct _LttField
* parent
;
254 struct _LttField
** child
; //for array, sequence, struct and union:
255 //list of fields, it may have only one
256 //field if the element is not a struct or
258 unsigned current_element
; //which element is currently processed
259 // Used for sequences and arrays.
265 //gchar * name; //facility name
267 guint32 checksum
; //checksum of the facility
268 guint32 id
; //id of the facility
270 guint32 pointer_size
;
275 //LttEventType ** events; //array of event types
276 //unsigned int event_number; //number of events in the facility
277 //LttType ** named_types;
278 //unsigned int named_types_number;
281 GData
*events_by_name
;
282 // GArray *named_types;
283 //GData *named_types_by_name;
286 unsigned char exists
; /* 0 does not exist, 1 exists */
289 typedef struct _LttBuffer
{
295 uint64_t cycle_count
;
299 uint64_t cycle_count
;
301 uint32_t lost_size
; /* Size unused at the end of the buffer */
304 uint64_t tsc
; /* Current timestamp counter */
305 double nsecs_per_cycle
;
308 struct _LttTracefile
{
309 gboolean cpu_online
; //is the cpu online ?
310 GQuark name
; //tracefile name
311 guint cpu_num
; //cpu number of the tracefile
312 LttTrace
* trace
; //trace containing the tracefile
313 int fd
; //file descriptor
314 off_t file_size
; //file size
315 unsigned block_size
; //block_size
316 unsigned int num_blocks
; //number of blocks in the file
317 gboolean reverse_bo
; //must we reverse byte order ?
320 LttEvent event
; //Event currently accessible in the trace
323 LttBuffer buffer
; //current buffer
324 guint32 buf_size
; /* The size of blocks */
327 //unsigned int count; //the number of overflow of cycle count
328 //double nsec_per_cycle; //Nsec per cycle
329 //TimeHeartbeat * last_heartbeat; //last heartbeat
331 //LttCycleCount cycles_per_nsec_reciprocal; // Optimisation for speed
332 //void * last_event_pos;
334 //LttTime prev_block_end_time; //the end time of previous block
335 //LttTime prev_event_time; //the time of the previous event
336 //LttCycleCount pre_cycle_count; //previous cycle count of the event
340 GQuark pathname
; //the pathname of the trace
341 //LttSystemDescription * system_description;//system description
343 GArray
*facilities_by_num
; /* fac_id as index in array */
344 GData
*facilities_by_name
; /* fac name (GQuark) as index */
345 /* Points to array of fac_id of all the
346 * facilities that has this name. */
348 guint8 ltt_major_version
;
349 guint8 ltt_minor_version
;
350 guint8 flight_recorder
;
351 guint8 has_heartbeat
;
355 GData
*tracefiles
; //tracefiles groups
358 /* The characteristics of the system on which the trace was obtained
359 is described in a LttSystemDescription structure. */
361 struct _LttSystemDescription
{
367 LttArchEndian endian
;
369 gchar
*kernel_release
;
370 gchar
*kernel_version
;
373 gchar
*hardware_platform
;
374 gchar
*operating_system
;
379 /*****************************************************************************
380 macro for size of some data types
381 *****************************************************************************/
382 // alignment -> dynamic!
384 //#define TIMESTAMP_SIZE sizeof(guint32)
385 //#define EVENT_ID_SIZE sizeof(guint16)
386 //#define EVENT_HEADER_SIZE (TIMESTAMP_SIZE + EVENT_ID_SIZE)
388 #define LTT_GET_BO(t) ((t)->reverse_bo)
391 #endif /* LTT_PRIVATE_H */