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>
27 #include <ltt/event.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
45 #define LTT_GET_BO(t) ((t)->reverse_bo)
47 #define LTT_HAS_FLOAT(t) ((t)->float_word_order ! =0)
48 #define LTT_GET_FLOAT_BO(t) \
49 (((t)->float_word_order == __BYTE_ORDER) ? 0 : 1)
51 #define SEQUENCE_AVG_ELEMENTS 1000
54 * offsetof taken from Linux kernel.
57 #ifdef __compiler_offsetof
58 #define offsetof(TYPE,MEMBER) __compiler_offsetof(TYPE,MEMBER)
60 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
63 typedef guint8
uint8_t;
64 typedef guint16
uint16_t;
65 typedef guint32
uint32_t;
66 typedef guint64
uint64_t;
68 /* Subbuffer header */
69 struct ltt_subbuffer_header_2_1
{
70 uint64_t cycle_count_begin
; /* Cycle count at subbuffer start */
71 uint64_t cycle_count_end
; /* Cycle count at subbuffer end */
72 uint32_t magic_number
; /*
74 * contains endianness information.
76 uint8_t major_version
;
77 uint8_t minor_version
;
78 uint8_t arch_size
; /* Architecture pointer size */
79 uint8_t alignment
; /* LTT data alignment */
80 uint64_t start_time_sec
; /* NTP-corrected start time */
81 uint64_t start_time_usec
;
82 uint64_t start_freq
; /*
83 * Frequency at trace start,
84 * used all along the trace.
86 uint32_t freq_scale
; /* Frequency scaling */
87 uint32_t lost_size
; /* Size unused at end of subbuffer */
88 uint32_t buf_size
; /* Size of this subbuffer */
89 char header_end
[0]; /* End of header */
92 typedef struct ltt_subbuffer_header_2_1 ltt_subbuffer_header_t
;
95 * Return header size without padding after the structure. Don't use packed
96 * structure because gcc generates inefficient code on some architectures
99 static inline size_t ltt_subbuffer_header_size(void)
101 return offsetof(ltt_subbuffer_header_t
, header_end
);
104 enum field_status
{ FIELD_UNKNOWN
, FIELD_VARIABLE
, FIELD_FIXED
};
106 typedef struct _LttBuffer
{
112 uint64_t cycle_count
;
113 uint64_t freq
; /* Frequency in khz */
117 uint64_t cycle_count
;
118 uint64_t freq
; /* Frequency in khz */
120 uint32_t lost_size
; /* Size unused at the end of the buffer */
123 uint64_t tsc
; /* Current timestamp counter */
124 uint64_t freq
; /* Frequency in khz */
125 guint32 cyc2ns_scale
;
128 struct LttTracefile
{
129 gboolean cpu_online
; //is the cpu online ?
130 GQuark long_name
; //tracefile complete filename
131 GQuark name
; //tracefile name
132 guint cpu_num
; //cpu number of the tracefile
133 guint tid
; //Usertrace tid, else 0
134 guint pgid
; //Usertrace pgid, else 0
135 guint64 creation
; //Usertrace creation, else 0
136 LttTrace
* trace
; //trace containing the tracefile
137 int fd
; //file descriptor
138 off_t file_size
; //file size
139 //unsigned block_size; //block_size
140 guint num_blocks
; //number of blocks in the file
141 gboolean reverse_bo
; //must we reverse byte order ?
142 gboolean float_word_order
; //what is the byte order of floats ?
143 size_t alignment
; //alignment of events in the tracefile.
144 // 0 or the architecture size in bytes.
146 size_t buffer_header_size
;
150 uint64_t tsc_mask_next_bit
; //next MSB after the mask
153 LttEvent event
; //Event currently accessible in the trace
156 LttBuffer buffer
; //current buffer
157 guint32 buf_size
; /* The size of blocks */
160 /* The characteristics of the system on which the trace was obtained
161 is described in a LttSystemDescription structure. */
163 struct LttSystemDescription
{
169 LttArchEndian endian
;
171 gchar
*kernel_release
;
172 gchar
*kernel_version
;
175 gchar
*hardware_platform
;
176 gchar
*operating_system
;
181 /* Calculate the offset needed to align the type.
182 * If alignment is 0, alignment is disactivated.
183 * else, the function returns the offset needed to
184 * align align_drift on the alignment value (should be
185 * the size of the architecture). */
186 static inline unsigned int ltt_align(size_t align_drift
,
190 size_t align_offset
= min(alignment
, size_of_type
);
195 g_assert(size_of_type
!= 0);
196 return ((align_offset
- align_drift
) & (align_offset
-1));
200 #endif /* LTT_PRIVATE_H */