1 | /* $Id: VBoxDbgStats.h 12183 2008-09-07 02:35:53Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Debugger GUI - Statistics.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
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 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
18 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
19 | * additional information or have any questions.
|
---|
20 | */
|
---|
21 |
|
---|
22 |
|
---|
23 | #ifndef __VBoxDbgStats_h__
|
---|
24 | #define __VBoxDbgStats_h__
|
---|
25 |
|
---|
26 | #include "VBoxDbgBase.h"
|
---|
27 |
|
---|
28 | #ifdef VBOXDBG_USE_QT4
|
---|
29 | # include <QTreeWidget>
|
---|
30 | # include <QTimer>
|
---|
31 | # include <QComboBox>
|
---|
32 | # include <QMenu>
|
---|
33 | typedef QMenu QPopupMenu;
|
---|
34 | typedef QTreeWidget QListView;
|
---|
35 | typedef QTreeWidgetItem QListViewItem;
|
---|
36 | #else
|
---|
37 | # include <qlistview.h>
|
---|
38 | # include <qvbox.h>
|
---|
39 | # include <qtimer.h>
|
---|
40 | # include <qcombobox.h>
|
---|
41 | # include <qpopupmenu.h>
|
---|
42 | #endif
|
---|
43 |
|
---|
44 | class VBoxDbgStats;
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * A statistics item.
|
---|
48 | *
|
---|
49 | * This class represent can be both a leaf and a branch item.
|
---|
50 | */
|
---|
51 | class VBoxDbgStatsItem : public QListViewItem
|
---|
52 | {
|
---|
53 | public:
|
---|
54 | /**
|
---|
55 | * Constructor.
|
---|
56 | *
|
---|
57 | * @param pszName The name of this item.
|
---|
58 | * @param pParent The parent view item.
|
---|
59 | * @param fBranch Set if this is a branch.
|
---|
60 | */
|
---|
61 | VBoxDbgStatsItem(const char *pszName, VBoxDbgStatsItem *pParent, bool fBranch = true);
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * Constructor.
|
---|
65 | *
|
---|
66 | * @param pszName The name of this item.
|
---|
67 | * @param pParent The parent list view.
|
---|
68 | * @param fBranch Set if this is a branch.
|
---|
69 | */
|
---|
70 | VBoxDbgStatsItem(const char *pszName, QListView *pParent, bool fBranch = true);
|
---|
71 |
|
---|
72 | /** Destructor. */
|
---|
73 | virtual ~VBoxDbgStatsItem();
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * Gets the STAM name of the item.
|
---|
77 | * @returns STAM Name.
|
---|
78 | */
|
---|
79 | const char *getName() const
|
---|
80 | {
|
---|
81 | return m_pszName;
|
---|
82 | }
|
---|
83 |
|
---|
84 | /**
|
---|
85 | * Branch item?
|
---|
86 | * @returns true if branch, false if leaf.
|
---|
87 | */
|
---|
88 | bool isBranch() const
|
---|
89 | {
|
---|
90 | return m_fBranch;
|
---|
91 | }
|
---|
92 |
|
---|
93 | /**
|
---|
94 | * Leaf item?
|
---|
95 | * @returns true if leaf, false if branch.
|
---|
96 | */
|
---|
97 | bool isLeaf() const
|
---|
98 | {
|
---|
99 | return !m_fBranch;
|
---|
100 | }
|
---|
101 |
|
---|
102 | /**
|
---|
103 | * Gets the parent item.
|
---|
104 | * @returns Pointer to parent item, NULL if this is the root item.
|
---|
105 | */
|
---|
106 | VBoxDbgStatsItem *getParent()
|
---|
107 | {
|
---|
108 | return m_pParent;
|
---|
109 | }
|
---|
110 |
|
---|
111 | #ifdef VBOXDBG_USE_QT4
|
---|
112 | ///virtual bool operator<(const QTreeWidgetItem &other) const;
|
---|
113 | #else
|
---|
114 | /**
|
---|
115 | * Get sort key.
|
---|
116 | *
|
---|
117 | * @returns The sort key.
|
---|
118 | * @param iColumn The column to sort.
|
---|
119 | * @param fAscending The sorting direction.
|
---|
120 | */
|
---|
121 | virtual QString key(int iColumn, bool fAscending) const
|
---|
122 | {
|
---|
123 | return QListViewItem::key(iColumn, fAscending);
|
---|
124 | }
|
---|
125 | #endif
|
---|
126 |
|
---|
127 | /**
|
---|
128 | * Logs the tree starting at this item to one of the default logs.
|
---|
129 | * @param fReleaseLog If set use RTLogRelPrintf instead of RTLogPrintf.
|
---|
130 | */
|
---|
131 | virtual void logTree(bool fReleaseLog) const;
|
---|
132 |
|
---|
133 | /**
|
---|
134 | * Converts the tree starting at this item into a string and adds it to
|
---|
135 | * the specified string object.
|
---|
136 | * @param String The string to append the stringified tree to.
|
---|
137 | */
|
---|
138 | virtual void stringifyTree(QString &String) const;
|
---|
139 |
|
---|
140 | /**
|
---|
141 | * Copies the stringified tree onto the clipboard.
|
---|
142 | */
|
---|
143 | void copyTreeToClipboard(void) const;
|
---|
144 |
|
---|
145 | #ifdef VBOXDBG_USE_QT4
|
---|
146 | void setVisible(bool fVisible)
|
---|
147 | {
|
---|
148 | setHidden(!fVisible);
|
---|
149 | }
|
---|
150 |
|
---|
151 | bool isVisible()
|
---|
152 | {
|
---|
153 | return !isHidden();
|
---|
154 | }
|
---|
155 | #endif
|
---|
156 |
|
---|
157 | protected:
|
---|
158 | /** The name of this item. */
|
---|
159 | char *m_pszName;
|
---|
160 | /** Branch (true) / Leaf (false) indicator */
|
---|
161 | bool m_fBranch;
|
---|
162 | /** Parent item.
|
---|
163 | * This is NULL for the root item. */
|
---|
164 | VBoxDbgStatsItem *m_pParent;
|
---|
165 | };
|
---|
166 |
|
---|
167 |
|
---|
168 | /**
|
---|
169 | * A statistics item.
|
---|
170 | *
|
---|
171 | * This class represent one statistical item from STAM.
|
---|
172 | */
|
---|
173 | class VBoxDbgStatsLeafItem : public VBoxDbgStatsItem
|
---|
174 | {
|
---|
175 | public:
|
---|
176 | /**
|
---|
177 | * Constructor.
|
---|
178 | *
|
---|
179 | * @param pszName The name of this item.
|
---|
180 | * @param pParent The parent view item.
|
---|
181 | */
|
---|
182 | VBoxDbgStatsLeafItem(const char *pszName, VBoxDbgStatsItem *pParent);
|
---|
183 |
|
---|
184 | /** Destructor. */
|
---|
185 | virtual ~VBoxDbgStatsLeafItem();
|
---|
186 |
|
---|
187 | /**
|
---|
188 | * Updates the item when current data.
|
---|
189 | *
|
---|
190 | * @param enmType The current type of the object.
|
---|
191 | * @param pvSample Pointer to the sample (may change).
|
---|
192 | * @param enmUnit The current unit.
|
---|
193 | * @param enmVisibility The current visibility settings.
|
---|
194 | * @param pszDesc The current description.
|
---|
195 | */
|
---|
196 | void update(STAMTYPE enmType, void *pvSample, STAMUNIT enmUnit, STAMVISIBILITY enmVisibility, const char *pszDesc);
|
---|
197 |
|
---|
198 | /**
|
---|
199 | * Get sort key.
|
---|
200 | *
|
---|
201 | * @returns The sort key.
|
---|
202 | * @param iColumn The column to sort.
|
---|
203 | * @param fAscending The sorting direction.
|
---|
204 | */
|
---|
205 | virtual QString key(int iColumn, bool fAscending) const;
|
---|
206 |
|
---|
207 | /**
|
---|
208 | * Logs the tree starting at this item to one of the default logs.
|
---|
209 | * @param fReleaseLog If set use RTLogRelPrintf instead of RTLogPrintf.
|
---|
210 | */
|
---|
211 | virtual void logTree(bool fReleaseLog) const;
|
---|
212 |
|
---|
213 | /**
|
---|
214 | * Converts the tree starting at this item into a string and adds it to
|
---|
215 | * the specified string object.
|
---|
216 | * @param String The string to append the stringified tree to.
|
---|
217 | */
|
---|
218 | virtual void stringifyTree(QString &String) const;
|
---|
219 |
|
---|
220 | /** Pointer to the next item in the list.
|
---|
221 | * The list is maintained by the creator of the object, not the object it self. */
|
---|
222 | VBoxDbgStatsLeafItem *m_pNext;
|
---|
223 | /** Pointer to the previous item in the list. */
|
---|
224 | VBoxDbgStatsLeafItem *m_pPrev;
|
---|
225 |
|
---|
226 |
|
---|
227 | protected:
|
---|
228 |
|
---|
229 | /** The data type. */
|
---|
230 | STAMTYPE m_enmType;
|
---|
231 | /** The data at last update. */
|
---|
232 | union
|
---|
233 | {
|
---|
234 | /** STAMTYPE_COUNTER. */
|
---|
235 | STAMCOUNTER Counter;
|
---|
236 | /** STAMTYPE_PROFILE. */
|
---|
237 | STAMPROFILE Profile;
|
---|
238 | /** STAMTYPE_PROFILE_ADV. */
|
---|
239 | STAMPROFILEADV ProfileAdv;
|
---|
240 | /** STAMTYPE_RATIO_U32. */
|
---|
241 | STAMRATIOU32 RatioU32;
|
---|
242 | /** STAMTYPE_U8 & STAMTYPE_U8_RESET. */
|
---|
243 | uint8_t u8;
|
---|
244 | /** STAMTYPE_U16 & STAMTYPE_U16_RESET. */
|
---|
245 | uint16_t u16;
|
---|
246 | /** STAMTYPE_U32 & STAMTYPE_U32_RESET. */
|
---|
247 | uint32_t u32;
|
---|
248 | /** STAMTYPE_U64 & STAMTYPE_U64_RESET. */
|
---|
249 | uint64_t u64;
|
---|
250 | } m_Data;
|
---|
251 | /** The unit. */
|
---|
252 | STAMUNIT m_enmUnit;
|
---|
253 | /** The description string. */
|
---|
254 | QString m_DescStr;
|
---|
255 | };
|
---|
256 |
|
---|
257 |
|
---|
258 | /**
|
---|
259 | * The VM statistics tree view.
|
---|
260 | *
|
---|
261 | * A tree represenation of the STAM statistics.
|
---|
262 | */
|
---|
263 | class VBoxDbgStatsView : public QListView, public VBoxDbgBase
|
---|
264 | {
|
---|
265 | Q_OBJECT;
|
---|
266 |
|
---|
267 | public:
|
---|
268 | /**
|
---|
269 | * Creates a VM statistics list view widget.
|
---|
270 | *
|
---|
271 | * @param pVM The VM which STAM data is being viewed.
|
---|
272 | * @param pParent Parent widget.
|
---|
273 | */
|
---|
274 | VBoxDbgStatsView(PVM pVM, VBoxDbgStats *pParent = NULL);
|
---|
275 |
|
---|
276 | /** Destructor. */
|
---|
277 | virtual ~VBoxDbgStatsView();
|
---|
278 |
|
---|
279 | /**
|
---|
280 | * Updates the view with current information from STAM.
|
---|
281 | * This will indirectly update the m_PatStr.
|
---|
282 | *
|
---|
283 | * @param rPatStr Selection pattern. NULL means everything, see STAM for further details.
|
---|
284 | */
|
---|
285 | void update(const QString &rPatStr);
|
---|
286 |
|
---|
287 | /**
|
---|
288 | * Resets the stats items matching the specified pattern.
|
---|
289 | * This pattern doesn't have to be the one used for update, thus m_PatStr isn't updated.
|
---|
290 | *
|
---|
291 | * @param rPatStr Selection pattern. NULL means everything, see STAM for further details.
|
---|
292 | */
|
---|
293 | void reset(const QString &rPatStr);
|
---|
294 |
|
---|
295 | #ifndef VBOXDBG_USE_QT4
|
---|
296 | /**
|
---|
297 | * Expand all items in the view.
|
---|
298 | */
|
---|
299 | void expandAll();
|
---|
300 |
|
---|
301 | /**
|
---|
302 | * Collaps all items in the view.
|
---|
303 | */
|
---|
304 | void collapsAll();
|
---|
305 | #endif /* QT3 */
|
---|
306 |
|
---|
307 | private:
|
---|
308 | /**
|
---|
309 | * Callback function for the STAMR3Enum() made by update().
|
---|
310 | *
|
---|
311 | * @returns 0 (i.e. never halt enumeration).
|
---|
312 | *
|
---|
313 | * @param pszName The name of the sample.
|
---|
314 | * @param enmType The type.
|
---|
315 | * @param pvSample Pointer to the data. enmType indicates the format of this data.
|
---|
316 | * @param enmUnit The unit.
|
---|
317 | * @param enmVisibility The visibility.
|
---|
318 | * @param pszDesc The description.
|
---|
319 | * @param pvUser Pointer to the VBoxDbgStatsView object.
|
---|
320 | */
|
---|
321 | static DECLCALLBACK(int) updateCallback(const char *pszName, STAMTYPE enmType, void *pvSample, STAMUNIT enmUnit,
|
---|
322 | STAMVISIBILITY enmVisibility, const char *pszDesc, void *pvUser);
|
---|
323 |
|
---|
324 | protected:
|
---|
325 | /**
|
---|
326 | * Creates / finds the path to the specified stats item and makes is visible.
|
---|
327 | *
|
---|
328 | * @returns Parent node.
|
---|
329 | * @param pszName Path to a stats item.
|
---|
330 | */
|
---|
331 | VBoxDbgStatsItem *createPath(const char *pszName);
|
---|
332 |
|
---|
333 | protected slots:
|
---|
334 | /** Context menu. */
|
---|
335 | void contextMenuReq(QListViewItem *pItem, const QPoint &rPoint, int iColumn);
|
---|
336 | /** Leaf context. */
|
---|
337 | void leafMenuActivated(int iId);
|
---|
338 | /** Branch context. */
|
---|
339 | void branchMenuActivated(int iId);
|
---|
340 | /** View context. */
|
---|
341 | void viewMenuActivated(int iId);
|
---|
342 |
|
---|
343 | protected:
|
---|
344 | typedef enum { eRefresh = 1, eReset, eExpand, eCollaps, eCopy, eLog, eLogRel } MenuId;
|
---|
345 |
|
---|
346 | protected:
|
---|
347 | /** The current selection pattern. */
|
---|
348 | QString m_PatStr;
|
---|
349 | /** The parent widget. */
|
---|
350 | VBoxDbgStats *m_pParent;
|
---|
351 | /** Head of the items list.
|
---|
352 | * This list is in the order that STAMR3Enum() uses.
|
---|
353 | * Access seralization should not be required, and is therefore omitted. */
|
---|
354 | VBoxDbgStatsLeafItem *m_pHead;
|
---|
355 | /** Tail of the items list (see m_pHead). */
|
---|
356 | VBoxDbgStatsLeafItem *m_pTail;
|
---|
357 | /** The current position in the enumeration.
|
---|
358 | * If NULL we've reached the end of the list and are adding elements. */
|
---|
359 | VBoxDbgStatsLeafItem *m_pCur;
|
---|
360 | /** The root item. */
|
---|
361 | VBoxDbgStatsItem *m_pRoot;
|
---|
362 | /** Leaf item menu. */
|
---|
363 | QPopupMenu *m_pLeafMenu;
|
---|
364 | /** Branch item menu. */
|
---|
365 | QPopupMenu *m_pBranchMenu;
|
---|
366 | /** View menu. */
|
---|
367 | QPopupMenu *m_pViewMenu;
|
---|
368 | /** The pointer to the context menu item which is the focus of a context menu. */
|
---|
369 | VBoxDbgStatsItem *m_pContextMenuItem;
|
---|
370 | };
|
---|
371 |
|
---|
372 |
|
---|
373 |
|
---|
374 | /**
|
---|
375 | * The VM statistics window.
|
---|
376 | *
|
---|
377 | * This class displays the statistics of a VM. The UI contains
|
---|
378 | * a entry field for the selection pattern, a refresh interval
|
---|
379 | * spinbutton, and the tree view with the statistics.
|
---|
380 | */
|
---|
381 | class VBoxDbgStats :
|
---|
382 | #ifdef VBOXDBG_USE_QT4
|
---|
383 | public QWidget,
|
---|
384 | #else
|
---|
385 | public QVBox,
|
---|
386 | #endif
|
---|
387 | public VBoxDbgBase
|
---|
388 | {
|
---|
389 | Q_OBJECT;
|
---|
390 |
|
---|
391 | public:
|
---|
392 | /**
|
---|
393 | * Creates a VM statistics list view widget.
|
---|
394 | *
|
---|
395 | * @param pVM The VM this is hooked up to.
|
---|
396 | * @param pszPat Initial selection pattern. NULL means everything. (See STAM for details.)
|
---|
397 | * @param uRefreshRate The refresh rate. 0 means not to refresh and is the default.
|
---|
398 | * @param pParent Parent widget.
|
---|
399 | */
|
---|
400 | VBoxDbgStats(PVM pVM, const char *pszPat = NULL, unsigned uRefreshRate= 0, QWidget *pParent = NULL);
|
---|
401 |
|
---|
402 | /** Destructor. */
|
---|
403 | virtual ~VBoxDbgStats();
|
---|
404 |
|
---|
405 | protected slots:
|
---|
406 | /** Apply the activated combobox pattern. */
|
---|
407 | void apply(const QString &Str);
|
---|
408 | /** The "All" button was pressed. */
|
---|
409 | void applyAll();
|
---|
410 | /** Refresh the data on timer tick and pattern changed. */
|
---|
411 | void refresh();
|
---|
412 | /**
|
---|
413 | * Set the refresh rate.
|
---|
414 | *
|
---|
415 | * @param iRefresh The refresh interval in seconds.
|
---|
416 | */
|
---|
417 | void setRefresh(int iRefresh);
|
---|
418 |
|
---|
419 | protected:
|
---|
420 |
|
---|
421 | /** The current selection pattern. */
|
---|
422 | QString m_PatStr;
|
---|
423 | /** The pattern combo box. */
|
---|
424 | QComboBox *m_pPatCB;
|
---|
425 | /** The refresh rate in seconds.
|
---|
426 | * 0 means not to refresh. */
|
---|
427 | unsigned m_uRefreshRate;
|
---|
428 | /** The refresh timer .*/
|
---|
429 | QTimer *m_pTimer;
|
---|
430 | /** The tree view widget. */
|
---|
431 | VBoxDbgStatsView *m_pView;
|
---|
432 | };
|
---|
433 |
|
---|
434 |
|
---|
435 | #endif
|
---|