VirtualBox

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

Last change on this file since 87518 was 87263, checked in by vboxsync, 4 years ago

vmm/stam.h: Just include asm-arm.h and use ASMReadTSC for STAM_GET_TS. bugref:9898

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 43.9 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/**
804 * Advanced profiling sample - STAMTYPE_PROFILE_ADV.
805 *
806 * Identical to a STAMPROFILE sample, but the start timestamp
807 * is stored after the STAMPROFILE structure so the sampling
808 * can start and stop in different functions.
809 */
810typedef struct STAMPROFILEADV
811{
812 /** The STAMPROFILE core. */
813 STAMPROFILE Core;
814 /** The start timestamp. */
815 volatile uint64_t tsStart;
816} STAMPROFILEADV;
817/** Pointer to a advanced profile sample. */
818typedef STAMPROFILEADV *PSTAMPROFILEADV;
819/** Pointer to a const advanced profile sample. */
820typedef const STAMPROFILEADV *PCSTAMPROFILEADV;
821
822
823/** @def STAM_REL_PROFILE_ADV_START
824 * Samples the start time of a profiling period.
825 *
826 * @param pProfileAdv Pointer to the STAMPROFILEADV structure to operate on.
827 * @param Prefix Identifier prefix used to internal variables.
828 */
829#ifndef VBOX_WITHOUT_RELEASE_STATISTICS
830# define STAM_REL_PROFILE_ADV_START(pProfileAdv, Prefix) \
831 STAM_GET_TS((pProfileAdv)->tsStart)
832#else
833# define STAM_REL_PROFILE_ADV_START(pProfileAdv, Prefix) do { } while (0)
834#endif
835/** @def STAM_PROFILE_ADV_START
836 * Samples the start time of a profiling period.
837 *
838 * @param pProfileAdv Pointer to the STAMPROFILEADV structure to operate on.
839 * @param Prefix Identifier prefix used to internal variables.
840 */
841#ifdef VBOX_WITH_STATISTICS
842# define STAM_PROFILE_ADV_START(pProfileAdv, Prefix) STAM_REL_PROFILE_ADV_START(pProfileAdv, Prefix)
843#else
844# define STAM_PROFILE_ADV_START(pProfileAdv, Prefix) do { } while (0)
845#endif
846
847
848/** @def STAM_REL_PROFILE_ADV_STOP
849 * Samples the stop time of a profiling period (if running) and updates the
850 * sample.
851 *
852 * @param pProfileAdv Pointer to the STAMPROFILEADV structure to operate on.
853 * @param Prefix Identifier prefix used to internal variables.
854 */
855#ifndef VBOX_WITHOUT_RELEASE_STATISTICS
856# define STAM_REL_PROFILE_ADV_STOP(pProfileAdv, Prefix) \
857 do { \
858 if ((pProfileAdv)->tsStart) \
859 { \
860 uint64_t Prefix##_cTicks; \
861 STAM_GET_TS(Prefix##_cTicks); \
862 Prefix##_cTicks -= (pProfileAdv)->tsStart; \
863 (pProfileAdv)->tsStart = 0; \
864 (pProfileAdv)->Core.cTicks += Prefix##_cTicks; \
865 (pProfileAdv)->Core.cPeriods++; \
866 if ((pProfileAdv)->Core.cTicksMax < Prefix##_cTicks) \
867 (pProfileAdv)->Core.cTicksMax = Prefix##_cTicks; \
868 if ((pProfileAdv)->Core.cTicksMin > Prefix##_cTicks) \
869 (pProfileAdv)->Core.cTicksMin = Prefix##_cTicks; \
870 } \
871 } while (0)
872#else
873# define STAM_REL_PROFILE_ADV_STOP(pProfileAdv, Prefix) do { } while (0)
874#endif
875/** @def STAM_PROFILE_ADV_STOP
876 * Samples the stop time of a profiling period (if running) and updates the
877 * sample.
878 *
879 * @param pProfileAdv Pointer to the STAMPROFILEADV structure to operate on.
880 * @param Prefix Identifier prefix used to internal variables.
881 */
882#ifdef VBOX_WITH_STATISTICS
883# define STAM_PROFILE_ADV_STOP(pProfileAdv, Prefix) STAM_REL_PROFILE_ADV_STOP(pProfileAdv, Prefix)
884#else
885# define STAM_PROFILE_ADV_STOP(pProfileAdv, Prefix) do { } while (0)
886#endif
887
888
889/** @def STAM_REL_PROFILE_ADV_STOP_START
890 * Stops one profile counter (if running) and starts another one.
891 *
892 * @param pProfileAdv1 Pointer to the STAMPROFILEADV structure to stop.
893 * @param pProfileAdv2 Pointer to the STAMPROFILEADV structure to start.
894 * @param Prefix Identifier prefix used to internal variables.
895 */
896#ifndef VBOX_WITHOUT_RELEASE_STATISTICS
897# define STAM_REL_PROFILE_ADV_STOP_START(pProfileAdv1, pProfileAdv2, Prefix) \
898 do { \
899 uint64_t Prefix##_cTicks; \
900 STAM_GET_TS(Prefix##_cTicks); \
901 (pProfileAdv2)->tsStart = Prefix##_cTicks; \
902 if ((pProfileAdv1)->tsStart) \
903 { \
904 Prefix##_cTicks -= (pProfileAdv1)->tsStart; \
905 (pProfileAdv1)->tsStart = 0; \
906 (pProfileAdv1)->Core.cTicks += Prefix##_cTicks; \
907 (pProfileAdv1)->Core.cPeriods++; \
908 if ((pProfileAdv1)->Core.cTicksMax < Prefix##_cTicks) \
909 (pProfileAdv1)->Core.cTicksMax = Prefix##_cTicks; \
910 if ((pProfileAdv1)->Core.cTicksMin > Prefix##_cTicks) \
911 (pProfileAdv1)->Core.cTicksMin = Prefix##_cTicks; \
912 } \
913 } while (0)
914#else
915# define STAM_REL_PROFILE_ADV_STOP_START(pProfileAdv1, pProfileAdv2, Prefix) \
916 do { } while (0)
917#endif
918/** @def STAM_PROFILE_ADV_STOP_START
919 * Samples the stop time of a profiling period (if running) and updates the
920 * sample.
921 *
922 * @param pProfileAdv1 Pointer to the STAMPROFILEADV structure to stop.
923 * @param pProfileAdv2 Pointer to the STAMPROFILEADV structure to start.
924 * @param Prefix Identifier prefix used to internal variables.
925 */
926#ifdef VBOX_WITH_STATISTICS
927# define STAM_PROFILE_ADV_STOP_START(pProfileAdv1, pProfileAdv2, Prefix) \
928 STAM_REL_PROFILE_ADV_STOP_START(pProfileAdv1, pProfileAdv2, Prefix)
929#else
930# define STAM_PROFILE_ADV_STOP_START(pProfileAdv1, pProfileAdv2, Prefix) \
931 do { } while (0)
932#endif
933
934
935/** @def STAM_REL_PROFILE_ADV_SUSPEND
936 * Suspends the sampling for a while. This can be useful to exclude parts
937 * covered by other samples without screwing up the count, and average+min times.
938 *
939 * @param pProfileAdv Pointer to the STAMPROFILEADV structure to operate on.
940 * @param Prefix Identifier prefix used to internal variables. The prefix
941 * must match that of the resume one since it stores the
942 * suspend time in a stack variable.
943 */
944#ifndef VBOX_WITHOUT_RELEASE_STATISTICS
945# define STAM_REL_PROFILE_ADV_SUSPEND(pProfileAdv, Prefix) \
946 uint64_t Prefix##_tsSuspend; \
947 STAM_GET_TS(Prefix##_tsSuspend)
948#else
949# define STAM_REL_PROFILE_ADV_SUSPEND(pProfileAdv, Prefix) do { } while (0)
950#endif
951/** @def STAM_PROFILE_ADV_SUSPEND
952 * Suspends the sampling for a while. This can be useful to exclude parts
953 * covered by other samples without screwing up the count, and average+min times.
954 *
955 * @param pProfileAdv Pointer to the STAMPROFILEADV structure to operate on.
956 * @param Prefix Identifier prefix used to internal variables. The prefix
957 * must match that of the resume one since it stores the
958 * suspend time in a stack variable.
959 */
960#ifdef VBOX_WITH_STATISTICS
961# define STAM_PROFILE_ADV_SUSPEND(pProfileAdv, Prefix) STAM_REL_PROFILE_ADV_SUSPEND(pProfileAdv, Prefix)
962#else
963# define STAM_PROFILE_ADV_SUSPEND(pProfileAdv, Prefix) do { } while (0)
964#endif
965
966
967/** @def STAM_REL_PROFILE_ADV_RESUME
968 * Counter to STAM_REL_PROFILE_ADV_SUSPEND.
969 *
970 * @param pProfileAdv Pointer to the STAMPROFILEADV structure to operate on.
971 * @param Prefix Identifier prefix used to internal variables. This must
972 * match the one used with the SUSPEND!
973 */
974#ifndef VBOX_WITHOUT_RELEASE_STATISTICS
975# define STAM_REL_PROFILE_ADV_RESUME(pProfileAdv, Prefix) \
976 do { \
977 uint64_t Prefix##_tsNow; \
978 STAM_GET_TS(Prefix##_tsNow); \
979 (pProfileAdv)->tsStart += Prefix##_tsNow - Prefix##_tsSuspend; \
980 } while (0)
981#else
982# define STAM_REL_PROFILE_ADV_RESUME(pProfileAdv, Prefix) do { } while (0)
983#endif
984/** @def STAM_PROFILE_ADV_RESUME
985 * Counter to STAM_PROFILE_ADV_SUSPEND.
986 *
987 * @param pProfileAdv Pointer to the STAMPROFILEADV structure to operate on.
988 * @param Prefix Identifier prefix used to internal variables. This must
989 * match the one used with the SUSPEND!
990 */
991#ifdef VBOX_WITH_STATISTICS
992# define STAM_PROFILE_ADV_RESUME(pProfileAdv, Prefix) STAM_REL_PROFILE_ADV_RESUME(pProfileAdv, Prefix)
993#else
994# define STAM_PROFILE_ADV_RESUME(pProfileAdv, Prefix) do { } while (0)
995#endif
996
997
998/** @def STAM_REL_PROFILE_ADV_STOP_EX
999 * Samples the stop time of a profiling period (if running) and updates both
1000 * the sample and an attribution sample.
1001 *
1002 * @param pProfileAdv Pointer to the STAMPROFILEADV structure to operate on.
1003 * @param pProfile2 Pointer to the STAMPROFILE structure which this
1004 * interval should be attributed to as well. This may be NULL.
1005 * @param Prefix Identifier prefix used to internal variables.
1006 */
1007#ifndef VBOX_WITHOUT_RELEASE_STATISTICS
1008# define STAM_REL_PROFILE_ADV_STOP_EX(pProfileAdv, pProfile2, Prefix) \
1009 do { \
1010 if ((pProfileAdv)->tsStart) \
1011 { \
1012 uint64_t Prefix##_cTicks; \
1013 STAM_GET_TS(Prefix##_cTicks); \
1014 Prefix##_cTicks -= (pProfileAdv)->tsStart; \
1015 (pProfileAdv)->tsStart = 0; \
1016 (pProfileAdv)->Core.cTicks += Prefix##_cTicks; \
1017 (pProfileAdv)->Core.cPeriods++; \
1018 if ((pProfileAdv)->Core.cTicksMax < Prefix##_cTicks) \
1019 (pProfileAdv)->Core.cTicksMax = Prefix##_cTicks; \
1020 if ((pProfileAdv)->Core.cTicksMin > Prefix##_cTicks) \
1021 (pProfileAdv)->Core.cTicksMin = Prefix##_cTicks; \
1022 if ((pProfile2)) \
1023 { \
1024 (pProfile2)->cTicks += Prefix##_cTicks; \
1025 (pProfile2)->cPeriods++; \
1026 if ((pProfile2)->cTicksMax < Prefix##_cTicks) \
1027 (pProfile2)->cTicksMax = Prefix##_cTicks; \
1028 if ((pProfile2)->cTicksMin > Prefix##_cTicks) \
1029 (pProfile2)->cTicksMin = Prefix##_cTicks; \
1030 } \
1031 } \
1032 } while (0)
1033#else
1034# define STAM_REL_PROFILE_ADV_STOP_EX(pProfileAdv, pProfile2, Prefix) do { } while (0)
1035#endif
1036/** @def STAM_PROFILE_ADV_STOP_EX
1037 * Samples the stop time of a profiling period (if running) and updates both
1038 * the sample and an attribution sample.
1039 *
1040 * @param pProfileAdv Pointer to the STAMPROFILEADV structure to operate on.
1041 * @param pProfile2 Pointer to the STAMPROFILE structure which this
1042 * interval should be attributed to as well. This may be NULL.
1043 * @param Prefix Identifier prefix used to internal variables.
1044 */
1045#ifdef VBOX_WITH_STATISTICS
1046# define STAM_PROFILE_ADV_STOP_EX(pProfileAdv, pProfile2, Prefix) STAM_REL_PROFILE_ADV_STOP_EX(pProfileAdv, pProfile2, Prefix)
1047#else
1048# define STAM_PROFILE_ADV_STOP_EX(pProfileAdv, pProfile2, Prefix) do { } while (0)
1049#endif
1050
1051/** @def STAM_REL_PROFILE_ADV_IS_RUNNING
1052 * Checks if it is running.
1053 *
1054 * @param pProfileAdv Pointer to the STAMPROFILEADV structure to operate on.
1055 */
1056#ifndef VBOX_WITHOUT_RELEASE_STATISTICS
1057# define STAM_REL_PROFILE_ADV_IS_RUNNING(pProfileAdv) (pProfileAdv)->tsStart
1058#else
1059# define STAM_REL_PROFILE_ADV_IS_RUNNING(pProfileAdv) (false)
1060#endif
1061/** @def STAM_PROFILE_ADV_IS_RUNNING
1062 * Checks if it is running.
1063 *
1064 * @param pProfileAdv Pointer to the STAMPROFILEADV structure to operate on.
1065 */
1066#ifdef VBOX_WITH_STATISTICS
1067# define STAM_PROFILE_ADV_IS_RUNNING(pProfileAdv) STAM_REL_PROFILE_ADV_IS_RUNNING(pProfileAdv)
1068#else
1069# define STAM_PROFILE_ADV_IS_RUNNING(pProfileAdv) (false)
1070#endif
1071
1072/** @def STAM_REL_PROFILE_ADV_SET_STOPPED
1073 * Marks the profile counter as stopped.
1074 *
1075 * This is for avoiding screwups in twisty code.
1076 *
1077 * @param pProfileAdv Pointer to the STAMPROFILEADV structure to operate on.
1078 */
1079#ifndef VBOX_WITHOUT_RELEASE_STATISTICS
1080# define STAM_REL_PROFILE_ADV_SET_STOPPED(pProfileAdv) do { (pProfileAdv)->tsStart = 0; } while (0)
1081#else
1082# define STAM_REL_PROFILE_ADV_SET_STOPPED(pProfileAdv) do { } while (0)
1083#endif
1084/** @def STAM_PROFILE_ADV_SET_STOPPED
1085 * Marks the profile counter as stopped.
1086 *
1087 * This is for avoiding screwups in twisty code.
1088 *
1089 * @param pProfileAdv Pointer to the STAMPROFILEADV structure to operate on.
1090 */
1091#ifdef VBOX_WITH_STATISTICS
1092# define STAM_PROFILE_ADV_SET_STOPPED(pProfileAdv) STAM_REL_PROFILE_ADV_SET_STOPPED(pProfileAdv)
1093#else
1094# define STAM_PROFILE_ADV_SET_STOPPED(pProfileAdv) do { } while (0)
1095#endif
1096
1097
1098/**
1099 * Ratio of A to B, uint32_t types.
1100 * @remark Use STAM_STATS or STAM_REL_STATS for modifying A & B values.
1101 */
1102typedef struct STAMRATIOU32
1103{
1104 /** Sample A. */
1105 uint32_t volatile u32A;
1106 /** Sample B. */
1107 uint32_t volatile u32B;
1108} STAMRATIOU32;
1109/** Pointer to a uint32_t ratio. */
1110typedef STAMRATIOU32 *PSTAMRATIOU32;
1111/** Pointer to const a uint32_t ratio. */
1112typedef const STAMRATIOU32 *PCSTAMRATIOU32;
1113
1114
1115
1116
1117/** @defgroup grp_stam_r3 The STAM Host Context Ring 3 API
1118 * @{
1119 */
1120
1121VMMR3DECL(int) STAMR3InitUVM(PUVM pUVM);
1122VMMR3DECL(void) STAMR3TermUVM(PUVM pUVM);
1123VMMR3DECL(int) STAMR3RegisterU(PUVM pUVM, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
1124 const char *pszName, STAMUNIT enmUnit, const char *pszDesc);
1125VMMR3DECL(int) STAMR3Register(PVM pVM, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
1126 const char *pszName, STAMUNIT enmUnit, const char *pszDesc);
1127
1128/** @def STAM_REL_REG
1129 * Registers a statistics sample.
1130 *
1131 * @param pVM The cross context VM structure.
1132 * @param pvSample Pointer to the sample.
1133 * @param enmType Sample type. This indicates what pvSample is pointing at.
1134 * @param pszName Sample name. The name is on this form "/<component>/<sample>".
1135 * Further nesting is possible.
1136 * @param enmUnit Sample unit.
1137 * @param pszDesc Sample description.
1138 */
1139#define STAM_REL_REG(pVM, pvSample, enmType, pszName, enmUnit, pszDesc) \
1140 STAM_REL_STATS({ int rcStam = STAMR3Register(pVM, pvSample, enmType, STAMVISIBILITY_ALWAYS, pszName, enmUnit, pszDesc); \
1141 AssertRC(rcStam); })
1142/** @def STAM_REG
1143 * Registers a statistics sample if statistics are enabled.
1144 *
1145 * @param pVM The cross context VM structure.
1146 * @param pvSample Pointer to the sample.
1147 * @param enmType Sample type. This indicates what pvSample is pointing at.
1148 * @param pszName Sample name. The name is on this form "/<component>/<sample>".
1149 * Further nesting is possible.
1150 * @param enmUnit Sample unit.
1151 * @param pszDesc Sample description.
1152 */
1153#define STAM_REG(pVM, pvSample, enmType, pszName, enmUnit, pszDesc) \
1154 STAM_STATS({STAM_REL_REG(pVM, pvSample, enmType, pszName, enmUnit, pszDesc);})
1155
1156/** @def STAM_REL_REG_USED
1157 * Registers a statistics sample which only shows when used.
1158 *
1159 * @param pVM The cross context VM structure.
1160 * @param pvSample Pointer to the sample.
1161 * @param enmType Sample type. This indicates what pvSample is pointing at.
1162 * @param pszName Sample name. The name is on this form "/<component>/<sample>".
1163 * Further nesting is possible.
1164 * @param enmUnit Sample unit.
1165 * @param pszDesc Sample description.
1166 */
1167#define STAM_REL_REG_USED(pVM, pvSample, enmType, pszName, enmUnit, pszDesc) \
1168 STAM_REL_STATS({ int rcStam = STAMR3Register(pVM, pvSample, enmType, STAMVISIBILITY_USED, pszName, enmUnit, pszDesc); \
1169 AssertRC(rcStam);})
1170/** @def STAM_REG_USED
1171 * Registers a statistics sample which only shows when used, if statistics are enabled.
1172 *
1173 * @param pVM The cross context VM structure.
1174 * @param pvSample Pointer to the sample.
1175 * @param enmType Sample type. This indicates what pvSample is pointing at.
1176 * @param pszName Sample name. The name is on this form "/<component>/<sample>".
1177 * Further nesting is possible.
1178 * @param enmUnit Sample unit.
1179 * @param pszDesc Sample description.
1180 */
1181#define STAM_REG_USED(pVM, pvSample, enmType, pszName, enmUnit, pszDesc) \
1182 STAM_STATS({ STAM_REL_REG_USED(pVM, pvSample, enmType, pszName, enmUnit, pszDesc); })
1183
1184VMMR3DECL(int) STAMR3RegisterFU(PUVM pUVM, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility, STAMUNIT enmUnit,
1185 const char *pszDesc, const char *pszName, ...) RT_IPRT_FORMAT_ATTR(7, 8);
1186VMMR3DECL(int) STAMR3RegisterF(PVM pVM, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility, STAMUNIT enmUnit,
1187 const char *pszDesc, const char *pszName, ...) RT_IPRT_FORMAT_ATTR(7, 8);
1188VMMR3DECL(int) STAMR3RegisterVU(PUVM pUVM, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility, STAMUNIT enmUnit,
1189 const char *pszDesc, const char *pszName, va_list args) RT_IPRT_FORMAT_ATTR(7, 0);
1190VMMR3DECL(int) STAMR3RegisterV(PVM pVM, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility, STAMUNIT enmUnit,
1191 const char *pszDesc, const char *pszName, va_list args) RT_IPRT_FORMAT_ATTR(7, 0);
1192
1193/**
1194 * Resets the sample.
1195 * @param pVM The cross context VM structure.
1196 * @param pvSample The sample registered using STAMR3RegisterCallback.
1197 */
1198typedef DECLCALLBACKTYPE(void, FNSTAMR3CALLBACKRESET,(PVM pVM, void *pvSample));
1199/** Pointer to a STAM sample reset callback. */
1200typedef FNSTAMR3CALLBACKRESET *PFNSTAMR3CALLBACKRESET;
1201
1202/**
1203 * Prints the sample into the buffer.
1204 *
1205 * @param pVM The cross context VM structure.
1206 * @param pvSample The sample registered using STAMR3RegisterCallback.
1207 * @param pszBuf The buffer to print into.
1208 * @param cchBuf The size of the buffer.
1209 */
1210typedef DECLCALLBACKTYPE(void, FNSTAMR3CALLBACKPRINT,(PVM pVM, void *pvSample, char *pszBuf, size_t cchBuf));
1211/** Pointer to a STAM sample print callback. */
1212typedef FNSTAMR3CALLBACKPRINT *PFNSTAMR3CALLBACKPRINT;
1213
1214VMMR3DECL(int) STAMR3RegisterCallback(PVM pVM, void *pvSample, STAMVISIBILITY enmVisibility, STAMUNIT enmUnit,
1215 PFNSTAMR3CALLBACKRESET pfnReset, PFNSTAMR3CALLBACKPRINT pfnPrint,
1216 const char *pszDesc, const char *pszName, ...) RT_IPRT_FORMAT_ATTR(8, 9);
1217VMMR3DECL(int) STAMR3RegisterCallbackV(PVM pVM, void *pvSample, STAMVISIBILITY enmVisibility, STAMUNIT enmUnit,
1218 PFNSTAMR3CALLBACKRESET pfnReset, PFNSTAMR3CALLBACKPRINT pfnPrint,
1219 const char *pszDesc, const char *pszName, va_list args) RT_IPRT_FORMAT_ATTR(8, 0);
1220
1221VMMR3DECL(int) STAMR3RegisterRefresh(PUVM pUVM, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
1222 STAMUNIT enmUnit, uint8_t iRefreshGrp, const char *pszDesc,
1223 const char *pszName, ...) RT_IPRT_FORMAT_ATTR(8, 9);
1224VMMR3DECL(int) STAMR3RegisterRefreshV(PUVM pUVM, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
1225 STAMUNIT enmUnit, uint8_t iRefreshGrp, const char *pszDesc,
1226 const char *pszName, va_list va) RT_IPRT_FORMAT_ATTR(8, 0);
1227
1228VMMR3DECL(int) STAMR3Deregister(PUVM pUVM, const char *pszPat);
1229VMMR3DECL(int) STAMR3DeregisterF(PUVM pUVM, const char *pszPatFmt, ...) RT_IPRT_FORMAT_ATTR(2, 3);
1230VMMR3DECL(int) STAMR3DeregisterV(PUVM pUVM, const char *pszPatFmt, va_list va) RT_IPRT_FORMAT_ATTR(2, 0);
1231VMMR3DECL(int) STAMR3DeregisterByPrefix(PUVM pUVM, const char *pszPrefix);
1232VMMR3DECL(int) STAMR3DeregisterByAddr(PUVM pUVM, void *pvSample);
1233
1234VMMR3DECL(int) STAMR3Reset(PUVM pUVM, const char *pszPat);
1235VMMR3DECL(int) STAMR3Snapshot(PUVM pUVM, const char *pszPat, char **ppszSnapshot, size_t *pcchSnapshot, bool fWithDesc);
1236VMMR3DECL(int) STAMR3SnapshotFree(PUVM pUVM, char *pszSnapshot);
1237VMMR3DECL(int) STAMR3Dump(PUVM pUVM, const char *pszPat);
1238VMMR3DECL(int) STAMR3DumpToReleaseLog(PUVM pUVM, const char *pszPat);
1239VMMR3DECL(int) STAMR3Print(PUVM pUVM, const char *pszPat);
1240
1241/**
1242 * Callback function for STAMR3Enum().
1243 *
1244 * @returns non-zero to halt the enumeration.
1245 *
1246 * @param pszName The name of the sample.
1247 * @param enmType The type.
1248 * @param pvSample Pointer to the data. enmType indicates the format of this data.
1249 * @param enmUnit The unit.
1250 * @param enmVisibility The visibility.
1251 * @param pszDesc The description.
1252 * @param pvUser The pvUser argument given to STAMR3Enum().
1253 */
1254typedef DECLCALLBACKTYPE(int, FNSTAMR3ENUM,(const char *pszName, STAMTYPE enmType, void *pvSample, STAMUNIT enmUnit,
1255 STAMVISIBILITY enmVisiblity, const char *pszDesc, void *pvUser));
1256/** Pointer to a FNSTAMR3ENUM(). */
1257typedef FNSTAMR3ENUM *PFNSTAMR3ENUM;
1258
1259VMMR3DECL(int) STAMR3Enum(PUVM pUVM, const char *pszPat, PFNSTAMR3ENUM pfnEnum, void *pvUser);
1260VMMR3DECL(const char *) STAMR3GetUnit(STAMUNIT enmUnit);
1261
1262/** @} */
1263
1264/** @} */
1265
1266RT_C_DECLS_END
1267
1268#endif /* !VBOX_INCLUDED_vmm_stam_h */
1269
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