VirtualBox

source: vbox/trunk/src/VBox/Main/testcase/tstVBoxAPIPerf.cpp@ 83113

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

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.6 KB
Line 
1/* $Id: tstVBoxAPIPerf.cpp 82968 2020-02-04 10:35:17Z vboxsync $ */
2/** @file
3 * tstVBoxAPIPerf - Checks the performance of the COM / XPOM API.
4 */
5
6/*
7 * Copyright (C) 2006-2020 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/com.h>
23#include <VBox/com/string.h>
24#include <VBox/com/array.h>
25#include <VBox/com/Guid.h>
26#include <VBox/com/ErrorInfo.h>
27#include <VBox/com/VirtualBox.h>
28#include <VBox/sup.h>
29
30#include <iprt/test.h>
31#include <iprt/time.h>
32
33
34
35/*********************************************************************************************************************************
36* Global Variables *
37*********************************************************************************************************************************/
38static RTTEST g_hTest;
39
40
41/** Worker fro TST_COM_EXPR(). */
42static HRESULT tstComExpr(HRESULT hrc, const char *pszOperation, int iLine)
43{
44 if (FAILED(hrc))
45 RTTestFailed(g_hTest, "%s failed on line %u with hrc=%Rhrc", pszOperation, iLine, hrc);
46 return hrc;
47}
48
49/** Macro that executes the given expression and report any failure.
50 * The expression must return a HRESULT. */
51#define TST_COM_EXPR(expr) tstComExpr(expr, #expr, __LINE__)
52
53
54
55static void tstApiPrf1(IVirtualBox *pVBox)
56{
57 RTTestSub(g_hTest, "IVirtualBox::Revision performance");
58
59 uint32_t const cCalls = 65536;
60 uint32_t cLeft = cCalls;
61 uint64_t uStartTS = RTTimeNanoTS();
62 while (cLeft-- > 0)
63 {
64 ULONG uRev;
65 HRESULT hrc = pVBox->COMGETTER(Revision)(&uRev);
66 if (FAILED(hrc))
67 {
68 tstComExpr(hrc, "IVirtualBox::Revision", __LINE__);
69 return;
70 }
71 }
72 uint64_t uElapsed = RTTimeNanoTS() - uStartTS;
73 RTTestValue(g_hTest, "IVirtualBox::Revision average", uElapsed / cCalls, RTTESTUNIT_NS_PER_CALL);
74 RTTestSubDone(g_hTest);
75}
76
77
78static void tstApiPrf2(IVirtualBox *pVBox)
79{
80 RTTestSub(g_hTest, "IVirtualBox::Version performance");
81
82 uint32_t const cCalls = 65536;
83 uint32_t cLeft = cCalls;
84 uint64_t uStartTS = RTTimeNanoTS();
85 while (cLeft-- > 0)
86 {
87 com::Bstr bstrVersion;
88 HRESULT hrc = pVBox->COMGETTER(Version)(bstrVersion.asOutParam());
89 if (FAILED(hrc))
90 {
91 tstComExpr(hrc, "IVirtualBox::Version", __LINE__);
92 return;
93 }
94 }
95 uint64_t uElapsed = RTTimeNanoTS() - uStartTS;
96 RTTestValue(g_hTest, "IVirtualBox::Version average", uElapsed / cCalls, RTTESTUNIT_NS_PER_CALL);
97 RTTestSubDone(g_hTest);
98}
99
100
101static void tstApiPrf3(IVirtualBox *pVBox)
102{
103 RTTestSub(g_hTest, "IVirtualBox::Host performance");
104
105 /* The first call. */
106 uint64_t uStartTS = RTTimeNanoTS();
107 IHost *pHost = NULL;
108 HRESULT hrc = pVBox->COMGETTER(Host)(&pHost);
109 if (FAILED(hrc))
110 {
111 tstComExpr(hrc, "IVirtualBox::Host", __LINE__);
112 return;
113 }
114 pHost->Release();
115 uint64_t uElapsed = RTTimeNanoTS() - uStartTS;
116 RTTestValue(g_hTest, "IVirtualBox::Host first", uElapsed, RTTESTUNIT_NS);
117
118 /* Subsequent calls. */
119 uint32_t const cCalls1 = 4096;
120 uint32_t cLeft = cCalls1;
121 uStartTS = RTTimeNanoTS();
122 while (cLeft-- > 0)
123 {
124 IHost *pHost2 = NULL;
125 hrc = pVBox->COMGETTER(Host)(&pHost2);
126 if (FAILED(hrc))
127 {
128 tstComExpr(hrc, "IVirtualBox::Host", __LINE__);
129 return;
130 }
131 pHost2->Release();
132 }
133 uElapsed = RTTimeNanoTS() - uStartTS;
134 RTTestValue(g_hTest, "IVirtualBox::Host average", uElapsed / cCalls1, RTTESTUNIT_NS_PER_CALL);
135
136 /* Keep a reference around and see how that changes things.
137 Note! VBoxSVC is not creating and destroying Host(). */
138 pHost = NULL;
139 hrc = pVBox->COMGETTER(Host)(&pHost);
140
141 uint32_t const cCalls2 = 16384;
142 cLeft = cCalls2;
143 uStartTS = RTTimeNanoTS();
144 while (cLeft-- > 0)
145 {
146 IHost *pHost2 = NULL;
147 hrc = pVBox->COMGETTER(Host)(&pHost2);
148 if (FAILED(hrc))
149 {
150 tstComExpr(hrc, "IVirtualBox::Host", __LINE__);
151 pHost->Release();
152 return;
153 }
154 pHost2->Release();
155 }
156 uElapsed = RTTimeNanoTS() - uStartTS;
157 RTTestValue(g_hTest, "IVirtualBox::Host 2nd ref", uElapsed / cCalls2, RTTESTUNIT_NS_PER_CALL);
158 pHost->Release();
159
160 RTTestSubDone(g_hTest);
161}
162
163
164static void tstApiPrf4(IVirtualBox *pVBox)
165{
166 RTTestSub(g_hTest, "IHost::GetProcessorFeature performance");
167
168 IHost *pHost = NULL;
169 HRESULT hrc = pVBox->COMGETTER(Host)(&pHost);
170 if (FAILED(hrc))
171 {
172 tstComExpr(hrc, "IVirtualBox::Host", __LINE__);
173 return;
174 }
175
176 uint32_t const cCalls = 65536;
177 uint32_t cLeft = cCalls;
178 uint64_t uStartTS = RTTimeNanoTS();
179 while (cLeft-- > 0)
180 {
181 BOOL fSupported;
182 hrc = pHost->GetProcessorFeature(ProcessorFeature_PAE, &fSupported);
183 if (FAILED(hrc))
184 {
185 tstComExpr(hrc, "IHost::GetProcessorFeature", __LINE__);
186 pHost->Release();
187 return;
188 }
189 }
190 uint64_t uElapsed = RTTimeNanoTS() - uStartTS;
191 RTTestValue(g_hTest, "IHost::GetProcessorFeature average", uElapsed / cCalls, RTTESTUNIT_NS_PER_CALL);
192 pHost->Release();
193 RTTestSubDone(g_hTest);
194}
195
196
197
198int main()
199{
200 /*
201 * Initialization.
202 */
203 RTEXITCODE rcExit = RTTestInitAndCreate("tstVBoxAPIPerf", &g_hTest);
204 if (rcExit != RTEXITCODE_SUCCESS)
205 return rcExit;
206 SUPR3Init(NULL); /* Better time support. */
207 RTTestBanner(g_hTest);
208
209 RTTestSub(g_hTest, "Initializing COM and singletons");
210 HRESULT hrc = com::Initialize();
211 if (SUCCEEDED(hrc))
212 {
213 ComPtr<IVirtualBoxClient> ptrVBoxClient;
214 ComPtr<IVirtualBox> ptrVBox;
215 hrc = TST_COM_EXPR(ptrVBoxClient.createInprocObject(CLSID_VirtualBoxClient));
216 if (SUCCEEDED(hrc))
217 hrc = TST_COM_EXPR(ptrVBoxClient->COMGETTER(VirtualBox)(ptrVBox.asOutParam()));
218 if (SUCCEEDED(hrc))
219 {
220 ComPtr<ISession> ptrSession;
221 hrc = TST_COM_EXPR(ptrSession.createInprocObject(CLSID_Session));
222 if (SUCCEEDED(hrc))
223 {
224 RTTestSubDone(g_hTest);
225
226 /*
227 * Call test functions.
228 */
229 tstApiPrf1(ptrVBox);
230 tstApiPrf2(ptrVBox);
231 tstApiPrf3(ptrVBox);
232
233 /** @todo Find something that returns a 2nd instance of an interface and see
234 * how if wrapper stuff is reused in any way. */
235 tstApiPrf4(ptrVBox);
236 }
237 }
238
239 ptrVBox.setNull();
240 ptrVBoxClient.setNull();
241 com::Shutdown();
242 }
243 else
244 RTTestIFailed("com::Initialize failed with hrc=%Rhrc", hrc);
245 return RTTestSummaryAndDestroy(g_hTest);
246}
247
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