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 | |
3b10b765 |
44 | /* Byte ordering */ |
45 | #define LTT_GET_BO(t) ((t)->reverse_bo) |
46 | |
64dd41a5 |
47 | #define LTT_HAS_FLOAT(t) ((t)->float_word_order ! =0) |
3b10b765 |
48 | #define LTT_GET_FLOAT_BO(t) \ |
64dd41a5 |
49 | (((t)->float_word_order == __BYTE_ORDER) ? 0 : 1) |
3b10b765 |
50 | |
f104d082 |
51 | #define SEQUENCE_AVG_ELEMENTS 1000 |
1550fba6 |
52 | |
53 | /* |
54 | * offsetof taken from Linux kernel. |
55 | */ |
56 | #undef offsetof |
57 | #ifdef __compiler_offsetof |
58 | #define offsetof(TYPE,MEMBER) __compiler_offsetof(TYPE,MEMBER) |
59 | #else |
60 | #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) |
61 | #endif |
62 | |
3aee1200 |
63 | typedef guint8 uint8_t; |
64 | typedef guint16 uint16_t; |
65 | typedef guint32 uint32_t; |
66 | typedef guint64 uint64_t; |
67 | |
64dd41a5 |
68 | /* Subbuffer header */ |
750eb11a |
69 | struct ltt_subbuffer_header_2_3 { |
64dd41a5 |
70 | uint64_t cycle_count_begin; /* Cycle count at subbuffer start */ |
71 | uint64_t cycle_count_end; /* Cycle count at subbuffer end */ |
1550fba6 |
72 | uint32_t magic_number; /* |
73 | * Trace magic number. |
64dd41a5 |
74 | * contains endianness information. |
75 | */ |
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. |
85 | */ |
d0e3122a |
86 | uint32_t freq_scale; /* Frequency scaling (divide freq) */ |
64dd41a5 |
87 | uint32_t lost_size; /* Size unused at end of subbuffer */ |
88 | uint32_t buf_size; /* Size of this subbuffer */ |
426f6149 |
89 | uint32_t events_lost; /* |
90 | * Events lost in this subbuffer since |
a2bbf2e5 |
91 | * the beginning of the trace. |
92 | * (may overflow) |
426f6149 |
93 | */ |
94 | uint32_t subbuf_corrupt; /* |
95 | * Corrupted (lost) subbuffers since |
96 | * the begginig of the trace. |
a2bbf2e5 |
97 | * (may overflow) |
426f6149 |
98 | */ |
1550fba6 |
99 | char header_end[0]; /* End of header */ |
64dd41a5 |
100 | }; |
101 | |
750eb11a |
102 | typedef struct ltt_subbuffer_header_2_3 ltt_subbuffer_header_t; |
1550fba6 |
103 | |
104 | /* |
105 | * Return header size without padding after the structure. Don't use packed |
106 | * structure because gcc generates inefficient code on some architectures |
107 | * (powerpc, mips..) |
108 | */ |
109 | static inline size_t ltt_subbuffer_header_size(void) |
110 | { |
111 | return offsetof(ltt_subbuffer_header_t, header_end); |
112 | } |
e3247aa5 |
113 | |
3aee1200 |
114 | enum field_status { FIELD_UNKNOWN, FIELD_VARIABLE, FIELD_FIXED }; |
115 | |
3aee1200 |
116 | typedef struct _LttBuffer { |
117 | void * head; |
118 | unsigned int index; |
119 | |
120 | struct { |
121 | LttTime timestamp; |
122 | uint64_t cycle_count; |
986e2a7c |
123 | uint64_t freq; /* Frequency in khz */ |
3aee1200 |
124 | } begin; |
125 | struct { |
126 | LttTime timestamp; |
127 | uint64_t cycle_count; |
986e2a7c |
128 | uint64_t freq; /* Frequency in khz */ |
3aee1200 |
129 | } end; |
130 | uint32_t lost_size; /* Size unused at the end of the buffer */ |
131 | |
132 | /* Timekeeping */ |
133 | uint64_t tsc; /* Current timestamp counter */ |
986e2a7c |
134 | uint64_t freq; /* Frequency in khz */ |
791dffa6 |
135 | guint32 cyc2ns_scale; |
3aee1200 |
136 | } LttBuffer; |
137 | |
29af7cfd |
138 | struct LttTracefile { |
3aee1200 |
139 | gboolean cpu_online; //is the cpu online ? |
d3d34f49 |
140 | GQuark long_name; //tracefile complete filename |
3aee1200 |
141 | GQuark name; //tracefile name |
142 | guint cpu_num; //cpu number of the tracefile |
c88ddec5 |
143 | guint tid; //Usertrace tid, else 0 |
144 | guint pgid; //Usertrace pgid, else 0 |
145 | guint64 creation; //Usertrace creation, else 0 |
e3247aa5 |
146 | LttTrace * trace; //trace containing the tracefile |
750eb11a |
147 | struct marker_data *mdata; // marker id/name/fields mapping |
e3247aa5 |
148 | int fd; //file descriptor |
149 | off_t file_size; //file size |
f628823c |
150 | //unsigned block_size; //block_size |
f104d082 |
151 | guint num_blocks; //number of blocks in the file |
3aee1200 |
152 | gboolean reverse_bo; //must we reverse byte order ? |
3b10b765 |
153 | gboolean float_word_order; //what is the byte order of floats ? |
256a5b3a |
154 | size_t alignment; //alignment of events in the tracefile. |
c88ddec5 |
155 | // 0 or the architecture size in bytes. |
3aee1200 |
156 | |
823820eb |
157 | size_t buffer_header_size; |
d1bb700c |
158 | uint8_t tscbits; |
2fc874ab |
159 | uint8_t eventbits; |
d1bb700c |
160 | uint64_t tsc_mask; |
426f6149 |
161 | uint64_t tsc_mask_next_bit; //next MSB after the mask< |
162 | uint32_t events_lost; |
163 | uint32_t subbuf_corrupt; |
823820eb |
164 | |
c88ddec5 |
165 | /* Current event */ |
3aee1200 |
166 | LttEvent event; //Event currently accessible in the trace |
167 | |
c88ddec5 |
168 | /* Current block */ |
3aee1200 |
169 | LttBuffer buffer; //current buffer |
170 | guint32 buf_size; /* The size of blocks */ |
e3247aa5 |
171 | }; |
7c6b3cd7 |
172 | |
a5dcde2f |
173 | /* The characteristics of the system on which the trace was obtained |
174 | is described in a LttSystemDescription structure. */ |
175 | |
29af7cfd |
176 | struct LttSystemDescription { |
45e14832 |
177 | gchar *description; |
178 | gchar *node_name; |
179 | gchar *domain_name; |
a5dcde2f |
180 | unsigned nb_cpu; |
181 | LttArchSize size; |
182 | LttArchEndian endian; |
45e14832 |
183 | gchar *kernel_name; |
184 | gchar *kernel_release; |
185 | gchar *kernel_version; |
186 | gchar *machine; |
187 | gchar *processor; |
188 | gchar *hardware_platform; |
189 | gchar *operating_system; |
a5dcde2f |
190 | LttTime trace_start; |
191 | LttTime trace_end; |
192 | }; |
193 | |
f104d082 |
194 | /* Calculate the offset needed to align the type. |
256a5b3a |
195 | * If alignment is 0, alignment is disactivated. |
f104d082 |
196 | * else, the function returns the offset needed to |
256a5b3a |
197 | * align align_drift on the alignment value (should be |
f104d082 |
198 | * the size of the architecture). */ |
199 | static inline unsigned int ltt_align(size_t align_drift, |
83e160f2 |
200 | size_t size_of_type, |
256a5b3a |
201 | size_t alignment) |
f104d082 |
202 | { |
256a5b3a |
203 | size_t align_offset = min(alignment, size_of_type); |
c88ddec5 |
204 | |
256a5b3a |
205 | if(!alignment) |
206 | return 0; |
c88ddec5 |
207 | |
208 | g_assert(size_of_type != 0); |
256a5b3a |
209 | return ((align_offset - align_drift) & (align_offset-1)); |
f104d082 |
210 | } |
211 | |
f104d082 |
212 | |
fcdf0ec2 |
213 | #endif /* LTT_PRIVATE_H */ |