VirtualBox

source: vbox/trunk/include/VBox/vmm/stam.h@ 90959

Last change on this file since 90959 was 90834, checked in by vboxsync, 3 years ago

Doxygen fixes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 46.0 KB
Line 
1/** @file
2 * STAM - Statistics Manager.
3 */
4
5/*
6 * Copyright (C) 2006-2020 Oracle Corporation
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_INCLUDED_vmm_stam_h
27#define VBOX_INCLUDED_vmm_stam_h
28#ifndef RT_WITHOUT_PRAGMA_ONCE
29# pragma once
30#endif
31
32#include <VBox/types.h>
33#include <iprt/stdarg.h>
34#ifdef _MSC_VER
35# if RT_MSC_PREREQ(RT_MSC_VER_VS2005)
36# include <iprt/sanitized/intrin.h>
37# endif
38#endif
39#if defined(RT_ARCH_ARM64) || defined(RT_ARCH_ARM32)
40# include <iprt/asm-arm.h>
41#endif
42
43RT_C_DECLS_BEGIN
44
45/** @defgroup grp_stam The Statistics Manager API
46 * @ingroup grp_vmm
47 * @{
48 */
49
50#if defined(VBOX_WITHOUT_RELEASE_STATISTICS) && defined(VBOX_WITH_STATISTICS)
51# error "Both VBOX_WITHOUT_RELEASE_STATISTICS and VBOX_WITH_STATISTICS are defined! Make up your mind!"
52#endif
53
54
55/** @def STAM_GET_TS
56 * Gets the CPU timestamp counter.
57 *
58 * @param u64 The 64-bit variable which the timestamp shall be saved in.
59 */
60#if defined(RT_ARCH_ARM64) || defined(RT_ARCH_ARM32)
61# define STAM_GET_TS(u64) do { (u64) = ASMReadTSC(); } while (0)
62#elif defined(__GNUC__)
63# if defined(RT_ARCH_X86)
64 /* This produces optimal assembler code for x86 but does not work for AMD64 ('A' means 'either rax or rdx') */
65# define STAM_GET_TS(u64) __asm__ __volatile__ ("rdtsc\n\t" : "=A" (u64))
66# elif defined(RT_ARCH_AMD64)
67# define STAM_GET_TS(u64) \
68 do { uint64_t low; uint64_t high; \
69 __asm__ __volatile__ ("rdtsc\n\t" : "=a"(low), "=d"(high)); \
70 (u64) = ((high << 32) | low); \
71 } while (0)
72# endif
73#else
74# if RT_MSC_PREREQ(RT_MSC_VER_VS2005)
75# pragma intrinsic(__rdtsc)
76# define STAM_GET_TS(u64) \
77 do { (u64) = __rdtsc(); } while (0)
78# else
79# define STAM_GET_TS(u64) \
80 do { \
81 uint64_t u64Tmp; \
82 __asm { \
83 __asm rdtsc \
84 __asm mov dword ptr [u64Tmp], eax \
85 __asm mov dword ptr [u64Tmp + 4], edx \
86 } \
87 (u64) = u64Tmp; \
88 } while (0)
89# endif
90#endif
91
92
93/** @def STAM_REL_STATS
94 * Code for inclusion only when VBOX_WITH_STATISTICS is defined.
95 * @param code A code block enclosed in {}.
96 */
97#ifndef VBOX_WITHOUT_RELEASE_STATISTICS
98# define STAM_REL_STATS(code) do code while(0)
99#else
100# define STAM_REL_STATS(code) do {} while(0)
101#endif
102/** @def STAM_STATS
103 * Code for inclusion only when VBOX_WITH_STATISTICS is defined.
104 * @param code A code block enclosed in {}.
105 */
106#ifdef VBOX_WITH_STATISTICS
107# define STAM_STATS(code) STAM_REL_STATS(code)
108#else
109# define STAM_STATS(code) do {} while(0)
110#endif
111
112
113/**
114 * Sample type.
115 */
116typedef enum STAMTYPE
117{
118 /** Invalid entry. */
119 STAMTYPE_INVALID = 0,
120 /** Generic counter. */
121 STAMTYPE_COUNTER,
122 /** Profiling of an function. */
123 STAMTYPE_PROFILE,
124 /** Profiling of an operation. */
125 STAMTYPE_PROFILE_ADV,
126 /** Ratio of A to B, uint32_t types. Not reset. */
127 STAMTYPE_RATIO_U32,
128 /** Ratio of A to B, uint32_t types. Reset both to 0. */
129 STAMTYPE_RATIO_U32_RESET,
130 /** Callback. */
131 STAMTYPE_CALLBACK,
132 /** Generic unsigned 8-bit value. Not reset. */
133 STAMTYPE_U8,
134 /** Generic unsigned 8-bit value. Reset to 0. */
135 STAMTYPE_U8_RESET,
136 /** Generic hexadecimal unsigned 8-bit value. Not reset. */
137 STAMTYPE_X8,
138 /** Generic hexadecimal unsigned 8-bit value. Reset to 0. */
139 STAMTYPE_X8_RESET,
140 /** Generic unsigned 16-bit value. Not reset. */
141 STAMTYPE_U16,
142 /** Generic unsigned 16-bit value. Reset to 0. */
143 STAMTYPE_U16_RESET,
144 /** Generic hexadecimal unsigned 16-bit value. Not reset. */
145 STAMTYPE_X16,
146 /** Generic hexadecimal unsigned 16-bit value. Reset to 0. */
147 STAMTYPE_X16_RESET,
148 /** Generic unsigned 32-bit value. Not reset. */
149 STAMTYPE_U32,
150 /** Generic unsigned 32-bit value. Reset to 0. */
151 STAMTYPE_U32_RESET,
152 /** Generic hexadecimal unsigned 32-bit value. Not reset. */
153 STAMTYPE_X32,
154 /** Generic hexadecimal unsigned 32-bit value. Reset to 0. */
155 STAMTYPE_X32_RESET,
156 /** Generic unsigned 64-bit value. Not reset. */
157 STAMTYPE_U64,
158 /** Generic unsigned 64-bit value. Reset to 0. */
159 STAMTYPE_U64_RESET,
160 /** Generic hexadecimal unsigned 64-bit value. Not reset. */
161 STAMTYPE_X64,
162 /** Generic hexadecimal unsigned 64-bit value. Reset to 0. */
163 STAMTYPE_X64_RESET,
164 /** Generic boolean value. Not reset. */
165 STAMTYPE_BOOL,
166 /** Generic boolean value. Reset to false. */
167 STAMTYPE_BOOL_RESET,
168 /** The end (exclusive). */
169 STAMTYPE_END
170} STAMTYPE;
171
172/**
173 * Sample visibility type.
174 */
175typedef enum STAMVISIBILITY
176{
177 /** Invalid entry. */
178 STAMVISIBILITY_INVALID = 0,
179 /** Always visible. */
180 STAMVISIBILITY_ALWAYS,
181 /** Only visible when used (/hit). */
182 STAMVISIBILITY_USED,
183 /** Not visible in the GUI. */
184 STAMVISIBILITY_NOT_GUI,
185 /** The end (exclusive). */
186 STAMVISIBILITY_END
187} STAMVISIBILITY;
188
189/**
190 * Sample unit.
191 */
192typedef enum STAMUNIT
193{
194 /** Invalid entry .*/
195 STAMUNIT_INVALID = 0,
196 /** No unit. */
197 STAMUNIT_NONE,
198 /** Number of calls. */
199 STAMUNIT_CALLS,
200 /** Count of whatever. */
201 STAMUNIT_COUNT,
202 /** Count of bytes. */
203 STAMUNIT_BYTES,
204 /** Count of bytes. */
205 STAMUNIT_PAGES,
206 /** Error count. */
207 STAMUNIT_ERRORS,
208 /** Number of occurences. */
209 STAMUNIT_OCCURENCES,
210 /** Ticks. */
211 STAMUNIT_TICKS,
212 /** Ticks per call. */
213 STAMUNIT_TICKS_PER_CALL,
214 /** Ticks per occurence. */
215 STAMUNIT_TICKS_PER_OCCURENCE,
216 /** Ratio of good vs. bad. */
217 STAMUNIT_GOOD_BAD,
218 /** Megabytes. */
219 STAMUNIT_MEGABYTES,
220 /** Kilobytes. */
221 STAMUNIT_KILOBYTES,
222 /** Nano seconds. */
223 STAMUNIT_NS,
224 /** Nanoseconds per call. */
225 STAMUNIT_NS_PER_CALL,
226 /** Nanoseconds per call. */
227 STAMUNIT_NS_PER_OCCURENCE,
228 /** Percentage. */
229 STAMUNIT_PCT,
230 /** Hertz. */
231 STAMUNIT_HZ,
232 /** The end (exclusive). */
233 STAMUNIT_END
234} STAMUNIT;
235
236/** @name STAM_REFRESH_GRP_XXX - STAM refresh groups
237 * @{ */
238#define STAM_REFRESH_GRP_NONE UINT8_MAX
239#define STAM_REFRESH_GRP_GVMM 0
240#define STAM_REFRESH_GRP_GMM 1
241#define STAM_REFRESH_GRP_NEM 2
242/** @} */
243
244
245/** @def STAM_REL_U8_INC
246 * Increments a uint8_t sample by one.
247 *
248 * @param pCounter Pointer to the uint8_t variable to operate on.
249 */
250#ifndef VBOX_WITHOUT_RELEASE_STATISTICS
251# define STAM_REL_U8_INC(pCounter) \
252 do { ++*(pCounter); } while (0)
253#else
254# define STAM_REL_U8_INC(pCounter) do { } while (0)
255#endif
256/** @def STAM_U8_INC
257 * Increments a uint8_t sample by one.
258 *
259 * @param pCounter Pointer to the uint8_t variable to operate on.
260 */
261#ifdef VBOX_WITH_STATISTICS
262# define STAM_U8_INC(pCounter) STAM_REL_U8_INC(pCounter)
263#else
264# define STAM_U8_INC(pCounter) do { } while (0)
265#endif
266
267
268/** @def STAM_REL_U8_DEC
269 * Decrements a uint8_t sample by one.
270 *
271 * @param pCounter Pointer to the uint8_t variable to operate on.
272 */
273#ifndef VBOX_WITHOUT_RELEASE_STATISTICS
274# define STAM_REL_U8_DEC(pCounter) \
275 do { --*(pCounter); } while (0)
276#else
277# define STAM_REL_U8_DEC(pCounter) do { } while (0)
278#endif
279/** @def STAM_U8_DEC
280 * Decrements a uint8_t sample by one.
281 *
282 * @param pCounter Pointer to the uint8_t variable to operate on.
283 */
284#ifdef VBOX_WITH_STATISTICS
285# define STAM_U8_DEC(pCounter) STAM_REL_U8_DEC(pCounter)
286#else
287# define STAM_U8_DEC(pCounter) do { } while (0)
288#endif
289
290
291/** @def STAM_REL_U8_ADD
292 * Increments a uint8_t sample by a value.
293 *
294 * @param pCounter Pointer to the uint8_t variable to operate on.
295 * @param Addend The value to add.
296 */
297#ifndef VBOX_WITHOUT_RELEASE_STATISTICS
298# define STAM_REL_U8_ADD(pCounter, Addend) \
299 do { *(pCounter) += (Addend); } while (0)
300#else
301# define STAM_REL_U8_ADD(pCounter, Addend) do { } while (0)
302#endif
303/** @def STAM_U8_ADD
304 * Increments a uint8_t sample by a value.
305 *
306 * @param pCounter Pointer to the uint8_t variable to operate on.
307 * @param Addend The value to add.
308 */
309#ifdef VBOX_WITH_STATISTICS
310# define STAM_U8_ADD(pCounter, Addend) STAM_REL_U8_ADD(pCounter, Addend
311#else
312# define STAM_U8_ADD(pCounter, Addend) do { } while (0)
313#endif
314
315
316/** @def STAM_REL_U16_INC
317 * Increments a uint16_t sample by one.
318 *
319 * @param pCounter Pointer to the uint16_t variable to operate on.
320 */
321#ifndef VBOX_WITHOUT_RELEASE_STATISTICS
322# define STAM_REL_U16_INC(pCounter) \
323 do { ++*(pCounter); } while (0)
324#else
325# define STAM_REL_U16_INC(pCounter) do { } while (0)
326#endif
327/** @def STAM_U16_INC
328 * Increments a uint16_t sample by one.
329 *
330 * @param pCounter Pointer to the uint16_t variable to operate on.
331 */
332#ifdef VBOX_WITH_STATISTICS
333# define STAM_U16_INC(pCounter) STAM_REL_U16_INC(pCounter)
334#else
335# define STAM_U16_INC(pCounter) do { } while (0)
336#endif
337
338
339/** @def STAM_REL_U16_DEC
340 * Decrements a uint16_t sample by one.
341 *
342 * @param pCounter Pointer to the uint16_t variable to operate on.
343 */
344#ifndef VBOX_WITHOUT_RELEASE_STATISTICS
345# define STAM_REL_U16_DEC(pCounter) \
346 do { --*(pCounter); } while (0)
347#else
348# define STAM_REL_U16_DEC(pCounter) do { } while (0)
349#endif
350/** @def STAM_U16_DEC
351 * Decrements a uint16_t sample by one.
352 *
353 * @param pCounter Pointer to the uint16_t variable to operate on.
354 */
355#ifdef VBOX_WITH_STATISTICS
356# define STAM_U16_DEC(pCounter) STAM_REL_U16_DEC(pCounter)
357#else
358# define STAM_U16_DEC(pCounter) do { } while (0)
359#endif
360
361
362/** @def STAM_REL_U16_ADD
363 * Increments a uint16_t sample by a value.
364 *
365 * @param pCounter Pointer to the uint16_t variable to operate on.
366 * @param Addend The value to add.
367 */
368#ifndef VBOX_WITHOUT_RELEASE_STATISTICS
369# define STAM_REL_U16_ADD(pCounter, Addend) \
370 do { *(pCounter) += (Addend); } while (0)
371#else
372# define STAM_REL_U16_ADD(pCounter, Addend) do { } while (0)
373#endif
374/** @def STAM_U16_ADD
375 * Increments a uint16_t sample by a value.
376 *
377 * @param pCounter Pointer to the uint16_t variable to operate on.
378 * @param Addend The value to add.
379 */
380#ifdef VBOX_WITH_STATISTICS
381# define STAM_U16_ADD(pCounter, Addend) STAM_REL_U16_ADD(pCounter, Addend)
382#else
383# define STAM_U16_ADD(pCounter, Addend) do { } while (0)
384#endif
385
386
387/** @def STAM_REL_U32_INC
388 * Increments a uint32_t sample by one.
389 *
390 * @param pCounter Pointer to the uint32_t variable to operate on.
391 */
392#ifndef VBOX_WITHOUT_RELEASE_STATISTICS
393# define STAM_REL_U32_INC(pCounter) \
394 do { ++*(pCounter); } while (0)
395#else
396# define STAM_REL_U32_INC(pCounter) do { } while (0)
397#endif
398/** @def STAM_U32_INC
399 * Increments a uint32_t sample by one.
400 *
401 * @param pCounter Pointer to the uint32_t variable to operate on.
402 */
403#ifdef VBOX_WITH_STATISTICS
404# define STAM_U32_INC(pCounter) STAM_REL_U32_INC(pCounter)
405#else
406# define STAM_U32_INC(pCounter) do { } while (0)
407#endif
408
409
410/** @def STAM_REL_U32_DEC
411 * Decrements a uint32_t sample by one.
412 *
413 * @param pCounter Pointer to the uint32_t variable to operate on.
414 */
415#ifndef VBOX_WITHOUT_RELEASE_STATISTICS
416# define STAM_REL_U32_DEC(pCounter) \
417 do { --*(pCounter); } while (0)
418#else
419# define STAM_REL_U32_DEC(pCounter) do { } while (0)
420#endif
421/** @def STAM_U32_DEC
422 * Decrements a uint32_t sample by one.
423 *
424 * @param pCounter Pointer to the uint32_t variable to operate on.
425 */
426#ifdef VBOX_WITH_STATISTICS
427# define STAM_U32_DEC(pCounter) STAM_REL_U32_DEC(pCounter)
428#else
429# define STAM_U32_DEC(pCounter) do { } while (0)
430#endif
431
432
433/** @def STAM_REL_U32_ADD
434 * Increments a uint32_t sample by value.
435 *
436 * @param pCounter Pointer to the uint32_t variable to operate on.
437 * @param Addend The value to add.
438 */
439#ifndef VBOX_WITHOUT_RELEASE_STATISTICS
440# define STAM_REL_U32_ADD(pCounter, Addend) \
441 do { *(pCounter) += (Addend); } while (0)
442#else
443# define STAM_REL_U32_ADD(pCounter, Addend) do { } while (0)
444#endif
445/** @def STAM_U32_ADD
446 * Increments a uint32_t sample by value.
447 *
448 * @param pCounter Pointer to the uint32_t variable to operate on.
449 * @param Addend The value to add.
450 */
451#ifdef VBOX_WITH_STATISTICS
452# define STAM_U32_ADD(pCounter, Addend) STAM_REL_U32_ADD(pCounter, Addend)
453#else
454# define STAM_U32_ADD(pCounter, Addend) do { } while (0)
455#endif
456
457
458/** @def STAM_REL_U64_INC
459 * Increments a uint64_t sample by one.
460 *
461 * @param pCounter Pointer to the uint64_t variable to operate on.
462 */
463#ifndef VBOX_WITHOUT_RELEASE_STATISTICS
464# define STAM_REL_U64_INC(pCounter) \
465 do { ++*(pCounter); } while (0)
466#else
467# define STAM_REL_U64_INC(pCounter) do { } while (0)
468#endif
469/** @def STAM_U64_INC
470 * Increments a uint64_t sample by one.
471 *
472 * @param pCounter Pointer to the uint64_t variable to operate on.
473 */
474#ifdef VBOX_WITH_STATISTICS
475# define STAM_U64_INC(pCounter) STAM_REL_U64_INC(pCounter)
476#else
477# define STAM_U64_INC(pCounter) do { } while (0)
478#endif
479
480
481/** @def STAM_REL_U64_DEC
482 * Decrements a uint64_t sample by one.
483 *
484 * @param pCounter Pointer to the uint64_t variable to operate on.
485 */
486#ifndef VBOX_WITHOUT_RELEASE_STATISTICS
487# define STAM_REL_U64_DEC(pCounter) \
488 do { --*(pCounter); } while (0)
489#else
490# define STAM_REL_U64_DEC(pCounter) do { } while (0)
491#endif
492/** @def STAM_U64_DEC
493 * Decrements a uint64_t sample by one.
494 *
495 * @param pCounter Pointer to the uint64_t variable to operate on.
496 */
497#ifdef VBOX_WITH_STATISTICS
498# define STAM_U64_DEC(pCounter) STAM_REL_U64_DEC(pCounter)
499#else
500# define STAM_U64_DEC(pCounter) do { } while (0)
501#endif
502
503
504/** @def STAM_REL_U64_ADD
505 * Increments a uint64_t sample by a value.
506 *
507 * @param pCounter Pointer to the uint64_t variable to operate on.
508 * @param Addend The value to add.
509 */
510#ifndef VBOX_WITHOUT_RELEASE_STATISTICS
511# define STAM_REL_U64_ADD(pCounter, Addend) \
512 do { *(pCounter) += (Addend); } while (0)
513#else
514# define STAM_REL_U64_ADD(pCounter, Addend) do { } while (0)
515#endif
516/** @def STAM_U64_ADD
517 * Increments a uint64_t sample by a value.
518 *
519 * @param pCounter Pointer to the uint64_t variable to operate on.
520 * @param Addend The value to add.
521 */
522#ifdef VBOX_WITH_STATISTICS
523# define STAM_U64_ADD(pCounter, Addend) STAM_REL_U64_ADD(pCounter, Addend)
524#else
525# define STAM_U64_ADD(pCounter, Addend) do { } while (0)
526#endif
527
528
529/**
530 * Counter sample - STAMTYPE_COUNTER.
531 */
532typedef struct STAMCOUNTER
533{
534 /** The current count. */
535 volatile uint64_t c;
536} STAMCOUNTER;
537/** Pointer to a counter. */
538typedef STAMCOUNTER *PSTAMCOUNTER;
539/** Pointer to a const counter. */
540typedef const STAMCOUNTER *PCSTAMCOUNTER;
541
542
543/** @def STAM_REL_COUNTER_INC
544 * Increments a counter sample by one.
545 *
546 * @param pCounter Pointer to the STAMCOUNTER structure to operate on.
547 */
548#ifndef VBOX_WITHOUT_RELEASE_STATISTICS
549# define STAM_REL_COUNTER_INC(pCounter) \
550 do { (pCounter)->c++; } while (0)
551#else
552# define STAM_REL_COUNTER_INC(pCounter) do { } while (0)
553#endif
554/** @def STAM_COUNTER_INC
555 * Increments a counter sample by one.
556 *
557 * @param pCounter Pointer to the STAMCOUNTER structure to operate on.
558 */
559#ifdef VBOX_WITH_STATISTICS
560# define STAM_COUNTER_INC(pCounter) STAM_REL_COUNTER_INC(pCounter)
561#else
562# define STAM_COUNTER_INC(pCounter) do { } while (0)
563#endif
564
565
566/** @def STAM_REL_COUNTER_DEC
567 * Decrements a counter sample by one.
568 *
569 * @param pCounter Pointer to the STAMCOUNTER structure to operate on.
570 */
571#ifndef VBOX_WITHOUT_RELEASE_STATISTICS
572# define STAM_REL_COUNTER_DEC(pCounter) \
573 do { (pCounter)->c--; } while (0)
574#else
575# define STAM_REL_COUNTER_DEC(pCounter) do { } while (0)
576#endif
577/** @def STAM_COUNTER_DEC
578 * Decrements a counter sample by one.
579 *
580 * @param pCounter Pointer to the STAMCOUNTER structure to operate on.
581 */
582#ifdef VBOX_WITH_STATISTICS
583# define STAM_COUNTER_DEC(pCounter) STAM_REL_COUNTER_DEC(pCounter)
584#else
585# define STAM_COUNTER_DEC(pCounter) do { } while (0)
586#endif
587
588
589/** @def STAM_REL_COUNTER_ADD
590 * Increments a counter sample by a value.
591 *
592 * @param pCounter Pointer to the STAMCOUNTER structure to operate on.
593 * @param Addend The value to add to the counter.
594 */
595#ifndef VBOX_WITHOUT_RELEASE_STATISTICS
596# define STAM_REL_COUNTER_ADD(pCounter, Addend) \
597 do { (pCounter)->c += (Addend); } while (0)
598#else
599# define STAM_REL_COUNTER_ADD(pCounter, Addend) do { } while (0)
600#endif
601/** @def STAM_COUNTER_ADD
602 * Increments a counter sample by a value.
603 *
604 * @param pCounter Pointer to the STAMCOUNTER structure to operate on.
605 * @param Addend The value to add to the counter.
606 */
607#ifdef VBOX_WITH_STATISTICS
608# define STAM_COUNTER_ADD(pCounter, Addend) STAM_REL_COUNTER_ADD(pCounter, Addend)
609#else
610# define STAM_COUNTER_ADD(pCounter, Addend) do { } while (0)
611#endif
612
613
614/** @def STAM_REL_COUNTER_RESET
615 * Resets the statistics sample.
616 */
617#ifndef VBOX_WITHOUT_RELEASE_STATISTICS
618# define STAM_REL_COUNTER_RESET(pCounter) do { (pCounter)->c = 0; } while (0)
619#else
620# define STAM_REL_COUNTER_RESET(pCounter) do { } while (0)
621#endif
622/** @def STAM_COUNTER_RESET
623 * Resets the statistics sample.
624 */
625#ifdef VBOX_WITH_STATISTICS
626# define STAM_COUNTER_RESET(pCounter) STAM_REL_COUNTER_RESET(pCounter)
627#else
628# define STAM_COUNTER_RESET(pCounter) do { } while (0)
629#endif
630
631
632
633/**
634 * Profiling sample - STAMTYPE_PROFILE.
635 */
636typedef struct STAMPROFILE
637{
638 /** Number of periods. */
639 volatile uint64_t cPeriods;
640 /** Total count of ticks. */
641 volatile uint64_t cTicks;
642 /** Maximum tick count during a sampling. */
643 volatile uint64_t cTicksMax;
644 /** Minimum tick count during a sampling. */
645 volatile uint64_t cTicksMin;
646} STAMPROFILE;
647/** Pointer to a profile sample. */
648typedef STAMPROFILE *PSTAMPROFILE;
649/** Pointer to a const profile sample. */
650typedef const STAMPROFILE *PCSTAMPROFILE;
651
652
653/** @def STAM_REL_PROFILE_ADD_PERIOD
654 * Adds a period.
655 *
656 * @param pProfile Pointer to the STAMPROFILE structure to operate on.
657 * @param cTicksInPeriod The number of tick (or whatever) of the preiod
658 * being added. This is only referenced once.
659 */
660#ifndef VBOX_WITHOUT_RELEASE_STATISTICS
661# define STAM_REL_PROFILE_ADD_PERIOD(pProfile, cTicksInPeriod) \
662 do { \
663 uint64_t const StamPrefix_cTicks = (cTicksInPeriod); \
664 (pProfile)->cTicks += StamPrefix_cTicks; \
665 (pProfile)->cPeriods++; \
666 if ((pProfile)->cTicksMax < StamPrefix_cTicks) \
667 (pProfile)->cTicksMax = StamPrefix_cTicks; \
668 if ((pProfile)->cTicksMin > StamPrefix_cTicks) \
669 (pProfile)->cTicksMin = StamPrefix_cTicks; \
670 } while (0)
671#else
672# define STAM_REL_PROFILE_ADD_PERIOD(pProfile, cTicksInPeriod) do { } while (0)
673#endif
674/** @def STAM_PROFILE_ADD_PERIOD
675 * Adds a period.
676 *
677 * @param pProfile Pointer to the STAMPROFILE structure to operate on.
678 * @param cTicksInPeriod The number of tick (or whatever) of the preiod
679 * being added. This is only referenced once.
680 */
681#ifdef VBOX_WITH_STATISTICS
682# define STAM_PROFILE_ADD_PERIOD(pProfile, cTicksInPeriod) STAM_REL_PROFILE_ADD_PERIOD(pProfile, cTicksInPeriod)
683#else
684# define STAM_PROFILE_ADD_PERIOD(pProfile, cTicksInPeriod) do { } while (0)
685#endif
686
687
688/** @def STAM_REL_PROFILE_START
689 * Samples the start time of a profiling period.
690 *
691 * @param pProfile Pointer to the STAMPROFILE structure to operate on.
692 * @param Prefix Identifier prefix used to internal variables.
693 *
694 * @remarks Declears a stack variable that will be used by related macros.
695 */
696#ifndef VBOX_WITHOUT_RELEASE_STATISTICS
697# define STAM_REL_PROFILE_START(pProfile, Prefix) \
698 uint64_t Prefix##_tsStart; \
699 STAM_GET_TS(Prefix##_tsStart)
700#else
701# define STAM_REL_PROFILE_START(pProfile, Prefix) do { } while (0)
702#endif
703/** @def STAM_PROFILE_START
704 * Samples the start time of a profiling period.
705 *
706 * @param pProfile Pointer to the STAMPROFILE structure to operate on.
707 * @param Prefix Identifier prefix used to internal variables.
708 *
709 * @remarks Declears a stack variable that will be used by related macros.
710 */
711#ifdef VBOX_WITH_STATISTICS
712# define STAM_PROFILE_START(pProfile, Prefix) STAM_REL_PROFILE_START(pProfile, Prefix)
713#else
714# define STAM_PROFILE_START(pProfile, Prefix) do { } while (0)
715#endif
716
717/** @def STAM_REL_PROFILE_STOP
718 * Samples the stop time of a profiling period and updates the sample.
719 *
720 * @param pProfile Pointer to the STAMPROFILE structure to operate on.
721 * @param Prefix Identifier prefix used to internal variables.
722 */
723#ifndef VBOX_WITHOUT_RELEASE_STATISTICS
724# define STAM_REL_PROFILE_STOP(pProfile, Prefix) \
725 do { \
726 uint64_t Prefix##_cTicks; \
727 STAM_GET_TS(Prefix##_cTicks); \
728 Prefix##_cTicks -= Prefix##_tsStart; \
729 (pProfile)->cTicks += Prefix##_cTicks; \
730 (pProfile)->cPeriods++; \
731 if ((pProfile)->cTicksMax < Prefix##_cTicks) \
732 (pProfile)->cTicksMax = Prefix##_cTicks; \
733 if ((pProfile)->cTicksMin > Prefix##_cTicks) \
734 (pProfile)->cTicksMin = Prefix##_cTicks; \
735 } while (0)
736#else
737# define STAM_REL_PROFILE_STOP(pProfile, Prefix) do { } while (0)
738#endif
739/** @def STAM_PROFILE_STOP
740 * Samples the stop time of a profiling period and updates the sample.
741 *
742 * @param pProfile Pointer to the STAMPROFILE structure to operate on.
743 * @param Prefix Identifier prefix used to internal variables.
744 */
745#ifdef VBOX_WITH_STATISTICS
746# define STAM_PROFILE_STOP(pProfile, Prefix) STAM_REL_PROFILE_STOP(pProfile, Prefix)
747#else
748# define STAM_PROFILE_STOP(pProfile, Prefix) do { } while (0)
749#endif
750
751
752/** @def STAM_REL_PROFILE_STOP_EX
753 * Samples the stop time of a profiling period and updates both the sample
754 * and an attribution sample.
755 *
756 * @param pProfile Pointer to the STAMPROFILE structure to operate on.
757 * @param pProfile2 Pointer to the STAMPROFILE structure which this
758 * interval should be attributed to as well. This may be NULL.
759 * @param Prefix Identifier prefix used to internal variables.
760 */
761#ifndef VBOX_WITHOUT_RELEASE_STATISTICS
762# define STAM_REL_PROFILE_STOP_EX(pProfile, pProfile2, Prefix) \
763 do { \
764 uint64_t Prefix##_cTicks; \
765 STAM_GET_TS(Prefix##_cTicks); \
766 Prefix##_cTicks -= Prefix##_tsStart; \
767 (pProfile)->cTicks += Prefix##_cTicks; \
768 (pProfile)->cPeriods++; \
769 if ((pProfile)->cTicksMax < Prefix##_cTicks) \
770 (pProfile)->cTicksMax = Prefix##_cTicks; \
771 if ((pProfile)->cTicksMin > Prefix##_cTicks) \
772 (pProfile)->cTicksMin = Prefix##_cTicks; \
773 \
774 if ((pProfile2)) \
775 { \
776 (pProfile2)->cTicks += Prefix##_cTicks; \
777 (pProfile2)->cPeriods++; \
778 if ((pProfile2)->cTicksMax < Prefix##_cTicks) \
779 (pProfile2)->cTicksMax = Prefix##_cTicks; \
780 if ((pProfile2)->cTicksMin > Prefix##_cTicks) \
781 (pProfile2)->cTicksMin = Prefix##_cTicks; \
782 } \
783 } while (0)
784#else
785# define STAM_REL_PROFILE_STOP_EX(pProfile, pProfile2, Prefix) do { } while (0)
786#endif
787/** @def STAM_PROFILE_STOP_EX
788 * Samples the stop time of a profiling period and updates both the sample
789 * and an attribution sample.
790 *
791 * @param pProfile Pointer to the STAMPROFILE structure to operate on.
792 * @param pProfile2 Pointer to the STAMPROFILE structure which this
793 * interval should be attributed to as well. This may be NULL.
794 * @param Prefix Identifier prefix used to internal variables.
795 */
796#ifdef VBOX_WITH_STATISTICS
797# define STAM_PROFILE_STOP_EX(pProfile, pProfile2, Prefix) STAM_REL_PROFILE_STOP_EX(pProfile, pProfile2, Prefix)
798#else
799# define STAM_PROFILE_STOP_EX(pProfile, pProfile2, Prefix) do { } while (0)
800#endif
801
802
803/** @def STAM_REL_PROFILE_START_NS
804 * Samples the start time of a profiling period, using RTTimeNanoTS().
805 *
806 * @param pProfile Pointer to the STAMPROFILE structure to operate on.
807 * @param Prefix Identifier prefix used to internal variables.
808 *
809 * @remarks Declears a stack variable that will be used by related macros.
810 */
811#ifndef VBOX_WITHOUT_RELEASE_STATISTICS
812# define STAM_REL_PROFILE_START_NS(pProfile, Prefix) \
813 uint64_t const Prefix##_tsStart = RTTimeNanoTS()
814#else
815# define STAM_REL_PROFILE_START_NS(pProfile, Prefix) do { } while (0)
816#endif
817/** @def STAM_PROFILE_START_NS
818 * Samples the start time of a profiling period, using RTTimeNanoTS().
819 *
820 * @param pProfile Pointer to the STAMPROFILE structure to operate on.
821 * @param Prefix Identifier prefix used to internal variables.
822 *
823 * @remarks Declears a stack variable that will be used by related macros.
824 */
825#ifdef VBOX_WITH_STATISTICS
826# define STAM_PROFILE_START_NS(pProfile, Prefix) STAM_REL_PROFILE_START_NS(pProfile, Prefix)
827#else
828# define STAM_PROFILE_START_NS(pProfile, Prefix) do { } while (0)
829#endif
830
831/** @def STAM_REL_PROFILE_STOP_NS
832 * Samples the stop time of a profiling period and updates the sample, using
833 * RTTimeNanoTS().
834 *
835 * @param pProfile Pointer to the STAMPROFILE structure to operate on.
836 * @param Prefix Identifier prefix used to internal variables.
837 */
838#ifndef VBOX_WITHOUT_RELEASE_STATISTICS
839# define STAM_REL_PROFILE_STOP_NS(pProfile, Prefix) \
840 STAM_REL_PROFILE_ADD_PERIOD(pProfile, RTTimeNanoTS() - Prefix##_tsStart)
841#else
842# define STAM_REL_PROFILE_STOP_NS(pProfile, Prefix) do { } while (0)
843#endif
844/** @def STAM_PROFILE_STOP_NS
845 * Samples the stop time of a profiling period and updates the sample, using
846 * RTTimeNanoTS().
847 *
848 * @param pProfile Pointer to the STAMPROFILE structure to operate on.
849 * @param Prefix Identifier prefix used to internal variables.
850 */
851#ifdef VBOX_WITH_STATISTICS
852# define STAM_PROFILE_STOP_NS(pProfile, Prefix) STAM_REL_PROFILE_STOP_NS(pProfile, Prefix)
853#else
854# define STAM_PROFILE_STOP_NS(pProfile, Prefix) do { } while (0)
855#endif
856
857
858/**
859 * Advanced profiling sample - STAMTYPE_PROFILE_ADV.
860 *
861 * Identical to a STAMPROFILE sample, but the start timestamp
862 * is stored after the STAMPROFILE structure so the sampling
863 * can start and stop in different functions.
864 */
865typedef struct STAMPROFILEADV
866{
867 /** The STAMPROFILE core. */
868 STAMPROFILE Core;
869 /** The start timestamp. */
870 volatile uint64_t tsStart;
871} STAMPROFILEADV;
872/** Pointer to a advanced profile sample. */
873typedef STAMPROFILEADV *PSTAMPROFILEADV;
874/** Pointer to a const advanced profile sample. */
875typedef const STAMPROFILEADV *PCSTAMPROFILEADV;
876
877
878/** @def STAM_REL_PROFILE_ADV_START
879 * Samples the start time of a profiling period.
880 *
881 * @param pProfileAdv Pointer to the STAMPROFILEADV structure to operate on.
882 * @param Prefix Identifier prefix used to internal variables.
883 */
884#ifndef VBOX_WITHOUT_RELEASE_STATISTICS
885# define STAM_REL_PROFILE_ADV_START(pProfileAdv, Prefix) \
886 STAM_GET_TS((pProfileAdv)->tsStart)
887#else
888# define STAM_REL_PROFILE_ADV_START(pProfileAdv, Prefix) do { } while (0)
889#endif
890/** @def STAM_PROFILE_ADV_START
891 * Samples the start time of a profiling period.
892 *
893 * @param pProfileAdv Pointer to the STAMPROFILEADV structure to operate on.
894 * @param Prefix Identifier prefix used to internal variables.
895 */
896#ifdef VBOX_WITH_STATISTICS
897# define STAM_PROFILE_ADV_START(pProfileAdv, Prefix) STAM_REL_PROFILE_ADV_START(pProfileAdv, Prefix)
898#else
899# define STAM_PROFILE_ADV_START(pProfileAdv, Prefix) do { } while (0)
900#endif
901
902
903/** @def STAM_REL_PROFILE_ADV_STOP
904 * Samples the stop time of a profiling period (if running) and updates the
905 * sample.
906 *
907 * @param pProfileAdv Pointer to the STAMPROFILEADV structure to operate on.
908 * @param Prefix Identifier prefix used to internal variables.
909 */
910#ifndef VBOX_WITHOUT_RELEASE_STATISTICS
911# define STAM_REL_PROFILE_ADV_STOP(pProfileAdv, Prefix) \
912 do { \
913 if ((pProfileAdv)->tsStart) \
914 { \
915 uint64_t Prefix##_cTicks; \
916 STAM_GET_TS(Prefix##_cTicks); \
917 Prefix##_cTicks -= (pProfileAdv)->tsStart; \
918 (pProfileAdv)->tsStart = 0; \
919 (pProfileAdv)->Core.cTicks += Prefix##_cTicks; \
920 (pProfileAdv)->Core.cPeriods++; \
921 if ((pProfileAdv)->Core.cTicksMax < Prefix##_cTicks) \
922 (pProfileAdv)->Core.cTicksMax = Prefix##_cTicks; \
923 if ((pProfileAdv)->Core.cTicksMin > Prefix##_cTicks) \
924 (pProfileAdv)->Core.cTicksMin = Prefix##_cTicks; \
925 } \
926 } while (0)
927#else
928# define STAM_REL_PROFILE_ADV_STOP(pProfileAdv, Prefix) do { } while (0)
929#endif
930/** @def STAM_PROFILE_ADV_STOP
931 * Samples the stop time of a profiling period (if running) and updates the
932 * sample.
933 *
934 * @param pProfileAdv Pointer to the STAMPROFILEADV structure to operate on.
935 * @param Prefix Identifier prefix used to internal variables.
936 */
937#ifdef VBOX_WITH_STATISTICS
938# define STAM_PROFILE_ADV_STOP(pProfileAdv, Prefix) STAM_REL_PROFILE_ADV_STOP(pProfileAdv, Prefix)
939#else
940# define STAM_PROFILE_ADV_STOP(pProfileAdv, Prefix) do { } while (0)
941#endif
942
943
944/** @def STAM_REL_PROFILE_ADV_STOP_START
945 * Stops one profile counter (if running) and starts another one.
946 *
947 * @param pProfileAdv1 Pointer to the STAMPROFILEADV structure to stop.
948 * @param pProfileAdv2 Pointer to the STAMPROFILEADV structure to start.
949 * @param Prefix Identifier prefix used to internal variables.
950 */
951#ifndef VBOX_WITHOUT_RELEASE_STATISTICS
952# define STAM_REL_PROFILE_ADV_STOP_START(pProfileAdv1, pProfileAdv2, Prefix) \
953 do { \
954 uint64_t Prefix##_cTicks; \
955 STAM_GET_TS(Prefix##_cTicks); \
956 (pProfileAdv2)->tsStart = Prefix##_cTicks; \
957 if ((pProfileAdv1)->tsStart) \
958 { \
959 Prefix##_cTicks -= (pProfileAdv1)->tsStart; \
960 (pProfileAdv1)->tsStart = 0; \
961 (pProfileAdv1)->Core.cTicks += Prefix##_cTicks; \
962 (pProfileAdv1)->Core.cPeriods++; \
963 if ((pProfileAdv1)->Core.cTicksMax < Prefix##_cTicks) \
964 (pProfileAdv1)->Core.cTicksMax = Prefix##_cTicks; \
965 if ((pProfileAdv1)->Core.cTicksMin > Prefix##_cTicks) \
966 (pProfileAdv1)->Core.cTicksMin = Prefix##_cTicks; \
967 } \
968 } while (0)
969#else
970# define STAM_REL_PROFILE_ADV_STOP_START(pProfileAdv1, pProfileAdv2, Prefix) \
971 do { } while (0)
972#endif
973/** @def STAM_PROFILE_ADV_STOP_START
974 * Samples the stop time of a profiling period (if running) and updates the
975 * sample.
976 *
977 * @param pProfileAdv1 Pointer to the STAMPROFILEADV structure to stop.
978 * @param pProfileAdv2 Pointer to the STAMPROFILEADV structure to start.
979 * @param Prefix Identifier prefix used to internal variables.
980 */
981#ifdef VBOX_WITH_STATISTICS
982# define STAM_PROFILE_ADV_STOP_START(pProfileAdv1, pProfileAdv2, Prefix) \
983 STAM_REL_PROFILE_ADV_STOP_START(pProfileAdv1, pProfileAdv2, Prefix)
984#else
985# define STAM_PROFILE_ADV_STOP_START(pProfileAdv1, pProfileAdv2, Prefix) \
986 do { } while (0)
987#endif
988
989
990/** @def STAM_REL_PROFILE_ADV_SUSPEND
991 * Suspends the sampling for a while. This can be useful to exclude parts
992 * covered by other samples without screwing up the count, and average+min times.
993 *
994 * @param pProfileAdv Pointer to the STAMPROFILEADV structure to operate on.
995 * @param Prefix Identifier prefix used to internal variables. The prefix
996 * must match that of the resume one since it stores the
997 * suspend time in a stack variable.
998 */
999#ifndef VBOX_WITHOUT_RELEASE_STATISTICS
1000# define STAM_REL_PROFILE_ADV_SUSPEND(pProfileAdv, Prefix) \
1001 uint64_t Prefix##_tsSuspend; \
1002 STAM_GET_TS(Prefix##_tsSuspend)
1003#else
1004# define STAM_REL_PROFILE_ADV_SUSPEND(pProfileAdv, Prefix) do { } while (0)
1005#endif
1006/** @def STAM_PROFILE_ADV_SUSPEND
1007 * Suspends the sampling for a while. This can be useful to exclude parts
1008 * covered by other samples without screwing up the count, and average+min times.
1009 *
1010 * @param pProfileAdv Pointer to the STAMPROFILEADV structure to operate on.
1011 * @param Prefix Identifier prefix used to internal variables. The prefix
1012 * must match that of the resume one since it stores the
1013 * suspend time in a stack variable.
1014 */
1015#ifdef VBOX_WITH_STATISTICS
1016# define STAM_PROFILE_ADV_SUSPEND(pProfileAdv, Prefix) STAM_REL_PROFILE_ADV_SUSPEND(pProfileAdv, Prefix)
1017#else
1018# define STAM_PROFILE_ADV_SUSPEND(pProfileAdv, Prefix) do { } while (0)
1019#endif
1020
1021
1022/** @def STAM_REL_PROFILE_ADV_RESUME
1023 * Counter to STAM_REL_PROFILE_ADV_SUSPEND.
1024 *
1025 * @param pProfileAdv Pointer to the STAMPROFILEADV structure to operate on.
1026 * @param Prefix Identifier prefix used to internal variables. This must
1027 * match the one used with the SUSPEND!
1028 */
1029#ifndef VBOX_WITHOUT_RELEASE_STATISTICS
1030# define STAM_REL_PROFILE_ADV_RESUME(pProfileAdv, Prefix) \
1031 do { \
1032 uint64_t Prefix##_tsNow; \
1033 STAM_GET_TS(Prefix##_tsNow); \
1034 (pProfileAdv)->tsStart += Prefix##_tsNow - Prefix##_tsSuspend; \
1035 } while (0)
1036#else
1037# define STAM_REL_PROFILE_ADV_RESUME(pProfileAdv, Prefix) do { } while (0)
1038#endif
1039/** @def STAM_PROFILE_ADV_RESUME
1040 * Counter to STAM_PROFILE_ADV_SUSPEND.
1041 *
1042 * @param pProfileAdv Pointer to the STAMPROFILEADV structure to operate on.
1043 * @param Prefix Identifier prefix used to internal variables. This must
1044 * match the one used with the SUSPEND!
1045 */
1046#ifdef VBOX_WITH_STATISTICS
1047# define STAM_PROFILE_ADV_RESUME(pProfileAdv, Prefix) STAM_REL_PROFILE_ADV_RESUME(pProfileAdv, Prefix)
1048#else
1049# define STAM_PROFILE_ADV_RESUME(pProfileAdv, Prefix) do { } while (0)
1050#endif
1051
1052
1053/** @def STAM_REL_PROFILE_ADV_STOP_EX
1054 * Samples the stop time of a profiling period (if running) and updates both
1055 * the sample and an attribution sample.
1056 *
1057 * @param pProfileAdv Pointer to the STAMPROFILEADV structure to operate on.
1058 * @param pProfile2 Pointer to the STAMPROFILE structure which this
1059 * interval should be attributed to as well. This may be NULL.
1060 * @param Prefix Identifier prefix used to internal variables.
1061 */
1062#ifndef VBOX_WITHOUT_RELEASE_STATISTICS
1063# define STAM_REL_PROFILE_ADV_STOP_EX(pProfileAdv, pProfile2, Prefix) \
1064 do { \
1065 if ((pProfileAdv)->tsStart) \
1066 { \
1067 uint64_t Prefix##_cTicks; \
1068 STAM_GET_TS(Prefix##_cTicks); \
1069 Prefix##_cTicks -= (pProfileAdv)->tsStart; \
1070 (pProfileAdv)->tsStart = 0; \
1071 (pProfileAdv)->Core.cTicks += Prefix##_cTicks; \
1072 (pProfileAdv)->Core.cPeriods++; \
1073 if ((pProfileAdv)->Core.cTicksMax < Prefix##_cTicks) \
1074 (pProfileAdv)->Core.cTicksMax = Prefix##_cTicks; \
1075 if ((pProfileAdv)->Core.cTicksMin > Prefix##_cTicks) \
1076 (pProfileAdv)->Core.cTicksMin = Prefix##_cTicks; \
1077 if ((pProfile2)) \
1078 { \
1079 (pProfile2)->cTicks += Prefix##_cTicks; \
1080 (pProfile2)->cPeriods++; \
1081 if ((pProfile2)->cTicksMax < Prefix##_cTicks) \
1082 (pProfile2)->cTicksMax = Prefix##_cTicks; \
1083 if ((pProfile2)->cTicksMin > Prefix##_cTicks) \
1084 (pProfile2)->cTicksMin = Prefix##_cTicks; \
1085 } \
1086 } \
1087 } while (0)
1088#else
1089# define STAM_REL_PROFILE_ADV_STOP_EX(pProfileAdv, pProfile2, Prefix) do { } while (0)
1090#endif
1091/** @def STAM_PROFILE_ADV_STOP_EX
1092 * Samples the stop time of a profiling period (if running) and updates both
1093 * the sample and an attribution sample.
1094 *
1095 * @param pProfileAdv Pointer to the STAMPROFILEADV structure to operate on.
1096 * @param pProfile2 Pointer to the STAMPROFILE structure which this
1097 * interval should be attributed to as well. This may be NULL.
1098 * @param Prefix Identifier prefix used to internal variables.
1099 */
1100#ifdef VBOX_WITH_STATISTICS
1101# define STAM_PROFILE_ADV_STOP_EX(pProfileAdv, pProfile2, Prefix) STAM_REL_PROFILE_ADV_STOP_EX(pProfileAdv, pProfile2, Prefix)
1102#else
1103# define STAM_PROFILE_ADV_STOP_EX(pProfileAdv, pProfile2, Prefix) do { } while (0)
1104#endif
1105
1106/** @def STAM_REL_PROFILE_ADV_IS_RUNNING
1107 * Checks if it is running.
1108 *
1109 * @param pProfileAdv Pointer to the STAMPROFILEADV structure to operate on.
1110 */
1111#ifndef VBOX_WITHOUT_RELEASE_STATISTICS
1112# define STAM_REL_PROFILE_ADV_IS_RUNNING(pProfileAdv) (pProfileAdv)->tsStart
1113#else
1114# define STAM_REL_PROFILE_ADV_IS_RUNNING(pProfileAdv) (false)
1115#endif
1116/** @def STAM_PROFILE_ADV_IS_RUNNING
1117 * Checks if it is running.
1118 *
1119 * @param pProfileAdv Pointer to the STAMPROFILEADV structure to operate on.
1120 */
1121#ifdef VBOX_WITH_STATISTICS
1122# define STAM_PROFILE_ADV_IS_RUNNING(pProfileAdv) STAM_REL_PROFILE_ADV_IS_RUNNING(pProfileAdv)
1123#else
1124# define STAM_PROFILE_ADV_IS_RUNNING(pProfileAdv) (false)
1125#endif
1126
1127/** @def STAM_REL_PROFILE_ADV_SET_STOPPED
1128 * Marks the profile counter as stopped.
1129 *
1130 * This is for avoiding screwups in twisty code.
1131 *
1132 * @param pProfileAdv Pointer to the STAMPROFILEADV structure to operate on.
1133 */
1134#ifndef VBOX_WITHOUT_RELEASE_STATISTICS
1135# define STAM_REL_PROFILE_ADV_SET_STOPPED(pProfileAdv) do { (pProfileAdv)->tsStart = 0; } while (0)
1136#else
1137# define STAM_REL_PROFILE_ADV_SET_STOPPED(pProfileAdv) do { } while (0)
1138#endif
1139/** @def STAM_PROFILE_ADV_SET_STOPPED
1140 * Marks the profile counter as stopped.
1141 *
1142 * This is for avoiding screwups in twisty code.
1143 *
1144 * @param pProfileAdv Pointer to the STAMPROFILEADV structure to operate on.
1145 */
1146#ifdef VBOX_WITH_STATISTICS
1147# define STAM_PROFILE_ADV_SET_STOPPED(pProfileAdv) STAM_REL_PROFILE_ADV_SET_STOPPED(pProfileAdv)
1148#else
1149# define STAM_PROFILE_ADV_SET_STOPPED(pProfileAdv) do { } while (0)
1150#endif
1151
1152
1153/**
1154 * Ratio of A to B, uint32_t types.
1155 * @remark Use STAM_STATS or STAM_REL_STATS for modifying A & B values.
1156 */
1157typedef struct STAMRATIOU32
1158{
1159 /** Sample A. */
1160 uint32_t volatile u32A;
1161 /** Sample B. */
1162 uint32_t volatile u32B;
1163} STAMRATIOU32;
1164/** Pointer to a uint32_t ratio. */
1165typedef STAMRATIOU32 *PSTAMRATIOU32;
1166/** Pointer to const a uint32_t ratio. */
1167typedef const STAMRATIOU32 *PCSTAMRATIOU32;
1168
1169
1170
1171
1172/** @defgroup grp_stam_r3 The STAM Host Context Ring 3 API
1173 * @{
1174 */
1175
1176VMMR3DECL(int) STAMR3InitUVM(PUVM pUVM);
1177VMMR3DECL(void) STAMR3TermUVM(PUVM pUVM);
1178VMMR3DECL(int) STAMR3RegisterU(PUVM pUVM, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
1179 const char *pszName, STAMUNIT enmUnit, const char *pszDesc);
1180VMMR3DECL(int) STAMR3Register(PVM pVM, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
1181 const char *pszName, STAMUNIT enmUnit, const char *pszDesc);
1182
1183/** @def STAM_REL_REG
1184 * Registers a statistics sample.
1185 *
1186 * @param pVM The cross context VM structure.
1187 * @param pvSample Pointer to the sample.
1188 * @param enmType Sample type. This indicates what pvSample is pointing at.
1189 * @param pszName Sample name. The name is on this form "/<component>/<sample>".
1190 * Further nesting is possible.
1191 * @param enmUnit Sample unit.
1192 * @param pszDesc Sample description.
1193 */
1194#define STAM_REL_REG(pVM, pvSample, enmType, pszName, enmUnit, pszDesc) \
1195 STAM_REL_STATS({ int rcStam = STAMR3Register(pVM, pvSample, enmType, STAMVISIBILITY_ALWAYS, pszName, enmUnit, pszDesc); \
1196 AssertRC(rcStam); })
1197/** @def STAM_REG
1198 * Registers a statistics sample if statistics are enabled.
1199 *
1200 * @param pVM The cross context VM structure.
1201 * @param pvSample Pointer to the sample.
1202 * @param enmType Sample type. This indicates what pvSample is pointing at.
1203 * @param pszName Sample name. The name is on this form "/<component>/<sample>".
1204 * Further nesting is possible.
1205 * @param enmUnit Sample unit.
1206 * @param pszDesc Sample description.
1207 */
1208#define STAM_REG(pVM, pvSample, enmType, pszName, enmUnit, pszDesc) \
1209 STAM_STATS({STAM_REL_REG(pVM, pvSample, enmType, pszName, enmUnit, pszDesc);})
1210
1211/** @def STAM_REL_REG_USED
1212 * Registers a statistics sample which only shows when used.
1213 *
1214 * @param pVM The cross context VM structure.
1215 * @param pvSample Pointer to the sample.
1216 * @param enmType Sample type. This indicates what pvSample is pointing at.
1217 * @param pszName Sample name. The name is on this form "/<component>/<sample>".
1218 * Further nesting is possible.
1219 * @param enmUnit Sample unit.
1220 * @param pszDesc Sample description.
1221 */
1222#define STAM_REL_REG_USED(pVM, pvSample, enmType, pszName, enmUnit, pszDesc) \
1223 STAM_REL_STATS({ int rcStam = STAMR3Register(pVM, pvSample, enmType, STAMVISIBILITY_USED, pszName, enmUnit, pszDesc); \
1224 AssertRC(rcStam);})
1225/** @def STAM_REG_USED
1226 * Registers a statistics sample which only shows when used, if statistics are enabled.
1227 *
1228 * @param pVM The cross context VM structure.
1229 * @param pvSample Pointer to the sample.
1230 * @param enmType Sample type. This indicates what pvSample is pointing at.
1231 * @param pszName Sample name. The name is on this form "/<component>/<sample>".
1232 * Further nesting is possible.
1233 * @param enmUnit Sample unit.
1234 * @param pszDesc Sample description.
1235 */
1236#define STAM_REG_USED(pVM, pvSample, enmType, pszName, enmUnit, pszDesc) \
1237 STAM_STATS({ STAM_REL_REG_USED(pVM, pvSample, enmType, pszName, enmUnit, pszDesc); })
1238
1239VMMR3DECL(int) STAMR3RegisterFU(PUVM pUVM, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility, STAMUNIT enmUnit,
1240 const char *pszDesc, const char *pszName, ...) RT_IPRT_FORMAT_ATTR(7, 8);
1241VMMR3DECL(int) STAMR3RegisterF(PVM pVM, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility, STAMUNIT enmUnit,
1242 const char *pszDesc, const char *pszName, ...) RT_IPRT_FORMAT_ATTR(7, 8);
1243VMMR3DECL(int) STAMR3RegisterVU(PUVM pUVM, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility, STAMUNIT enmUnit,
1244 const char *pszDesc, const char *pszName, va_list args) RT_IPRT_FORMAT_ATTR(7, 0);
1245VMMR3DECL(int) STAMR3RegisterV(PVM pVM, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility, STAMUNIT enmUnit,
1246 const char *pszDesc, const char *pszName, va_list args) RT_IPRT_FORMAT_ATTR(7, 0);
1247
1248/**
1249 * Resets the sample.
1250 * @param pVM The cross context VM structure.
1251 * @param pvSample The sample registered using STAMR3RegisterCallback.
1252 */
1253typedef DECLCALLBACKTYPE(void, FNSTAMR3CALLBACKRESET,(PVM pVM, void *pvSample));
1254/** Pointer to a STAM sample reset callback. */
1255typedef FNSTAMR3CALLBACKRESET *PFNSTAMR3CALLBACKRESET;
1256
1257/**
1258 * Prints the sample into the buffer.
1259 *
1260 * @param pVM The cross context VM structure.
1261 * @param pvSample The sample registered using STAMR3RegisterCallback.
1262 * @param pszBuf The buffer to print into.
1263 * @param cchBuf The size of the buffer.
1264 */
1265typedef DECLCALLBACKTYPE(void, FNSTAMR3CALLBACKPRINT,(PVM pVM, void *pvSample, char *pszBuf, size_t cchBuf));
1266/** Pointer to a STAM sample print callback. */
1267typedef FNSTAMR3CALLBACKPRINT *PFNSTAMR3CALLBACKPRINT;
1268
1269VMMR3DECL(int) STAMR3RegisterCallback(PVM pVM, void *pvSample, STAMVISIBILITY enmVisibility, STAMUNIT enmUnit,
1270 PFNSTAMR3CALLBACKRESET pfnReset, PFNSTAMR3CALLBACKPRINT pfnPrint,
1271 const char *pszDesc, const char *pszName, ...) RT_IPRT_FORMAT_ATTR(8, 9);
1272VMMR3DECL(int) STAMR3RegisterCallbackV(PVM pVM, void *pvSample, STAMVISIBILITY enmVisibility, STAMUNIT enmUnit,
1273 PFNSTAMR3CALLBACKRESET pfnReset, PFNSTAMR3CALLBACKPRINT pfnPrint,
1274 const char *pszDesc, const char *pszName, va_list args) RT_IPRT_FORMAT_ATTR(8, 0);
1275
1276VMMR3DECL(int) STAMR3RegisterRefresh(PUVM pUVM, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
1277 STAMUNIT enmUnit, uint8_t iRefreshGrp, const char *pszDesc,
1278 const char *pszName, ...) RT_IPRT_FORMAT_ATTR(8, 9);
1279VMMR3DECL(int) STAMR3RegisterRefreshV(PUVM pUVM, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
1280 STAMUNIT enmUnit, uint8_t iRefreshGrp, const char *pszDesc,
1281 const char *pszName, va_list va) RT_IPRT_FORMAT_ATTR(8, 0);
1282
1283VMMR3DECL(int) STAMR3Deregister(PUVM pUVM, const char *pszPat);
1284VMMR3DECL(int) STAMR3DeregisterF(PUVM pUVM, const char *pszPatFmt, ...) RT_IPRT_FORMAT_ATTR(2, 3);
1285VMMR3DECL(int) STAMR3DeregisterV(PUVM pUVM, const char *pszPatFmt, va_list va) RT_IPRT_FORMAT_ATTR(2, 0);
1286VMMR3DECL(int) STAMR3DeregisterByPrefix(PUVM pUVM, const char *pszPrefix);
1287VMMR3DECL(int) STAMR3DeregisterByAddr(PUVM pUVM, void *pvSample);
1288
1289VMMR3DECL(int) STAMR3Reset(PUVM pUVM, const char *pszPat);
1290VMMR3DECL(int) STAMR3Snapshot(PUVM pUVM, const char *pszPat, char **ppszSnapshot, size_t *pcchSnapshot, bool fWithDesc);
1291VMMR3DECL(int) STAMR3SnapshotFree(PUVM pUVM, char *pszSnapshot);
1292VMMR3DECL(int) STAMR3Dump(PUVM pUVM, const char *pszPat);
1293VMMR3DECL(int) STAMR3DumpToReleaseLog(PUVM pUVM, const char *pszPat);
1294VMMR3DECL(int) STAMR3Print(PUVM pUVM, const char *pszPat);
1295
1296/**
1297 * Callback function for STAMR3Enum().
1298 *
1299 * @returns non-zero to halt the enumeration.
1300 *
1301 * @param pszName The name of the sample.
1302 * @param enmType The type.
1303 * @param pvSample Pointer to the data. enmType indicates the format of this data.
1304 * @param enmUnit The unit.
1305 * @param enmVisibility The visibility.
1306 * @param pszDesc The description.
1307 * @param pvUser The pvUser argument given to STAMR3Enum().
1308 */
1309typedef DECLCALLBACKTYPE(int, FNSTAMR3ENUM,(const char *pszName, STAMTYPE enmType, void *pvSample, STAMUNIT enmUnit,
1310 STAMVISIBILITY enmVisibility, const char *pszDesc, void *pvUser));
1311/** Pointer to a FNSTAMR3ENUM(). */
1312typedef FNSTAMR3ENUM *PFNSTAMR3ENUM;
1313
1314VMMR3DECL(int) STAMR3Enum(PUVM pUVM, const char *pszPat, PFNSTAMR3ENUM pfnEnum, void *pvUser);
1315VMMR3DECL(const char *) STAMR3GetUnit(STAMUNIT enmUnit);
1316
1317/** @} */
1318
1319/** @} */
1320
1321RT_C_DECLS_END
1322
1323#endif /* !VBOX_INCLUDED_vmm_stam_h */
1324
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette