VirtualBox

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

Last change on this file since 75320 was 72300, checked in by vboxsync, 7 years ago

NEM,STAM: Partition memory statistics for NEM. bugref:9044

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