VirtualBox

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

Last change on this file since 2397 was 1, checked in by vboxsync, 55 years ago

import

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