1 | /** @file
|
---|
2 | * STAM - Statistics Manager.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * The contents of this file may alternatively be used under the terms
|
---|
17 | * of the Common Development and Distribution License Version 1.0
|
---|
18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
20 | * CDDL are applicable instead of those of the GPL.
|
---|
21 | *
|
---|
22 | * You may elect to license modified versions of this file under the
|
---|
23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
24 | */
|
---|
25 |
|
---|
26 | #ifndef ___VBox_stam_h
|
---|
27 | #define ___VBox_stam_h
|
---|
28 |
|
---|
29 | #include <VBox/cdefs.h>
|
---|
30 | #include <VBox/types.h>
|
---|
31 | #include <iprt/stdarg.h>
|
---|
32 | #ifdef _MSC_VER
|
---|
33 | # if _MSC_VER >= 1400
|
---|
34 | # include <intrin.h>
|
---|
35 | # endif
|
---|
36 | #endif
|
---|
37 |
|
---|
38 | __BEGIN_DECLS
|
---|
39 |
|
---|
40 | /** @defgroup grp_stam The Statistics Manager API
|
---|
41 | * @{
|
---|
42 | */
|
---|
43 |
|
---|
44 | #if defined(VBOX_WITHOUT_RELEASE_STATISTICS) && defined(VBOX_WITH_STATISTICS)
|
---|
45 | # error "Both VBOX_WITHOUT_RELEASE_STATISTICS and VBOX_WITH_STATISTICS are defined! Make up your mind!"
|
---|
46 | #endif
|
---|
47 |
|
---|
48 |
|
---|
49 | /** @def STAM_GET_TS
|
---|
50 | * Gets the CPU timestamp counter.
|
---|
51 | *
|
---|
52 | * @param u64 The 64-bit variable which the timestamp shall be saved in.
|
---|
53 | */
|
---|
54 | #ifdef __GNUC__
|
---|
55 | # if defined(RT_ARCH_X86)
|
---|
56 | /* This produces optimal assembler code for x86 but does not work for AMD64 ('A' means 'either rax or rdx') */
|
---|
57 | # define STAM_GET_TS(u64) __asm__ __volatile__ ("rdtsc\n\t" : "=A" (u64));
|
---|
58 | # elif defined(RT_ARCH_AMD64)
|
---|
59 | # define STAM_GET_TS(u64) \
|
---|
60 | do { uint64_t low; uint64_t high; \
|
---|
61 | __asm__ __volatile__ ("rdtsc\n\t" : "=a"(low), "=d"(high)); \
|
---|
62 | (u64) = ((high << 32) | low); \
|
---|
63 | } while (0)
|
---|
64 | # endif
|
---|
65 | #elif _MSC_VER >= 1400
|
---|
66 | # pragma intrinsic(__rdtsc)
|
---|
67 | # define STAM_GET_TS(u64) \
|
---|
68 | do { (u64) = __rdtsc(); } while (0)
|
---|
69 | #else
|
---|
70 | # define STAM_GET_TS(u64) \
|
---|
71 | do { \
|
---|
72 | uint64_t u64Tmp; \
|
---|
73 | __asm { \
|
---|
74 | __asm rdtsc \
|
---|
75 | __asm mov dword ptr [u64Tmp], eax \
|
---|
76 | __asm mov dword ptr [u64Tmp + 4], edx \
|
---|
77 | } \
|
---|
78 | (u64) = u64Tmp; \
|
---|
79 | } while (0)
|
---|
80 | #endif
|
---|
81 |
|
---|
82 |
|
---|
83 | /** @def STAM_REL_STATS
|
---|
84 | * Code for inclusion only when VBOX_WITH_STATISTICS is defined.
|
---|
85 | * @param code A code block enclosed in {}.
|
---|
86 | */
|
---|
87 | #ifndef VBOX_WITHOUT_RELEASE_STATISTICS
|
---|
88 | # define STAM_REL_STATS(code) do code while(0)
|
---|
89 | #else
|
---|
90 | # define STAM_REL_STATS(code) do {} while(0)
|
---|
91 | #endif
|
---|
92 | /** @def STAM_STATS
|
---|
93 | * Code for inclusion only when VBOX_WITH_STATISTICS is defined.
|
---|
94 | * @param code A code block enclosed in {}.
|
---|
95 | */
|
---|
96 | #ifdef VBOX_WITH_STATISTICS
|
---|
97 | # define STAM_STATS(code) STAM_REL_STATS(code)
|
---|
98 | #else
|
---|
99 | # define STAM_STATS(code) do {} while(0)
|
---|
100 | #endif
|
---|
101 |
|
---|
102 |
|
---|
103 | /**
|
---|
104 | * Sample type.
|
---|
105 | */
|
---|
106 | typedef enum STAMTYPE
|
---|
107 | {
|
---|
108 | /** Invalid entry. */
|
---|
109 | STAMTYPE_INVALID = 0,
|
---|
110 | /** Generic counter. */
|
---|
111 | STAMTYPE_COUNTER,
|
---|
112 | /** Profiling of an function. */
|
---|
113 | STAMTYPE_PROFILE,
|
---|
114 | /** Profiling of an operation. */
|
---|
115 | STAMTYPE_PROFILE_ADV,
|
---|
116 | /** Ratio of A to B, uint32_t types. Not reset. */
|
---|
117 | STAMTYPE_RATIO_U32,
|
---|
118 | /** Ratio of A to B, uint32_t types. Reset both to 0. */
|
---|
119 | STAMTYPE_RATIO_U32_RESET,
|
---|
120 | /** Callback. */
|
---|
121 | STAMTYPE_CALLBACK,
|
---|
122 | /** Generic unsigned 8-bit value. Not reset. */
|
---|
123 | STAMTYPE_U8,
|
---|
124 | /** Generic unsigned 8-bit value. Reset to 0. */
|
---|
125 | STAMTYPE_U8_RESET,
|
---|
126 | /** Generic hexadecimal unsigned 8-bit value. Not reset. */
|
---|
127 | STAMTYPE_X8,
|
---|
128 | /** Generic hexadecimal unsigned 8-bit value. Reset to 0. */
|
---|
129 | STAMTYPE_X8_RESET,
|
---|
130 | /** Generic unsigned 16-bit value. Not reset. */
|
---|
131 | STAMTYPE_U16,
|
---|
132 | /** Generic unsigned 16-bit value. Reset to 0. */
|
---|
133 | STAMTYPE_U16_RESET,
|
---|
134 | /** Generic hexadecimal unsigned 16-bit value. Not reset. */
|
---|
135 | STAMTYPE_X16,
|
---|
136 | /** Generic hexadecimal unsigned 16-bit value. Reset to 0. */
|
---|
137 | STAMTYPE_X16_RESET,
|
---|
138 | /** Generic unsigned 32-bit value. Not reset. */
|
---|
139 | STAMTYPE_U32,
|
---|
140 | /** Generic unsigned 32-bit value. Reset to 0. */
|
---|
141 | STAMTYPE_U32_RESET,
|
---|
142 | /** Generic hexadecimal unsigned 32-bit value. Not reset. */
|
---|
143 | STAMTYPE_X32,
|
---|
144 | /** Generic hexadecimal unsigned 32-bit value. Reset to 0. */
|
---|
145 | STAMTYPE_X32_RESET,
|
---|
146 | /** Generic unsigned 64-bit value. Not reset. */
|
---|
147 | STAMTYPE_U64,
|
---|
148 | /** Generic unsigned 64-bit value. Reset to 0. */
|
---|
149 | STAMTYPE_U64_RESET,
|
---|
150 | /** Generic hexadecimal unsigned 64-bit value. Not reset. */
|
---|
151 | STAMTYPE_X64,
|
---|
152 | /** Generic hexadecimal unsigned 64-bit value. Reset to 0. */
|
---|
153 | STAMTYPE_X64_RESET,
|
---|
154 | /** The end (exclusive). */
|
---|
155 | STAMTYPE_END
|
---|
156 | } STAMTYPE;
|
---|
157 |
|
---|
158 | /**
|
---|
159 | * Sample visibility type.
|
---|
160 | */
|
---|
161 | typedef enum STAMVISIBILITY
|
---|
162 | {
|
---|
163 | /** Invalid entry. */
|
---|
164 | STAMVISIBILITY_INVALID = 0,
|
---|
165 | /** Always visible. */
|
---|
166 | STAMVISIBILITY_ALWAYS,
|
---|
167 | /** Only visible when used (/hit). */
|
---|
168 | STAMVISIBILITY_USED,
|
---|
169 | /** Not visible in the GUI. */
|
---|
170 | STAMVISIBILITY_NOT_GUI,
|
---|
171 | /** The end (exclusive). */
|
---|
172 | STAMVISIBILITY_END
|
---|
173 | } STAMVISIBILITY;
|
---|
174 |
|
---|
175 | /**
|
---|
176 | * Sample unit.
|
---|
177 | */
|
---|
178 | typedef enum STAMUNIT
|
---|
179 | {
|
---|
180 | /** Invalid entry .*/
|
---|
181 | STAMUNIT_INVALID = 0,
|
---|
182 | /** No unit. */
|
---|
183 | STAMUNIT_NONE,
|
---|
184 | /** Number of calls. */
|
---|
185 | STAMUNIT_CALLS,
|
---|
186 | /** Count of whatever. */
|
---|
187 | STAMUNIT_COUNT,
|
---|
188 | /** Count of bytes. */
|
---|
189 | STAMUNIT_BYTES,
|
---|
190 | /** Count of bytes. */
|
---|
191 | STAMUNIT_PAGES,
|
---|
192 | /** Error count. */
|
---|
193 | STAMUNIT_ERRORS,
|
---|
194 | /** Number of occurences. */
|
---|
195 | STAMUNIT_OCCURENCES,
|
---|
196 | /** Ticks per call. */
|
---|
197 | STAMUNIT_TICKS_PER_CALL,
|
---|
198 | /** Ticks per occurence. */
|
---|
199 | STAMUNIT_TICKS_PER_OCCURENCE,
|
---|
200 | /** Ratio of good vs. bad. */
|
---|
201 | STAMUNIT_GOOD_BAD,
|
---|
202 | /** Megabytes. */
|
---|
203 | STAMUNIT_MEGABYTES,
|
---|
204 | /** Kilobytes. */
|
---|
205 | STAMUNIT_KILOBYTES,
|
---|
206 | /** Nano seconds. */
|
---|
207 | STAMUNIT_NS,
|
---|
208 | /** Nanoseconds per call. */
|
---|
209 | STAMUNIT_NS_PER_CALL,
|
---|
210 | /** Nanoseconds per call. */
|
---|
211 | STAMUNIT_NS_PER_OCCURENCE,
|
---|
212 | /** Percentage. */
|
---|
213 | STAMUNIT_PCT,
|
---|
214 | /** The end (exclusive). */
|
---|
215 | STAMUNIT_END
|
---|
216 | } STAMUNIT;
|
---|
217 |
|
---|
218 |
|
---|
219 | /** @def STAM_REL_U8_INC
|
---|
220 | * Increments a uint8_t sample by one.
|
---|
221 | *
|
---|
222 | * @param pCounter Pointer to the uint8_t variable to operate on.
|
---|
223 | */
|
---|
224 | #ifndef VBOX_WITHOUT_RELEASE_STATISTICS
|
---|
225 | # define STAM_REL_U8_INC(pCounter) \
|
---|
226 | do { ++*(pCounter); } while (0)
|
---|
227 | #else
|
---|
228 | # define STAM_REL_U8_INC(pCounter) do { } while (0)
|
---|
229 | #endif
|
---|
230 | /** @def STAM_U8_INC
|
---|
231 | * Increments a uint8_t sample by one.
|
---|
232 | *
|
---|
233 | * @param pCounter Pointer to the uint8_t variable to operate on.
|
---|
234 | */
|
---|
235 | #ifdef VBOX_WITH_STATISTICS
|
---|
236 | # define STAM_U8_INC(pCounter) STAM_REL_U8_INC(pCounter)
|
---|
237 | #else
|
---|
238 | # define STAM_U8_INC(pCounter) do { } while (0)
|
---|
239 | #endif
|
---|
240 |
|
---|
241 |
|
---|
242 | /** @def STAM_REL_U8_DEC
|
---|
243 | * Decrements a uint8_t sample by one.
|
---|
244 | *
|
---|
245 | * @param pCounter Pointer to the uint8_t variable to operate on.
|
---|
246 | */
|
---|
247 | #ifndef VBOX_WITHOUT_RELEASE_STATISTICS
|
---|
248 | # define STAM_REL_U8_DEC(pCounter) \
|
---|
249 | do { --*(pCounter); } while (0)
|
---|
250 | #else
|
---|
251 | # define STAM_REL_U8_DEC(pCounter) do { } while (0)
|
---|
252 | #endif
|
---|
253 | /** @def STAM_U8_DEC
|
---|
254 | * Decrements a uint8_t sample by one.
|
---|
255 | *
|
---|
256 | * @param pCounter Pointer to the uint8_t variable to operate on.
|
---|
257 | */
|
---|
258 | #ifdef VBOX_WITH_STATISTICS
|
---|
259 | # define STAM_U8_DEC(pCounter) STAM_REL_U8_DEC(pCounter)
|
---|
260 | #else
|
---|
261 | # define STAM_U8_DEC(pCounter) do { } while (0)
|
---|
262 | #endif
|
---|
263 |
|
---|
264 |
|
---|
265 | /** @def STAM_REL_U8_ADD
|
---|
266 | * Increments a uint8_t sample by a value.
|
---|
267 | *
|
---|
268 | * @param pCounter Pointer to the uint8_t variable to operate on.
|
---|
269 | * @param Addend The value to add.
|
---|
270 | */
|
---|
271 | #ifndef VBOX_WITHOUT_RELEASE_STATISTICS
|
---|
272 | # define STAM_REL_U8_ADD(pCounter, Addend) \
|
---|
273 | do { *(pCounter) += (Addend); } while (0)
|
---|
274 | #else
|
---|
275 | # define STAM_REL_U8_ADD(pCounter, Addend) do { } while (0)
|
---|
276 | #endif
|
---|
277 | /** @def STAM_U8_ADD
|
---|
278 | * Increments a uint8_t sample by a value.
|
---|
279 | *
|
---|
280 | * @param pCounter Pointer to the uint8_t variable to operate on.
|
---|
281 | * @param Addend The value to add.
|
---|
282 | */
|
---|
283 | #ifdef VBOX_WITH_STATISTICS
|
---|
284 | # define STAM_U8_ADD(pCounter, Addend) STAM_REL_U8_ADD(pCounter, Addend
|
---|
285 | #else
|
---|
286 | # define STAM_U8_ADD(pCounter, Addend) do { } while (0)
|
---|
287 | #endif
|
---|
288 |
|
---|
289 |
|
---|
290 | /** @def STAM_REL_U16_INC
|
---|
291 | * Increments a uint16_t sample by one.
|
---|
292 | *
|
---|
293 | * @param pCounter Pointer to the uint16_t variable to operate on.
|
---|
294 | */
|
---|
295 | #ifndef VBOX_WITHOUT_RELEASE_STATISTICS
|
---|
296 | # define STAM_REL_U16_INC(pCounter) \
|
---|
297 | do { ++*(pCounter); } while (0)
|
---|
298 | #else
|
---|
299 | # define STAM_REL_U16_INC(pCounter) do { } while (0)
|
---|
300 | #endif
|
---|
301 | /** @def STAM_U16_INC
|
---|
302 | * Increments a uint16_t sample by one.
|
---|
303 | *
|
---|
304 | * @param pCounter Pointer to the uint16_t variable to operate on.
|
---|
305 | */
|
---|
306 | #ifdef VBOX_WITH_STATISTICS
|
---|
307 | # define STAM_U16_INC(pCounter) STAM_REL_U16_INC(pCounter)
|
---|
308 | #else
|
---|
309 | # define STAM_U16_INC(pCounter) do { } while (0)
|
---|
310 | #endif
|
---|
311 |
|
---|
312 |
|
---|
313 | /** @def STAM_REL_U16_DEC
|
---|
314 | * Decrements a uint16_t sample by one.
|
---|
315 | *
|
---|
316 | * @param pCounter Pointer to the uint16_t variable to operate on.
|
---|
317 | */
|
---|
318 | #ifndef VBOX_WITHOUT_RELEASE_STATISTICS
|
---|
319 | # define STAM_REL_U16_DEC(pCounter) \
|
---|
320 | do { --*(pCounter); } while (0)
|
---|
321 | #else
|
---|
322 | # define STAM_REL_U16_DEC(pCounter) do { } while (0)
|
---|
323 | #endif
|
---|
324 | /** @def STAM_U16_DEC
|
---|
325 | * Decrements a uint16_t sample by one.
|
---|
326 | *
|
---|
327 | * @param pCounter Pointer to the uint16_t variable to operate on.
|
---|
328 | */
|
---|
329 | #ifdef VBOX_WITH_STATISTICS
|
---|
330 | # define STAM_U16_DEC(pCounter) STAM_REL_U16_DEC(pCounter)
|
---|
331 | #else
|
---|
332 | # define STAM_U16_DEC(pCounter) do { } while (0)
|
---|
333 | #endif
|
---|
334 |
|
---|
335 |
|
---|
336 | /** @def STAM_REL_U16_INC
|
---|
337 | * Increments a uint16_t sample by a value.
|
---|
338 | *
|
---|
339 | * @param pCounter Pointer to the uint16_t variable to operate on.
|
---|
340 | * @param Addend The value to add.
|
---|
341 | */
|
---|
342 | #ifndef VBOX_WITHOUT_RELEASE_STATISTICS
|
---|
343 | # define STAM_REL_U16_ADD(pCounter, Addend) \
|
---|
344 | do { *(pCounter) += (Addend); } while (0)
|
---|
345 | #else
|
---|
346 | # define STAM_REL_U16_ADD(pCounter, Addend) do { } while (0)
|
---|
347 | #endif
|
---|
348 | /** @def STAM_U16_INC
|
---|
349 | * Increments a uint16_t sample by a value.
|
---|
350 | *
|
---|
351 | * @param pCounter Pointer to the uint16_t variable to operate on.
|
---|
352 | * @param Addend The value to add.
|
---|
353 | */
|
---|
354 | #ifdef VBOX_WITH_STATISTICS
|
---|
355 | # define STAM_U16_ADD(pCounter, Addend) STAM_REL_U16_ADD(pCounter, Addend)
|
---|
356 | #else
|
---|
357 | # define STAM_U16_ADD(pCounter, Addend) do { } while (0)
|
---|
358 | #endif
|
---|
359 |
|
---|
360 |
|
---|
361 | /** @def STAM_REL_U32_INC
|
---|
362 | * Increments a uint32_t sample by one.
|
---|
363 | *
|
---|
364 | * @param pCounter Pointer to the uint32_t variable to operate on.
|
---|
365 | */
|
---|
366 | #ifndef VBOX_WITHOUT_RELEASE_STATISTICS
|
---|
367 | # define STAM_REL_U32_INC(pCounter) \
|
---|
368 | do { ++*(pCounter); } while (0)
|
---|
369 | #else
|
---|
370 | # define STAM_REL_U32_INC(pCounter) do { } while (0)
|
---|
371 | #endif
|
---|
372 | /** @def STAM_U32_INC
|
---|
373 | * Increments a uint32_t sample by one.
|
---|
374 | *
|
---|
375 | * @param pCounter Pointer to the uint32_t variable to operate on.
|
---|
376 | */
|
---|
377 | #ifdef VBOX_WITH_STATISTICS
|
---|
378 | # define STAM_U32_INC(pCounter) STAM_REL_U32_INC(pCounter)
|
---|
379 | #else
|
---|
380 | # define STAM_U32_INC(pCounter) do { } while (0)
|
---|
381 | #endif
|
---|
382 |
|
---|
383 |
|
---|
384 | /** @def STAM_REL_U32_DEC
|
---|
385 | * Decrements a uint32_t sample by one.
|
---|
386 | *
|
---|
387 | * @param pCounter Pointer to the uint32_t variable to operate on.
|
---|
388 | */
|
---|
389 | #ifndef VBOX_WITHOUT_RELEASE_STATISTICS
|
---|
390 | # define STAM_REL_U32_DEC(pCounter) \
|
---|
391 | do { --*(pCounter); } while (0)
|
---|
392 | #else
|
---|
393 | # define STAM_REL_U32_DEC(pCounter) do { } while (0)
|
---|
394 | #endif
|
---|
395 | /** @def STAM_U32_DEC
|
---|
396 | * Decrements a uint32_t sample by one.
|
---|
397 | *
|
---|
398 | * @param pCounter Pointer to the uint32_t variable to operate on.
|
---|
399 | */
|
---|
400 | #ifdef VBOX_WITH_STATISTICS
|
---|
401 | # define STAM_U32_DEC(pCounter) STAM_REL_U32_DEC(pCounter)
|
---|
402 | #else
|
---|
403 | # define STAM_U32_DEC(pCounter) do { } while (0)
|
---|
404 | #endif
|
---|
405 |
|
---|
406 |
|
---|
407 | /** @def STAM_REL_U32_ADD
|
---|
408 | * Increments a uint32_t sample by value.
|
---|
409 | *
|
---|
410 | * @param pCounter Pointer to the uint32_t variable to operate on.
|
---|
411 | * @param Addend The value to add.
|
---|
412 | */
|
---|
413 | #ifndef VBOX_WITHOUT_RELEASE_STATISTICS
|
---|
414 | # define STAM_REL_U32_ADD(pCounter, Addend) \
|
---|
415 | do { *(pCounter) += (Addend); } while (0)
|
---|
416 | #else
|
---|
417 | # define STAM_REL_U32_ADD(pCounter, Addend) do { } while (0)
|
---|
418 | #endif
|
---|
419 | /** @def STAM_U32_ADD
|
---|
420 | * Increments a uint32_t sample by value.
|
---|
421 | *
|
---|
422 | * @param pCounter Pointer to the uint32_t variable to operate on.
|
---|
423 | * @param Addend The value to add.
|
---|
424 | */
|
---|
425 | #ifdef VBOX_WITH_STATISTICS
|
---|
426 | # define STAM_U32_ADD(pCounter, Addend) STAM_REL_U32_ADD(pCounter, Addend)
|
---|
427 | #else
|
---|
428 | # define STAM_U32_ADD(pCounter, Addend) do { } while (0)
|
---|
429 | #endif
|
---|
430 |
|
---|
431 |
|
---|
432 | /** @def STAM_REL_U64_INC
|
---|
433 | * Increments a uint64_t sample by one.
|
---|
434 | *
|
---|
435 | * @param pCounter Pointer to the uint64_t variable to operate on.
|
---|
436 | */
|
---|
437 | #ifndef VBOX_WITHOUT_RELEASE_STATISTICS
|
---|
438 | # define STAM_REL_U64_INC(pCounter) \
|
---|
439 | do { ++*(pCounter); } while (0)
|
---|
440 | #else
|
---|
441 | # define STAM_REL_U64_INC(pCounter) do { } while (0)
|
---|
442 | #endif
|
---|
443 | /** @def STAM_U64_INC
|
---|
444 | * Increments a uint64_t sample by one.
|
---|
445 | *
|
---|
446 | * @param pCounter Pointer to the uint64_t variable to operate on.
|
---|
447 | */
|
---|
448 | #ifdef VBOX_WITH_STATISTICS
|
---|
449 | # define STAM_U64_INC(pCounter) STAM_REL_U64_INC(pCounter)
|
---|
450 | #else
|
---|
451 | # define STAM_U64_INC(pCounter) do { } while (0)
|
---|
452 | #endif
|
---|
453 |
|
---|
454 |
|
---|
455 | /** @def STAM_REL_U64_DEC
|
---|
456 | * Decrements a uint64_t sample by one.
|
---|
457 | *
|
---|
458 | * @param pCounter Pointer to the uint64_t variable to operate on.
|
---|
459 | */
|
---|
460 | #ifndef VBOX_WITHOUT_RELEASE_STATISTICS
|
---|
461 | # define STAM_REL_U64_DEC(pCounter) \
|
---|
462 | do { --*(pCounter); } while (0)
|
---|
463 | #else
|
---|
464 | # define STAM_REL_U64_DEC(pCounter) do { } while (0)
|
---|
465 | #endif
|
---|
466 | /** @def STAM_U64_DEC
|
---|
467 | * Decrements a uint64_t sample by one.
|
---|
468 | *
|
---|
469 | * @param pCounter Pointer to the uint64_t variable to operate on.
|
---|
470 | */
|
---|
471 | #ifdef VBOX_WITH_STATISTICS
|
---|
472 | # define STAM_U64_DEC(pCounter) STAM_REL_U64_DEC(pCounter)
|
---|
473 | #else
|
---|
474 | # define STAM_U64_DEC(pCounter) do { } while (0)
|
---|
475 | #endif
|
---|
476 |
|
---|
477 |
|
---|
478 | /** @def STAM_REL_U64_ADD
|
---|
479 | * Increments a uint64_t sample by a value.
|
---|
480 | *
|
---|
481 | * @param pCounter Pointer to the uint64_t variable to operate on.
|
---|
482 | * @param Addend The value to add.
|
---|
483 | */
|
---|
484 | #ifndef VBOX_WITHOUT_RELEASE_STATISTICS
|
---|
485 | # define STAM_REL_U64_ADD(pCounter, Addend) \
|
---|
486 | do { *(pCounter) += (Addend); } while (0)
|
---|
487 | #else
|
---|
488 | # define STAM_REL_U64_ADD(pCounter, Addend) do { } while (0)
|
---|
489 | #endif
|
---|
490 | /** @def STAM_U64_ADD
|
---|
491 | * Increments a uint64_t sample by a value.
|
---|
492 | *
|
---|
493 | * @param pCounter Pointer to the uint64_t variable to operate on.
|
---|
494 | * @param Addend The value to add.
|
---|
495 | */
|
---|
496 | #ifdef VBOX_WITH_STATISTICS
|
---|
497 | # define STAM_U64_ADD(pCounter, Addend) STAM_REL_U64_ADD(pCounter, Addend)
|
---|
498 | #else
|
---|
499 | # define STAM_U64_ADD(pCounter, Addend) do { } while (0)
|
---|
500 | #endif
|
---|
501 |
|
---|
502 |
|
---|
503 | /**
|
---|
504 | * Counter sample - STAMTYPE_COUNTER.
|
---|
505 | */
|
---|
506 | typedef struct STAMCOUNTER
|
---|
507 | {
|
---|
508 | /** The current count. */
|
---|
509 | volatile uint64_t c;
|
---|
510 | } STAMCOUNTER;
|
---|
511 | /** Pointer to a counter. */
|
---|
512 | typedef STAMCOUNTER *PSTAMCOUNTER;
|
---|
513 | /** Pointer to a const counter. */
|
---|
514 | typedef const STAMCOUNTER *PCSTAMCOUNTER;
|
---|
515 |
|
---|
516 |
|
---|
517 | /** @def STAM_REL_COUNTER_INC
|
---|
518 | * Increments a counter sample by one.
|
---|
519 | *
|
---|
520 | * @param pCounter Pointer to the STAMCOUNTER structure to operate on.
|
---|
521 | */
|
---|
522 | #ifndef VBOX_WITHOUT_RELEASE_STATISTICS
|
---|
523 | # define STAM_REL_COUNTER_INC(pCounter) \
|
---|
524 | do { (pCounter)->c++; } while (0)
|
---|
525 | #else
|
---|
526 | # define STAM_REL_COUNTER_INC(pCounter) do { } while (0)
|
---|
527 | #endif
|
---|
528 | /** @def STAM_COUNTER_INC
|
---|
529 | * Increments a counter sample by one.
|
---|
530 | *
|
---|
531 | * @param pCounter Pointer to the STAMCOUNTER structure to operate on.
|
---|
532 | */
|
---|
533 | #ifdef VBOX_WITH_STATISTICS
|
---|
534 | # define STAM_COUNTER_INC(pCounter) STAM_REL_COUNTER_INC(pCounter)
|
---|
535 | #else
|
---|
536 | # define STAM_COUNTER_INC(pCounter) do { } while (0)
|
---|
537 | #endif
|
---|
538 |
|
---|
539 |
|
---|
540 | /** @def STAM_REL_COUNTER_DEC
|
---|
541 | * Decrements a counter sample by one.
|
---|
542 | *
|
---|
543 | * @param pCounter Pointer to the STAMCOUNTER structure to operate on.
|
---|
544 | */
|
---|
545 | #ifndef VBOX_WITHOUT_RELEASE_STATISTICS
|
---|
546 | # define STAM_REL_COUNTER_DEC(pCounter) \
|
---|
547 | do { (pCounter)->c--; } while (0)
|
---|
548 | #else
|
---|
549 | # define STAM_REL_COUNTER_DEC(pCounter) do { } while (0)
|
---|
550 | #endif
|
---|
551 | /** @def STAM_COUNTER_DEC
|
---|
552 | * Decrements a counter sample by one.
|
---|
553 | *
|
---|
554 | * @param pCounter Pointer to the STAMCOUNTER structure to operate on.
|
---|
555 | */
|
---|
556 | #ifdef VBOX_WITH_STATISTICS
|
---|
557 | # define STAM_COUNTER_DEC(pCounter) STAM_REL_COUNTER_DEC(pCounter)
|
---|
558 | #else
|
---|
559 | # define STAM_COUNTER_DEC(pCounter) do { } while (0)
|
---|
560 | #endif
|
---|
561 |
|
---|
562 |
|
---|
563 | /** @def STAM_REL_COUNTER_ADD
|
---|
564 | * Increments a counter sample by a value.
|
---|
565 | *
|
---|
566 | * @param pCounter Pointer to the STAMCOUNTER structure to operate on.
|
---|
567 | * @param Addend The value to add to the counter.
|
---|
568 | */
|
---|
569 | #ifndef VBOX_WITHOUT_RELEASE_STATISTICS
|
---|
570 | # define STAM_REL_COUNTER_ADD(pCounter, Addend) \
|
---|
571 | do { (pCounter)->c += (Addend); } while (0)
|
---|
572 | #else
|
---|
573 | # define STAM_REL_COUNTER_ADD(pCounter, Addend) do { } while (0)
|
---|
574 | #endif
|
---|
575 | /** @def STAM_COUNTER_ADD
|
---|
576 | * Increments a counter sample by a value.
|
---|
577 | *
|
---|
578 | * @param pCounter Pointer to the STAMCOUNTER structure to operate on.
|
---|
579 | * @param Addend The value to add to the counter.
|
---|
580 | */
|
---|
581 | #ifdef VBOX_WITH_STATISTICS
|
---|
582 | # define STAM_COUNTER_ADD(pCounter, Addend) STAM_REL_COUNTER_ADD(pCounter, Addend)
|
---|
583 | #else
|
---|
584 | # define STAM_COUNTER_ADD(pCounter, Addend) do { } while (0)
|
---|
585 | #endif
|
---|
586 |
|
---|
587 |
|
---|
588 | /** @def STAM_REL_COUNTER_RESET
|
---|
589 | * Resets the statistics sample.
|
---|
590 | */
|
---|
591 | #ifndef VBOX_WITHOUT_RELEASE_STATISTICS
|
---|
592 | # define STAM_REL_COUNTER_RESET(pCounter) do { (pCounter)->c = 0; } while (0)
|
---|
593 | #else
|
---|
594 | # define STAM_REL_COUNTER_RESET(pCounter) do { } while (0)
|
---|
595 | #endif
|
---|
596 | /** @def STAM_COUNTER_RESET
|
---|
597 | * Resets the statistics sample.
|
---|
598 | */
|
---|
599 | #ifndef VBOX_WITH_STATISTICS
|
---|
600 | # define STAM_COUNTER_RESET(pCounter) STAM_REL_COUNTER_RESET(pCounter)
|
---|
601 | #else
|
---|
602 | # define STAM_COUNTER_RESET(pCounter) do { } while (0)
|
---|
603 | #endif
|
---|
604 |
|
---|
605 |
|
---|
606 |
|
---|
607 | /**
|
---|
608 | * Profiling sample - STAMTYPE_PROFILE.
|
---|
609 | */
|
---|
610 | typedef struct STAMPROFILE
|
---|
611 | {
|
---|
612 | /** Number of periods. */
|
---|
613 | volatile uint64_t cPeriods;
|
---|
614 | /** Total count of ticks. */
|
---|
615 | volatile uint64_t cTicks;
|
---|
616 | /** Maximum tick count during a sampling. */
|
---|
617 | volatile uint64_t cTicksMax;
|
---|
618 | /** Minimum tick count during a sampling. */
|
---|
619 | volatile uint64_t cTicksMin;
|
---|
620 | } STAMPROFILE;
|
---|
621 | /** Pointer to a profile sample. */
|
---|
622 | typedef STAMPROFILE *PSTAMPROFILE;
|
---|
623 | /** Pointer to a const profile sample. */
|
---|
624 | typedef const STAMPROFILE *PCSTAMPROFILE;
|
---|
625 |
|
---|
626 |
|
---|
627 | /** @def STAM_REL_PROFILE_START
|
---|
628 | * Samples the start time of a profiling period.
|
---|
629 | *
|
---|
630 | * @param pProfile Pointer to the STAMPROFILE structure to operate on.
|
---|
631 | * @param Prefix Identifier prefix used to internal variables.
|
---|
632 | */
|
---|
633 | #ifndef VBOX_WITHOUT_RELEASE_STATISTICS
|
---|
634 | # define STAM_REL_PROFILE_START(pProfile, Prefix) \
|
---|
635 | uint64_t Prefix##_tsStart; \
|
---|
636 | STAM_GET_TS(Prefix##_tsStart)
|
---|
637 | #else
|
---|
638 | # define STAM_REL_PROFILE_START(pProfile, Prefix) do { } while (0)
|
---|
639 | #endif
|
---|
640 | /** @def STAM_PROFILE_START
|
---|
641 | * Samples the start time of a profiling period.
|
---|
642 | *
|
---|
643 | * @param pProfile Pointer to the STAMPROFILE structure to operate on.
|
---|
644 | * @param Prefix Identifier prefix used to internal variables.
|
---|
645 | */
|
---|
646 | #ifdef VBOX_WITH_STATISTICS
|
---|
647 | # define STAM_PROFILE_START(pProfile, Prefix) STAM_REL_PROFILE_START(pProfile, Prefix)
|
---|
648 | #else
|
---|
649 | # define STAM_PROFILE_START(pProfile, Prefix) do { } while (0)
|
---|
650 | #endif
|
---|
651 |
|
---|
652 | /** @def STAM_REL_PROFILE_STOP
|
---|
653 | * Samples the stop time of a profiling period and updates the sample.
|
---|
654 | *
|
---|
655 | * @param pProfile Pointer to the STAMPROFILE structure to operate on.
|
---|
656 | * @param Prefix Identifier prefix used to internal variables.
|
---|
657 | */
|
---|
658 | #ifndef VBOX_WITHOUT_RELEASE_STATISTICS
|
---|
659 | # define STAM_REL_PROFILE_STOP(pProfile, Prefix) \
|
---|
660 | do { \
|
---|
661 | uint64_t Prefix##_cTicks; \
|
---|
662 | uint64_t Prefix##_tsStop; \
|
---|
663 | STAM_GET_TS(Prefix##_tsStop); \
|
---|
664 | Prefix##_cTicks = Prefix##_tsStop - Prefix##_tsStart; \
|
---|
665 | (pProfile)->cTicks += Prefix##_cTicks; \
|
---|
666 | (pProfile)->cPeriods++; \
|
---|
667 | if ((pProfile)->cTicksMax < Prefix##_cTicks) \
|
---|
668 | (pProfile)->cTicksMax = Prefix##_cTicks; \
|
---|
669 | if ((pProfile)->cTicksMin > Prefix##_cTicks) \
|
---|
670 | (pProfile)->cTicksMin = Prefix##_cTicks; \
|
---|
671 | } while (0)
|
---|
672 | #else
|
---|
673 | # define STAM_REL_PROFILE_STOP(pProfile, Prefix) do { } while (0)
|
---|
674 | #endif
|
---|
675 | /** @def STAM_PROFILE_STOP
|
---|
676 | * Samples the stop time of a profiling period and updates the sample.
|
---|
677 | *
|
---|
678 | * @param pProfile Pointer to the STAMPROFILE structure to operate on.
|
---|
679 | * @param Prefix Identifier prefix used to internal variables.
|
---|
680 | */
|
---|
681 | #ifdef VBOX_WITH_STATISTICS
|
---|
682 | # define STAM_PROFILE_STOP(pProfile, Prefix) STAM_REL_PROFILE_STOP(pProfile, Prefix)
|
---|
683 | #else
|
---|
684 | # define STAM_PROFILE_STOP(pProfile, Prefix) do { } while (0)
|
---|
685 | #endif
|
---|
686 |
|
---|
687 |
|
---|
688 | /** @def STAM_REL_PROFILE_STOP_EX
|
---|
689 | * Samples the stop time of a profiling period and updates both the sample
|
---|
690 | * and an attribution sample.
|
---|
691 | *
|
---|
692 | * @param pProfile Pointer to the STAMPROFILE structure to operate on.
|
---|
693 | * @param pProfile2 Pointer to the STAMPROFILE structure which this
|
---|
694 | * interval should be attributed too. This may be NULL.
|
---|
695 | * @param Prefix Identifier prefix used to internal variables.
|
---|
696 | */
|
---|
697 | #ifndef VBOX_WITHOUT_RELEASE_STATISTICS
|
---|
698 | # define STAM_REL_PROFILE_STOP_EX(pProfile, pProfile2, Prefix) \
|
---|
699 | do { \
|
---|
700 | uint64_t Prefix##_cTicks; \
|
---|
701 | uint64_t Prefix##_tsStop; \
|
---|
702 | STAM_GET_TS(Prefix##_tsStop); \
|
---|
703 | Prefix##_cTicks = Prefix##_tsStop - Prefix##_tsStart; \
|
---|
704 | (pProfile)->cTicks += Prefix##_cTicks; \
|
---|
705 | (pProfile)->cPeriods++; \
|
---|
706 | if ((pProfile)->cTicksMax < Prefix##_cTicks) \
|
---|
707 | (pProfile)->cTicksMax = Prefix##_cTicks; \
|
---|
708 | if ((pProfile)->cTicksMin > Prefix##_cTicks) \
|
---|
709 | (pProfile)->cTicksMin = Prefix##_cTicks; \
|
---|
710 | \
|
---|
711 | if ((pProfile2)) \
|
---|
712 | { \
|
---|
713 | (pProfile2)->cTicks += Prefix##_cTicks; \
|
---|
714 | (pProfile2)->cPeriods++; \
|
---|
715 | if ((pProfile2)->cTicksMax < Prefix##_cTicks) \
|
---|
716 | (pProfile2)->cTicksMax = Prefix##_cTicks; \
|
---|
717 | if ((pProfile2)->cTicksMin > Prefix##_cTicks) \
|
---|
718 | (pProfile2)->cTicksMin = Prefix##_cTicks; \
|
---|
719 | } \
|
---|
720 | } while (0)
|
---|
721 | #else
|
---|
722 | # define STAM_REL_PROFILE_STOP_EX(pProfile, pProfile2, Prefix) do { } while (0)
|
---|
723 | #endif
|
---|
724 | /** @def STAM_PROFILE_STOP_EX
|
---|
725 | * Samples the stop time of a profiling period and updates both the sample
|
---|
726 | * and an attribution sample.
|
---|
727 | *
|
---|
728 | * @param pProfile Pointer to the STAMPROFILE structure to operate on.
|
---|
729 | * @param pProfile2 Pointer to the STAMPROFILE structure which this
|
---|
730 | * interval should be attributed too. This may be NULL.
|
---|
731 | * @param Prefix Identifier prefix used to internal variables.
|
---|
732 | */
|
---|
733 | #ifdef VBOX_WITH_STATISTICS
|
---|
734 | # define STAM_PROFILE_STOP_EX(pProfile, pProfile2, Prefix) STAM_REL_PROFILE_STOP_EX(pProfile, pProfile2, Prefix)
|
---|
735 | #else
|
---|
736 | # define STAM_PROFILE_STOP_EX(pProfile, pProfile2, Prefix) do { } while (0)
|
---|
737 | #endif
|
---|
738 |
|
---|
739 |
|
---|
740 | /**
|
---|
741 | * Advanced profiling sample - STAMTYPE_PROFILE_ADV.
|
---|
742 | *
|
---|
743 | * Identical to a STAMPROFILE sample, but the start timestamp
|
---|
744 | * is stored after the STAMPROFILE structure so the sampling
|
---|
745 | * can start and stop in different functions.
|
---|
746 | */
|
---|
747 | typedef struct STAMPROFILEADV
|
---|
748 | {
|
---|
749 | /** The STAMPROFILE core. */
|
---|
750 | STAMPROFILE Core;
|
---|
751 | /** The start timestamp. */
|
---|
752 | volatile uint64_t tsStart;
|
---|
753 | } STAMPROFILEADV;
|
---|
754 | /** Pointer to a advanced profile sample. */
|
---|
755 | typedef STAMPROFILEADV *PSTAMPROFILEADV;
|
---|
756 | /** Pointer to a const advanced profile sample. */
|
---|
757 | typedef const STAMPROFILEADV *PCSTAMPROFILEADV;
|
---|
758 |
|
---|
759 |
|
---|
760 | /** @def STAM_REL_PROFILE_ADV_START
|
---|
761 | * Samples the start time of a profiling period.
|
---|
762 | *
|
---|
763 | * @param pProfileAdv Pointer to the STAMPROFILEADV structure to operate on.
|
---|
764 | * @param Prefix Identifier prefix used to internal variables.
|
---|
765 | */
|
---|
766 | #ifndef VBOX_WITHOUT_RELEASE_STATISTICS
|
---|
767 | # define STAM_REL_PROFILE_ADV_START(pProfileAdv, Prefix) \
|
---|
768 | STAM_GET_TS((pProfileAdv)->tsStart)
|
---|
769 | #else
|
---|
770 | # define STAM_REL_PROFILE_ADV_START(pProfileAdv, Prefix) do { } while (0)
|
---|
771 | #endif
|
---|
772 | /** @def STAM_PROFILE_ADV_START
|
---|
773 | * Samples the start time of a profiling period.
|
---|
774 | *
|
---|
775 | * @param pProfileAdv Pointer to the STAMPROFILEADV structure to operate on.
|
---|
776 | * @param Prefix Identifier prefix used to internal variables.
|
---|
777 | */
|
---|
778 | #ifdef VBOX_WITH_STATISTICS
|
---|
779 | # define STAM_PROFILE_ADV_START(pProfileAdv, Prefix) STAM_REL_PROFILE_ADV_START(pProfileAdv, Prefix)
|
---|
780 | #else
|
---|
781 | # define STAM_PROFILE_ADV_START(pProfileAdv, Prefix) do { } while (0)
|
---|
782 | #endif
|
---|
783 |
|
---|
784 |
|
---|
785 | /** @def STAM_REL_PROFILE_ADV_STOP
|
---|
786 | * Samples the stop time of a profiling period and updates the sample.
|
---|
787 | *
|
---|
788 | * @param pProfileAdv Pointer to the STAMPROFILEADV structure to operate on.
|
---|
789 | * @param Prefix Identifier prefix used to internal variables.
|
---|
790 | */
|
---|
791 | #ifndef VBOX_WITHOUT_RELEASE_STATISTICS
|
---|
792 | # define STAM_REL_PROFILE_ADV_STOP(pProfileAdv, Prefix) \
|
---|
793 | do { \
|
---|
794 | uint64_t Prefix##_tsStop; \
|
---|
795 | STAM_GET_TS(Prefix##_tsStop); \
|
---|
796 | if ((pProfileAdv)->tsStart) \
|
---|
797 | { \
|
---|
798 | uint64_t Prefix##_cTicks = Prefix##_tsStop - (pProfileAdv)->tsStart; \
|
---|
799 | (pProfileAdv)->tsStart = 0; \
|
---|
800 | (pProfileAdv)->Core.cTicks += Prefix##_cTicks; \
|
---|
801 | (pProfileAdv)->Core.cPeriods++; \
|
---|
802 | if ((pProfileAdv)->Core.cTicksMax < Prefix##_cTicks) \
|
---|
803 | (pProfileAdv)->Core.cTicksMax = Prefix##_cTicks; \
|
---|
804 | if ((pProfileAdv)->Core.cTicksMin > Prefix##_cTicks) \
|
---|
805 | (pProfileAdv)->Core.cTicksMin = Prefix##_cTicks; \
|
---|
806 | } \
|
---|
807 | } while (0)
|
---|
808 | #else
|
---|
809 | # define STAM_REL_PROFILE_ADV_STOP(pProfileAdv, Prefix) do { } while (0)
|
---|
810 | #endif
|
---|
811 | /** @def STAM_PROFILE_ADV_STOP
|
---|
812 | * Samples the stop time of a profiling period and updates the sample.
|
---|
813 | *
|
---|
814 | * @param pProfileAdv Pointer to the STAMPROFILEADV structure to operate on.
|
---|
815 | * @param Prefix Identifier prefix used to internal variables.
|
---|
816 | */
|
---|
817 | #ifdef VBOX_WITH_STATISTICS
|
---|
818 | # define STAM_PROFILE_ADV_STOP(pProfileAdv, Prefix) STAM_REL_PROFILE_ADV_STOP(pProfileAdv, Prefix)
|
---|
819 | #else
|
---|
820 | # define STAM_PROFILE_ADV_STOP(pProfileAdv, Prefix) do { } while (0)
|
---|
821 | #endif
|
---|
822 |
|
---|
823 |
|
---|
824 | /** @def STAM_REL_PROFILE_ADV_SUSPEND
|
---|
825 | * Suspends the sampling for a while. This can be useful to exclude parts
|
---|
826 | * covered by other samples without screwing up the count, and average+min times.
|
---|
827 | *
|
---|
828 | * @param pProfileAdv Pointer to the STAMPROFILEADV structure to operate on.
|
---|
829 | * @param Prefix Identifier prefix used to internal variables. The prefix
|
---|
830 | * must match that of the resume one since it stores the
|
---|
831 | * suspend time in a stack variable.
|
---|
832 | */
|
---|
833 | #ifndef VBOX_WITHOUT_RELEASE_STATISTICS
|
---|
834 | # define STAM_REL_PROFILE_ADV_SUSPEND(pProfileAdv, Prefix) \
|
---|
835 | uint64_t Prefix##_tsSuspend; \
|
---|
836 | STAM_GET_TS(Prefix##_tsSuspend)
|
---|
837 | #else
|
---|
838 | # define STAM_REL_PROFILE_ADV_SUSPEND(pProfileAdv, Prefix) do { } while (0)
|
---|
839 | #endif
|
---|
840 | /** @def STAM_PROFILE_ADV_SUSPEND
|
---|
841 | * Suspends the sampling for a while. This can be useful to exclude parts
|
---|
842 | * covered by other samples without screwing up the count, and average+min times.
|
---|
843 | *
|
---|
844 | * @param pProfileAdv Pointer to the STAMPROFILEADV structure to operate on.
|
---|
845 | * @param Prefix Identifier prefix used to internal variables. The prefix
|
---|
846 | * must match that of the resume one since it stores the
|
---|
847 | * suspend time in a stack variable.
|
---|
848 | */
|
---|
849 | #ifdef VBOX_WITH_STATISTICS
|
---|
850 | # define STAM_PROFILE_ADV_SUSPEND(pProfileAdv, Prefix) STAM_REL_PROFILE_ADV_SUSPEND(pProfileAdv, Prefix)
|
---|
851 | #else
|
---|
852 | # define STAM_PROFILE_ADV_SUSPEND(pProfileAdv, Prefix) do { } while (0)
|
---|
853 | #endif
|
---|
854 |
|
---|
855 |
|
---|
856 | /** @def STAM_REL_PROFILE_ADV_RESUME
|
---|
857 | * Counter to STAM_REL_PROFILE_ADV_SUSPEND.
|
---|
858 | *
|
---|
859 | * @param pProfileAdv Pointer to the STAMPROFILEADV structure to operate on.
|
---|
860 | * @param Prefix Identifier prefix used to internal variables. This must
|
---|
861 | * match the one used with the SUSPEND!
|
---|
862 | */
|
---|
863 | #ifndef VBOX_WITHOUT_RELEASE_STATISTICS
|
---|
864 | # define STAM_REL_PROFILE_ADV_RESUME(pProfileAdv, Prefix) \
|
---|
865 | do { \
|
---|
866 | uint64_t Prefix##_tsNow; \
|
---|
867 | STAM_GET_TS(Prefix##_tsNow); \
|
---|
868 | (pProfileAdv)->tsStart += Prefix##_tsNow - Prefix##_tsSuspend; \
|
---|
869 | } while (0)
|
---|
870 | #else
|
---|
871 | # define STAM_REL_PROFILE_ADV_RESUME(pProfileAdv, Prefix) do { } while (0)
|
---|
872 | #endif
|
---|
873 | /** @def STAM_PROFILE_ADV_RESUME
|
---|
874 | * Counter to STAM_PROFILE_ADV_SUSPEND.
|
---|
875 | *
|
---|
876 | * @param pProfileAdv Pointer to the STAMPROFILEADV structure to operate on.
|
---|
877 | * @param Prefix Identifier prefix used to internal variables. This must
|
---|
878 | * match the one used with the SUSPEND!
|
---|
879 | */
|
---|
880 | #ifdef VBOX_WITH_STATISTICS
|
---|
881 | # define STAM_PROFILE_ADV_RESUME(pProfileAdv, Prefix) STAM_REL_PROFILE_ADV_RESUME(pProfileAdv, Prefix)
|
---|
882 | #else
|
---|
883 | # define STAM_PROFILE_ADV_RESUME(pProfileAdv, Prefix) do { } while (0)
|
---|
884 | #endif
|
---|
885 |
|
---|
886 |
|
---|
887 | /** @def STAM_REL_PROFILE_ADV_STOP_EX
|
---|
888 | * Samples the stop time of a profiling period and updates both the sample
|
---|
889 | * and an attribution sample.
|
---|
890 | *
|
---|
891 | * @param pProfileAdv Pointer to the STAMPROFILEADV structure to operate on.
|
---|
892 | * @param pProfile2 Pointer to the STAMPROFILE structure which this
|
---|
893 | * interval should be attributed too. This may be NULL.
|
---|
894 | * @param Prefix Identifier prefix used to internal variables.
|
---|
895 | */
|
---|
896 | #ifndef VBOX_WITHOUT_RELEASE_STATISTICS
|
---|
897 | # define STAM_REL_PROFILE_ADV_STOP_EX(pProfileAdv, pProfile2, Prefix) \
|
---|
898 | do { \
|
---|
899 | uint64_t Prefix##_tsStop; \
|
---|
900 | STAM_GET_TS(Prefix##_tsStop); \
|
---|
901 | if ((pProfileAdv)->tsStart) \
|
---|
902 | { \
|
---|
903 | uint64_t Prefix##_cTicks = Prefix##_tsStop - (pProfileAdv)->tsStart; \
|
---|
904 | (pProfileAdv)->tsStart = 0; \
|
---|
905 | (pProfileAdv)->Core.cTicks += Prefix##_cTicks; \
|
---|
906 | (pProfileAdv)->Core.cPeriods++; \
|
---|
907 | if ((pProfileAdv)->Core.cTicksMax < Prefix##_cTicks) \
|
---|
908 | (pProfileAdv)->Core.cTicksMax = Prefix##_cTicks; \
|
---|
909 | if ((pProfileAdv)->Core.cTicksMin > Prefix##_cTicks) \
|
---|
910 | (pProfileAdv)->Core.cTicksMin = Prefix##_cTicks; \
|
---|
911 | if ((pProfile2)) \
|
---|
912 | { \
|
---|
913 | (pProfile2)->cTicks += Prefix##_cTicks; \
|
---|
914 | (pProfile2)->cPeriods++; \
|
---|
915 | if ((pProfile2)->cTicksMax < Prefix##_cTicks) \
|
---|
916 | (pProfile2)->cTicksMax = Prefix##_cTicks; \
|
---|
917 | if ((pProfile2)->cTicksMin > Prefix##_cTicks) \
|
---|
918 | (pProfile2)->cTicksMin = Prefix##_cTicks; \
|
---|
919 | } \
|
---|
920 | } \
|
---|
921 | } while (0)
|
---|
922 | #else
|
---|
923 | # define STAM_REL_PROFILE_ADV_STOP_EX(pProfileAdv, pProfile2, Prefix) do { } while (0)
|
---|
924 | #endif
|
---|
925 | /** @def STAM_PROFILE_ADV_STOP_EX
|
---|
926 | * Samples the stop time of a profiling period and updates both the sample
|
---|
927 | * and an attribution sample.
|
---|
928 | *
|
---|
929 | * @param pProfileAdv Pointer to the STAMPROFILEADV structure to operate on.
|
---|
930 | * @param pProfile2 Pointer to the STAMPROFILE structure which this
|
---|
931 | * interval should be attributed too. This may be NULL.
|
---|
932 | * @param Prefix Identifier prefix used to internal variables.
|
---|
933 | */
|
---|
934 | #ifdef VBOX_WITH_STATISTICS
|
---|
935 | # define STAM_PROFILE_ADV_STOP_EX(pProfileAdv, pProfile2, Prefix) STAM_REL_PROFILE_ADV_STOP_EX(pProfileAdv, pProfile2, Prefix)
|
---|
936 | #else
|
---|
937 | # define STAM_PROFILE_ADV_STOP_EX(pProfileAdv, pProfile2, Prefix) do { } while (0)
|
---|
938 | #endif
|
---|
939 |
|
---|
940 |
|
---|
941 | /**
|
---|
942 | * Ratio of A to B, uint32_t types.
|
---|
943 | * @remark Use STAM_STATS or STAM_REL_STATS for modifying A & B values.
|
---|
944 | */
|
---|
945 | typedef struct STAMRATIOU32
|
---|
946 | {
|
---|
947 | /** Sample A. */
|
---|
948 | uint32_t volatile u32A;
|
---|
949 | /** Sample B. */
|
---|
950 | uint32_t volatile u32B;
|
---|
951 | } STAMRATIOU32;
|
---|
952 | /** Pointer to a uint32_t ratio. */
|
---|
953 | typedef STAMRATIOU32 *PSTAMRATIOU32;
|
---|
954 | /** Pointer to const a uint32_t ratio. */
|
---|
955 | typedef const STAMRATIOU32 *PCSTAMRATIOU32;
|
---|
956 |
|
---|
957 |
|
---|
958 |
|
---|
959 |
|
---|
960 | /** @defgroup grp_stam_r3 The STAM Host Context Ring 3 API
|
---|
961 | * @ingroup grp_stam
|
---|
962 | * @{
|
---|
963 | */
|
---|
964 |
|
---|
965 | STAMR3DECL(int) STAMR3InitUVM(PUVM pUVM);
|
---|
966 | STAMR3DECL(void) STAMR3TermUVM(PUVM pUVM);
|
---|
967 | STAMR3DECL(int) STAMR3RegisterU(PUVM pUVM, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
|
---|
968 | const char *pszName, STAMUNIT enmUnit, const char *pszDesc);
|
---|
969 | STAMR3DECL(int) STAMR3Register(PVM pVM, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
|
---|
970 | const char *pszName, STAMUNIT enmUnit, const char *pszDesc);
|
---|
971 |
|
---|
972 | /** @def STAM_REL_REG
|
---|
973 | * Registers a statistics sample.
|
---|
974 | *
|
---|
975 | * @param pVM VM Handle.
|
---|
976 | * @param pvSample Pointer to the sample.
|
---|
977 | * @param enmType Sample type. This indicates what pvSample is pointing at.
|
---|
978 | * @param pszName Sample name. The name is on this form "/<component>/<sample>".
|
---|
979 | * Further nesting is possible.
|
---|
980 | * @param enmUnit Sample unit.
|
---|
981 | * @param pszDesc Sample description.
|
---|
982 | */
|
---|
983 | #define STAM_REL_REG(pVM, pvSample, enmType, pszName, enmUnit, pszDesc) \
|
---|
984 | STAM_REL_STATS({ int rcStam = STAMR3Register(pVM, pvSample, enmType, STAMVISIBILITY_ALWAYS, pszName, enmUnit, pszDesc); \
|
---|
985 | AssertRC(rcStam); })
|
---|
986 | /** @def STAM_REG
|
---|
987 | * Registers a statistics sample if statistics are enabled.
|
---|
988 | *
|
---|
989 | * @param pVM VM Handle.
|
---|
990 | * @param pvSample Pointer to the sample.
|
---|
991 | * @param enmType Sample type. This indicates what pvSample is pointing at.
|
---|
992 | * @param pszName Sample name. The name is on this form "/<component>/<sample>".
|
---|
993 | * Further nesting is possible.
|
---|
994 | * @param enmUnit Sample unit.
|
---|
995 | * @param pszDesc Sample description.
|
---|
996 | */
|
---|
997 | #define STAM_REG(pVM, pvSample, enmType, pszName, enmUnit, pszDesc) \
|
---|
998 | STAM_STATS({STAM_REL_REG(pVM, pvSample, enmType, pszName, enmUnit, pszDesc);})
|
---|
999 |
|
---|
1000 | /** @def STAM_REL_REG_USED
|
---|
1001 | * Registers a statistics sample which only shows when used.
|
---|
1002 | *
|
---|
1003 | * @param pVM VM Handle.
|
---|
1004 | * @param pvSample Pointer to the sample.
|
---|
1005 | * @param enmType Sample type. This indicates what pvSample is pointing at.
|
---|
1006 | * @param pszName Sample name. The name is on this form "/<component>/<sample>".
|
---|
1007 | * Further nesting is possible.
|
---|
1008 | * @param enmUnit Sample unit.
|
---|
1009 | * @param pszDesc Sample description.
|
---|
1010 | */
|
---|
1011 | #define STAM_REL_REG_USED(pVM, pvSample, enmType, pszName, enmUnit, pszDesc) \
|
---|
1012 | STAM_REL_STATS({ int rcStam = STAMR3Register(pVM, pvSample, enmType, STAMVISIBILITY_USED, pszName, enmUnit, pszDesc); \
|
---|
1013 | AssertRC(rcStam);})
|
---|
1014 | /** @def STAM_REG_USED
|
---|
1015 | * Registers a statistics sample which only shows when used, if statistics are enabled.
|
---|
1016 | *
|
---|
1017 | * @param pVM VM Handle.
|
---|
1018 | * @param pvSample Pointer to the sample.
|
---|
1019 | * @param enmType Sample type. This indicates what pvSample is pointing at.
|
---|
1020 | * @param pszName Sample name. The name is on this form "/<component>/<sample>".
|
---|
1021 | * Further nesting is possible.
|
---|
1022 | * @param enmUnit Sample unit.
|
---|
1023 | * @param pszDesc Sample description.
|
---|
1024 | */
|
---|
1025 | #define STAM_REG_USED(pVM, pvSample, enmType, pszName, enmUnit, pszDesc) \
|
---|
1026 | STAM_STATS({ STAM_REL_REG_USED(pVM, pvSample, enmType, pszName, enmUnit, pszDesc); })
|
---|
1027 |
|
---|
1028 | STAMR3DECL(int) STAMR3RegisterFU(PUVM pUVM, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility, STAMUNIT enmUnit,
|
---|
1029 | const char *pszDesc, const char *pszName, ...);
|
---|
1030 | STAMR3DECL(int) STAMR3RegisterF(PVM pVM, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility, STAMUNIT enmUnit,
|
---|
1031 | const char *pszDesc, const char *pszName, ...);
|
---|
1032 | STAMR3DECL(int) STAMR3RegisterVU(PUVM pUVM, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility, STAMUNIT enmUnit,
|
---|
1033 | const char *pszDesc, const char *pszName, va_list args);
|
---|
1034 | STAMR3DECL(int) STAMR3RegisterV(PVM pVM, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility, STAMUNIT enmUnit,
|
---|
1035 | const char *pszDesc, const char *pszName, va_list args);
|
---|
1036 |
|
---|
1037 | /**
|
---|
1038 | * Resets the sample.
|
---|
1039 | * @param pVM The VM handle.
|
---|
1040 | * @param pvSample The sample registered using STAMR3RegisterCallback.
|
---|
1041 | */
|
---|
1042 | typedef void FNSTAMR3CALLBACKRESET(PVM pVM, void *pvSample);
|
---|
1043 | /** Pointer to a STAM sample reset callback. */
|
---|
1044 | typedef FNSTAMR3CALLBACKRESET *PFNSTAMR3CALLBACKRESET;
|
---|
1045 |
|
---|
1046 | /**
|
---|
1047 | * Prints the sample into the buffer.
|
---|
1048 | *
|
---|
1049 | * @param pVM The VM handle.
|
---|
1050 | * @param pvSample The sample registered using STAMR3RegisterCallback.
|
---|
1051 | * @param pszBuf The buffer to print into.
|
---|
1052 | * @param cchBuf The size of the buffer.
|
---|
1053 | */
|
---|
1054 | typedef void FNSTAMR3CALLBACKPRINT(PVM pVM, void *pvSample, char *pszBuf, size_t cchBuf);
|
---|
1055 | /** Pointer to a STAM sample print callback. */
|
---|
1056 | typedef FNSTAMR3CALLBACKPRINT *PFNSTAMR3CALLBACKPRINT;
|
---|
1057 |
|
---|
1058 | STAMR3DECL(int) STAMR3RegisterCallback(PVM pVM, void *pvSample, STAMVISIBILITY enmVisibility, STAMUNIT enmUnit,
|
---|
1059 | PFNSTAMR3CALLBACKRESET pfnReset, PFNSTAMR3CALLBACKPRINT pfnPrint,
|
---|
1060 | const char *pszDesc, const char *pszName, ...);
|
---|
1061 | STAMR3DECL(int) STAMR3RegisterCallbackV(PVM pVM, void *pvSample, STAMVISIBILITY enmVisibility, STAMUNIT enmUnit,
|
---|
1062 | PFNSTAMR3CALLBACKRESET pfnReset, PFNSTAMR3CALLBACKPRINT pfnPrint,
|
---|
1063 | const char *pszDesc, const char *pszName, va_list args);
|
---|
1064 | STAMR3DECL(int) STAMR3DeregisterU(PUVM pUVM, void *pvSample);
|
---|
1065 | STAMR3DECL(int) STAMR3Deregister(PVM pVM, void *pvSample);
|
---|
1066 |
|
---|
1067 | /** @def STAM_REL_DEREG
|
---|
1068 | * Deregisters a statistics sample if statistics are enabled.
|
---|
1069 | *
|
---|
1070 | * @param pVM VM Handle.
|
---|
1071 | * @param pvSample Pointer to the sample.
|
---|
1072 | */
|
---|
1073 | #define STAM_REL_DEREG(pVM, pvSample) \
|
---|
1074 | STAM_REL_STATS({ int rcStam = STAMR3Deregister(pVM, pvSample); AssertRC(rcStam); })
|
---|
1075 | /** @def STAM_DEREG
|
---|
1076 | * Deregisters a statistics sample if statistics are enabled.
|
---|
1077 | *
|
---|
1078 | * @param pVM VM Handle.
|
---|
1079 | * @param pvSample Pointer to the sample.
|
---|
1080 | */
|
---|
1081 | #define STAM_DEREG(pVM, pvSample) \
|
---|
1082 | STAM_STATS({ STAM_REL_DEREG(pVM, pvSample); })
|
---|
1083 |
|
---|
1084 | STAMR3DECL(int) STAMR3ResetU(PUVM pUVM, const char *pszPat);
|
---|
1085 | STAMR3DECL(int) STAMR3Reset(PVM pVM, const char *pszPat);
|
---|
1086 | STAMR3DECL(int) STAMR3SnapshotU(PUVM pUVM, const char *pszPat, char **ppszSnapshot, size_t *pcchSnapshot, bool fWithDesc);
|
---|
1087 | STAMR3DECL(int) STAMR3Snapshot(PVM pVM, const char *pszPat, char **ppszSnapshot, size_t *pcchSnapshot, bool fWithDesc);
|
---|
1088 | STAMR3DECL(int) STAMR3SnapshotFreeU(PUVM pUVM, char *pszSnapshot);
|
---|
1089 | STAMR3DECL(int) STAMR3SnapshotFree(PVM pVM, char *pszSnapshot);
|
---|
1090 | STAMR3DECL(int) STAMR3DumpU(PUVM pUVM, const char *pszPat);
|
---|
1091 | STAMR3DECL(int) STAMR3Dump(PVM pVM, const char *pszPat);
|
---|
1092 | STAMR3DECL(int) STAMR3DumpToReleaseLogU(PUVM pUVM, const char *pszPat);
|
---|
1093 | STAMR3DECL(int) STAMR3DumpToReleaseLog(PVM pVM, const char *pszPat);
|
---|
1094 | STAMR3DECL(int) STAMR3PrintU(PUVM pUVM, const char *pszPat);
|
---|
1095 | STAMR3DECL(int) STAMR3Print(PVM pVM, const char *pszPat);
|
---|
1096 |
|
---|
1097 | /**
|
---|
1098 | * Callback function for STAMR3Enum().
|
---|
1099 | *
|
---|
1100 | * @returns non-zero to halt the enumeration.
|
---|
1101 | *
|
---|
1102 | * @param pszName The name of the sample.
|
---|
1103 | * @param enmType The type.
|
---|
1104 | * @param pvSample Pointer to the data. enmType indicates the format of this data.
|
---|
1105 | * @param enmUnit The unit.
|
---|
1106 | * @param enmVisibility The visibility.
|
---|
1107 | * @param pszDesc The description.
|
---|
1108 | * @param pvUser The pvUser argument given to STAMR3Enum().
|
---|
1109 | */
|
---|
1110 | typedef DECLCALLBACK(int) FNSTAMR3ENUM(const char *pszName, STAMTYPE enmType, void *pvSample, STAMUNIT enmUnit,
|
---|
1111 | STAMVISIBILITY enmVisiblity, const char *pszDesc, void *pvUser);
|
---|
1112 | /** Pointer to a FNSTAMR3ENUM(). */
|
---|
1113 | typedef FNSTAMR3ENUM *PFNSTAMR3ENUM;
|
---|
1114 |
|
---|
1115 | STAMR3DECL(int) STAMR3EnumU(PUVM pUVM, const char *pszPat, PFNSTAMR3ENUM pfnEnum, void *pvUser);
|
---|
1116 | STAMR3DECL(int) STAMR3Enum(PVM pVM, const char *pszPat, PFNSTAMR3ENUM pfnEnum, void *pvUser);
|
---|
1117 | STAMR3DECL(const char *) STAMR3GetUnit(STAMUNIT enmUnit);
|
---|
1118 |
|
---|
1119 | /** @} */
|
---|
1120 |
|
---|
1121 | /** @} */
|
---|
1122 |
|
---|
1123 | __END_DECLS
|
---|
1124 |
|
---|
1125 | #endif
|
---|