VirtualBox

source: vbox/trunk/src/VBox/Debugger/VBoxDbgStats.h@ 12180

Last change on this file since 12180 was 12180, checked in by vboxsync, 17 years ago

Debugger GUI: Qt4 port in progress.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.5 KB
Line 
1/* $Id: VBoxDbgStats.h 12180 2008-09-06 18:31:18Z 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.215389.xyz. 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
44class VBoxDbgStats;
45
46/**
47 * A statistics item.
48 *
49 * This class represent can be both a leaf and a branch item.
50 */
51class VBoxDbgStatsItem : public QListViewItem
52{
53public:
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 /**
112 * Get sort key.
113 *
114 * @returns The sort key.
115 * @param iColumn The column to sort.
116 * @param fAscending The sorting direction.
117 */
118 virtual QString key(int iColumn, bool fAscending) const
119 {
120#ifdef VBOXDBG_USE_QT4
121 /** @todo */ NOREF(iColumn); NOREF(fAscending);
122 return "";
123#else
124 return QListViewItem::key(iColumn, fAscending);
125#endif
126 }
127
128 /**
129 * Logs the tree starting at this item to one of the default logs.
130 * @param fReleaseLog If set use RTLogRelPrintf instead of RTLogPrintf.
131 */
132 virtual void logTree(bool fReleaseLog) const;
133
134 /**
135 * Converts the tree starting at this item into a string and adds it to
136 * the specified string object.
137 * @param String The string to append the stringified tree to.
138 */
139 virtual void stringifyTree(QString &String) const;
140
141 /**
142 * Copies the stringified tree onto the clipboard.
143 */
144 void copyTreeToClipboard(void) const;
145
146
147protected:
148 /** The name of this item. */
149 char *m_pszName;
150 /** Branch (true) / Leaf (false) indicator */
151 bool m_fBranch;
152 /** Parent item.
153 * This is NULL for the root item. */
154 VBoxDbgStatsItem *m_pParent;
155};
156
157
158/**
159 * A statistics item.
160 *
161 * This class represent one statistical item from STAM.
162 */
163class VBoxDbgStatsLeafItem : public VBoxDbgStatsItem
164{
165public:
166 /**
167 * Constructor.
168 *
169 * @param pszName The name of this item.
170 * @param pParent The parent view item.
171 */
172 VBoxDbgStatsLeafItem(const char *pszName, VBoxDbgStatsItem *pParent);
173
174 /** Destructor. */
175 virtual ~VBoxDbgStatsLeafItem();
176
177 /**
178 * Updates the item when current data.
179 *
180 * @param enmType The current type of the object.
181 * @param pvSample Pointer to the sample (may change).
182 * @param enmUnit The current unit.
183 * @param enmVisibility The current visibility settings.
184 * @param pszDesc The current description.
185 */
186 void update(STAMTYPE enmType, void *pvSample, STAMUNIT enmUnit, STAMVISIBILITY enmVisibility, const char *pszDesc);
187
188 /**
189 * Get sort key.
190 *
191 * @returns The sort key.
192 * @param iColumn The column to sort.
193 * @param fAscending The sorting direction.
194 */
195 virtual QString key(int iColumn, bool fAscending) const;
196
197 /**
198 * Logs the tree starting at this item to one of the default logs.
199 * @param fReleaseLog If set use RTLogRelPrintf instead of RTLogPrintf.
200 */
201 virtual void logTree(bool fReleaseLog) const;
202
203 /**
204 * Converts the tree starting at this item into a string and adds it to
205 * the specified string object.
206 * @param String The string to append the stringified tree to.
207 */
208 virtual void stringifyTree(QString &String) const;
209
210 /** Pointer to the next item in the list.
211 * The list is maintained by the creator of the object, not the object it self. */
212 VBoxDbgStatsLeafItem *m_pNext;
213 /** Pointer to the previous item in the list. */
214 VBoxDbgStatsLeafItem *m_pPrev;
215
216
217protected:
218
219 /** The data type. */
220 STAMTYPE m_enmType;
221 /** The data at last update. */
222 union
223 {
224 /** STAMTYPE_COUNTER. */
225 STAMCOUNTER Counter;
226 /** STAMTYPE_PROFILE. */
227 STAMPROFILE Profile;
228 /** STAMTYPE_PROFILE_ADV. */
229 STAMPROFILEADV ProfileAdv;
230 /** STAMTYPE_RATIO_U32. */
231 STAMRATIOU32 RatioU32;
232 /** STAMTYPE_U8 & STAMTYPE_U8_RESET. */
233 uint8_t u8;
234 /** STAMTYPE_U16 & STAMTYPE_U16_RESET. */
235 uint16_t u16;
236 /** STAMTYPE_U32 & STAMTYPE_U32_RESET. */
237 uint32_t u32;
238 /** STAMTYPE_U64 & STAMTYPE_U64_RESET. */
239 uint64_t u64;
240 } m_Data;
241 /** The unit. */
242 STAMUNIT m_enmUnit;
243 /** The description string. */
244 QString m_DescStr;
245};
246
247
248/**
249 * The VM statistics tree view.
250 *
251 * A tree represenation of the STAM statistics.
252 */
253class VBoxDbgStatsView : public QListView, public VBoxDbgBase
254{
255 Q_OBJECT;
256
257public:
258#ifdef VBOXDBG_USE_QT4
259 /** @todo */
260#else
261 /**
262 * Creates a VM statistics list view widget.
263 *
264 * @param pVM The VM which STAM data is being viewed.
265 * @param pParent Parent widget.
266 * @param pszName Widget name.
267 * @param f Widget flags.
268 */
269 VBoxDbgStatsView(PVM pVM, VBoxDbgStats *pParent = NULL, const char *pszName = NULL, WFlags f = 0);
270#endif
271
272 /** Destructor. */
273 virtual ~VBoxDbgStatsView();
274
275 /**
276 * Updates the view with current information from STAM.
277 * This will indirectly update the m_PatStr.
278 *
279 * @param rPatStr Selection pattern. NULL means everything, see STAM for further details.
280 */
281 void update(const QString &rPatStr);
282
283 /**
284 * Resets the stats items matching the specified pattern.
285 * This pattern doesn't have to be the one used for update, thus m_PatStr isn't updated.
286 *
287 * @param rPatStr Selection pattern. NULL means everything, see STAM for further details.
288 */
289 void reset(const QString &rPatStr);
290
291 /**
292 * Expand all items in the view.
293 */
294 void expandAll();
295
296 /**
297 * Collaps all items in the view.
298 */
299 void collapsAll();
300
301private:
302 /**
303 * Callback function for the STAMR3Enum() made by update().
304 *
305 * @returns 0 (i.e. never halt enumeration).
306 *
307 * @param pszName The name of the sample.
308 * @param enmType The type.
309 * @param pvSample Pointer to the data. enmType indicates the format of this data.
310 * @param enmUnit The unit.
311 * @param enmVisibility The visibility.
312 * @param pszDesc The description.
313 * @param pvUser Pointer to the VBoxDbgStatsView object.
314 */
315 static DECLCALLBACK(int) updateCallback(const char *pszName, STAMTYPE enmType, void *pvSample, STAMUNIT enmUnit,
316 STAMVISIBILITY enmVisibility, const char *pszDesc, void *pvUser);
317
318protected:
319 /**
320 * Creates / finds the path to the specified stats item and makes is visible.
321 *
322 * @returns Parent node.
323 * @param pszName Path to a stats item.
324 */
325 VBoxDbgStatsItem *createPath(const char *pszName);
326
327protected slots:
328 /** Context menu. */
329 void contextMenuReq(QListViewItem *pItem, const QPoint &rPoint, int iColumn);
330 /** Leaf context. */
331 void leafMenuActivated(int iId);
332 /** Branch context. */
333 void branchMenuActivated(int iId);
334 /** View context. */
335 void viewMenuActivated(int iId);
336
337protected:
338 typedef enum { eRefresh = 1, eReset, eExpand, eCollaps, eCopy, eLog, eLogRel } MenuId;
339
340protected:
341 /** The current selection pattern. */
342 QString m_PatStr;
343 /** The parent widget. */
344 VBoxDbgStats *m_pParent;
345 /** Head of the items list.
346 * This list is in the order that STAMR3Enum() uses.
347 * Access seralization should not be required, and is therefore omitted. */
348 VBoxDbgStatsLeafItem *m_pHead;
349 /** Tail of the items list (see m_pHead). */
350 VBoxDbgStatsLeafItem *m_pTail;
351 /** The current position in the enumeration.
352 * If NULL we've reached the end of the list and are adding elements. */
353 VBoxDbgStatsLeafItem *m_pCur;
354 /** The root item. */
355 VBoxDbgStatsItem *m_pRoot;
356 /** Leaf item menu. */
357 QPopupMenu *m_pLeafMenu;
358 /** Branch item menu. */
359 QPopupMenu *m_pBranchMenu;
360 /** View menu. */
361 QPopupMenu *m_pViewMenu;
362 /** The pointer to the context menu item which is the focus of a context menu. */
363 VBoxDbgStatsItem *m_pContextMenuItem;
364};
365
366
367
368/**
369 * The VM statistics window.
370 *
371 * This class displays the statistics of a VM. The UI contains
372 * a entry field for the selection pattern, a refresh interval
373 * spinbutton, and the tree view with the statistics.
374 */
375class VBoxDbgStats :
376#ifdef VBOXDBG_USE_QT4
377 public QWidget,
378#else
379 public QVBox,
380#endif
381 public VBoxDbgBase
382{
383 Q_OBJECT;
384
385public:
386#ifdef VBOXDBG_USE_QT4
387 /**
388 * Creates a VM statistics list view widget.
389 *
390 * @param pVM The VM this is hooked up to.
391 * @param pszPat Initial selection pattern. NULL means everything. (See STAM for details.)
392 * @param uRefreshRate The refresh rate. 0 means not to refresh and is the default.
393 * @param pParent Parent widget.
394 */
395 VBoxDbgStats(PVM pVM, const char *pszPat = NULL, unsigned uRefreshRate= 0, QWidget *pParent = NULL);
396#else
397 /**
398 * Creates a VM statistics list view widget.
399 *
400 * @param pVM The VM this is hooked up to.
401 * @param pszPat Initial selection pattern. NULL means everything. (See STAM for details.)
402 * @param uRefreshRate The refresh rate. 0 means not to refresh and is the default.
403 * @param pParent Parent widget.
404 * @param pszName Widget name.
405 * @param f Widget flags.
406 */
407 VBoxDbgStats(PVM pVM, const char *pszPat = NULL, unsigned uRefreshRate= 0, QWidget *pParent = NULL, const char *pszName = NULL, WFlags f = 0);
408#endif
409
410 /** Destructor. */
411 virtual ~VBoxDbgStats();
412
413protected slots:
414 /** Apply the activated combobox pattern. */
415 void apply(const QString &Str);
416 /** The "All" button was pressed. */
417 void applyAll();
418 /** Refresh the data on timer tick and pattern changed. */
419 void refresh();
420 /**
421 * Set the refresh rate.
422 *
423 * @param iRefresh The refresh interval in seconds.
424 */
425 void setRefresh(int iRefresh);
426
427protected:
428
429 /** The current selection pattern. */
430 QString m_PatStr;
431 /** The pattern combo box. */
432 QComboBox *m_pPatCB;
433 /** The refresh rate in seconds.
434 * 0 means not to refresh. */
435 unsigned m_uRefreshRate;
436 /** The refresh timer .*/
437 QTimer *m_pTimer;
438 /** The tree view widget. */
439 VBoxDbgStatsView *m_pView;
440};
441
442
443#endif
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