VirtualBox

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

Last change on this file since 84119 was 84119, checked in by vboxsync, 5 years ago

hmvmxinline.h,stam.h: Use the intrin.h wrapper in iprt or we'll end up trying to drag in malloc.h when IPRT_NO_CRT is defined. bugref:8489

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