1 | /* $Id: tstVBoxAPIPerf.cpp 49943 2013-12-16 20:19:58Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * tstVBoxAPIPerf - Checks the performance of the COM / XPOM API.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2013 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 | *******************************************************************************/
|
---|
38 | static RTTEST g_hTest;
|
---|
39 |
|
---|
40 |
|
---|
41 | /** Worker fro TST_COM_EXPR(). */
|
---|
42 | static 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 |
|
---|
55 | static 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 |
|
---|
78 | static 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 |
|
---|
101 | static 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 |
|
---|
164 | static 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 |
|
---|
198 | int main(int argc, char **argv)
|
---|
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<IVirtualBox> ptrVBox;
|
---|
214 | hrc = TST_COM_EXPR(ptrVBox.createLocalObject(CLSID_VirtualBox));
|
---|
215 | if (SUCCEEDED(hrc))
|
---|
216 | {
|
---|
217 | ComPtr<ISession> ptrSession;
|
---|
218 | hrc = TST_COM_EXPR(ptrSession.createInprocObject(CLSID_Session));
|
---|
219 | if (SUCCEEDED(hrc))
|
---|
220 | {
|
---|
221 | RTTestSubDone(g_hTest);
|
---|
222 |
|
---|
223 | /*
|
---|
224 | * Call test functions.
|
---|
225 | */
|
---|
226 | tstApiPrf1(ptrVBox);
|
---|
227 | tstApiPrf2(ptrVBox);
|
---|
228 | tstApiPrf3(ptrVBox);
|
---|
229 |
|
---|
230 | /** @todo Find something that returns a 2nd instance of an interface and see
|
---|
231 | * how if wrapper stuff is reused in any way. */
|
---|
232 | tstApiPrf4(ptrVBox);
|
---|
233 | }
|
---|
234 | }
|
---|
235 |
|
---|
236 | ptrVBox.setNull();
|
---|
237 | com::Shutdown();
|
---|
238 | }
|
---|
239 | else
|
---|
240 | RTTestIFailed("com::Initialize failed with hrc=%Rhrc", hrc);
|
---|
241 | return RTTestSummaryAndDestroy(g_hTest);
|
---|
242 | }
|
---|
243 |
|
---|