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>
26 #define LTT_MAGIC_NUMBER 0x00D6B7ED
27 #define LTT_REV_MAGIC_NUMBER 0xEDB7D600
29 #define NSEC_PER_USEC 1000
31 #define LTT_PACKED_STRUCT __attribute__ ((packed))
34 /* enumeration definition */
36 typedef enum _BuildinEvent
{
37 TRACE_FACILITY_LOAD
= 0,
38 TRACE_BLOCK_START
= 17,
40 TRACE_TIME_HEARTBEAT
= 19
44 /* structure definition */
46 typedef struct _FacilityLoad
{
50 } LTT_PACKED_STRUCT FacilityLoad
;
52 typedef struct _BlockStart
{
53 LttTime time
; //Time stamp of this block
54 LttCycleCount cycle_count
; //cycle count of the event
55 guint32 block_id
; //block id
56 } LTT_PACKED_STRUCT BlockStart
;
58 typedef struct _BlockEnd
{
59 LttTime time
; //Time stamp of this block
60 LttCycleCount cycle_count
; //cycle count of the event
61 guint32 block_id
; //block id
62 } LTT_PACKED_STRUCT BlockEnd
;
66 typedef guint8
uint8_t;
67 typedef guint16
uint16_t;
68 typedef guint32
uint32_t;
69 typedef guint64
uint64_t;
71 typedef struct _TimeHeartbeat
{
72 LttTime time
; //Time stamp of this block
73 uint64_t cycle_count
; //cycle count of the event
74 } LTT_PACKED_STRUCT TimeHeartbeat
;
76 struct ltt_event_header_hb
{
78 unsigned char facility_id
;
79 unsigned char event_id
;
81 } __attribute((aligned(8)));
83 struct ltt_event_header_nohb
{
85 unsigned char facility_id
;
86 unsigned char event_id
;
88 } __attribute((aligned(8)));
90 struct ltt_trace_header
{
91 uint32_t magic_number
;
93 uint32_t arch_variant
;
95 //uint32_t system_type;
96 uint8_t major_version
;
97 uint8_t minor_version
;
98 uint8_t flight_recorder
;
99 uint8_t has_heartbeat
;
100 uint8_t has_alignment
; /* Event header alignment */
102 } __attribute((aligned(8)));
105 struct ltt_block_start_header
{
107 struct timeval timestamp
;
108 uint64_t cycle_count
;
111 struct timeval timestamp
;
112 uint64_t cycle_count
;
114 uint32_t lost_size
; /* Size unused at the end of the buffer */
115 uint32_t buf_size
; /* The size of this sub-buffer */
116 struct ltt_trace_header trace
;
117 } __attribute((aligned(8)));
121 GQuark type_name
; //type name if it is a named type
122 GQuark element_name
; //elements name of the struct
125 LttTypeEnum type_class
; //which type
126 gchar
** enum_strings
; //for enum labels
127 struct _LttType
** element_type
; //for array, sequence and struct
128 unsigned element_number
; //the number of elements
129 //for enum, array, sequence and structure
132 struct _LttEventType
{
135 int index
; //id of the event type within the facility
136 LttFacility
* facility
; //the facility that contains the event type
137 LttField
* root_field
; //root field
138 //unsigned int latest_block; //the latest block using the event type
139 //unsigned int latest_event; //the latest event using the event type
144 /* Where is this event ? */
145 LttTracefile
*tracefile
;
149 union { /* choice by trace has_tsc */
150 guint32 timestamp
; /* truncated timestamp */
154 unsigned char facility_id
; /* facility ID are never reused. */
155 unsigned char event_id
;
159 void * data
; //event data
161 int count
; //the number of overflow of cycle count
162 gint64 overflow_nsec
; //precalculated nsec for overflows
163 TimeHeartbeat
* last_heartbeat
; //last heartbeat
168 unsigned field_pos
; //field position within its parent
169 LttType
* field_type
; //field type, if it is root field
170 //then it must be struct type
172 off_t offset_root
; //offset from the root, -1:uninitialized
173 short fixed_root
; //offset fixed according to the root
174 //-1:uninitialized, 0:unfixed, 1:fixed
175 off_t offset_parent
; //offset from the parent,-1:uninitialized
176 short fixed_parent
; //offset fixed according to its parent
177 //-1:uninitialized, 0:unfixed, 1:fixed
178 // void * base_address; //base address of the field ????
180 int field_size
; //>0: size of the field,
183 int sequ_number_size
; //the size of unsigned used to save the
184 //number of elements in the sequence
186 int element_size
; //the element size of the sequence
187 int field_fixed
; //0: field has string or sequence
188 //1: field has no string or sequenc
191 struct _LttField
* parent
;
192 struct _LttField
** child
; //for array, sequence and struct:
193 //list of fields, it may have only one
194 //field if the element is not a struct
195 unsigned current_element
; //which element is currently processed
200 //gchar * name; //facility name
202 unsigned int event_number
; //number of events in the facility
203 guint32 checksum
; //checksum of the facility
204 //guint32 base_id; //base id of the facility
205 LttEventType
** events
; //array of event types
206 LttType
** named_types
;
207 unsigned int named_types_number
;
210 typedef struct _LttBuffer
{
215 struct timeval timestamp
;
216 uint64_t cycle_count
;
219 struct timeval timestamp
;
220 uint64_t cycle_count
;
222 uint32_t lost_size
; /* Size unused at the end of the buffer */
225 uint64_t tsc
; /* Current timestamp counter */
226 double nsecs_per_cycle
;
229 struct _LttTracefile
{
230 gboolean cpu_online
; //is the cpu online ?
231 GQuark name
; //tracefile name
232 LttTrace
* trace
; //trace containing the tracefile
233 int fd
; //file descriptor
234 off_t file_size
; //file size
235 unsigned block_size
; //block_size
236 unsigned int num_blocks
; //number of blocks in the file
237 gboolean reverse_bo
; //must we reverse byte order ?
240 LttEvent event
; //Event currently accessible in the trace
243 LttBuffer buffer
; //current buffer
244 guint32 buf_size
; /* The size of blocks */
247 //unsigned int count; //the number of overflow of cycle count
248 //double nsec_per_cycle; //Nsec per cycle
249 //TimeHeartbeat * last_heartbeat; //last heartbeat
251 //LttCycleCount cycles_per_nsec_reciprocal; // Optimisation for speed
252 //void * last_event_pos;
254 //LttTime prev_block_end_time; //the end time of previous block
255 //LttTime prev_event_time; //the time of the previous event
256 //LttCycleCount pre_cycle_count; //previous cycle count of the event
260 GQuark pathname
; //the pathname of the trace
261 guint facility_number
; //the number of facilities
262 //LttSystemDescription * system_description;//system description
264 //GPtrArray *control_tracefiles; //array of control tracefiles
265 //GPtrArray *per_cpu_tracefiles; //array of per cpu tracefiles
266 GPtrArray
*facilities
; //array of facilities
267 guint8 ltt_major_version
;
268 guint8 ltt_minor_version
;
269 guint8 flight_recorder
;
270 guint8 has_heartbeat
;
274 GData
*tracefiles
; //tracefiles groups
277 struct _LttEventPosition
{
278 LttTracefile
*tracefile
;
283 uint64_t tsc
; /* Current timestamp counter */
286 /* The characteristics of the system on which the trace was obtained
287 is described in a LttSystemDescription structure. */
289 struct _LttSystemDescription
{
295 LttArchEndian endian
;
297 gchar
*kernel_release
;
298 gchar
*kernel_version
;
301 gchar
*hardware_platform
;
302 gchar
*operating_system
;
303 //unsigned ltt_block_size;
308 /*****************************************************************************
309 macro for size of some data types
310 *****************************************************************************/
311 // alignment -> dynamic!
313 //#define TIMESTAMP_SIZE sizeof(guint32)
314 //#define EVENT_ID_SIZE sizeof(guint16)
315 //#define EVENT_HEADER_SIZE (TIMESTAMP_SIZE + EVENT_ID_SIZE)
317 #define LTT_GET_BO(t) ((t)->reverse_bo)
320 #endif /* LTT_PRIVATE_H */