449cb9d7 |
1 | /* This file is part of the Linux Trace Toolkit viewer |
2 | * Copyright (C) 2003-2004 Xiangxiu Yang |
1b44b0b5 |
3 | * 2006 Mathieu Desnoyers |
449cb9d7 |
4 | * |
1b44b0b5 |
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. |
449cb9d7 |
8 | * |
1b44b0b5 |
9 | * This library is distributed in the hope that it will be useful, |
449cb9d7 |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1b44b0b5 |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Lesser General Public License for more details. |
449cb9d7 |
13 | * |
1b44b0b5 |
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. |
449cb9d7 |
18 | */ |
19 | |
fcdf0ec2 |
20 | #ifndef LTT_PRIVATE_H |
21 | #define LTT_PRIVATE_H |
22 | |
858bd80a |
23 | #include <glib.h> |
cbd41522 |
24 | #include <sys/types.h> |
fcdf0ec2 |
25 | #include <ltt/ltt.h> |
3b10b765 |
26 | #include <endian.h> |
29af7cfd |
27 | #include <ltt/event.h> |
e3247aa5 |
28 | |
eed2ef37 |
29 | #ifndef max |
30 | #define max(a,b) ((a)>(b)?(a):(b)) |
31 | #endif |
32 | |
2312de30 |
33 | #ifndef min |
34 | #define min(a,b) ((a)<(b)?(a):(b)) |
35 | #endif |
36 | |
37 | |
eed2ef37 |
38 | |
3aee1200 |
39 | #define LTT_MAGIC_NUMBER 0x00D6B7ED |
40 | #define LTT_REV_MAGIC_NUMBER 0xEDB7D600 |
41 | |
42 | #define NSEC_PER_USEC 1000 |
43 | |
cbd41522 |
44 | #define LTT_PACKED_STRUCT __attribute__ ((packed)) |
45 | |
3b10b765 |
46 | /* Byte ordering */ |
47 | #define LTT_GET_BO(t) ((t)->reverse_bo) |
48 | |
49 | #define LTT_HAS_FLOAT(t) ((t)->float_word_order!=0) |
50 | #define LTT_GET_FLOAT_BO(t) \ |
51 | (((t)->float_word_order==__BYTE_ORDER)?0:1) |
52 | |
f104d082 |
53 | #define SEQUENCE_AVG_ELEMENTS 1000 |
54 | |
3aee1200 |
55 | typedef guint8 uint8_t; |
56 | typedef guint16 uint16_t; |
57 | typedef guint32 uint32_t; |
58 | typedef guint64 uint64_t; |
59 | |
3aee1200 |
60 | struct ltt_event_header_hb { |
61 | uint32_t timestamp; |
3c165eaf |
62 | uint16_t event_id; |
3aee1200 |
63 | uint16_t event_size; |
16fcbb80 |
64 | } LTT_PACKED_STRUCT; |
3aee1200 |
65 | |
66 | struct ltt_event_header_nohb { |
67 | uint64_t timestamp; |
3c165eaf |
68 | uint16_t event_id; |
3aee1200 |
69 | uint16_t event_size; |
16fcbb80 |
70 | } LTT_PACKED_STRUCT; |
3aee1200 |
71 | |
b7576a11 |
72 | |
73 | /* Block and trace headers */ |
74 | |
75 | struct ltt_trace_header_any { |
76 | uint32_t magic_number; |
77 | uint32_t arch_type; |
78 | uint32_t arch_variant; |
79 | uint32_t float_word_order; |
80 | uint8_t arch_size; |
81 | uint8_t major_version; |
82 | uint8_t minor_version; |
83 | uint8_t flight_recorder; |
2fc874ab |
84 | uint8_t alignment; /* Architecture alignment */ |
b7576a11 |
85 | } LTT_PACKED_STRUCT; |
86 | |
2fc874ab |
87 | struct ltt_trace_header_2_0 { |
d1bb700c |
88 | uint32_t magic_number; |
89 | uint32_t arch_type; |
90 | uint32_t arch_variant; |
91 | uint32_t float_word_order; |
92 | uint8_t arch_size; |
93 | uint8_t major_version; |
94 | uint8_t minor_version; |
95 | uint8_t flight_recorder; |
2fc874ab |
96 | uint8_t alignment; /* Architecture alignment */ |
d1bb700c |
97 | uint8_t tscbits; |
2fc874ab |
98 | uint8_t eventbits; |
99 | uint8_t unused1; |
d1bb700c |
100 | uint32_t freq_scale; |
101 | uint64_t start_freq; |
102 | uint64_t start_tsc; |
103 | uint64_t start_monotonic; |
104 | uint64_t start_time_sec; |
105 | uint64_t start_time_usec; |
106 | } LTT_PACKED_STRUCT; |
107 | |
3aee1200 |
108 | struct ltt_block_start_header { |
109 | struct { |
3aee1200 |
110 | uint64_t cycle_count; |
986e2a7c |
111 | uint64_t freq; |
3aee1200 |
112 | } begin; |
113 | struct { |
3aee1200 |
114 | uint64_t cycle_count; |
986e2a7c |
115 | uint64_t freq; |
3aee1200 |
116 | } end; |
117 | uint32_t lost_size; /* Size unused at the end of the buffer */ |
118 | uint32_t buf_size; /* The size of this sub-buffer */ |
51551c6f |
119 | struct ltt_trace_header_any trace[0]; |
16fcbb80 |
120 | } LTT_PACKED_STRUCT; |
3aee1200 |
121 | |
e3247aa5 |
122 | |
3aee1200 |
123 | enum field_status { FIELD_UNKNOWN, FIELD_VARIABLE, FIELD_FIXED }; |
124 | |
3aee1200 |
125 | typedef struct _LttBuffer { |
126 | void * head; |
127 | unsigned int index; |
128 | |
129 | struct { |
130 | LttTime timestamp; |
131 | uint64_t cycle_count; |
986e2a7c |
132 | uint64_t freq; /* Frequency in khz */ |
3aee1200 |
133 | } begin; |
134 | struct { |
135 | LttTime timestamp; |
136 | uint64_t cycle_count; |
986e2a7c |
137 | uint64_t freq; /* Frequency in khz */ |
3aee1200 |
138 | } end; |
139 | uint32_t lost_size; /* Size unused at the end of the buffer */ |
140 | |
141 | /* Timekeeping */ |
142 | uint64_t tsc; /* Current timestamp counter */ |
986e2a7c |
143 | uint64_t freq; /* Frequency in khz */ |
791dffa6 |
144 | //double nsecs_per_cycle; /* Precalculated from freq */ |
145 | guint32 cyc2ns_scale; |
3aee1200 |
146 | } LttBuffer; |
147 | |
29af7cfd |
148 | struct LttTracefile { |
3aee1200 |
149 | gboolean cpu_online; //is the cpu online ? |
d3d34f49 |
150 | GQuark long_name; //tracefile complete filename |
3aee1200 |
151 | GQuark name; //tracefile name |
152 | guint cpu_num; //cpu number of the tracefile |
c88ddec5 |
153 | guint tid; //Usertrace tid, else 0 |
154 | guint pgid; //Usertrace pgid, else 0 |
155 | guint64 creation; //Usertrace creation, else 0 |
e3247aa5 |
156 | LttTrace * trace; //trace containing the tracefile |
157 | int fd; //file descriptor |
158 | off_t file_size; //file size |
f628823c |
159 | //unsigned block_size; //block_size |
f104d082 |
160 | guint num_blocks; //number of blocks in the file |
3aee1200 |
161 | gboolean reverse_bo; //must we reverse byte order ? |
3b10b765 |
162 | gboolean float_word_order; //what is the byte order of floats ? |
256a5b3a |
163 | size_t alignment; //alignment of events in the tracefile. |
c88ddec5 |
164 | // 0 or the architecture size in bytes. |
3aee1200 |
165 | |
823820eb |
166 | size_t buffer_header_size; |
d1bb700c |
167 | uint8_t tscbits; |
2fc874ab |
168 | uint8_t eventbits; |
d1bb700c |
169 | uint64_t tsc_mask; |
170 | uint64_t tsc_mask_next_bit; //next MSB after the mask |
823820eb |
171 | |
c88ddec5 |
172 | /* Current event */ |
3aee1200 |
173 | LttEvent event; //Event currently accessible in the trace |
174 | |
c88ddec5 |
175 | /* Current block */ |
3aee1200 |
176 | LttBuffer buffer; //current buffer |
177 | guint32 buf_size; /* The size of blocks */ |
e3247aa5 |
178 | }; |
7c6b3cd7 |
179 | |
a5dcde2f |
180 | /* The characteristics of the system on which the trace was obtained |
181 | is described in a LttSystemDescription structure. */ |
182 | |
29af7cfd |
183 | struct LttSystemDescription { |
45e14832 |
184 | gchar *description; |
185 | gchar *node_name; |
186 | gchar *domain_name; |
a5dcde2f |
187 | unsigned nb_cpu; |
188 | LttArchSize size; |
189 | LttArchEndian endian; |
45e14832 |
190 | gchar *kernel_name; |
191 | gchar *kernel_release; |
192 | gchar *kernel_version; |
193 | gchar *machine; |
194 | gchar *processor; |
195 | gchar *hardware_platform; |
196 | gchar *operating_system; |
a5dcde2f |
197 | LttTime trace_start; |
198 | LttTime trace_end; |
199 | }; |
200 | |
f104d082 |
201 | /* Calculate the offset needed to align the type. |
256a5b3a |
202 | * If alignment is 0, alignment is disactivated. |
f104d082 |
203 | * else, the function returns the offset needed to |
256a5b3a |
204 | * align align_drift on the alignment value (should be |
f104d082 |
205 | * the size of the architecture). */ |
206 | static inline unsigned int ltt_align(size_t align_drift, |
83e160f2 |
207 | size_t size_of_type, |
256a5b3a |
208 | size_t alignment) |
f104d082 |
209 | { |
256a5b3a |
210 | size_t align_offset = min(alignment, size_of_type); |
c88ddec5 |
211 | |
256a5b3a |
212 | if(!alignment) |
213 | return 0; |
c88ddec5 |
214 | |
215 | g_assert(size_of_type != 0); |
256a5b3a |
216 | return ((align_offset - align_drift) & (align_offset-1)); |
f104d082 |
217 | } |
218 | |
f104d082 |
219 | |
fcdf0ec2 |
220 | #endif /* LTT_PRIVATE_H */ |