VirtualBox

source: vbox/trunk/src/VBox/Frontends/VBoxBalloonCtrl/VBoxWatchdogUtils.cpp@ 39943

Last change on this file since 39943 was 39936, checked in by vboxsync, 13 years ago

VBoxBalloonCtrl: properties

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.5 KB
Line 
1/* $Id: */
2/** @file
3 * VBoxWatchdogUtils - Misc. utility functions for modules.
4 */
5
6/*
7 * Copyright (C) 2011-2012 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/*******************************************************************************
20* Header Files *
21*******************************************************************************/
22#include <VBox/com/array.h>
23#include "VBoxWatchdogInternal.h"
24
25
26/**
27 * Retrieves a metric from a specified machine.
28 *
29 * @return IPRT status code.
30 * @param pMachine Pointer to the machine's internal structure.
31 * @param strName Name of metric to retrieve.
32 * @param pulData Pointer to value to retrieve the actual metric value.
33 */
34int getMetric(PVBOXWATCHDOG_MACHINE pMachine, const Bstr& strName, LONG *pulData)
35{
36 AssertPtrReturn(pMachine, VERR_INVALID_POINTER);
37 AssertPtrReturn(pulData, VERR_INVALID_POINTER);
38
39 /* Input. */
40 com::SafeArray<BSTR> metricNames(1);
41 com::SafeIfaceArray<IUnknown> metricObjects(1);
42 pMachine->machine.queryInterfaceTo(&metricObjects[0]);
43
44 /* Output. */
45 com::SafeArray<BSTR> retNames;
46 com::SafeIfaceArray<IUnknown> retObjects;
47 com::SafeArray<BSTR> retUnits;
48 com::SafeArray<ULONG> retScales;
49 com::SafeArray<ULONG> retSequenceNumbers;
50 com::SafeArray<ULONG> retIndices;
51 com::SafeArray<ULONG> retLengths;
52 com::SafeArray<LONG> retData;
53
54 /* Query current memory free. */
55 strName.cloneTo(&metricNames[0]);
56#ifdef VBOX_BALLOONCTRL_GLOBAL_PERFCOL
57 Assert(!g_pPerfCollector.isNull());
58 HRESULT hrc = g_pPerfCollector->QueryMetricsData(
59#else
60 Assert(!pMachine->collector.isNull());
61 HRESULT hrc = pMachine->collector->QueryMetricsData(
62#endif
63 ComSafeArrayAsInParam(metricNames),
64 ComSafeArrayAsInParam(metricObjects),
65 ComSafeArrayAsOutParam(retNames),
66 ComSafeArrayAsOutParam(retObjects),
67 ComSafeArrayAsOutParam(retUnits),
68 ComSafeArrayAsOutParam(retScales),
69 ComSafeArrayAsOutParam(retSequenceNumbers),
70 ComSafeArrayAsOutParam(retIndices),
71 ComSafeArrayAsOutParam(retLengths),
72 ComSafeArrayAsOutParam(retData));
73#if 0
74 /* Useful for metrics debugging. */
75 for (unsigned j = 0; j < retNames.size(); j++)
76 {
77 Bstr metricUnit(retUnits[j]);
78 Bstr metricName(retNames[j]);
79 RTPrintf("%-20ls ", metricName.raw());
80 const char *separator = "";
81 for (unsigned k = 0; k < retLengths[j]; k++)
82 {
83 if (retScales[j] == 1)
84 RTPrintf("%s%d %ls", separator, retData[retIndices[j] + k], metricUnit.raw());
85 else
86 RTPrintf("%s%d.%02d%ls", separator, retData[retIndices[j] + k] / retScales[j],
87 (retData[retIndices[j] + k] * 100 / retScales[j]) % 100, metricUnit.raw());
88 separator = ", ";
89 }
90 RTPrintf("\n");
91 }
92#endif
93
94 if (SUCCEEDED(hrc))
95 *pulData = retData.size() ? retData[retIndices[0]] : 0;
96
97 return SUCCEEDED(hrc) ? VINF_SUCCESS : VINF_NOT_SUPPORTED;
98}
99
100/**
101 * Returns the payload of a machine.
102 *
103 * @return void* Pointer to payload data. Mutable!
104 * @param pMachine Machine to get payload for.
105 * @param pszModule Module name to get payload from.
106 */
107void* getPayload(PVBOXWATCHDOG_MACHINE pMachine, const char *pszModule)
108{
109 AssertPtrReturn(pMachine, NULL);
110 AssertPtrReturn(pszModule, NULL);
111 mapPayloadIter it = pMachine->payload.find(pszModule);
112 if (it == pMachine->payload.end())
113 return NULL;
114 Assert(it->second.cbPayload);
115 return it->second.pvPayload;
116}
117
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