VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispProfile.h@ 39132

Last change on this file since 39132 was 36867, checked in by vboxsync, 14 years ago

Additions/Video: display/miniport drivers

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.2 KB
Line 
1/* $Id: VBoxDispProfile.h 36867 2011-04-28 07:27:03Z vboxsync $ */
2
3/** @file
4 * VBoxVideo Display D3D User mode dll
5 */
6
7/*
8 * Copyright (C) 2011 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19#ifndef ___VBoxDispProfile_h__
20#define ___VBoxDispProfile_h__
21#include <iprt/ctype.h>
22#include <iprt/time.h>
23
24#include "VBoxDispD3DCmn.h"
25
26#define VBOXDISPPROFILE_MAX_SETSIZE 512
27#define VBOXDISPPROFILE_GET_TIME_NANO() RTTimeNanoTS()
28#define VBOXDISPPROFILE_GET_TIME_MILLI() RTTimeMilliTS()
29#define VBOXDISPPROFILE_DUMP(_m) do {\
30 LogRel (_m); \
31 } while (0)
32
33class VBoxDispProfileEntry
34{
35public:
36 VBoxDispProfileEntry() :
37 m_cCalls(0),
38 m_cTime(0),
39 m_pName(NULL)
40 {}
41
42 VBoxDispProfileEntry(const char *pName) :
43 m_cCalls(0),
44 m_cTime(0),
45 m_pName(pName)
46 {}
47
48 void step(uint64_t cTime)
49 {
50 ++m_cCalls;
51 m_cTime+= cTime;
52 }
53
54 void reset()
55 {
56 m_cCalls = 0;
57 m_cTime = 0;
58 }
59
60 void dump(const PVBOXWDDMDISP_DEVICE pDevice) const
61 {
62// VBOXDISPPROFILE_DUMP((pDevice, "Entry '%s': calls(%d), time: nanos(%I64u), micros(%I64u), millis(%I64u)\n",
63// m_pName, m_cCalls,
64// m_cTime, m_cTime/1000, m_cTime/1000000));
65 VBOXDISPPROFILE_DUMP(("%s\t%d\t%I64u\t%I64u\t%I64u\n",
66 m_pName, m_cCalls,
67 m_cTime, m_cTime/1000, m_cTime/1000000));
68 }
69private:
70 uint32_t m_cCalls;
71 uint64_t m_cTime;
72 const char * m_pName;
73};
74
75class VBoxDispProfileSet
76{
77public:
78 VBoxDispProfileSet(const char *pName) :
79 m_cEntries(0),
80 m_pName(pName)
81 {}
82
83 VBoxDispProfileEntry * alloc(const char *pName)
84 {
85 if (m_cEntries < RT_ELEMENTS(m_Entries))
86 {
87 VBoxDispProfileEntry * entry = &m_Entries[m_cEntries];
88 ++m_cEntries;
89 *entry = VBoxDispProfileEntry(pName);
90 return entry;
91 }
92 return NULL;
93 }
94
95 void resetEntries()
96 {
97 for (uint32_t i = 0; i < m_cEntries; ++i)
98 {
99 m_Entries[i].reset();
100 }
101 }
102
103 void dump(const PVBOXWDDMDISP_DEVICE pDevice)
104 {
105 VBOXDISPPROFILE_DUMP((">>>> Start of VBox Disp Dump '%s': num entries(%d) >>>>>\n", m_pName, m_cEntries));
106 VBOXDISPPROFILE_DUMP(("Name\tCalls\tNanos\tMicros\tMillis\n"));
107 for (uint32_t i = 0; i < m_cEntries; ++i)
108 {
109 m_Entries[i].dump(pDevice);
110 }
111 VBOXDISPPROFILE_DUMP(("<<<< Endi of VBox Disp Dump '%s' <<<<<\n", m_pName));
112 }
113
114private:
115 VBoxDispProfileEntry m_Entries[VBOXDISPPROFILE_MAX_SETSIZE];
116 uint32_t m_cEntries;
117 const char * m_pName;
118};
119
120template<typename T> class VBoxDispProfileScopeLogger
121{
122public:
123 VBoxDispProfileScopeLogger(T *pEntry) :
124 m_pEntry(pEntry),
125 m_bDisable(FALSE)
126 {
127 m_cTime = VBOXDISPPROFILE_GET_TIME_NANO();
128 }
129
130 ~VBoxDispProfileScopeLogger()
131 {
132 if (!m_bDisable)
133 {
134 logStep();
135 }
136 }
137
138 void disable()
139 {
140 m_bDisable = TRUE;
141 }
142
143 void logAndDisable()
144 {
145 logStep();
146 disable();
147 }
148
149private:
150 void logStep()
151 {
152 uint64_t cNewTime = VBOXDISPPROFILE_GET_TIME_NANO();
153 m_pEntry->step(cNewTime - m_cTime);
154 }
155 T *m_pEntry;
156 uint64_t m_cTime;
157 BOOL m_bDisable;
158};
159
160
161class VBoxDispProfileFpsCounter
162{
163public:
164 VBoxDispProfileFpsCounter(uint32_t cPeriods)
165 {
166 memset(&m_Data, 0, sizeof (m_Data));
167 m_Data.mcPeriods = cPeriods;
168 m_Data.mpaPeriods = (uint64_t *)RTMemAllocZ(sizeof (m_Data.mpaPeriods[0]) * cPeriods);
169 m_Data.mpaCalls = (uint32_t *)RTMemAllocZ(sizeof (m_Data.mpaCalls[0]) * cPeriods);
170 m_Data.mpaTimes = (uint64_t *)RTMemAllocZ(sizeof (m_Data.mpaTimes[0]) * cPeriods);
171 }
172
173 ~VBoxDispProfileFpsCounter()
174 {
175 RTMemFree(m_Data.mpaPeriods);
176 RTMemFree(m_Data.mpaCalls);
177 RTMemFree(m_Data.mpaTimes);
178 }
179
180 void ReportFrame()
181 {
182 uint64_t cur = VBOXDISPPROFILE_GET_TIME_NANO();
183
184 if(m_Data.mPrevTime)
185 {
186 uint64_t curPeriod = cur - m_Data.mPrevTime;
187
188 m_Data.mPeriodSum += curPeriod - m_Data.mpaPeriods[m_Data.miPeriod];
189 m_Data.mpaPeriods[m_Data.miPeriod] = curPeriod;
190
191 m_Data.mCallsSum += m_Data.mCurCalls - m_Data.mpaCalls[m_Data.miPeriod];
192 m_Data.mpaCalls[m_Data.miPeriod] = m_Data.mCurCalls;
193
194 m_Data.mTimeUsedSum += m_Data.mCurTimeUsed - m_Data.mpaTimes[m_Data.miPeriod];
195 m_Data.mpaTimes[m_Data.miPeriod] = m_Data.mCurTimeUsed;
196
197 ++m_Data.miPeriod;
198 m_Data.miPeriod %= m_Data.mcPeriods;
199 }
200 m_Data.mPrevTime = cur;
201 ++m_Data.mcFrames;
202
203 m_Data.mCurTimeUsed = 0;
204 m_Data.mCurCalls = 0;
205 }
206
207 void step(uint64_t Time)
208 {
209 m_Data.mCurTimeUsed += Time;
210 ++m_Data.mCurCalls;
211 }
212
213 uint64_t GetEveragePeriod()
214 {
215 return m_Data.mPeriodSum / m_Data.mcPeriods;
216 }
217
218 double GetFps()
219 {
220 return ((double)1000000000.0) / GetEveragePeriod();
221 }
222
223 double GetCps()
224 {
225 return GetFps() * m_Data.mCallsSum / m_Data.mcPeriods;
226 }
227
228 double GetTimeProcPercent()
229 {
230 return 100.0*m_Data.mTimeUsedSum/m_Data.mPeriodSum;
231 }
232
233 uint64_t GetNumFrames()
234 {
235 return m_Data.mcFrames;
236 }
237private:
238 struct
239 {
240 uint64_t mPeriodSum;
241 uint64_t *mpaPeriods;
242 uint64_t mPrevTime;
243 uint64_t mcFrames;
244 uint32_t mcPeriods;
245 uint32_t miPeriod;
246
247 uint64_t mCallsSum;
248 uint32_t *mpaCalls;
249
250 uint64_t mTimeUsedSum;
251 uint64_t *mpaTimes;
252
253 uint64_t mCurTimeUsed;
254 uint64_t mCurCalls;
255 } m_Data;
256};
257
258#define VBOXDISPPROFILE_FUNCTION_LOGGER_DISABLE_CURRENT() do { \
259 __vboxDispProfileFunctionLogger.disable();\
260 } while (0)
261
262#define VBOXDISPPROFILE_FUNCTION_LOGGER_LOG_AND_DISABLE_CURRENT() do { \
263 __vboxDispProfileFunctionLogger.logAndDisable();\
264 } while (0)
265
266#define VBOXDISPPROFILE_FUNCTION_LOGGER_DEFINE(_p) \
267 static VBoxDispProfileEntry * __pVBoxDispProfileEntry = NULL; \
268 if (!__pVBoxDispProfileEntry) { __pVBoxDispProfileEntry = _p.alloc(__FUNCTION__); } \
269 VBoxDispProfileScopeLogger<VBoxDispProfileEntry> __vboxDispProfileFunctionLogger(__pVBoxDispProfileEntry);
270
271#define VBOXDISPPROFILE_STATISTIC_LOGGER_DISABLE_CURRENT() do { \
272 __vboxDispProfileStatisticLogger.disable();\
273 } while (0)
274
275#define VBOXDISPPROFILE_STATISTIC_LOGGER_LOG_AND_DISABLE_CURRENT() do { \
276 __vboxDispProfileStatisticLogger.logAndDisable();\
277 } while (0)
278
279
280#define VBOXDISPPROFILE_STATISTIC_LOGGER_DEFINE(_p) \
281 VBoxDispProfileScopeLogger<VBoxDispProfileFpsCounter> __vboxDispProfileStatisticLogger(_p);
282
283//#define VBOXDISPPROFILE_FUNCTION_PROLOGUE(_p) \
284// VBOXDISPPROFILE_FUNCTION_LOGGER_DEFINE(_p)
285
286#endif /* #ifndef ___VBoxDispProfile_h__ */
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette