1 | /* $Id: VBoxDbgStatsQt.cpp 103474 2024-02-20 10:10:15Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Debugger GUI - Statistics.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 |
|
---|
29 | /*********************************************************************************************************************************
|
---|
30 | * Header Files *
|
---|
31 | *********************************************************************************************************************************/
|
---|
32 | #define LOG_GROUP LOG_GROUP_DBGG
|
---|
33 | #include "VBoxDbgStatsQt.h"
|
---|
34 |
|
---|
35 | #include <QAction>
|
---|
36 | #include <QApplication>
|
---|
37 | #include <QCheckBox>
|
---|
38 | #include <QClipboard>
|
---|
39 | #include <QContextMenuEvent>
|
---|
40 | #include <QDialog>
|
---|
41 | #include <QDialogButtonBox>
|
---|
42 | #include <QGroupBox>
|
---|
43 | #include <QGridLayout>
|
---|
44 | #include <QHBoxLayout>
|
---|
45 | #include <QHeaderView>
|
---|
46 | #include <QKeySequence>
|
---|
47 | #include <QLabel>
|
---|
48 | #include <QLineEdit>
|
---|
49 | #include <QLocale>
|
---|
50 | #include <QMessageBox>
|
---|
51 | #include <QPushButton>
|
---|
52 | #include <QSortFilterProxyModel>
|
---|
53 | #include <QSpinBox>
|
---|
54 | #include <QVBoxLayout>
|
---|
55 |
|
---|
56 | #include <iprt/errcore.h>
|
---|
57 | #include <VBox/log.h>
|
---|
58 | #include <iprt/string.h>
|
---|
59 | #include <iprt/mem.h>
|
---|
60 | #include <iprt/assert.h>
|
---|
61 |
|
---|
62 | #include "VBoxDbgGui.h"
|
---|
63 |
|
---|
64 |
|
---|
65 | /*********************************************************************************************************************************
|
---|
66 | * Defined Constants And Macros *
|
---|
67 | *********************************************************************************************************************************/
|
---|
68 | /** The number of column. */
|
---|
69 | #define DBGGUI_STATS_COLUMNS 9
|
---|
70 |
|
---|
71 | /** Enables the sorting and filtering. */
|
---|
72 | #define VBOXDBG_WITH_SORTED_AND_FILTERED_STATS
|
---|
73 |
|
---|
74 |
|
---|
75 | /*********************************************************************************************************************************
|
---|
76 | * Structures and Typedefs *
|
---|
77 | *********************************************************************************************************************************/
|
---|
78 | /**
|
---|
79 | * The state of a statistics sample node.
|
---|
80 | *
|
---|
81 | * This is used for two pass refresh (1. get data, 2. update the view) and
|
---|
82 | * for saving the result of a diff.
|
---|
83 | */
|
---|
84 | typedef enum DBGGUISTATSNODESTATE
|
---|
85 | {
|
---|
86 | /** The typical invalid zeroth entry. */
|
---|
87 | kDbgGuiStatsNodeState_kInvalid = 0,
|
---|
88 | /** The node is the root node. */
|
---|
89 | kDbgGuiStatsNodeState_kRoot,
|
---|
90 | /** The node is visible. */
|
---|
91 | kDbgGuiStatsNodeState_kVisible,
|
---|
92 | /** The node should be refreshed. */
|
---|
93 | kDbgGuiStatsNodeState_kRefresh,
|
---|
94 | #if 0 /// @todo not implemented
|
---|
95 | /** diff: The node equals. */
|
---|
96 | kDbgGuiStatsNodeState_kDiffEqual,
|
---|
97 | /** diff: The node in set 1 is less than the one in set 2. */
|
---|
98 | kDbgGuiStatsNodeState_kDiffSmaller,
|
---|
99 | /** diff: The node in set 1 is greater than the one in set 2. */
|
---|
100 | kDbgGuiStatsNodeState_kDiffGreater,
|
---|
101 | /** diff: The node is only in set 1. */
|
---|
102 | kDbgGuiStatsNodeState_kDiffOnlyIn1,
|
---|
103 | /** diff: The node is only in set 2. */
|
---|
104 | kDbgGuiStatsNodeState_kDiffOnlyIn2,
|
---|
105 | #endif
|
---|
106 | /** The end of the valid state values. */
|
---|
107 | kDbgGuiStatsNodeState_kEnd
|
---|
108 | } DBGGUISTATENODESTATE;
|
---|
109 |
|
---|
110 |
|
---|
111 | /**
|
---|
112 | * Filtering data.
|
---|
113 | */
|
---|
114 | typedef struct VBoxGuiStatsFilterData
|
---|
115 | {
|
---|
116 | /** Number of instances. */
|
---|
117 | static uint32_t volatile s_cInstances;
|
---|
118 | uint64_t uMinValue;
|
---|
119 | uint64_t uMaxValue;
|
---|
120 | QRegularExpression *pRegexName;
|
---|
121 |
|
---|
122 | VBoxGuiStatsFilterData()
|
---|
123 | : uMinValue(0)
|
---|
124 | , uMaxValue(UINT64_MAX)
|
---|
125 | , pRegexName(NULL)
|
---|
126 | {
|
---|
127 | s_cInstances += 1;
|
---|
128 | }
|
---|
129 |
|
---|
130 | ~VBoxGuiStatsFilterData()
|
---|
131 | {
|
---|
132 | if (pRegexName)
|
---|
133 | {
|
---|
134 | delete pRegexName;
|
---|
135 | pRegexName = NULL;
|
---|
136 | }
|
---|
137 | s_cInstances -= 1;
|
---|
138 | }
|
---|
139 |
|
---|
140 | bool isAllDefaults(void) const
|
---|
141 | {
|
---|
142 | return (uMinValue == 0 || uMinValue == UINT64_MAX)
|
---|
143 | && (uMaxValue == 0 || uMaxValue == UINT64_MAX)
|
---|
144 | && pRegexName == NULL;
|
---|
145 | }
|
---|
146 |
|
---|
147 | void reset(void)
|
---|
148 | {
|
---|
149 | uMinValue = 0;
|
---|
150 | uMaxValue = UINT64_MAX;
|
---|
151 | if (pRegexName)
|
---|
152 | {
|
---|
153 | delete pRegexName;
|
---|
154 | pRegexName = NULL;
|
---|
155 | }
|
---|
156 | }
|
---|
157 |
|
---|
158 | struct VBoxGuiStatsFilterData *duplicate(void) const
|
---|
159 | {
|
---|
160 | VBoxGuiStatsFilterData *pDup = new VBoxGuiStatsFilterData();
|
---|
161 | pDup->uMinValue = uMinValue;
|
---|
162 | pDup->uMaxValue = uMaxValue;
|
---|
163 | if (pRegexName)
|
---|
164 | pDup->pRegexName = new QRegularExpression(*pRegexName);
|
---|
165 | return pDup;
|
---|
166 | }
|
---|
167 |
|
---|
168 | } VBoxGuiStatsFilterData;
|
---|
169 |
|
---|
170 |
|
---|
171 | /**
|
---|
172 | * A tree node representing a statistic sample.
|
---|
173 | *
|
---|
174 | * The nodes carry a reference to the parent and to its position among its
|
---|
175 | * siblings. Both of these need updating when the grand parent or parent adds a
|
---|
176 | * new child. This will hopefully not be too expensive but rather pay off when
|
---|
177 | * we need to create a parent index.
|
---|
178 | */
|
---|
179 | typedef struct DBGGUISTATSNODE
|
---|
180 | {
|
---|
181 | /** Pointer to the parent. */
|
---|
182 | PDBGGUISTATSNODE pParent;
|
---|
183 | /** Array of pointers to the child nodes. */
|
---|
184 | PDBGGUISTATSNODE *papChildren;
|
---|
185 | /** The number of children. */
|
---|
186 | uint32_t cChildren;
|
---|
187 | /** Our index among the parent's children. */
|
---|
188 | uint32_t iSelf;
|
---|
189 | /** Sub-tree filtering config (typically NULL). */
|
---|
190 | VBoxGuiStatsFilterData *pFilter;
|
---|
191 | /** The unit string. (not allocated) */
|
---|
192 | const char *pszUnit;
|
---|
193 | /** The delta. */
|
---|
194 | int64_t i64Delta;
|
---|
195 | /** The name. */
|
---|
196 | char *pszName;
|
---|
197 | /** The length of the name. */
|
---|
198 | size_t cchName;
|
---|
199 | /** The description string. */
|
---|
200 | QString *pDescStr;
|
---|
201 | /** The node state. */
|
---|
202 | DBGGUISTATENODESTATE enmState;
|
---|
203 | /** The data type.
|
---|
204 | * For filler nodes not containing data, this will be set to STAMTYPE_INVALID. */
|
---|
205 | STAMTYPE 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 | /** STAMTYPE_BOOL and STAMTYPE_BOOL_RESET. */
|
---|
226 | bool f;
|
---|
227 | /** STAMTYPE_CALLBACK. */
|
---|
228 | QString *pStr;
|
---|
229 | } Data;
|
---|
230 | } DBGGUISTATSNODE;
|
---|
231 |
|
---|
232 |
|
---|
233 | /**
|
---|
234 | * Recursion stack.
|
---|
235 | */
|
---|
236 | typedef struct DBGGUISTATSSTACK
|
---|
237 | {
|
---|
238 | /** The top stack entry. */
|
---|
239 | int32_t iTop;
|
---|
240 | /** The stack array. */
|
---|
241 | struct DBGGUISTATSSTACKENTRY
|
---|
242 | {
|
---|
243 | /** The node. */
|
---|
244 | PDBGGUISTATSNODE pNode;
|
---|
245 | /** The current child. */
|
---|
246 | int32_t iChild;
|
---|
247 | /** Name string offset (if used). */
|
---|
248 | uint16_t cchName;
|
---|
249 | } a[32];
|
---|
250 | } DBGGUISTATSSTACK;
|
---|
251 |
|
---|
252 |
|
---|
253 |
|
---|
254 |
|
---|
255 | /**
|
---|
256 | * The item model for the statistics tree view.
|
---|
257 | *
|
---|
258 | * This manages the DBGGUISTATSNODE trees.
|
---|
259 | */
|
---|
260 | class VBoxDbgStatsModel : public QAbstractItemModel
|
---|
261 | {
|
---|
262 | protected:
|
---|
263 | /** The root of the sample tree. */
|
---|
264 | PDBGGUISTATSNODE m_pRoot;
|
---|
265 |
|
---|
266 | private:
|
---|
267 | /** Next update child. This is UINT32_MAX when invalid. */
|
---|
268 | uint32_t m_iUpdateChild;
|
---|
269 | /** Pointer to the node m_szUpdateParent represent and m_iUpdateChild refers to. */
|
---|
270 | PDBGGUISTATSNODE m_pUpdateParent;
|
---|
271 | /** The length of the path. */
|
---|
272 | size_t m_cchUpdateParent;
|
---|
273 | /** The path to the current update parent, including a trailing slash. */
|
---|
274 | char m_szUpdateParent[1024];
|
---|
275 | /** Inserted or/and removed nodes during the update. */
|
---|
276 | bool m_fUpdateInsertRemove;
|
---|
277 |
|
---|
278 | /** Container indexed by node path and giving a filter config in return. */
|
---|
279 | QHash<QString, VBoxGuiStatsFilterData *> m_FilterHash;
|
---|
280 |
|
---|
281 | public:
|
---|
282 | /**
|
---|
283 | * Constructor.
|
---|
284 | *
|
---|
285 | * @param a_pszConfig Advanced filter configuration (min/max/regexp on
|
---|
286 | * sub-trees) and more.
|
---|
287 | * @param a_pParent The parent object. See QAbstractItemModel in the Qt
|
---|
288 | * docs for details.
|
---|
289 | */
|
---|
290 | VBoxDbgStatsModel(const char *a_pszConfig, QObject *a_pParent);
|
---|
291 |
|
---|
292 | /**
|
---|
293 | * Destructor.
|
---|
294 | *
|
---|
295 | * This will free all the data the model holds.
|
---|
296 | */
|
---|
297 | virtual ~VBoxDbgStatsModel();
|
---|
298 |
|
---|
299 | /**
|
---|
300 | * Updates the data matching the specified pattern, normally for the whole tree
|
---|
301 | * but optionally a sub-tree if @a a_pSubTree is given.
|
---|
302 | *
|
---|
303 | * This will should invoke updatePrep, updateCallback and updateDone.
|
---|
304 | *
|
---|
305 | * It is vitally important that updateCallback is fed the data in the right
|
---|
306 | * order. The code make very definite ASSUMPTIONS about the ordering being
|
---|
307 | * strictly sorted and taking the slash into account when doing so.
|
---|
308 | *
|
---|
309 | * @returns true if we reset the model and it's necessary to set the root index.
|
---|
310 | * @param a_rPatStr The selection pattern.
|
---|
311 | * @param a_pSubTree The node / sub-tree to update if this is partial update.
|
---|
312 | * This is NULL for a full tree update.
|
---|
313 | *
|
---|
314 | * @remarks The default implementation is an empty stub.
|
---|
315 | */
|
---|
316 | virtual bool updateStatsByPattern(const QString &a_rPatStr, PDBGGUISTATSNODE a_pSubTree = NULL);
|
---|
317 |
|
---|
318 | /**
|
---|
319 | * Similar to updateStatsByPattern, except that it only works on a sub-tree and
|
---|
320 | * will not remove anything that's outside that tree.
|
---|
321 | *
|
---|
322 | * The default implementation will call redirect to updateStatsByPattern().
|
---|
323 | *
|
---|
324 | * @param a_rIndex The sub-tree root. Invalid index means root.
|
---|
325 | */
|
---|
326 | virtual void updateStatsByIndex(QModelIndex const &a_rIndex);
|
---|
327 |
|
---|
328 | /**
|
---|
329 | * Reset the stats matching the specified pattern.
|
---|
330 | *
|
---|
331 | * @param a_rPatStr The selection pattern.
|
---|
332 | *
|
---|
333 | * @remarks The default implementation is an empty stub.
|
---|
334 | */
|
---|
335 | virtual void resetStatsByPattern(QString const &a_rPatStr);
|
---|
336 |
|
---|
337 | /**
|
---|
338 | * Reset the stats of a sub-tree.
|
---|
339 | *
|
---|
340 | * @param a_rIndex The sub-tree root. Invalid index means root.
|
---|
341 | * @param a_fSubTree Whether to reset the sub-tree as well. Default is true.
|
---|
342 | *
|
---|
343 | * @remarks The default implementation makes use of resetStatsByPattern
|
---|
344 | */
|
---|
345 | virtual void resetStatsByIndex(QModelIndex const &a_rIndex, bool a_fSubTree = true);
|
---|
346 |
|
---|
347 | /**
|
---|
348 | * Iterator callback function.
|
---|
349 | * @returns true to continue, false to stop.
|
---|
350 | */
|
---|
351 | typedef bool FNITERATOR(PDBGGUISTATSNODE pNode, QModelIndex const &a_rIndex, const char *pszFullName, void *pvUser);
|
---|
352 |
|
---|
353 | /**
|
---|
354 | * Callback iterator.
|
---|
355 | *
|
---|
356 | * @param a_rPatStr The selection pattern.
|
---|
357 | * @param a_pfnCallback Callback function.
|
---|
358 | * @param a_pvUser Callback argument.
|
---|
359 | * @param a_fMatchChildren How to handle children of matching nodes:
|
---|
360 | * - @c true: continue with the children,
|
---|
361 | * - @c false: skip children.
|
---|
362 | */
|
---|
363 | virtual void iterateStatsByPattern(QString const &a_rPatStr, FNITERATOR *a_pfnCallback, void *a_pvUser,
|
---|
364 | bool a_fMatchChildren = true);
|
---|
365 |
|
---|
366 | /**
|
---|
367 | * Gets the model index of the root node.
|
---|
368 | *
|
---|
369 | * @returns root index.
|
---|
370 | */
|
---|
371 | QModelIndex getRootIndex(void) const;
|
---|
372 |
|
---|
373 |
|
---|
374 | protected:
|
---|
375 | /**
|
---|
376 | * Set the root node.
|
---|
377 | *
|
---|
378 | * This will free all the current data before taking the ownership of the new
|
---|
379 | * root node and its children.
|
---|
380 | *
|
---|
381 | * @param a_pRoot The new root node.
|
---|
382 | */
|
---|
383 | void setRootNode(PDBGGUISTATSNODE a_pRoot);
|
---|
384 |
|
---|
385 | /** Creates the root node. */
|
---|
386 | PDBGGUISTATSNODE createRootNode(void);
|
---|
387 |
|
---|
388 | /** Creates and insert a node under the given parent. */
|
---|
389 | PDBGGUISTATSNODE createAndInsertNode(PDBGGUISTATSNODE pParent, const char *pchName, size_t cchName, uint32_t iPosition,
|
---|
390 | const char *pchFullName, size_t cchFullName);
|
---|
391 |
|
---|
392 | /** Creates and insert a node under the given parent with correct Qt
|
---|
393 | * signalling. */
|
---|
394 | PDBGGUISTATSNODE createAndInsert(PDBGGUISTATSNODE pParent, const char *pszName, size_t cchName, uint32_t iPosition,
|
---|
395 | const char *pchFullName, size_t cchFullName);
|
---|
396 |
|
---|
397 | /**
|
---|
398 | * Resets the node to a pristine state.
|
---|
399 | *
|
---|
400 | * @param pNode The node.
|
---|
401 | */
|
---|
402 | static void resetNode(PDBGGUISTATSNODE pNode);
|
---|
403 |
|
---|
404 | /**
|
---|
405 | * Initializes a pristine node.
|
---|
406 | */
|
---|
407 | static int initNode(PDBGGUISTATSNODE pNode, STAMTYPE enmType, void *pvSample, const char *pszUnit, const char *pszDesc);
|
---|
408 |
|
---|
409 | /**
|
---|
410 | * Updates (or reinitializes if you like) a node.
|
---|
411 | */
|
---|
412 | static void updateNode(PDBGGUISTATSNODE pNode, STAMTYPE enmType, void *pvSample, const char *pszUnit, const char *pszDesc);
|
---|
413 |
|
---|
414 | /**
|
---|
415 | * Called by updateStatsByPattern(), makes the necessary preparations.
|
---|
416 | *
|
---|
417 | * @returns Success indicator.
|
---|
418 | * @param a_pSubTree The node / sub-tree to update if this is partial update.
|
---|
419 | * This is NULL for a full tree update.
|
---|
420 | */
|
---|
421 | bool updatePrepare(PDBGGUISTATSNODE a_pSubTree = NULL);
|
---|
422 |
|
---|
423 | /**
|
---|
424 | * Called by updateStatsByPattern(), finalizes the update.
|
---|
425 | *
|
---|
426 | * @returns See updateStatsByPattern().
|
---|
427 | *
|
---|
428 | * @param a_fSuccess Whether the update was successful or not.
|
---|
429 | * @param a_pSubTree The node / sub-tree to update if this is partial update.
|
---|
430 | * This is NULL for a full tree update.
|
---|
431 | */
|
---|
432 | bool updateDone(bool a_fSuccess, PDBGGUISTATSNODE a_pSubTree = NULL);
|
---|
433 |
|
---|
434 | /**
|
---|
435 | * updateCallback() worker taking care of in-tree inserts and removals.
|
---|
436 | *
|
---|
437 | * @returns The current node.
|
---|
438 | * @param pszName The name of the tree element to update.
|
---|
439 | */
|
---|
440 | PDBGGUISTATSNODE updateCallbackHandleOutOfOrder(const char * const pszName);
|
---|
441 |
|
---|
442 | /**
|
---|
443 | * updateCallback() worker taking care of tail insertions.
|
---|
444 | *
|
---|
445 | * @returns The current node.
|
---|
446 | * @param pszName The name of the tree element to update.
|
---|
447 | */
|
---|
448 | PDBGGUISTATSNODE updateCallbackHandleTail(const char *pszName);
|
---|
449 |
|
---|
450 | /**
|
---|
451 | * updateCallback() worker that advances the update state to the next data node
|
---|
452 | * in anticipation of the next updateCallback call.
|
---|
453 | *
|
---|
454 | * @param pNode The current node.
|
---|
455 | */
|
---|
456 | void updateCallbackAdvance(PDBGGUISTATSNODE pNode);
|
---|
457 |
|
---|
458 | /** Callback used by updateStatsByPattern() and updateStatsByIndex() to feed
|
---|
459 | * changes.
|
---|
460 | * @copydoc FNSTAMR3ENUM */
|
---|
461 | static DECLCALLBACK(int) updateCallback(const char *pszName, STAMTYPE enmType, void *pvSample, STAMUNIT enmUnit,
|
---|
462 | const char *pszUnit, STAMVISIBILITY enmVisibility, const char *pszDesc, void *pvUser);
|
---|
463 |
|
---|
464 | public:
|
---|
465 | /**
|
---|
466 | * Calculates the full path of a node.
|
---|
467 | *
|
---|
468 | * @returns Number of bytes returned, negative value on buffer overflow
|
---|
469 | *
|
---|
470 | * @param pNode The node.
|
---|
471 | * @param psz The output buffer.
|
---|
472 | * @param cch The size of the buffer.
|
---|
473 | */
|
---|
474 | static ssize_t getNodePath(PCDBGGUISTATSNODE pNode, char *psz, ssize_t cch);
|
---|
475 |
|
---|
476 | protected:
|
---|
477 | /**
|
---|
478 | * Calculates the full path of a node, returning the string pointer.
|
---|
479 | *
|
---|
480 | * @returns @a psz. On failure, NULL.
|
---|
481 | *
|
---|
482 | * @param pNode The node.
|
---|
483 | * @param psz The output buffer.
|
---|
484 | * @param cch The size of the buffer.
|
---|
485 | */
|
---|
486 | static char *getNodePath2(PCDBGGUISTATSNODE pNode, char *psz, ssize_t cch);
|
---|
487 |
|
---|
488 | /**
|
---|
489 | * Returns the pattern for the node, optionally including the entire sub-tree
|
---|
490 | * under it.
|
---|
491 | *
|
---|
492 | * @returns Pattern.
|
---|
493 | * @param pNode The node.
|
---|
494 | * @param fSubTree Whether to include the sub-tree in the pattern.
|
---|
495 | */
|
---|
496 | static QString getNodePattern(PCDBGGUISTATSNODE pNode, bool fSubTree = true);
|
---|
497 |
|
---|
498 | /**
|
---|
499 | * Check if the first node is an ancestor to the second one.
|
---|
500 | *
|
---|
501 | * @returns true/false.
|
---|
502 | * @param pAncestor The first node, the alleged ancestor.
|
---|
503 | * @param pDescendant The second node, the alleged descendant.
|
---|
504 | */
|
---|
505 | static bool isNodeAncestorOf(PCDBGGUISTATSNODE pAncestor, PCDBGGUISTATSNODE pDescendant);
|
---|
506 |
|
---|
507 | /**
|
---|
508 | * Advance to the next node in the tree.
|
---|
509 | *
|
---|
510 | * @returns Pointer to the next node, NULL if we've reached the end or
|
---|
511 | * was handed a NULL node.
|
---|
512 | * @param pNode The current node.
|
---|
513 | */
|
---|
514 | static PDBGGUISTATSNODE nextNode(PDBGGUISTATSNODE pNode);
|
---|
515 |
|
---|
516 | /**
|
---|
517 | * Advance to the next node in the tree that contains data.
|
---|
518 | *
|
---|
519 | * @returns Pointer to the next data node, NULL if we've reached the end or
|
---|
520 | * was handed a NULL node.
|
---|
521 | * @param pNode The current node.
|
---|
522 | */
|
---|
523 | static PDBGGUISTATSNODE nextDataNode(PDBGGUISTATSNODE pNode);
|
---|
524 |
|
---|
525 | /**
|
---|
526 | * Advance to the previous node in the tree.
|
---|
527 | *
|
---|
528 | * @returns Pointer to the previous node, NULL if we've reached the end or
|
---|
529 | * was handed a NULL node.
|
---|
530 | * @param pNode The current node.
|
---|
531 | */
|
---|
532 | static PDBGGUISTATSNODE prevNode(PDBGGUISTATSNODE pNode);
|
---|
533 |
|
---|
534 | /**
|
---|
535 | * Advance to the previous node in the tree that contains data.
|
---|
536 | *
|
---|
537 | * @returns Pointer to the previous data node, NULL if we've reached the end or
|
---|
538 | * was handed a NULL node.
|
---|
539 | * @param pNode The current node.
|
---|
540 | */
|
---|
541 | static PDBGGUISTATSNODE prevDataNode(PDBGGUISTATSNODE pNode);
|
---|
542 |
|
---|
543 | /**
|
---|
544 | * Removes a node from the tree.
|
---|
545 | *
|
---|
546 | * @returns pNode.
|
---|
547 | * @param pNode The node.
|
---|
548 | */
|
---|
549 | static PDBGGUISTATSNODE removeNode(PDBGGUISTATSNODE pNode);
|
---|
550 |
|
---|
551 | /**
|
---|
552 | * Removes a node from the tree and destroys it and all its descendants.
|
---|
553 | *
|
---|
554 | * @param pNode The node.
|
---|
555 | */
|
---|
556 | static void removeAndDestroyNode(PDBGGUISTATSNODE pNode);
|
---|
557 |
|
---|
558 | /** Removes a node from the tree and destroys it and all its descendants
|
---|
559 | * performing the required Qt signalling. */
|
---|
560 | void removeAndDestroy(PDBGGUISTATSNODE pNode);
|
---|
561 |
|
---|
562 | /**
|
---|
563 | * Destroys a statistics tree.
|
---|
564 | *
|
---|
565 | * @param a_pRoot The root of the tree. NULL is fine.
|
---|
566 | */
|
---|
567 | static void destroyTree(PDBGGUISTATSNODE a_pRoot);
|
---|
568 |
|
---|
569 | public:
|
---|
570 | /**
|
---|
571 | * Stringifies exactly one node, no children.
|
---|
572 | *
|
---|
573 | * This is for logging and clipboard.
|
---|
574 | *
|
---|
575 | * @param a_pNode The node.
|
---|
576 | * @param a_rString The string to append the stringified node to.
|
---|
577 | * @param a_cchNameWidth The width of the basename.
|
---|
578 | */
|
---|
579 | static void stringifyNodeNoRecursion(PDBGGUISTATSNODE a_pNode, QString &a_rString, size_t a_cchNameWidth);
|
---|
580 |
|
---|
581 | protected:
|
---|
582 | /**
|
---|
583 | * Stringifies a node and its children.
|
---|
584 | *
|
---|
585 | * This is for logging and clipboard.
|
---|
586 | *
|
---|
587 | * @param a_pNode The node.
|
---|
588 | * @param a_rString The string to append the stringified node to.
|
---|
589 | * @param a_cchNameWidth The width of the basename.
|
---|
590 | */
|
---|
591 | static void stringifyNode(PDBGGUISTATSNODE a_pNode, QString &a_rString, size_t a_cchNameWidth);
|
---|
592 |
|
---|
593 | public:
|
---|
594 | /**
|
---|
595 | * Converts the specified tree to string.
|
---|
596 | *
|
---|
597 | * This is for logging and clipboard.
|
---|
598 | *
|
---|
599 | * @param a_rRoot Where to start. Use QModelIndex() to start at the root.
|
---|
600 | * @param a_rString Where to return to return the string dump.
|
---|
601 | */
|
---|
602 | void stringifyTree(QModelIndex &a_rRoot, QString &a_rString) const;
|
---|
603 |
|
---|
604 | /**
|
---|
605 | * Dumps the given (sub-)tree as XML.
|
---|
606 | *
|
---|
607 | * @param a_rRoot Where to start. Use QModelIndex() to start at the root.
|
---|
608 | * @param a_rString Where to return to return the XML dump.
|
---|
609 | */
|
---|
610 | void xmlifyTree(QModelIndex &a_rRoot, QString &a_rString) const;
|
---|
611 |
|
---|
612 | public:
|
---|
613 |
|
---|
614 | /** Gets the unit. */
|
---|
615 | static QString strUnit(PCDBGGUISTATSNODE pNode);
|
---|
616 | /** Gets the value/times. */
|
---|
617 | static QString strValueTimes(PCDBGGUISTATSNODE pNode);
|
---|
618 | /** Gets the value/times. */
|
---|
619 | static uint64_t getValueTimesAsUInt(PCDBGGUISTATSNODE pNode);
|
---|
620 | /** Gets the value/avg. */
|
---|
621 | static uint64_t getValueOrAvgAsUInt(PCDBGGUISTATSNODE pNode);
|
---|
622 | /** Gets the minimum value. */
|
---|
623 | static QString strMinValue(PCDBGGUISTATSNODE pNode);
|
---|
624 | /** Gets the minimum value. */
|
---|
625 | static uint64_t getMinValueAsUInt(PCDBGGUISTATSNODE pNode);
|
---|
626 | /** Gets the average value. */
|
---|
627 | static QString strAvgValue(PCDBGGUISTATSNODE pNode);
|
---|
628 | /** Gets the average value. */
|
---|
629 | static uint64_t getAvgValueAsUInt(PCDBGGUISTATSNODE pNode);
|
---|
630 | /** Gets the maximum value. */
|
---|
631 | static QString strMaxValue(PCDBGGUISTATSNODE pNode);
|
---|
632 | /** Gets the maximum value. */
|
---|
633 | static uint64_t getMaxValueAsUInt(PCDBGGUISTATSNODE pNode);
|
---|
634 | /** Gets the total value. */
|
---|
635 | static QString strTotalValue(PCDBGGUISTATSNODE pNode);
|
---|
636 | /** Gets the total value. */
|
---|
637 | static uint64_t getTotalValueAsUInt(PCDBGGUISTATSNODE pNode);
|
---|
638 | /** Gets the delta value. */
|
---|
639 | static QString strDeltaValue(PCDBGGUISTATSNODE pNode);
|
---|
640 |
|
---|
641 |
|
---|
642 | protected:
|
---|
643 | /**
|
---|
644 | * Destroys a node and all its children.
|
---|
645 | *
|
---|
646 | * @param a_pNode The node to destroy.
|
---|
647 | */
|
---|
648 | static void destroyNode(PDBGGUISTATSNODE a_pNode);
|
---|
649 |
|
---|
650 | public:
|
---|
651 | /**
|
---|
652 | * Converts an index to a node pointer.
|
---|
653 | *
|
---|
654 | * @returns Pointer to the node, NULL if invalid reference.
|
---|
655 | * @param a_rIndex Reference to the index
|
---|
656 | */
|
---|
657 | inline PDBGGUISTATSNODE nodeFromIndex(const QModelIndex &a_rIndex) const
|
---|
658 | {
|
---|
659 | if (RT_LIKELY(a_rIndex.isValid()))
|
---|
660 | return (PDBGGUISTATSNODE)a_rIndex.internalPointer();
|
---|
661 | return NULL;
|
---|
662 | }
|
---|
663 |
|
---|
664 | protected:
|
---|
665 | /**
|
---|
666 | * Populates m_FilterHash with configurations from @a a_pszConfig.
|
---|
667 | *
|
---|
668 | * @note This currently only work at construction time.
|
---|
669 | */
|
---|
670 | void loadFilterConfig(const char *a_pszConfig);
|
---|
671 |
|
---|
672 | public:
|
---|
673 |
|
---|
674 | /** @name Overridden QAbstractItemModel methods
|
---|
675 | * @{ */
|
---|
676 | virtual int columnCount(const QModelIndex &a_rParent) const RT_OVERRIDE;
|
---|
677 | virtual QVariant data(const QModelIndex &a_rIndex, int a_eRole) const RT_OVERRIDE;
|
---|
678 | virtual Qt::ItemFlags flags(const QModelIndex &a_rIndex) const RT_OVERRIDE;
|
---|
679 | virtual bool hasChildren(const QModelIndex &a_rParent) const RT_OVERRIDE;
|
---|
680 | virtual QVariant headerData(int a_iSection, Qt::Orientation a_ePrientation, int a_eRole) const RT_OVERRIDE;
|
---|
681 | virtual QModelIndex index(int a_iRow, int a_iColumn, const QModelIndex &a_rParent) const RT_OVERRIDE;
|
---|
682 | virtual QModelIndex parent(const QModelIndex &a_rChild) const RT_OVERRIDE;
|
---|
683 | virtual int rowCount(const QModelIndex &a_rParent) const RT_OVERRIDE;
|
---|
684 | ///virtual void sort(int a_iColumn, Qt::SortOrder a_eOrder) RT_OVERRIDE;
|
---|
685 | /** @} */
|
---|
686 | };
|
---|
687 |
|
---|
688 |
|
---|
689 | /**
|
---|
690 | * Model using the VM / STAM interface as data source.
|
---|
691 | */
|
---|
692 | class VBoxDbgStatsModelVM : public VBoxDbgStatsModel, public VBoxDbgBase
|
---|
693 | {
|
---|
694 | public:
|
---|
695 | /**
|
---|
696 | * Constructor.
|
---|
697 | *
|
---|
698 | * @param a_pDbgGui Pointer to the debugger gui object.
|
---|
699 | * @param a_rPatStr The selection pattern.
|
---|
700 | * @param a_pszConfig Advanced filter configuration (min/max/regexp on
|
---|
701 | * sub-trees) and more.
|
---|
702 | * @param a_pVMM The VMM function table.
|
---|
703 | * @param a_pParent The parent object. NULL is fine and default.
|
---|
704 | */
|
---|
705 | VBoxDbgStatsModelVM(VBoxDbgGui *a_pDbgGui, QString &a_rPatStr, const char *a_pszConfig,
|
---|
706 | PCVMMR3VTABLE a_pVMM, QObject *a_pParent = NULL);
|
---|
707 |
|
---|
708 | /** Destructor */
|
---|
709 | virtual ~VBoxDbgStatsModelVM();
|
---|
710 |
|
---|
711 | virtual bool updateStatsByPattern(const QString &a_rPatStr, PDBGGUISTATSNODE a_pSubTree = NULL);
|
---|
712 | virtual void resetStatsByPattern(const QString &a_rPatStr);
|
---|
713 |
|
---|
714 | protected:
|
---|
715 | typedef struct
|
---|
716 | {
|
---|
717 | PDBGGUISTATSNODE pRoot;
|
---|
718 | VBoxDbgStatsModelVM *pThis;
|
---|
719 | } CreateNewTreeCallbackArgs_T;
|
---|
720 |
|
---|
721 | /**
|
---|
722 | * Enumeration callback used by createNewTree.
|
---|
723 | */
|
---|
724 | static DECLCALLBACK(int) createNewTreeCallback(const char *pszName, STAMTYPE enmType, void *pvSample, STAMUNIT enmUnit,
|
---|
725 | const char *pszUnit, STAMVISIBILITY enmVisibility, const char *pszDesc,
|
---|
726 | void *pvUser);
|
---|
727 |
|
---|
728 | /**
|
---|
729 | * Constructs a new statistics tree by query data from the VM.
|
---|
730 | *
|
---|
731 | * @returns Pointer to the root of the tree we've constructed. This will be NULL
|
---|
732 | * if the STAM API throws an error or we run out of memory.
|
---|
733 | * @param a_rPatStr The selection pattern.
|
---|
734 | */
|
---|
735 | PDBGGUISTATSNODE createNewTree(QString &a_rPatStr);
|
---|
736 |
|
---|
737 | /** The VMM function table. */
|
---|
738 | PCVMMR3VTABLE m_pVMM;
|
---|
739 | };
|
---|
740 |
|
---|
741 | #ifdef VBOXDBG_WITH_SORTED_AND_FILTERED_STATS
|
---|
742 |
|
---|
743 | /**
|
---|
744 | * Model using the VM / STAM interface as data source.
|
---|
745 | */
|
---|
746 | class VBoxDbgStatsSortFileProxyModel : public QSortFilterProxyModel
|
---|
747 | {
|
---|
748 | public:
|
---|
749 | /**
|
---|
750 | * Constructor.
|
---|
751 | *
|
---|
752 | * @param a_pParent The parent object.
|
---|
753 | */
|
---|
754 | VBoxDbgStatsSortFileProxyModel(QObject *a_pParent);
|
---|
755 |
|
---|
756 | /** Destructor */
|
---|
757 | virtual ~VBoxDbgStatsSortFileProxyModel()
|
---|
758 | {}
|
---|
759 |
|
---|
760 | /** Gets the unused-rows visibility status. */
|
---|
761 | bool isShowingUnusedRows() const { return m_fShowUnusedRows; }
|
---|
762 |
|
---|
763 | /** Sets whether or not to show unused rows (all zeros). */
|
---|
764 | void setShowUnusedRows(bool a_fHide);
|
---|
765 |
|
---|
766 | /**
|
---|
767 | * Notification that a filter has been added, removed or modified.
|
---|
768 | */
|
---|
769 | void notifyFilterChanges();
|
---|
770 |
|
---|
771 | /**
|
---|
772 | * Converts the specified tree to string.
|
---|
773 | *
|
---|
774 | * This is for logging and clipboard.
|
---|
775 | *
|
---|
776 | * @param a_rRoot Where to start. Use QModelIndex() to start at the root.
|
---|
777 | * @param a_rString Where to return to return the string dump.
|
---|
778 | * @param a_cchNameWidth The width of the basename.
|
---|
779 | */
|
---|
780 | void stringifyTree(QModelIndex const &a_rRoot, QString &a_rString, size_t a_cchNameWidth = 0) const;
|
---|
781 |
|
---|
782 | protected:
|
---|
783 | /**
|
---|
784 | * Converts a source index to a node pointer.
|
---|
785 | *
|
---|
786 | * @returns Pointer to the node, NULL if invalid reference.
|
---|
787 | * @param a_rSrcIndex Reference to the source index.
|
---|
788 | */
|
---|
789 | inline PDBGGUISTATSNODE nodeFromSrcIndex(const QModelIndex &a_rSrcIndex) const
|
---|
790 | {
|
---|
791 | if (RT_LIKELY(a_rSrcIndex.isValid()))
|
---|
792 | return (PDBGGUISTATSNODE)a_rSrcIndex.internalPointer();
|
---|
793 | return NULL;
|
---|
794 | }
|
---|
795 |
|
---|
796 | /**
|
---|
797 | * Converts a proxy index to a node pointer.
|
---|
798 | *
|
---|
799 | * @returns Pointer to the node, NULL if invalid reference.
|
---|
800 | * @param a_rProxyIndex The reference to the proxy index.
|
---|
801 | */
|
---|
802 | inline PDBGGUISTATSNODE nodeFromProxyIndex(const QModelIndex &a_rProxyIndex) const
|
---|
803 | {
|
---|
804 | QModelIndex const SrcIndex = mapToSource(a_rProxyIndex);
|
---|
805 | return nodeFromSrcIndex(SrcIndex);
|
---|
806 | }
|
---|
807 |
|
---|
808 | /** Does the row filtering. */
|
---|
809 | bool filterAcceptsRow(int a_iSrcRow, const QModelIndex &a_rSrcParent) const RT_OVERRIDE;
|
---|
810 | /** For implementing the sorting. */
|
---|
811 | bool lessThan(const QModelIndex &a_rSrcLeft, const QModelIndex &a_rSrcRight) const RT_OVERRIDE;
|
---|
812 |
|
---|
813 | /** Whether to show unused rows (all zeros) or not. */
|
---|
814 | bool m_fShowUnusedRows;
|
---|
815 | };
|
---|
816 |
|
---|
817 |
|
---|
818 | /**
|
---|
819 | * Dialog for sub-tree filtering config.
|
---|
820 | */
|
---|
821 | class VBoxDbgStatsFilterDialog : public QDialog
|
---|
822 | {
|
---|
823 | public:
|
---|
824 | /**
|
---|
825 | * Constructor.
|
---|
826 | *
|
---|
827 | * @param a_pNode The node to configure filtering for.
|
---|
828 | * @param a_pParent The parent object.
|
---|
829 | */
|
---|
830 | VBoxDbgStatsFilterDialog(QWidget *a_pParent, PCDBGGUISTATSNODE a_pNode);
|
---|
831 |
|
---|
832 | /** Destructor. */
|
---|
833 | virtual ~VBoxDbgStatsFilterDialog();
|
---|
834 |
|
---|
835 | /**
|
---|
836 | * Returns a copy of the filter data or NULL if all defaults.
|
---|
837 | */
|
---|
838 | VBoxGuiStatsFilterData *dupFilterData(void) const;
|
---|
839 |
|
---|
840 | protected slots:
|
---|
841 |
|
---|
842 | /** Validates and (maybe) accepts the dialog data. */
|
---|
843 | void validateAndAccept(void);
|
---|
844 |
|
---|
845 | protected:
|
---|
846 | /**
|
---|
847 | * Validates and converts the content of an uint64_t entry field.s
|
---|
848 | *
|
---|
849 | * @returns The converted value (or default)
|
---|
850 | * @param a_pField The entry field widget.
|
---|
851 | * @param a_uDefault The default return value.
|
---|
852 | * @param a_pszField The field name (for error messages).
|
---|
853 | * @param a_pLstErrors The error list to append validation errors to.
|
---|
854 | */
|
---|
855 | static uint64_t validateUInt64Field(QLineEdit const *a_pField, uint64_t a_uDefault,
|
---|
856 | const char *a_pszField, QStringList *a_pLstErrors);
|
---|
857 |
|
---|
858 |
|
---|
859 | private:
|
---|
860 | /** The filter data. */
|
---|
861 | VBoxGuiStatsFilterData m_Data;
|
---|
862 |
|
---|
863 | /** The minium value/average entry field. */
|
---|
864 | QLineEdit *m_pValueAvgMin;
|
---|
865 | /** The maxium value/average entry field. */
|
---|
866 | QLineEdit *m_pValueAvgMax;
|
---|
867 | /** The name filtering regexp entry field. */
|
---|
868 | QLineEdit *m_pNameRegExp;
|
---|
869 |
|
---|
870 | /** Regular expression for validating the uint64_t entry fields. */
|
---|
871 | static QRegularExpression const s_UInt64ValidatorRegExp;
|
---|
872 |
|
---|
873 | /**
|
---|
874 | * Creates an entry field for a uint64_t value.
|
---|
875 | */
|
---|
876 | static QLineEdit *createUInt64LineEdit(uint64_t uValue);
|
---|
877 | };
|
---|
878 |
|
---|
879 | #endif /* VBOXDBG_WITH_SORTED_AND_FILTERED_STATS */
|
---|
880 |
|
---|
881 |
|
---|
882 | /*********************************************************************************************************************************
|
---|
883 | * Global Variables *
|
---|
884 | *********************************************************************************************************************************/
|
---|
885 | /*static*/ uint32_t volatile VBoxGuiStatsFilterData::s_cInstances = 0;
|
---|
886 |
|
---|
887 |
|
---|
888 | /*********************************************************************************************************************************
|
---|
889 | * Internal Functions *
|
---|
890 | *********************************************************************************************************************************/
|
---|
891 |
|
---|
892 |
|
---|
893 | /**
|
---|
894 | * Formats a number into a 64-byte buffer.
|
---|
895 | */
|
---|
896 | static char *formatNumber(char *psz, uint64_t u64)
|
---|
897 | {
|
---|
898 | if (!u64)
|
---|
899 | {
|
---|
900 | psz[0] = '0';
|
---|
901 | psz[1] = '\0';
|
---|
902 | }
|
---|
903 | else
|
---|
904 | {
|
---|
905 | static const char s_szDigits[] = "0123456789";
|
---|
906 | psz += 63;
|
---|
907 | *psz-- = '\0';
|
---|
908 | unsigned cDigits = 0;
|
---|
909 | for (;;)
|
---|
910 | {
|
---|
911 | const unsigned iDigit = u64 % 10;
|
---|
912 | u64 /= 10;
|
---|
913 | *psz = s_szDigits[iDigit];
|
---|
914 | if (!u64)
|
---|
915 | break;
|
---|
916 | psz--;
|
---|
917 | if (!(++cDigits % 3))
|
---|
918 | *psz-- = ',';
|
---|
919 | }
|
---|
920 | }
|
---|
921 | return psz;
|
---|
922 | }
|
---|
923 |
|
---|
924 |
|
---|
925 | /**
|
---|
926 | * Formats a number into a 64-byte buffer.
|
---|
927 | * (18 446 744 073 709 551 615)
|
---|
928 | */
|
---|
929 | static char *formatNumberSigned(char *psz, int64_t i64, bool fPositivePlus)
|
---|
930 | {
|
---|
931 | static const char s_szDigits[] = "0123456789";
|
---|
932 | psz += 63;
|
---|
933 | *psz-- = '\0';
|
---|
934 | const bool fNegative = i64 < 0;
|
---|
935 | uint64_t u64 = fNegative ? -i64 : i64;
|
---|
936 | unsigned cDigits = 0;
|
---|
937 | for (;;)
|
---|
938 | {
|
---|
939 | const unsigned iDigit = u64 % 10;
|
---|
940 | u64 /= 10;
|
---|
941 | *psz = s_szDigits[iDigit];
|
---|
942 | if (!u64)
|
---|
943 | break;
|
---|
944 | psz--;
|
---|
945 | if (!(++cDigits % 3))
|
---|
946 | *psz-- = ',';
|
---|
947 | }
|
---|
948 | if (fNegative)
|
---|
949 | *--psz = '-';
|
---|
950 | else if (fPositivePlus)
|
---|
951 | *--psz = '+';
|
---|
952 | return psz;
|
---|
953 | }
|
---|
954 |
|
---|
955 |
|
---|
956 | /**
|
---|
957 | * Formats a unsigned hexadecimal number into a into a 64-byte buffer.
|
---|
958 | */
|
---|
959 | static char *formatHexNumber(char *psz, uint64_t u64, unsigned cZeros)
|
---|
960 | {
|
---|
961 | static const char s_szDigits[] = "0123456789abcdef";
|
---|
962 | psz += 63;
|
---|
963 | *psz-- = '\0';
|
---|
964 | unsigned cDigits = 0;
|
---|
965 | for (;;)
|
---|
966 | {
|
---|
967 | const unsigned iDigit = u64 % 16;
|
---|
968 | u64 /= 16;
|
---|
969 | *psz = s_szDigits[iDigit];
|
---|
970 | ++cDigits;
|
---|
971 | if (!u64 && cDigits >= cZeros)
|
---|
972 | break;
|
---|
973 | psz--;
|
---|
974 | if (!(cDigits % 8))
|
---|
975 | *psz-- = '\'';
|
---|
976 | }
|
---|
977 | return psz;
|
---|
978 | }
|
---|
979 |
|
---|
980 |
|
---|
981 | #if 0/* unused */
|
---|
982 | /**
|
---|
983 | * Formats a sort key number.
|
---|
984 | */
|
---|
985 | static void formatSortKey(char *psz, uint64_t u64)
|
---|
986 | {
|
---|
987 | static const char s_szDigits[] = "0123456789abcdef";
|
---|
988 | /* signed */
|
---|
989 | *psz++ = '+';
|
---|
990 |
|
---|
991 | /* 16 hex digits */
|
---|
992 | psz[16] = '\0';
|
---|
993 | unsigned i = 16;
|
---|
994 | while (i-- > 0)
|
---|
995 | {
|
---|
996 | if (u64)
|
---|
997 | {
|
---|
998 | const unsigned iDigit = u64 % 16;
|
---|
999 | u64 /= 16;
|
---|
1000 | psz[i] = s_szDigits[iDigit];
|
---|
1001 | }
|
---|
1002 | else
|
---|
1003 | psz[i] = '0';
|
---|
1004 | }
|
---|
1005 | }
|
---|
1006 | #endif
|
---|
1007 |
|
---|
1008 |
|
---|
1009 | #if 0/* unused */
|
---|
1010 | /**
|
---|
1011 | * Formats a sort key number.
|
---|
1012 | */
|
---|
1013 | static void formatSortKeySigned(char *psz, int64_t i64)
|
---|
1014 | {
|
---|
1015 | static const char s_szDigits[] = "0123456789abcdef";
|
---|
1016 |
|
---|
1017 | /* signed */
|
---|
1018 | uint64_t u64;
|
---|
1019 | if (i64 >= 0)
|
---|
1020 | {
|
---|
1021 | *psz++ = '+';
|
---|
1022 | u64 = i64;
|
---|
1023 | }
|
---|
1024 | else
|
---|
1025 | {
|
---|
1026 | *psz++ = '-';
|
---|
1027 | u64 = -i64;
|
---|
1028 | }
|
---|
1029 |
|
---|
1030 | /* 16 hex digits */
|
---|
1031 | psz[16] = '\0';
|
---|
1032 | unsigned i = 16;
|
---|
1033 | while (i-- > 0)
|
---|
1034 | {
|
---|
1035 | if (u64)
|
---|
1036 | {
|
---|
1037 | const unsigned iDigit = u64 % 16;
|
---|
1038 | u64 /= 16;
|
---|
1039 | psz[i] = s_szDigits[iDigit];
|
---|
1040 | }
|
---|
1041 | else
|
---|
1042 | psz[i] = '0';
|
---|
1043 | }
|
---|
1044 | }
|
---|
1045 | #endif
|
---|
1046 |
|
---|
1047 |
|
---|
1048 |
|
---|
1049 | /*
|
---|
1050 | *
|
---|
1051 | * V B o x D b g S t a t s M o d e l
|
---|
1052 | * V B o x D b g S t a t s M o d e l
|
---|
1053 | * V B o x D b g S t a t s M o d e l
|
---|
1054 | *
|
---|
1055 | *
|
---|
1056 | */
|
---|
1057 |
|
---|
1058 |
|
---|
1059 | VBoxDbgStatsModel::VBoxDbgStatsModel(const char *a_pszConfig, QObject *a_pParent)
|
---|
1060 | : QAbstractItemModel(a_pParent)
|
---|
1061 | , m_pRoot(NULL)
|
---|
1062 | , m_iUpdateChild(UINT32_MAX)
|
---|
1063 | , m_pUpdateParent(NULL)
|
---|
1064 | , m_cchUpdateParent(0)
|
---|
1065 | {
|
---|
1066 | /*
|
---|
1067 | * Parse the advance filtering string as best as we can and
|
---|
1068 | * populate the map of pending node filter configs with it.
|
---|
1069 | */
|
---|
1070 | loadFilterConfig(a_pszConfig);
|
---|
1071 | }
|
---|
1072 |
|
---|
1073 |
|
---|
1074 |
|
---|
1075 | VBoxDbgStatsModel::~VBoxDbgStatsModel()
|
---|
1076 | {
|
---|
1077 | destroyTree(m_pRoot);
|
---|
1078 | m_pRoot = NULL;
|
---|
1079 | }
|
---|
1080 |
|
---|
1081 |
|
---|
1082 | /*static*/ void
|
---|
1083 | VBoxDbgStatsModel::destroyTree(PDBGGUISTATSNODE a_pRoot)
|
---|
1084 | {
|
---|
1085 | if (!a_pRoot)
|
---|
1086 | return;
|
---|
1087 | Assert(!a_pRoot->pParent);
|
---|
1088 | Assert(!a_pRoot->iSelf);
|
---|
1089 |
|
---|
1090 | destroyNode(a_pRoot);
|
---|
1091 | }
|
---|
1092 |
|
---|
1093 |
|
---|
1094 | /* static*/ void
|
---|
1095 | VBoxDbgStatsModel::destroyNode(PDBGGUISTATSNODE a_pNode)
|
---|
1096 | {
|
---|
1097 | /* destroy all our children */
|
---|
1098 | uint32_t i = a_pNode->cChildren;
|
---|
1099 | while (i-- > 0)
|
---|
1100 | {
|
---|
1101 | destroyNode(a_pNode->papChildren[i]);
|
---|
1102 | a_pNode->papChildren[i] = NULL;
|
---|
1103 | }
|
---|
1104 |
|
---|
1105 | /* free the resources we're using */
|
---|
1106 | a_pNode->pParent = NULL;
|
---|
1107 |
|
---|
1108 | RTMemFree(a_pNode->papChildren);
|
---|
1109 | a_pNode->papChildren = NULL;
|
---|
1110 |
|
---|
1111 | if (a_pNode->enmType == STAMTYPE_CALLBACK)
|
---|
1112 | {
|
---|
1113 | delete a_pNode->Data.pStr;
|
---|
1114 | a_pNode->Data.pStr = NULL;
|
---|
1115 | }
|
---|
1116 |
|
---|
1117 | a_pNode->cChildren = 0;
|
---|
1118 | a_pNode->iSelf = UINT32_MAX;
|
---|
1119 | a_pNode->pszUnit = "";
|
---|
1120 | a_pNode->enmType = STAMTYPE_INVALID;
|
---|
1121 |
|
---|
1122 | RTMemFree(a_pNode->pszName);
|
---|
1123 | a_pNode->pszName = NULL;
|
---|
1124 |
|
---|
1125 | if (a_pNode->pDescStr)
|
---|
1126 | {
|
---|
1127 | delete a_pNode->pDescStr;
|
---|
1128 | a_pNode->pDescStr = NULL;
|
---|
1129 | }
|
---|
1130 |
|
---|
1131 | VBoxGuiStatsFilterData const *pFilter = a_pNode->pFilter;
|
---|
1132 | if (!pFilter)
|
---|
1133 | { /* likely */ }
|
---|
1134 | else
|
---|
1135 | {
|
---|
1136 | delete pFilter;
|
---|
1137 | a_pNode->pFilter = NULL;
|
---|
1138 | }
|
---|
1139 |
|
---|
1140 | #ifdef VBOX_STRICT
|
---|
1141 | /* poison it. */
|
---|
1142 | a_pNode->pParent++;
|
---|
1143 | a_pNode->Data.pStr++;
|
---|
1144 | a_pNode->pDescStr++;
|
---|
1145 | a_pNode->papChildren++;
|
---|
1146 | a_pNode->cChildren = 8442;
|
---|
1147 | a_pNode->pFilter++;
|
---|
1148 | #endif
|
---|
1149 |
|
---|
1150 | /* Finally ourselves */
|
---|
1151 | a_pNode->enmState = kDbgGuiStatsNodeState_kInvalid;
|
---|
1152 | RTMemFree(a_pNode);
|
---|
1153 | }
|
---|
1154 |
|
---|
1155 |
|
---|
1156 | PDBGGUISTATSNODE
|
---|
1157 | VBoxDbgStatsModel::createRootNode(void)
|
---|
1158 | {
|
---|
1159 | PDBGGUISTATSNODE pRoot = (PDBGGUISTATSNODE)RTMemAllocZ(sizeof(DBGGUISTATSNODE));
|
---|
1160 | if (!pRoot)
|
---|
1161 | return NULL;
|
---|
1162 | pRoot->iSelf = 0;
|
---|
1163 | pRoot->enmType = STAMTYPE_INVALID;
|
---|
1164 | pRoot->pszUnit = "";
|
---|
1165 | pRoot->pszName = (char *)RTMemDup("/", sizeof("/"));
|
---|
1166 | pRoot->cchName = 1;
|
---|
1167 | pRoot->enmState = kDbgGuiStatsNodeState_kRoot;
|
---|
1168 | pRoot->pFilter = m_FilterHash.take("/");
|
---|
1169 |
|
---|
1170 | return pRoot;
|
---|
1171 | }
|
---|
1172 |
|
---|
1173 |
|
---|
1174 | PDBGGUISTATSNODE
|
---|
1175 | VBoxDbgStatsModel::createAndInsertNode(PDBGGUISTATSNODE pParent, const char *pchName, size_t cchName, uint32_t iPosition,
|
---|
1176 | const char *pchFullName, size_t cchFullName)
|
---|
1177 | {
|
---|
1178 | /*
|
---|
1179 | * Create it.
|
---|
1180 | */
|
---|
1181 | PDBGGUISTATSNODE pNode = (PDBGGUISTATSNODE)RTMemAllocZ(sizeof(DBGGUISTATSNODE));
|
---|
1182 | if (!pNode)
|
---|
1183 | return NULL;
|
---|
1184 | pNode->iSelf = UINT32_MAX;
|
---|
1185 | pNode->enmType = STAMTYPE_INVALID;
|
---|
1186 | pNode->pszUnit = "";
|
---|
1187 | pNode->pszName = (char *)RTMemDupEx(pchName, cchName, 1);
|
---|
1188 | pNode->cchName = cchName;
|
---|
1189 | pNode->enmState = kDbgGuiStatsNodeState_kVisible;
|
---|
1190 | if (m_FilterHash.size() > 0 && cchFullName > 0)
|
---|
1191 | {
|
---|
1192 | char *pszTmp = RTStrDupN(pchFullName, cchFullName);
|
---|
1193 | pNode->pFilter = m_FilterHash.take(QString(pszTmp));
|
---|
1194 | RTStrFree(pszTmp);
|
---|
1195 | }
|
---|
1196 |
|
---|
1197 | /*
|
---|
1198 | * Do we need to expand the array?
|
---|
1199 | */
|
---|
1200 | if (!(pParent->cChildren & 31))
|
---|
1201 | {
|
---|
1202 | void *pvNew = RTMemRealloc(pParent->papChildren, sizeof(*pParent->papChildren) * (pParent->cChildren + 32));
|
---|
1203 | if (!pvNew)
|
---|
1204 | {
|
---|
1205 | destroyNode(pNode);
|
---|
1206 | return NULL;
|
---|
1207 | }
|
---|
1208 | pParent->papChildren = (PDBGGUISTATSNODE *)pvNew;
|
---|
1209 | }
|
---|
1210 |
|
---|
1211 | /*
|
---|
1212 | * Insert it.
|
---|
1213 | */
|
---|
1214 | pNode->pParent = pParent;
|
---|
1215 | if (iPosition >= pParent->cChildren)
|
---|
1216 | /* Last. */
|
---|
1217 | iPosition = pParent->cChildren;
|
---|
1218 | else
|
---|
1219 | {
|
---|
1220 | /* Shift all the items after ours. */
|
---|
1221 | uint32_t iShift = pParent->cChildren;
|
---|
1222 | while (iShift-- > iPosition)
|
---|
1223 | {
|
---|
1224 | PDBGGUISTATSNODE pChild = pParent->papChildren[iShift];
|
---|
1225 | pParent->papChildren[iShift + 1] = pChild;
|
---|
1226 | pChild->iSelf = iShift + 1;
|
---|
1227 | }
|
---|
1228 | }
|
---|
1229 |
|
---|
1230 | /* Insert ours */
|
---|
1231 | pNode->iSelf = iPosition;
|
---|
1232 | pParent->papChildren[iPosition] = pNode;
|
---|
1233 | pParent->cChildren++;
|
---|
1234 |
|
---|
1235 | return pNode;
|
---|
1236 | }
|
---|
1237 |
|
---|
1238 |
|
---|
1239 | PDBGGUISTATSNODE
|
---|
1240 | VBoxDbgStatsModel::createAndInsert(PDBGGUISTATSNODE pParent, const char *pszName, size_t cchName, uint32_t iPosition,
|
---|
1241 | const char *pchFullName, size_t cchFullName)
|
---|
1242 | {
|
---|
1243 | PDBGGUISTATSNODE pNode;
|
---|
1244 | if (m_fUpdateInsertRemove)
|
---|
1245 | pNode = createAndInsertNode(pParent, pszName, cchName, iPosition, pchFullName, cchFullName);
|
---|
1246 | else
|
---|
1247 | {
|
---|
1248 | beginInsertRows(createIndex(pParent->iSelf, 0, pParent), iPosition, iPosition);
|
---|
1249 | pNode = createAndInsertNode(pParent, pszName, cchName, iPosition, pchFullName, cchFullName);
|
---|
1250 | endInsertRows();
|
---|
1251 | }
|
---|
1252 | return pNode;
|
---|
1253 | }
|
---|
1254 |
|
---|
1255 | /*static*/ PDBGGUISTATSNODE
|
---|
1256 | VBoxDbgStatsModel::removeNode(PDBGGUISTATSNODE pNode)
|
---|
1257 | {
|
---|
1258 | PDBGGUISTATSNODE pParent = pNode->pParent;
|
---|
1259 | if (pParent)
|
---|
1260 | {
|
---|
1261 | uint32_t iPosition = pNode->iSelf;
|
---|
1262 | Assert(pParent->papChildren[iPosition] == pNode);
|
---|
1263 | uint32_t const cChildren = --pParent->cChildren;
|
---|
1264 | for (; iPosition < cChildren; iPosition++)
|
---|
1265 | {
|
---|
1266 | PDBGGUISTATSNODE pChild = pParent->papChildren[iPosition + 1];
|
---|
1267 | pParent->papChildren[iPosition] = pChild;
|
---|
1268 | pChild->iSelf = iPosition;
|
---|
1269 | }
|
---|
1270 | #ifdef VBOX_STRICT /* poison */
|
---|
1271 | pParent->papChildren[iPosition] = (PDBGGUISTATSNODE)0x42;
|
---|
1272 | #endif
|
---|
1273 | }
|
---|
1274 | return pNode;
|
---|
1275 | }
|
---|
1276 |
|
---|
1277 |
|
---|
1278 | /*static*/ void
|
---|
1279 | VBoxDbgStatsModel::removeAndDestroyNode(PDBGGUISTATSNODE pNode)
|
---|
1280 | {
|
---|
1281 | removeNode(pNode);
|
---|
1282 | destroyNode(pNode);
|
---|
1283 | }
|
---|
1284 |
|
---|
1285 |
|
---|
1286 | void
|
---|
1287 | VBoxDbgStatsModel::removeAndDestroy(PDBGGUISTATSNODE pNode)
|
---|
1288 | {
|
---|
1289 | if (m_fUpdateInsertRemove)
|
---|
1290 | removeAndDestroyNode(pNode);
|
---|
1291 | else
|
---|
1292 | {
|
---|
1293 | /*
|
---|
1294 | * Removing is fun since the docs are imprecise as to how persistent
|
---|
1295 | * indexes are updated (or aren't). So, let try a few different ideas
|
---|
1296 | * and see which works.
|
---|
1297 | */
|
---|
1298 | #if 1
|
---|
1299 | /* destroy the children first with the appropriate begin/endRemoveRows signals. */
|
---|
1300 | DBGGUISTATSSTACK Stack;
|
---|
1301 | Stack.a[0].pNode = pNode;
|
---|
1302 | Stack.a[0].iChild = -1;
|
---|
1303 | Stack.iTop = 0;
|
---|
1304 | while (Stack.iTop >= 0)
|
---|
1305 | {
|
---|
1306 | /* get top element */
|
---|
1307 | PDBGGUISTATSNODE pCurNode = Stack.a[Stack.iTop].pNode;
|
---|
1308 | uint32_t iChild = ++Stack.a[Stack.iTop].iChild;
|
---|
1309 | if (iChild < pCurNode->cChildren)
|
---|
1310 | {
|
---|
1311 | /* push */
|
---|
1312 | Stack.iTop++;
|
---|
1313 | Assert(Stack.iTop < (int32_t)RT_ELEMENTS(Stack.a));
|
---|
1314 | Stack.a[Stack.iTop].pNode = pCurNode->papChildren[iChild];
|
---|
1315 | Stack.a[Stack.iTop].iChild = 0;
|
---|
1316 | }
|
---|
1317 | else
|
---|
1318 | {
|
---|
1319 | /* pop and destroy all the children. */
|
---|
1320 | Stack.iTop--;
|
---|
1321 | uint32_t i = pCurNode->cChildren;
|
---|
1322 | if (i)
|
---|
1323 | {
|
---|
1324 | beginRemoveRows(createIndex(pCurNode->iSelf, 0, pCurNode), 0, i - 1);
|
---|
1325 | while (i-- > 0)
|
---|
1326 | destroyNode(pCurNode->papChildren[i]);
|
---|
1327 | pCurNode->cChildren = 0;
|
---|
1328 | endRemoveRows();
|
---|
1329 | }
|
---|
1330 | }
|
---|
1331 | }
|
---|
1332 | Assert(!pNode->cChildren);
|
---|
1333 |
|
---|
1334 | /* finally the node it self. */
|
---|
1335 | PDBGGUISTATSNODE pParent = pNode->pParent;
|
---|
1336 | beginRemoveRows(createIndex(pParent->iSelf, 0, pParent), pNode->iSelf, pNode->iSelf);
|
---|
1337 | removeAndDestroyNode(pNode);
|
---|
1338 | endRemoveRows();
|
---|
1339 |
|
---|
1340 | #elif 0
|
---|
1341 | /* This ain't working, leaves invalid indexes behind. */
|
---|
1342 | PDBGGUISTATSNODE pParent = pNode->pParent;
|
---|
1343 | beginRemoveRows(createIndex(pParent->iSelf, 0, pParent), pNode->iSelf, pNode->iSelf);
|
---|
1344 | removeAndDestroyNode(pNode);
|
---|
1345 | endRemoveRows();
|
---|
1346 | #else
|
---|
1347 | /* Force reset() of the model after the update. */
|
---|
1348 | m_fUpdateInsertRemove = true;
|
---|
1349 | removeAndDestroyNode(pNode);
|
---|
1350 | #endif
|
---|
1351 | }
|
---|
1352 | }
|
---|
1353 |
|
---|
1354 |
|
---|
1355 | /*static*/ void
|
---|
1356 | VBoxDbgStatsModel::resetNode(PDBGGUISTATSNODE pNode)
|
---|
1357 | {
|
---|
1358 | /* free and reinit the data. */
|
---|
1359 | if (pNode->enmType == STAMTYPE_CALLBACK)
|
---|
1360 | {
|
---|
1361 | delete pNode->Data.pStr;
|
---|
1362 | pNode->Data.pStr = NULL;
|
---|
1363 | }
|
---|
1364 | pNode->enmType = STAMTYPE_INVALID;
|
---|
1365 |
|
---|
1366 | /* free the description. */
|
---|
1367 | if (pNode->pDescStr)
|
---|
1368 | {
|
---|
1369 | delete pNode->pDescStr;
|
---|
1370 | pNode->pDescStr = NULL;
|
---|
1371 | }
|
---|
1372 | }
|
---|
1373 |
|
---|
1374 |
|
---|
1375 | /*static*/ int
|
---|
1376 | VBoxDbgStatsModel::initNode(PDBGGUISTATSNODE pNode, STAMTYPE enmType, void *pvSample,
|
---|
1377 | const char *pszUnit, const char *pszDesc)
|
---|
1378 | {
|
---|
1379 | /*
|
---|
1380 | * Copy the data.
|
---|
1381 | */
|
---|
1382 | pNode->pszUnit = pszUnit;
|
---|
1383 | Assert(pNode->enmType == STAMTYPE_INVALID);
|
---|
1384 | pNode->enmType = enmType;
|
---|
1385 | if (pszDesc)
|
---|
1386 | pNode->pDescStr = new QString(pszDesc); /* ignore allocation failure (well, at least up to the point we can ignore it) */
|
---|
1387 |
|
---|
1388 | switch (enmType)
|
---|
1389 | {
|
---|
1390 | case STAMTYPE_COUNTER:
|
---|
1391 | pNode->Data.Counter = *(PSTAMCOUNTER)pvSample;
|
---|
1392 | break;
|
---|
1393 |
|
---|
1394 | case STAMTYPE_PROFILE:
|
---|
1395 | case STAMTYPE_PROFILE_ADV:
|
---|
1396 | pNode->Data.Profile = *(PSTAMPROFILE)pvSample;
|
---|
1397 | break;
|
---|
1398 |
|
---|
1399 | case STAMTYPE_RATIO_U32:
|
---|
1400 | case STAMTYPE_RATIO_U32_RESET:
|
---|
1401 | pNode->Data.RatioU32 = *(PSTAMRATIOU32)pvSample;
|
---|
1402 | break;
|
---|
1403 |
|
---|
1404 | case STAMTYPE_CALLBACK:
|
---|
1405 | {
|
---|
1406 | const char *pszString = (const char *)pvSample;
|
---|
1407 | pNode->Data.pStr = new QString(pszString);
|
---|
1408 | break;
|
---|
1409 | }
|
---|
1410 |
|
---|
1411 | case STAMTYPE_U8:
|
---|
1412 | case STAMTYPE_U8_RESET:
|
---|
1413 | case STAMTYPE_X8:
|
---|
1414 | case STAMTYPE_X8_RESET:
|
---|
1415 | pNode->Data.u8 = *(uint8_t *)pvSample;
|
---|
1416 | break;
|
---|
1417 |
|
---|
1418 | case STAMTYPE_U16:
|
---|
1419 | case STAMTYPE_U16_RESET:
|
---|
1420 | case STAMTYPE_X16:
|
---|
1421 | case STAMTYPE_X16_RESET:
|
---|
1422 | pNode->Data.u16 = *(uint16_t *)pvSample;
|
---|
1423 | break;
|
---|
1424 |
|
---|
1425 | case STAMTYPE_U32:
|
---|
1426 | case STAMTYPE_U32_RESET:
|
---|
1427 | case STAMTYPE_X32:
|
---|
1428 | case STAMTYPE_X32_RESET:
|
---|
1429 | pNode->Data.u32 = *(uint32_t *)pvSample;
|
---|
1430 | break;
|
---|
1431 |
|
---|
1432 | case STAMTYPE_U64:
|
---|
1433 | case STAMTYPE_U64_RESET:
|
---|
1434 | case STAMTYPE_X64:
|
---|
1435 | case STAMTYPE_X64_RESET:
|
---|
1436 | pNode->Data.u64 = *(uint64_t *)pvSample;
|
---|
1437 | break;
|
---|
1438 |
|
---|
1439 | case STAMTYPE_BOOL:
|
---|
1440 | case STAMTYPE_BOOL_RESET:
|
---|
1441 | pNode->Data.f = *(bool *)pvSample;
|
---|
1442 | break;
|
---|
1443 |
|
---|
1444 | default:
|
---|
1445 | AssertMsgFailed(("%d\n", enmType));
|
---|
1446 | break;
|
---|
1447 | }
|
---|
1448 |
|
---|
1449 | return VINF_SUCCESS;
|
---|
1450 | }
|
---|
1451 |
|
---|
1452 |
|
---|
1453 |
|
---|
1454 |
|
---|
1455 | /*static*/ void
|
---|
1456 | VBoxDbgStatsModel::updateNode(PDBGGUISTATSNODE pNode, STAMTYPE enmType, void *pvSample, const char *pszUnit, const char *pszDesc)
|
---|
1457 | {
|
---|
1458 | /*
|
---|
1459 | * Reset and init the node if the type changed.
|
---|
1460 | */
|
---|
1461 | if (enmType != pNode->enmType)
|
---|
1462 | {
|
---|
1463 | if (pNode->enmType != STAMTYPE_INVALID)
|
---|
1464 | resetNode(pNode);
|
---|
1465 | initNode(pNode, enmType, pvSample, pszUnit, pszDesc);
|
---|
1466 | pNode->enmState = kDbgGuiStatsNodeState_kRefresh;
|
---|
1467 | }
|
---|
1468 | else
|
---|
1469 | {
|
---|
1470 | /*
|
---|
1471 | * ASSUME that only the sample value will change and that the unit, visibility
|
---|
1472 | * and description remains the same.
|
---|
1473 | */
|
---|
1474 |
|
---|
1475 | int64_t iDelta;
|
---|
1476 | switch (enmType)
|
---|
1477 | {
|
---|
1478 | case STAMTYPE_COUNTER:
|
---|
1479 | {
|
---|
1480 | uint64_t cPrev = pNode->Data.Counter.c;
|
---|
1481 | pNode->Data.Counter = *(PSTAMCOUNTER)pvSample;
|
---|
1482 | iDelta = pNode->Data.Counter.c - cPrev;
|
---|
1483 | if (iDelta || pNode->i64Delta)
|
---|
1484 | {
|
---|
1485 | pNode->i64Delta = iDelta;
|
---|
1486 | pNode->enmState = kDbgGuiStatsNodeState_kRefresh;
|
---|
1487 | }
|
---|
1488 | break;
|
---|
1489 | }
|
---|
1490 |
|
---|
1491 | case STAMTYPE_PROFILE:
|
---|
1492 | case STAMTYPE_PROFILE_ADV:
|
---|
1493 | {
|
---|
1494 | uint64_t cPrevPeriods = pNode->Data.Profile.cPeriods;
|
---|
1495 | pNode->Data.Profile = *(PSTAMPROFILE)pvSample;
|
---|
1496 | iDelta = pNode->Data.Profile.cPeriods - cPrevPeriods;
|
---|
1497 | if (iDelta || pNode->i64Delta)
|
---|
1498 | {
|
---|
1499 | pNode->i64Delta = iDelta;
|
---|
1500 | pNode->enmState = kDbgGuiStatsNodeState_kRefresh;
|
---|
1501 | }
|
---|
1502 | break;
|
---|
1503 | }
|
---|
1504 |
|
---|
1505 | case STAMTYPE_RATIO_U32:
|
---|
1506 | case STAMTYPE_RATIO_U32_RESET:
|
---|
1507 | {
|
---|
1508 | STAMRATIOU32 Prev = pNode->Data.RatioU32;
|
---|
1509 | pNode->Data.RatioU32 = *(PSTAMRATIOU32)pvSample;
|
---|
1510 | int32_t iDeltaA = pNode->Data.RatioU32.u32A - Prev.u32A;
|
---|
1511 | int32_t iDeltaB = pNode->Data.RatioU32.u32B - Prev.u32B;
|
---|
1512 | if (iDeltaA == 0 && iDeltaB == 0)
|
---|
1513 | {
|
---|
1514 | if (pNode->i64Delta)
|
---|
1515 | {
|
---|
1516 | pNode->i64Delta = 0;
|
---|
1517 | pNode->enmState = kDbgGuiStatsNodeState_kRefresh;
|
---|
1518 | }
|
---|
1519 | }
|
---|
1520 | else
|
---|
1521 | {
|
---|
1522 | if (iDeltaA >= 0)
|
---|
1523 | pNode->i64Delta = iDeltaA + (iDeltaB >= 0 ? iDeltaB : -iDeltaB);
|
---|
1524 | else
|
---|
1525 | pNode->i64Delta = iDeltaA + (iDeltaB < 0 ? iDeltaB : -iDeltaB);
|
---|
1526 | pNode->enmState = kDbgGuiStatsNodeState_kRefresh;
|
---|
1527 | }
|
---|
1528 | break;
|
---|
1529 | }
|
---|
1530 |
|
---|
1531 | case STAMTYPE_CALLBACK:
|
---|
1532 | {
|
---|
1533 | const char *pszString = (const char *)pvSample;
|
---|
1534 | if (!pNode->Data.pStr)
|
---|
1535 | {
|
---|
1536 | pNode->Data.pStr = new QString(pszString);
|
---|
1537 | pNode->enmState = kDbgGuiStatsNodeState_kRefresh;
|
---|
1538 | }
|
---|
1539 | else if (*pNode->Data.pStr == pszString)
|
---|
1540 | {
|
---|
1541 | delete pNode->Data.pStr;
|
---|
1542 | pNode->Data.pStr = new QString(pszString);
|
---|
1543 | pNode->enmState = kDbgGuiStatsNodeState_kRefresh;
|
---|
1544 | }
|
---|
1545 | break;
|
---|
1546 | }
|
---|
1547 |
|
---|
1548 | case STAMTYPE_U8:
|
---|
1549 | case STAMTYPE_U8_RESET:
|
---|
1550 | case STAMTYPE_X8:
|
---|
1551 | case STAMTYPE_X8_RESET:
|
---|
1552 | {
|
---|
1553 | uint8_t uPrev = pNode->Data.u8;
|
---|
1554 | pNode->Data.u8 = *(uint8_t *)pvSample;
|
---|
1555 | iDelta = (int32_t)pNode->Data.u8 - (int32_t)uPrev;
|
---|
1556 | if (iDelta || pNode->i64Delta)
|
---|
1557 | {
|
---|
1558 | pNode->i64Delta = iDelta;
|
---|
1559 | pNode->enmState = kDbgGuiStatsNodeState_kRefresh;
|
---|
1560 | }
|
---|
1561 | break;
|
---|
1562 | }
|
---|
1563 |
|
---|
1564 | case STAMTYPE_U16:
|
---|
1565 | case STAMTYPE_U16_RESET:
|
---|
1566 | case STAMTYPE_X16:
|
---|
1567 | case STAMTYPE_X16_RESET:
|
---|
1568 | {
|
---|
1569 | uint16_t uPrev = pNode->Data.u16;
|
---|
1570 | pNode->Data.u16 = *(uint16_t *)pvSample;
|
---|
1571 | iDelta = (int32_t)pNode->Data.u16 - (int32_t)uPrev;
|
---|
1572 | if (iDelta || pNode->i64Delta)
|
---|
1573 | {
|
---|
1574 | pNode->i64Delta = iDelta;
|
---|
1575 | pNode->enmState = kDbgGuiStatsNodeState_kRefresh;
|
---|
1576 | }
|
---|
1577 | break;
|
---|
1578 | }
|
---|
1579 |
|
---|
1580 | case STAMTYPE_U32:
|
---|
1581 | case STAMTYPE_U32_RESET:
|
---|
1582 | case STAMTYPE_X32:
|
---|
1583 | case STAMTYPE_X32_RESET:
|
---|
1584 | {
|
---|
1585 | uint32_t uPrev = pNode->Data.u32;
|
---|
1586 | pNode->Data.u32 = *(uint32_t *)pvSample;
|
---|
1587 | iDelta = (int64_t)pNode->Data.u32 - (int64_t)uPrev;
|
---|
1588 | if (iDelta || pNode->i64Delta)
|
---|
1589 | {
|
---|
1590 | pNode->i64Delta = iDelta;
|
---|
1591 | pNode->enmState = kDbgGuiStatsNodeState_kRefresh;
|
---|
1592 | }
|
---|
1593 | break;
|
---|
1594 | }
|
---|
1595 |
|
---|
1596 | case STAMTYPE_U64:
|
---|
1597 | case STAMTYPE_U64_RESET:
|
---|
1598 | case STAMTYPE_X64:
|
---|
1599 | case STAMTYPE_X64_RESET:
|
---|
1600 | {
|
---|
1601 | uint64_t uPrev = pNode->Data.u64;
|
---|
1602 | pNode->Data.u64 = *(uint64_t *)pvSample;
|
---|
1603 | iDelta = pNode->Data.u64 - uPrev;
|
---|
1604 | if (iDelta || pNode->i64Delta)
|
---|
1605 | {
|
---|
1606 | pNode->i64Delta = iDelta;
|
---|
1607 | pNode->enmState = kDbgGuiStatsNodeState_kRefresh;
|
---|
1608 | }
|
---|
1609 | break;
|
---|
1610 | }
|
---|
1611 |
|
---|
1612 | case STAMTYPE_BOOL:
|
---|
1613 | case STAMTYPE_BOOL_RESET:
|
---|
1614 | {
|
---|
1615 | bool fPrev = pNode->Data.f;
|
---|
1616 | pNode->Data.f = *(bool *)pvSample;
|
---|
1617 | iDelta = pNode->Data.f - fPrev;
|
---|
1618 | if (iDelta || pNode->i64Delta)
|
---|
1619 | {
|
---|
1620 | pNode->i64Delta = iDelta;
|
---|
1621 | pNode->enmState = kDbgGuiStatsNodeState_kRefresh;
|
---|
1622 | }
|
---|
1623 | break;
|
---|
1624 | }
|
---|
1625 |
|
---|
1626 | default:
|
---|
1627 | AssertMsgFailed(("%d\n", enmType));
|
---|
1628 | break;
|
---|
1629 | }
|
---|
1630 | }
|
---|
1631 | }
|
---|
1632 |
|
---|
1633 |
|
---|
1634 | /*static*/ ssize_t
|
---|
1635 | VBoxDbgStatsModel::getNodePath(PCDBGGUISTATSNODE pNode, char *psz, ssize_t cch)
|
---|
1636 | {
|
---|
1637 | ssize_t off;
|
---|
1638 | if (!pNode->pParent)
|
---|
1639 | {
|
---|
1640 | /* root - don't add it's slash! */
|
---|
1641 | AssertReturn(cch >= 1, -1);
|
---|
1642 | off = 0;
|
---|
1643 | *psz = '\0';
|
---|
1644 | }
|
---|
1645 | else
|
---|
1646 | {
|
---|
1647 | cch -= pNode->cchName + 1;
|
---|
1648 | AssertReturn(cch > 0, -1);
|
---|
1649 | off = getNodePath(pNode->pParent, psz, cch);
|
---|
1650 | if (off >= 0)
|
---|
1651 | {
|
---|
1652 | psz[off++] = '/';
|
---|
1653 | memcpy(&psz[off], pNode->pszName, pNode->cchName + 1);
|
---|
1654 | off += pNode->cchName;
|
---|
1655 | }
|
---|
1656 | }
|
---|
1657 | return off;
|
---|
1658 | }
|
---|
1659 |
|
---|
1660 |
|
---|
1661 | /*static*/ char *
|
---|
1662 | VBoxDbgStatsModel::getNodePath2(PCDBGGUISTATSNODE pNode, char *psz, ssize_t cch)
|
---|
1663 | {
|
---|
1664 | if (VBoxDbgStatsModel::getNodePath(pNode, psz, cch) < 0)
|
---|
1665 | return NULL;
|
---|
1666 | return psz;
|
---|
1667 | }
|
---|
1668 |
|
---|
1669 |
|
---|
1670 | /*static*/ QString
|
---|
1671 | VBoxDbgStatsModel::getNodePattern(PCDBGGUISTATSNODE pNode, bool fSubTree /*= true*/)
|
---|
1672 | {
|
---|
1673 | /* the node pattern. */
|
---|
1674 | char szPat[1024+1024+4];
|
---|
1675 | ssize_t cch = getNodePath(pNode, szPat, 1024);
|
---|
1676 | AssertReturn(cch >= 0, QString("//////////////////////////////////////////////////////"));
|
---|
1677 |
|
---|
1678 | /* the sub-tree pattern. */
|
---|
1679 | if (fSubTree && pNode->cChildren)
|
---|
1680 | {
|
---|
1681 | char *psz = &szPat[cch];
|
---|
1682 | *psz++ = '|';
|
---|
1683 | memcpy(psz, szPat, cch);
|
---|
1684 | psz += cch;
|
---|
1685 | *psz++ = '/';
|
---|
1686 | *psz++ = '*';
|
---|
1687 | *psz++ = '\0';
|
---|
1688 | }
|
---|
1689 | return szPat;
|
---|
1690 | }
|
---|
1691 |
|
---|
1692 |
|
---|
1693 | /*static*/ bool
|
---|
1694 | VBoxDbgStatsModel::isNodeAncestorOf(PCDBGGUISTATSNODE pAncestor, PCDBGGUISTATSNODE pDescendant)
|
---|
1695 | {
|
---|
1696 | while (pDescendant)
|
---|
1697 | {
|
---|
1698 | pDescendant = pDescendant->pParent;
|
---|
1699 | if (pDescendant == pAncestor)
|
---|
1700 | return true;
|
---|
1701 | }
|
---|
1702 | return false;
|
---|
1703 | }
|
---|
1704 |
|
---|
1705 |
|
---|
1706 | /*static*/ PDBGGUISTATSNODE
|
---|
1707 | VBoxDbgStatsModel::nextNode(PDBGGUISTATSNODE pNode)
|
---|
1708 | {
|
---|
1709 | if (!pNode)
|
---|
1710 | return NULL;
|
---|
1711 |
|
---|
1712 | /* descend to children. */
|
---|
1713 | if (pNode->cChildren)
|
---|
1714 | return pNode->papChildren[0];
|
---|
1715 |
|
---|
1716 | PDBGGUISTATSNODE pParent = pNode->pParent;
|
---|
1717 | if (!pParent)
|
---|
1718 | return NULL;
|
---|
1719 |
|
---|
1720 | /* next sibling. */
|
---|
1721 | if (pNode->iSelf + 1 < pNode->pParent->cChildren)
|
---|
1722 | return pParent->papChildren[pNode->iSelf + 1];
|
---|
1723 |
|
---|
1724 | /* ascend and advanced to a parent's sibiling. */
|
---|
1725 | for (;;)
|
---|
1726 | {
|
---|
1727 | uint32_t iSelf = pParent->iSelf;
|
---|
1728 | pParent = pParent->pParent;
|
---|
1729 | if (!pParent)
|
---|
1730 | return NULL;
|
---|
1731 | if (iSelf + 1 < pParent->cChildren)
|
---|
1732 | return pParent->papChildren[iSelf + 1];
|
---|
1733 | }
|
---|
1734 | }
|
---|
1735 |
|
---|
1736 |
|
---|
1737 | /*static*/ PDBGGUISTATSNODE
|
---|
1738 | VBoxDbgStatsModel::nextDataNode(PDBGGUISTATSNODE pNode)
|
---|
1739 | {
|
---|
1740 | do
|
---|
1741 | pNode = nextNode(pNode);
|
---|
1742 | while ( pNode
|
---|
1743 | && pNode->enmType == STAMTYPE_INVALID);
|
---|
1744 | return pNode;
|
---|
1745 | }
|
---|
1746 |
|
---|
1747 |
|
---|
1748 | /*static*/ PDBGGUISTATSNODE
|
---|
1749 | VBoxDbgStatsModel::prevNode(PDBGGUISTATSNODE pNode)
|
---|
1750 | {
|
---|
1751 | if (!pNode)
|
---|
1752 | return NULL;
|
---|
1753 | PDBGGUISTATSNODE pParent = pNode->pParent;
|
---|
1754 | if (!pParent)
|
---|
1755 | return NULL;
|
---|
1756 |
|
---|
1757 | /* previous sibling's latest descendant (better expression anyone?). */
|
---|
1758 | if (pNode->iSelf > 0)
|
---|
1759 | {
|
---|
1760 | pNode = pParent->papChildren[pNode->iSelf - 1];
|
---|
1761 | while (pNode->cChildren)
|
---|
1762 | pNode = pNode->papChildren[pNode->cChildren - 1];
|
---|
1763 | return pNode;
|
---|
1764 | }
|
---|
1765 |
|
---|
1766 | /* ascend to the parent. */
|
---|
1767 | return pParent;
|
---|
1768 | }
|
---|
1769 |
|
---|
1770 |
|
---|
1771 | /*static*/ PDBGGUISTATSNODE
|
---|
1772 | VBoxDbgStatsModel::prevDataNode(PDBGGUISTATSNODE pNode)
|
---|
1773 | {
|
---|
1774 | do
|
---|
1775 | pNode = prevNode(pNode);
|
---|
1776 | while ( pNode
|
---|
1777 | && pNode->enmType == STAMTYPE_INVALID);
|
---|
1778 | return pNode;
|
---|
1779 | }
|
---|
1780 |
|
---|
1781 |
|
---|
1782 | #if 0
|
---|
1783 | /*static*/ PDBGGUISTATSNODE
|
---|
1784 | VBoxDbgStatsModel::createNewTree(IMachineDebugger *a_pIMachineDebugger)
|
---|
1785 | {
|
---|
1786 | /** @todo */
|
---|
1787 | return NULL;
|
---|
1788 | }
|
---|
1789 | #endif
|
---|
1790 |
|
---|
1791 |
|
---|
1792 | #if 0
|
---|
1793 | /*static*/ PDBGGUISTATSNODE
|
---|
1794 | VBoxDbgStatsModel::createNewTree(const char *pszFilename)
|
---|
1795 | {
|
---|
1796 | /** @todo */
|
---|
1797 | return NULL;
|
---|
1798 | }
|
---|
1799 | #endif
|
---|
1800 |
|
---|
1801 |
|
---|
1802 | #if 0
|
---|
1803 | /*static*/ PDBGGUISTATSNODE
|
---|
1804 | VBoxDbgStatsModel::createDiffTree(PDBGGUISTATSNODE pTree1, PDBGGUISTATSNODE pTree2)
|
---|
1805 | {
|
---|
1806 | /** @todo */
|
---|
1807 | return NULL;
|
---|
1808 | }
|
---|
1809 | #endif
|
---|
1810 |
|
---|
1811 |
|
---|
1812 | PDBGGUISTATSNODE
|
---|
1813 | VBoxDbgStatsModel::updateCallbackHandleOutOfOrder(const char * const pszName)
|
---|
1814 | {
|
---|
1815 | #if defined(VBOX_STRICT) || defined(LOG_ENABLED)
|
---|
1816 | char szStrict[1024];
|
---|
1817 | #endif
|
---|
1818 |
|
---|
1819 | /*
|
---|
1820 | * We might be inserting a new node between pPrev and pNode
|
---|
1821 | * or we might be removing one or more nodes. Either case is
|
---|
1822 | * handled in the same rough way.
|
---|
1823 | *
|
---|
1824 | * Might consider optimizing insertion at some later point since this
|
---|
1825 | * is a normal occurrence (dynamic statistics in PATM, IOM, MM, ++).
|
---|
1826 | */
|
---|
1827 | Assert(pszName[0] == '/');
|
---|
1828 | Assert(m_szUpdateParent[m_cchUpdateParent - 1] == '/');
|
---|
1829 |
|
---|
1830 | /*
|
---|
1831 | * Start with the current parent node and look for a common ancestor
|
---|
1832 | * hoping that this is faster than going from the root (saves lookup).
|
---|
1833 | */
|
---|
1834 | PDBGGUISTATSNODE pNode = m_pUpdateParent->papChildren[m_iUpdateChild];
|
---|
1835 | PDBGGUISTATSNODE const pPrev = prevDataNode(pNode);
|
---|
1836 | AssertMsg(strcmp(pszName, getNodePath2(pNode, szStrict, sizeof(szStrict))), ("%s\n", szStrict));
|
---|
1837 | AssertMsg(!pPrev || strcmp(pszName, getNodePath2(pPrev, szStrict, sizeof(szStrict))), ("%s\n", szStrict));
|
---|
1838 | Log(("updateCallbackHandleOutOfOrder: pszName='%s' m_szUpdateParent='%s' m_cchUpdateParent=%u pNode='%s'\n",
|
---|
1839 | pszName, m_szUpdateParent, m_cchUpdateParent, getNodePath2(pNode, szStrict, sizeof(szStrict))));
|
---|
1840 |
|
---|
1841 | pNode = pNode->pParent;
|
---|
1842 | while (pNode != m_pRoot)
|
---|
1843 | {
|
---|
1844 | if (!strncmp(pszName, m_szUpdateParent, m_cchUpdateParent))
|
---|
1845 | break;
|
---|
1846 | Assert(m_cchUpdateParent > pNode->cchName);
|
---|
1847 | m_cchUpdateParent -= pNode->cchName + 1;
|
---|
1848 | m_szUpdateParent[m_cchUpdateParent] = '\0';
|
---|
1849 | Log2(("updateCallbackHandleOutOfOrder: m_szUpdateParent='%s' m_cchUpdateParent=%u, removed '/%s' (%u)\n", m_szUpdateParent, m_cchUpdateParent, pNode->pszName, __LINE__));
|
---|
1850 | pNode = pNode->pParent;
|
---|
1851 | }
|
---|
1852 | Assert(m_szUpdateParent[m_cchUpdateParent - 1] == '/');
|
---|
1853 |
|
---|
1854 | /*
|
---|
1855 | * Descend until we've found/created the node pszName indicates,
|
---|
1856 | * modifying m_szUpdateParent as we go along.
|
---|
1857 | */
|
---|
1858 | while (pszName[m_cchUpdateParent - 1] == '/')
|
---|
1859 | {
|
---|
1860 | /* Find the end of this component. */
|
---|
1861 | const char * const pszSubName = &pszName[m_cchUpdateParent];
|
---|
1862 | const char *pszEnd = strchr(pszSubName, '/');
|
---|
1863 | if (!pszEnd)
|
---|
1864 | pszEnd = strchr(pszSubName, '\0');
|
---|
1865 | size_t cchSubName = pszEnd - pszSubName;
|
---|
1866 |
|
---|
1867 | /* Add the name to the path. */
|
---|
1868 | memcpy(&m_szUpdateParent[m_cchUpdateParent], pszSubName, cchSubName);
|
---|
1869 | m_cchUpdateParent += cchSubName;
|
---|
1870 | m_szUpdateParent[m_cchUpdateParent++] = '/';
|
---|
1871 | m_szUpdateParent[m_cchUpdateParent] = '\0';
|
---|
1872 | Assert(m_cchUpdateParent < sizeof(m_szUpdateParent));
|
---|
1873 | Log2(("updateCallbackHandleOutOfOrder: m_szUpdateParent='%s' m_cchUpdateParent=%u (%u)\n", m_szUpdateParent, m_cchUpdateParent, __LINE__));
|
---|
1874 |
|
---|
1875 | if (!pNode->cChildren)
|
---|
1876 | {
|
---|
1877 | /* first child */
|
---|
1878 | pNode = createAndInsert(pNode, pszSubName, cchSubName, 0, pszName, pszEnd - pszName);
|
---|
1879 | AssertReturn(pNode, NULL);
|
---|
1880 | }
|
---|
1881 | else
|
---|
1882 | {
|
---|
1883 | /* binary search. */
|
---|
1884 | int32_t iStart = 0;
|
---|
1885 | int32_t iLast = pNode->cChildren - 1;
|
---|
1886 | for (;;)
|
---|
1887 | {
|
---|
1888 | int32_t i = iStart + (iLast + 1 - iStart) / 2;
|
---|
1889 | int iDiff;
|
---|
1890 | size_t const cchCompare = RT_MIN(pNode->papChildren[i]->cchName, cchSubName);
|
---|
1891 | iDiff = memcmp(pszSubName, pNode->papChildren[i]->pszName, cchCompare);
|
---|
1892 | if (!iDiff)
|
---|
1893 | {
|
---|
1894 | iDiff = cchSubName == cchCompare ? 0 : cchSubName > cchCompare ? 1 : -1;
|
---|
1895 | /* For cases when exisiting node name is same as new node name with additional characters. */
|
---|
1896 | if (!iDiff)
|
---|
1897 | iDiff = cchSubName == pNode->papChildren[i]->cchName ? 0 : cchSubName > pNode->papChildren[i]->cchName ? 1 : -1;
|
---|
1898 | }
|
---|
1899 | if (iDiff > 0)
|
---|
1900 | {
|
---|
1901 | iStart = i + 1;
|
---|
1902 | if (iStart > iLast)
|
---|
1903 | {
|
---|
1904 | pNode = createAndInsert(pNode, pszSubName, cchSubName, iStart, pszName, pszEnd - pszName);
|
---|
1905 | AssertReturn(pNode, NULL);
|
---|
1906 | break;
|
---|
1907 | }
|
---|
1908 | }
|
---|
1909 | else if (iDiff < 0)
|
---|
1910 | {
|
---|
1911 | iLast = i - 1;
|
---|
1912 | if (iLast < iStart)
|
---|
1913 | {
|
---|
1914 | pNode = createAndInsert(pNode, pszSubName, cchSubName, i, pszName, pszEnd - pszName);
|
---|
1915 | AssertReturn(pNode, NULL);
|
---|
1916 | break;
|
---|
1917 | }
|
---|
1918 | }
|
---|
1919 | else
|
---|
1920 | {
|
---|
1921 | pNode = pNode->papChildren[i];
|
---|
1922 | break;
|
---|
1923 | }
|
---|
1924 | }
|
---|
1925 | }
|
---|
1926 | }
|
---|
1927 | Assert( !memcmp(pszName, m_szUpdateParent, m_cchUpdateParent - 2)
|
---|
1928 | && pszName[m_cchUpdateParent - 1] == '\0');
|
---|
1929 |
|
---|
1930 | /*
|
---|
1931 | * Remove all the nodes between pNode and pPrev but keep all
|
---|
1932 | * of pNode's ancestors (or it'll get orphaned).
|
---|
1933 | */
|
---|
1934 | PDBGGUISTATSNODE pCur = prevNode(pNode);
|
---|
1935 | while (pCur != pPrev)
|
---|
1936 | {
|
---|
1937 | PDBGGUISTATSNODE pAdv = prevNode(pCur); Assert(pAdv || !pPrev);
|
---|
1938 | if (!isNodeAncestorOf(pCur, pNode))
|
---|
1939 | {
|
---|
1940 | Assert(pCur != m_pRoot);
|
---|
1941 | removeAndDestroy(pCur);
|
---|
1942 | }
|
---|
1943 | pCur = pAdv;
|
---|
1944 | }
|
---|
1945 |
|
---|
1946 | /*
|
---|
1947 | * Remove the data from all ancestors of pNode that it doesn't
|
---|
1948 | * share them pPrev.
|
---|
1949 | */
|
---|
1950 | if (pPrev)
|
---|
1951 | {
|
---|
1952 | pCur = pNode->pParent;
|
---|
1953 | while (!isNodeAncestorOf(pCur, pPrev))
|
---|
1954 | {
|
---|
1955 | resetNode(pNode);
|
---|
1956 | pCur = pCur->pParent;
|
---|
1957 | }
|
---|
1958 | }
|
---|
1959 |
|
---|
1960 | /*
|
---|
1961 | * Finally, adjust the globals (szUpdateParent is one level too deep).
|
---|
1962 | */
|
---|
1963 | Assert(m_cchUpdateParent > pNode->cchName + 1);
|
---|
1964 | m_cchUpdateParent -= pNode->cchName + 1;
|
---|
1965 | m_szUpdateParent[m_cchUpdateParent] = '\0';
|
---|
1966 | m_pUpdateParent = pNode->pParent;
|
---|
1967 | m_iUpdateChild = pNode->iSelf;
|
---|
1968 | Log2(("updateCallbackHandleOutOfOrder: m_szUpdateParent='%s' m_cchUpdateParent=%u (%u)\n", m_szUpdateParent, m_cchUpdateParent, __LINE__));
|
---|
1969 |
|
---|
1970 | return pNode;
|
---|
1971 | }
|
---|
1972 |
|
---|
1973 |
|
---|
1974 | PDBGGUISTATSNODE
|
---|
1975 | VBoxDbgStatsModel::updateCallbackHandleTail(const char *pszName)
|
---|
1976 | {
|
---|
1977 | /*
|
---|
1978 | * Insert it at the end of the tree.
|
---|
1979 | *
|
---|
1980 | * Do the same as we're doing down in createNewTreeCallback, walk from the
|
---|
1981 | * root and create whatever we need.
|
---|
1982 | */
|
---|
1983 | AssertReturn(*pszName == '/' && pszName[1] != '/', NULL);
|
---|
1984 | PDBGGUISTATSNODE pNode = m_pRoot;
|
---|
1985 | const char *pszCur = pszName + 1;
|
---|
1986 | while (*pszCur)
|
---|
1987 | {
|
---|
1988 | /* Find the end of this component. */
|
---|
1989 | const char *pszNext = strchr(pszCur, '/');
|
---|
1990 | if (!pszNext)
|
---|
1991 | pszNext = strchr(pszCur, '\0');
|
---|
1992 | size_t cchCur = pszNext - pszCur;
|
---|
1993 |
|
---|
1994 | /* Create it if it doesn't exist (it will be last if it exists). */
|
---|
1995 | if ( !pNode->cChildren
|
---|
1996 | || strncmp(pNode->papChildren[pNode->cChildren - 1]->pszName, pszCur, cchCur)
|
---|
1997 | || pNode->papChildren[pNode->cChildren - 1]->pszName[cchCur])
|
---|
1998 | {
|
---|
1999 | pNode = createAndInsert(pNode, pszCur, pszNext - pszCur, pNode->cChildren, pszName, pszNext - pszName);
|
---|
2000 | AssertReturn(pNode, NULL);
|
---|
2001 | }
|
---|
2002 | else
|
---|
2003 | pNode = pNode->papChildren[pNode->cChildren - 1];
|
---|
2004 |
|
---|
2005 | /* Advance */
|
---|
2006 | pszCur = *pszNext ? pszNext + 1 : pszNext;
|
---|
2007 | }
|
---|
2008 |
|
---|
2009 | return pNode;
|
---|
2010 | }
|
---|
2011 |
|
---|
2012 |
|
---|
2013 | void
|
---|
2014 | VBoxDbgStatsModel::updateCallbackAdvance(PDBGGUISTATSNODE pNode)
|
---|
2015 | {
|
---|
2016 | /*
|
---|
2017 | * Advance to the next node with data.
|
---|
2018 | *
|
---|
2019 | * ASSUMES a leaf *must* have data and again we're ASSUMING the sorting
|
---|
2020 | * on slash separated sub-strings.
|
---|
2021 | */
|
---|
2022 | if (m_iUpdateChild != UINT32_MAX)
|
---|
2023 | {
|
---|
2024 | #ifdef VBOX_STRICT
|
---|
2025 | PDBGGUISTATSNODE const pCorrectNext = nextDataNode(pNode);
|
---|
2026 | #endif
|
---|
2027 | PDBGGUISTATSNODE pParent = pNode->pParent;
|
---|
2028 | if (pNode->cChildren)
|
---|
2029 | {
|
---|
2030 | /* descend to the first child. */
|
---|
2031 | Assert(m_cchUpdateParent + pNode->cchName + 2 < sizeof(m_szUpdateParent));
|
---|
2032 | memcpy(&m_szUpdateParent[m_cchUpdateParent], pNode->pszName, pNode->cchName);
|
---|
2033 | m_cchUpdateParent += pNode->cchName;
|
---|
2034 | m_szUpdateParent[m_cchUpdateParent++] = '/';
|
---|
2035 | m_szUpdateParent[m_cchUpdateParent] = '\0';
|
---|
2036 |
|
---|
2037 | pNode = pNode->papChildren[0];
|
---|
2038 | }
|
---|
2039 | else if (pNode->iSelf + 1 < pParent->cChildren)
|
---|
2040 | {
|
---|
2041 | /* next sibling or one if its descendants. */
|
---|
2042 | Assert(m_pUpdateParent == pParent);
|
---|
2043 | pNode = pParent->papChildren[pNode->iSelf + 1];
|
---|
2044 | }
|
---|
2045 | else
|
---|
2046 | {
|
---|
2047 | /* move up and down- / on-wards */
|
---|
2048 | for (;;)
|
---|
2049 | {
|
---|
2050 | /* ascend */
|
---|
2051 | pNode = pParent;
|
---|
2052 | pParent = pParent->pParent;
|
---|
2053 | if (!pParent)
|
---|
2054 | {
|
---|
2055 | Assert(pNode == m_pRoot);
|
---|
2056 | m_iUpdateChild = UINT32_MAX;
|
---|
2057 | m_szUpdateParent[0] = '\0';
|
---|
2058 | m_cchUpdateParent = 0;
|
---|
2059 | m_pUpdateParent = NULL;
|
---|
2060 | break;
|
---|
2061 | }
|
---|
2062 | Assert(m_cchUpdateParent > pNode->cchName + 1);
|
---|
2063 | m_cchUpdateParent -= pNode->cchName + 1;
|
---|
2064 |
|
---|
2065 | /* try advance */
|
---|
2066 | if (pNode->iSelf + 1 < pParent->cChildren)
|
---|
2067 | {
|
---|
2068 | pNode = pParent->papChildren[pNode->iSelf + 1];
|
---|
2069 | m_szUpdateParent[m_cchUpdateParent] = '\0';
|
---|
2070 | break;
|
---|
2071 | }
|
---|
2072 | }
|
---|
2073 | }
|
---|
2074 |
|
---|
2075 | /* descend to a node containing data and finalize the globals. (ASSUMES leaf has data.) */
|
---|
2076 | if (m_iUpdateChild != UINT32_MAX)
|
---|
2077 | {
|
---|
2078 | while ( pNode->enmType == STAMTYPE_INVALID
|
---|
2079 | && pNode->cChildren > 0)
|
---|
2080 | {
|
---|
2081 | Assert(pNode->enmState == kDbgGuiStatsNodeState_kVisible);
|
---|
2082 |
|
---|
2083 | Assert(m_cchUpdateParent + pNode->cchName + 2 < sizeof(m_szUpdateParent));
|
---|
2084 | memcpy(&m_szUpdateParent[m_cchUpdateParent], pNode->pszName, pNode->cchName);
|
---|
2085 | m_cchUpdateParent += pNode->cchName;
|
---|
2086 | m_szUpdateParent[m_cchUpdateParent++] = '/';
|
---|
2087 | m_szUpdateParent[m_cchUpdateParent] = '\0';
|
---|
2088 |
|
---|
2089 | pNode = pNode->papChildren[0];
|
---|
2090 | }
|
---|
2091 | Assert(pNode->enmType != STAMTYPE_INVALID);
|
---|
2092 | m_iUpdateChild = pNode->iSelf;
|
---|
2093 | m_pUpdateParent = pNode->pParent;
|
---|
2094 | Assert(pNode == pCorrectNext);
|
---|
2095 | }
|
---|
2096 | }
|
---|
2097 | /* else: we're at the end */
|
---|
2098 | }
|
---|
2099 |
|
---|
2100 |
|
---|
2101 | /*static*/ DECLCALLBACK(int)
|
---|
2102 | VBoxDbgStatsModel::updateCallback(const char *pszName, STAMTYPE enmType, void *pvSample, STAMUNIT enmUnit,
|
---|
2103 | const char *pszUnit, STAMVISIBILITY enmVisibility, const char *pszDesc, void *pvUser)
|
---|
2104 | {
|
---|
2105 | VBoxDbgStatsModelVM *pThis = (VBoxDbgStatsModelVM *)pvUser;
|
---|
2106 | Log3(("updateCallback: %s\n", pszName));
|
---|
2107 | RT_NOREF(enmUnit);
|
---|
2108 |
|
---|
2109 | /*
|
---|
2110 | * Skip the ones which shouldn't be visible in the GUI.
|
---|
2111 | */
|
---|
2112 | if (enmVisibility == STAMVISIBILITY_NOT_GUI)
|
---|
2113 | return 0;
|
---|
2114 |
|
---|
2115 | /*
|
---|
2116 | * The default assumption is that nothing has changed.
|
---|
2117 | * For now we'll reset the model when ever something changes.
|
---|
2118 | */
|
---|
2119 | PDBGGUISTATSNODE pNode;
|
---|
2120 | if (pThis->m_iUpdateChild != UINT32_MAX)
|
---|
2121 | {
|
---|
2122 | pNode = pThis->m_pUpdateParent->papChildren[pThis->m_iUpdateChild];
|
---|
2123 | if ( !strncmp(pszName, pThis->m_szUpdateParent, pThis->m_cchUpdateParent)
|
---|
2124 | && !strcmp(pszName + pThis->m_cchUpdateParent, pNode->pszName))
|
---|
2125 | /* got it! */;
|
---|
2126 | else
|
---|
2127 | {
|
---|
2128 | /* insert/remove */
|
---|
2129 | pNode = pThis->updateCallbackHandleOutOfOrder(pszName);
|
---|
2130 | if (!pNode)
|
---|
2131 | return VERR_NO_MEMORY;
|
---|
2132 | }
|
---|
2133 | }
|
---|
2134 | else
|
---|
2135 | {
|
---|
2136 | /* append */
|
---|
2137 | pNode = pThis->updateCallbackHandleTail(pszName);
|
---|
2138 | if (!pNode)
|
---|
2139 | return VERR_NO_MEMORY;
|
---|
2140 | }
|
---|
2141 |
|
---|
2142 | /*
|
---|
2143 | * Perform the update and advance to the next one.
|
---|
2144 | */
|
---|
2145 | updateNode(pNode, enmType, pvSample, pszUnit, pszDesc);
|
---|
2146 | pThis->updateCallbackAdvance(pNode);
|
---|
2147 |
|
---|
2148 | return VINF_SUCCESS;
|
---|
2149 | }
|
---|
2150 |
|
---|
2151 |
|
---|
2152 | bool
|
---|
2153 | VBoxDbgStatsModel::updatePrepare(PDBGGUISTATSNODE a_pSubTree /*= NULL*/)
|
---|
2154 | {
|
---|
2155 | /*
|
---|
2156 | * Find the first child with data and set it up as the 'next'
|
---|
2157 | * node to be updated.
|
---|
2158 | */
|
---|
2159 | PDBGGUISTATSNODE pFirst;
|
---|
2160 | Assert(m_pRoot);
|
---|
2161 | Assert(m_pRoot->enmType == STAMTYPE_INVALID);
|
---|
2162 | if (!a_pSubTree)
|
---|
2163 | pFirst = nextDataNode(m_pRoot);
|
---|
2164 | else
|
---|
2165 | pFirst = a_pSubTree->enmType != STAMTYPE_INVALID ? a_pSubTree : nextDataNode(a_pSubTree);
|
---|
2166 | if (pFirst)
|
---|
2167 | {
|
---|
2168 | m_iUpdateChild = pFirst->iSelf;
|
---|
2169 | m_pUpdateParent = pFirst->pParent; Assert(m_pUpdateParent);
|
---|
2170 | m_cchUpdateParent = getNodePath(m_pUpdateParent, m_szUpdateParent, sizeof(m_szUpdateParent) - 1);
|
---|
2171 | AssertReturn(m_cchUpdateParent >= 1, false);
|
---|
2172 | m_szUpdateParent[m_cchUpdateParent++] = '/';
|
---|
2173 | m_szUpdateParent[m_cchUpdateParent] = '\0';
|
---|
2174 | }
|
---|
2175 | else
|
---|
2176 | {
|
---|
2177 | m_iUpdateChild = UINT32_MAX;
|
---|
2178 | m_pUpdateParent = NULL;
|
---|
2179 | m_szUpdateParent[0] = '\0';
|
---|
2180 | m_cchUpdateParent = 0;
|
---|
2181 | }
|
---|
2182 |
|
---|
2183 | /*
|
---|
2184 | * Set the flag and signal possible layout change.
|
---|
2185 | */
|
---|
2186 | m_fUpdateInsertRemove = false;
|
---|
2187 | /* emit layoutAboutToBeChanged(); - debug this, it gets stuck... */
|
---|
2188 | return true;
|
---|
2189 | }
|
---|
2190 |
|
---|
2191 |
|
---|
2192 | bool
|
---|
2193 | VBoxDbgStatsModel::updateDone(bool a_fSuccess, PDBGGUISTATSNODE a_pSubTree /*= NULL*/)
|
---|
2194 | {
|
---|
2195 | /*
|
---|
2196 | * Remove any nodes following the last in the update (unless the update failed).
|
---|
2197 | */
|
---|
2198 | if ( a_fSuccess
|
---|
2199 | && m_iUpdateChild != UINT32_MAX
|
---|
2200 | && a_pSubTree == NULL)
|
---|
2201 | {
|
---|
2202 | PDBGGUISTATSNODE const pLast = prevDataNode(m_pUpdateParent->papChildren[m_iUpdateChild]);
|
---|
2203 | if (!pLast)
|
---|
2204 | {
|
---|
2205 | /* nuking the whole tree. */
|
---|
2206 | setRootNode(createRootNode());
|
---|
2207 | m_fUpdateInsertRemove = true;
|
---|
2208 | }
|
---|
2209 | else
|
---|
2210 | {
|
---|
2211 | PDBGGUISTATSNODE pNode;
|
---|
2212 | while ((pNode = nextNode(pLast)))
|
---|
2213 | {
|
---|
2214 | Assert(pNode != m_pRoot);
|
---|
2215 | removeAndDestroy(pNode);
|
---|
2216 | }
|
---|
2217 | }
|
---|
2218 | }
|
---|
2219 |
|
---|
2220 | /*
|
---|
2221 | * We're done making layout changes (if I understood it correctly), so,
|
---|
2222 | * signal this and then see what to do next. If we did too many removals
|
---|
2223 | * we'll just reset the whole shebang.
|
---|
2224 | */
|
---|
2225 | if (m_fUpdateInsertRemove)
|
---|
2226 | {
|
---|
2227 | #if 0 /* hrmpf, layoutChanged() didn't work reliably at some point so doing this as well... */
|
---|
2228 | beginResetModel();
|
---|
2229 | endResetModel();
|
---|
2230 | #else
|
---|
2231 | emit layoutChanged();
|
---|
2232 | #endif
|
---|
2233 | }
|
---|
2234 | else
|
---|
2235 | {
|
---|
2236 | /*
|
---|
2237 | * Send dataChanged events.
|
---|
2238 | *
|
---|
2239 | * We do this here instead of from the updateCallback because it reduces
|
---|
2240 | * the clutter in that method and allow us to emit bulk signals in an
|
---|
2241 | * easier way because we can traverse the tree in a different fashion.
|
---|
2242 | */
|
---|
2243 | DBGGUISTATSSTACK Stack;
|
---|
2244 | Stack.a[0].pNode = !a_pSubTree ? m_pRoot : a_pSubTree;
|
---|
2245 | Stack.a[0].iChild = -1;
|
---|
2246 | Stack.iTop = 0;
|
---|
2247 |
|
---|
2248 | while (Stack.iTop >= 0)
|
---|
2249 | {
|
---|
2250 | /* get top element */
|
---|
2251 | PDBGGUISTATSNODE pNode = Stack.a[Stack.iTop].pNode;
|
---|
2252 | uint32_t iChild = ++Stack.a[Stack.iTop].iChild;
|
---|
2253 | if (iChild < pNode->cChildren)
|
---|
2254 | {
|
---|
2255 | /* push */
|
---|
2256 | Stack.iTop++;
|
---|
2257 | Assert(Stack.iTop < (int32_t)RT_ELEMENTS(Stack.a));
|
---|
2258 | Stack.a[Stack.iTop].pNode = pNode->papChildren[iChild];
|
---|
2259 | Stack.a[Stack.iTop].iChild = -1;
|
---|
2260 | }
|
---|
2261 | else
|
---|
2262 | {
|
---|
2263 | /* pop */
|
---|
2264 | Stack.iTop--;
|
---|
2265 |
|
---|
2266 | /* do the actual work. */
|
---|
2267 | iChild = 0;
|
---|
2268 | while (iChild < pNode->cChildren)
|
---|
2269 | {
|
---|
2270 | /* skip to the first needing updating. */
|
---|
2271 | while ( iChild < pNode->cChildren
|
---|
2272 | && pNode->papChildren[iChild]->enmState != kDbgGuiStatsNodeState_kRefresh)
|
---|
2273 | iChild++;
|
---|
2274 | if (iChild >= pNode->cChildren)
|
---|
2275 | break;
|
---|
2276 | PDBGGUISTATSNODE pChild = pNode->papChildren[iChild];
|
---|
2277 | QModelIndex const TopLeft = createIndex(iChild, 2, pChild);
|
---|
2278 | pChild->enmState = kDbgGuiStatsNodeState_kVisible;
|
---|
2279 |
|
---|
2280 | /* Any subsequent nodes that also needs refreshing? */
|
---|
2281 | int const iRightCol = pChild->enmType != STAMTYPE_PROFILE && pChild->enmType != STAMTYPE_PROFILE_ADV ? 4 : 7;
|
---|
2282 | if (iRightCol == 4)
|
---|
2283 | while ( iChild + 1 < pNode->cChildren
|
---|
2284 | && (pChild = pNode->papChildren[iChild + 1])->enmState == kDbgGuiStatsNodeState_kRefresh
|
---|
2285 | && pChild->enmType != STAMTYPE_PROFILE
|
---|
2286 | && pChild->enmType != STAMTYPE_PROFILE_ADV)
|
---|
2287 | iChild++;
|
---|
2288 | else
|
---|
2289 | while ( iChild + 1 < pNode->cChildren
|
---|
2290 | && (pChild = pNode->papChildren[iChild + 1])->enmState == kDbgGuiStatsNodeState_kRefresh
|
---|
2291 | && ( pChild->enmType == STAMTYPE_PROFILE
|
---|
2292 | || pChild->enmType == STAMTYPE_PROFILE_ADV))
|
---|
2293 | iChild++;
|
---|
2294 |
|
---|
2295 | /* emit the refresh signal */
|
---|
2296 | QModelIndex const BottomRight = createIndex(iChild, iRightCol, pNode->papChildren[iChild]);
|
---|
2297 | emit dataChanged(TopLeft, BottomRight);
|
---|
2298 | iChild++;
|
---|
2299 | }
|
---|
2300 | }
|
---|
2301 | }
|
---|
2302 |
|
---|
2303 | /*
|
---|
2304 | * If a_pSubTree is not an intermediate node, invalidate it explicitly.
|
---|
2305 | */
|
---|
2306 | if (a_pSubTree && a_pSubTree->enmType != STAMTYPE_INVALID)
|
---|
2307 | {
|
---|
2308 | int const iRightCol = a_pSubTree->enmType != STAMTYPE_PROFILE && a_pSubTree->enmType != STAMTYPE_PROFILE_ADV
|
---|
2309 | ? 4 : 7;
|
---|
2310 | QModelIndex const BottomRight = createIndex(a_pSubTree->iSelf, iRightCol, a_pSubTree);
|
---|
2311 | QModelIndex const TopLeft = createIndex(a_pSubTree->iSelf, 2, a_pSubTree);
|
---|
2312 | emit dataChanged(TopLeft, BottomRight);
|
---|
2313 | }
|
---|
2314 | }
|
---|
2315 |
|
---|
2316 | return m_fUpdateInsertRemove;
|
---|
2317 | }
|
---|
2318 |
|
---|
2319 |
|
---|
2320 | bool
|
---|
2321 | VBoxDbgStatsModel::updateStatsByPattern(const QString &a_rPatStr, PDBGGUISTATSNODE a_pSubTree /*= NULL*/)
|
---|
2322 | {
|
---|
2323 | /* stub */
|
---|
2324 | RT_NOREF(a_rPatStr, a_pSubTree);
|
---|
2325 | return false;
|
---|
2326 | }
|
---|
2327 |
|
---|
2328 |
|
---|
2329 | void
|
---|
2330 | VBoxDbgStatsModel::updateStatsByIndex(QModelIndex const &a_rIndex)
|
---|
2331 | {
|
---|
2332 | PDBGGUISTATSNODE pNode = nodeFromIndex(a_rIndex);
|
---|
2333 | if (pNode == m_pRoot || !a_rIndex.isValid())
|
---|
2334 | updateStatsByPattern(QString());
|
---|
2335 | else if (pNode)
|
---|
2336 | /** @todo this doesn't quite work if pNode is excluded by the m_PatStr. */
|
---|
2337 | updateStatsByPattern(getNodePattern(pNode, true /*fSubTree*/), pNode);
|
---|
2338 | }
|
---|
2339 |
|
---|
2340 |
|
---|
2341 | void
|
---|
2342 | VBoxDbgStatsModel::resetStatsByPattern(QString const &a_rPatStr)
|
---|
2343 | {
|
---|
2344 | /* stub */
|
---|
2345 | NOREF(a_rPatStr);
|
---|
2346 | }
|
---|
2347 |
|
---|
2348 |
|
---|
2349 | void
|
---|
2350 | VBoxDbgStatsModel::resetStatsByIndex(QModelIndex const &a_rIndex, bool fSubTree /*= true*/)
|
---|
2351 | {
|
---|
2352 | PCDBGGUISTATSNODE pNode = nodeFromIndex(a_rIndex);
|
---|
2353 | if (pNode == m_pRoot || !a_rIndex.isValid())
|
---|
2354 | {
|
---|
2355 | /* The root can't be reset, so only take action if fSubTree is set. */
|
---|
2356 | if (fSubTree)
|
---|
2357 | resetStatsByPattern(QString());
|
---|
2358 | }
|
---|
2359 | else if (pNode)
|
---|
2360 | resetStatsByPattern(getNodePattern(pNode, fSubTree));
|
---|
2361 | }
|
---|
2362 |
|
---|
2363 |
|
---|
2364 | void
|
---|
2365 | VBoxDbgStatsModel::iterateStatsByPattern(QString const &a_rPatStr, VBoxDbgStatsModel::FNITERATOR *a_pfnCallback, void *a_pvUser,
|
---|
2366 | bool a_fMatchChildren /*= true*/)
|
---|
2367 | {
|
---|
2368 | const QByteArray &PatBytes = a_rPatStr.toUtf8();
|
---|
2369 | const char * const pszPattern = PatBytes.constData();
|
---|
2370 | size_t const cchPattern = strlen(pszPattern);
|
---|
2371 |
|
---|
2372 | DBGGUISTATSSTACK Stack;
|
---|
2373 | Stack.a[0].pNode = m_pRoot;
|
---|
2374 | Stack.a[0].iChild = 0;
|
---|
2375 | Stack.a[0].cchName = 0;
|
---|
2376 | Stack.iTop = 0;
|
---|
2377 |
|
---|
2378 | char szName[1024];
|
---|
2379 | szName[0] = '\0';
|
---|
2380 |
|
---|
2381 | while (Stack.iTop >= 0)
|
---|
2382 | {
|
---|
2383 | /* get top element */
|
---|
2384 | PDBGGUISTATSNODE const pNode = Stack.a[Stack.iTop].pNode;
|
---|
2385 | uint16_t cchName = Stack.a[Stack.iTop].cchName;
|
---|
2386 | uint32_t const iChild = Stack.a[Stack.iTop].iChild++;
|
---|
2387 | if (iChild < pNode->cChildren)
|
---|
2388 | {
|
---|
2389 | PDBGGUISTATSNODE pChild = pNode->papChildren[iChild];
|
---|
2390 |
|
---|
2391 | /* Build the name and match the pattern. */
|
---|
2392 | Assert(cchName + 1 + pChild->cchName < sizeof(szName));
|
---|
2393 | szName[cchName++] = '/';
|
---|
2394 | memcpy(&szName[cchName], pChild->pszName, pChild->cchName);
|
---|
2395 | cchName += (uint16_t)pChild->cchName;
|
---|
2396 | szName[cchName] = '\0';
|
---|
2397 |
|
---|
2398 | if (RTStrSimplePatternMultiMatch(pszPattern, cchPattern, szName, cchName, NULL))
|
---|
2399 | {
|
---|
2400 | /* Do callback. */
|
---|
2401 | QModelIndex const Index = createIndex(iChild, 0, pChild);
|
---|
2402 | if (!a_pfnCallback(pChild, Index, szName, a_pvUser))
|
---|
2403 | return;
|
---|
2404 | if (!a_fMatchChildren)
|
---|
2405 | continue;
|
---|
2406 | }
|
---|
2407 |
|
---|
2408 | /* push */
|
---|
2409 | Stack.iTop++;
|
---|
2410 | Assert(Stack.iTop < (int32_t)RT_ELEMENTS(Stack.a));
|
---|
2411 | Stack.a[Stack.iTop].pNode = pChild;
|
---|
2412 | Stack.a[Stack.iTop].iChild = 0;
|
---|
2413 | Stack.a[Stack.iTop].cchName = cchName;
|
---|
2414 | }
|
---|
2415 | else
|
---|
2416 | {
|
---|
2417 | /* pop */
|
---|
2418 | Stack.iTop--;
|
---|
2419 | }
|
---|
2420 | }
|
---|
2421 | }
|
---|
2422 |
|
---|
2423 |
|
---|
2424 | QModelIndex
|
---|
2425 | VBoxDbgStatsModel::getRootIndex(void) const
|
---|
2426 | {
|
---|
2427 | if (!m_pRoot)
|
---|
2428 | return QModelIndex();
|
---|
2429 | return createIndex(0, 0, m_pRoot);
|
---|
2430 | }
|
---|
2431 |
|
---|
2432 |
|
---|
2433 | void
|
---|
2434 | VBoxDbgStatsModel::setRootNode(PDBGGUISTATSNODE a_pRoot)
|
---|
2435 | {
|
---|
2436 | PDBGGUISTATSNODE pOldTree = m_pRoot;
|
---|
2437 | m_pRoot = a_pRoot;
|
---|
2438 | destroyTree(pOldTree);
|
---|
2439 | beginResetModel();
|
---|
2440 | endResetModel();
|
---|
2441 | }
|
---|
2442 |
|
---|
2443 |
|
---|
2444 | Qt::ItemFlags
|
---|
2445 | VBoxDbgStatsModel::flags(const QModelIndex &a_rIndex) const
|
---|
2446 | {
|
---|
2447 | Qt::ItemFlags fFlags = QAbstractItemModel::flags(a_rIndex);
|
---|
2448 | return fFlags;
|
---|
2449 | }
|
---|
2450 |
|
---|
2451 |
|
---|
2452 | int
|
---|
2453 | VBoxDbgStatsModel::columnCount(const QModelIndex &a_rParent) const
|
---|
2454 | {
|
---|
2455 | NOREF(a_rParent);
|
---|
2456 | return DBGGUI_STATS_COLUMNS;
|
---|
2457 | }
|
---|
2458 |
|
---|
2459 |
|
---|
2460 | int
|
---|
2461 | VBoxDbgStatsModel::rowCount(const QModelIndex &a_rParent) const
|
---|
2462 | {
|
---|
2463 | PDBGGUISTATSNODE pParent = nodeFromIndex(a_rParent);
|
---|
2464 | return pParent ? pParent->cChildren : 1 /* root */;
|
---|
2465 | }
|
---|
2466 |
|
---|
2467 |
|
---|
2468 | bool
|
---|
2469 | VBoxDbgStatsModel::hasChildren(const QModelIndex &a_rParent) const
|
---|
2470 | {
|
---|
2471 | PDBGGUISTATSNODE pParent = nodeFromIndex(a_rParent);
|
---|
2472 | return pParent ? pParent->cChildren > 0 : true /* root */;
|
---|
2473 | }
|
---|
2474 |
|
---|
2475 |
|
---|
2476 | QModelIndex
|
---|
2477 | VBoxDbgStatsModel::index(int iRow, int iColumn, const QModelIndex &a_rParent) const
|
---|
2478 | {
|
---|
2479 | PDBGGUISTATSNODE pParent = nodeFromIndex(a_rParent);
|
---|
2480 | if (pParent)
|
---|
2481 | {
|
---|
2482 | AssertMsgReturn((unsigned)iRow < pParent->cChildren,
|
---|
2483 | ("iRow=%d >= cChildren=%u (iColumn=%d)\n", iRow, (unsigned)pParent->cChildren, iColumn),
|
---|
2484 | QModelIndex());
|
---|
2485 | AssertMsgReturn((unsigned)iColumn < DBGGUI_STATS_COLUMNS, ("iColumn=%d (iRow=%d)\n", iColumn, iRow), QModelIndex());
|
---|
2486 |
|
---|
2487 | PDBGGUISTATSNODE pChild = pParent->papChildren[iRow];
|
---|
2488 | return createIndex(iRow, iColumn, pChild);
|
---|
2489 | }
|
---|
2490 |
|
---|
2491 | /* root? */
|
---|
2492 | AssertReturn(a_rParent.isValid() || (iRow == 0 && iColumn >= 0), QModelIndex());
|
---|
2493 | AssertMsgReturn(iRow == 0 && (unsigned)iColumn < DBGGUI_STATS_COLUMNS, ("iRow=%d iColumn=%d", iRow, iColumn), QModelIndex());
|
---|
2494 | return createIndex(0, iColumn, m_pRoot);
|
---|
2495 | }
|
---|
2496 |
|
---|
2497 |
|
---|
2498 | QModelIndex
|
---|
2499 | VBoxDbgStatsModel::parent(const QModelIndex &a_rChild) const
|
---|
2500 | {
|
---|
2501 | PDBGGUISTATSNODE pChild = nodeFromIndex(a_rChild);
|
---|
2502 | if (!pChild)
|
---|
2503 | {
|
---|
2504 | Log(("parent: invalid child\n"));
|
---|
2505 | return QModelIndex(); /* bug */
|
---|
2506 | }
|
---|
2507 | PDBGGUISTATSNODE pParent = pChild->pParent;
|
---|
2508 | if (!pParent)
|
---|
2509 | return QModelIndex(); /* ultimate root */
|
---|
2510 |
|
---|
2511 | return createIndex(pParent->iSelf, 0, pParent);
|
---|
2512 | }
|
---|
2513 |
|
---|
2514 |
|
---|
2515 | QVariant
|
---|
2516 | VBoxDbgStatsModel::headerData(int a_iSection, Qt::Orientation a_eOrientation, int a_eRole) const
|
---|
2517 | {
|
---|
2518 | if ( a_eOrientation == Qt::Horizontal
|
---|
2519 | && a_eRole == Qt::DisplayRole)
|
---|
2520 | switch (a_iSection)
|
---|
2521 | {
|
---|
2522 | case 0: return tr("Name");
|
---|
2523 | case 1: return tr("Unit");
|
---|
2524 | case 2: return tr("Value/Times");
|
---|
2525 | case 3: return tr("dInt");
|
---|
2526 | case 4: return tr("Min");
|
---|
2527 | case 5: return tr("Average");
|
---|
2528 | case 6: return tr("Max");
|
---|
2529 | case 7: return tr("Total");
|
---|
2530 | case 8: return tr("Description");
|
---|
2531 | default:
|
---|
2532 | AssertCompile(DBGGUI_STATS_COLUMNS == 9);
|
---|
2533 | return QVariant(); /* bug */
|
---|
2534 | }
|
---|
2535 | else if ( a_eOrientation == Qt::Horizontal
|
---|
2536 | && a_eRole == Qt::TextAlignmentRole)
|
---|
2537 | switch (a_iSection)
|
---|
2538 | {
|
---|
2539 | case 0:
|
---|
2540 | case 1:
|
---|
2541 | return QVariant();
|
---|
2542 | case 2:
|
---|
2543 | case 3:
|
---|
2544 | case 4:
|
---|
2545 | case 5:
|
---|
2546 | case 6:
|
---|
2547 | case 7:
|
---|
2548 | return (int)(Qt::AlignRight | Qt::AlignVCenter);
|
---|
2549 | case 8:
|
---|
2550 | return QVariant();
|
---|
2551 | default:
|
---|
2552 | AssertCompile(DBGGUI_STATS_COLUMNS == 9);
|
---|
2553 | return QVariant(); /* bug */
|
---|
2554 | }
|
---|
2555 |
|
---|
2556 | return QVariant();
|
---|
2557 | }
|
---|
2558 |
|
---|
2559 |
|
---|
2560 | /*static*/ QString
|
---|
2561 | VBoxDbgStatsModel::strUnit(PCDBGGUISTATSNODE pNode)
|
---|
2562 | {
|
---|
2563 | return pNode->pszUnit;
|
---|
2564 | }
|
---|
2565 |
|
---|
2566 |
|
---|
2567 | /*static*/ QString
|
---|
2568 | VBoxDbgStatsModel::strValueTimes(PCDBGGUISTATSNODE pNode)
|
---|
2569 | {
|
---|
2570 | char sz[128];
|
---|
2571 |
|
---|
2572 | switch (pNode->enmType)
|
---|
2573 | {
|
---|
2574 | case STAMTYPE_COUNTER:
|
---|
2575 | return formatNumber(sz, pNode->Data.Counter.c);
|
---|
2576 |
|
---|
2577 | case STAMTYPE_PROFILE:
|
---|
2578 | case STAMTYPE_PROFILE_ADV:
|
---|
2579 | return formatNumber(sz, pNode->Data.Profile.cPeriods);
|
---|
2580 |
|
---|
2581 | case STAMTYPE_RATIO_U32:
|
---|
2582 | case STAMTYPE_RATIO_U32_RESET:
|
---|
2583 | {
|
---|
2584 | char szTmp[64];
|
---|
2585 | char *psz = formatNumber(szTmp, pNode->Data.RatioU32.u32A);
|
---|
2586 | size_t off = strlen(psz);
|
---|
2587 | memcpy(sz, psz, off);
|
---|
2588 | sz[off++] = ':';
|
---|
2589 | strcpy(&sz[off], formatNumber(szTmp, pNode->Data.RatioU32.u32B));
|
---|
2590 | return sz;
|
---|
2591 | }
|
---|
2592 |
|
---|
2593 | case STAMTYPE_CALLBACK:
|
---|
2594 | return *pNode->Data.pStr;
|
---|
2595 |
|
---|
2596 | case STAMTYPE_U8:
|
---|
2597 | case STAMTYPE_U8_RESET:
|
---|
2598 | return formatNumber(sz, pNode->Data.u8);
|
---|
2599 |
|
---|
2600 | case STAMTYPE_X8:
|
---|
2601 | case STAMTYPE_X8_RESET:
|
---|
2602 | return formatHexNumber(sz, pNode->Data.u8, 2);
|
---|
2603 |
|
---|
2604 | case STAMTYPE_U16:
|
---|
2605 | case STAMTYPE_U16_RESET:
|
---|
2606 | return formatNumber(sz, pNode->Data.u16);
|
---|
2607 |
|
---|
2608 | case STAMTYPE_X16:
|
---|
2609 | case STAMTYPE_X16_RESET:
|
---|
2610 | return formatHexNumber(sz, pNode->Data.u16, 4);
|
---|
2611 |
|
---|
2612 | case STAMTYPE_U32:
|
---|
2613 | case STAMTYPE_U32_RESET:
|
---|
2614 | return formatNumber(sz, pNode->Data.u32);
|
---|
2615 |
|
---|
2616 | case STAMTYPE_X32:
|
---|
2617 | case STAMTYPE_X32_RESET:
|
---|
2618 | return formatHexNumber(sz, pNode->Data.u32, 8);
|
---|
2619 |
|
---|
2620 | case STAMTYPE_U64:
|
---|
2621 | case STAMTYPE_U64_RESET:
|
---|
2622 | return formatNumber(sz, pNode->Data.u64);
|
---|
2623 |
|
---|
2624 | case STAMTYPE_X64:
|
---|
2625 | case STAMTYPE_X64_RESET:
|
---|
2626 | return formatHexNumber(sz, pNode->Data.u64, 16);
|
---|
2627 |
|
---|
2628 | case STAMTYPE_BOOL:
|
---|
2629 | case STAMTYPE_BOOL_RESET:
|
---|
2630 | return pNode->Data.f ? "true" : "false";
|
---|
2631 |
|
---|
2632 | default:
|
---|
2633 | AssertMsgFailed(("%d\n", pNode->enmType));
|
---|
2634 | RT_FALL_THRU();
|
---|
2635 | case STAMTYPE_INVALID:
|
---|
2636 | return "";
|
---|
2637 | }
|
---|
2638 | }
|
---|
2639 |
|
---|
2640 |
|
---|
2641 | /*static*/ uint64_t
|
---|
2642 | VBoxDbgStatsModel::getValueTimesAsUInt(PCDBGGUISTATSNODE pNode)
|
---|
2643 | {
|
---|
2644 | switch (pNode->enmType)
|
---|
2645 | {
|
---|
2646 | case STAMTYPE_COUNTER:
|
---|
2647 | return pNode->Data.Counter.c;
|
---|
2648 |
|
---|
2649 | case STAMTYPE_PROFILE:
|
---|
2650 | case STAMTYPE_PROFILE_ADV:
|
---|
2651 | return pNode->Data.Profile.cPeriods;
|
---|
2652 |
|
---|
2653 | case STAMTYPE_RATIO_U32:
|
---|
2654 | case STAMTYPE_RATIO_U32_RESET:
|
---|
2655 | return RT_MAKE_U64(pNode->Data.RatioU32.u32A, pNode->Data.RatioU32.u32B);
|
---|
2656 |
|
---|
2657 | case STAMTYPE_CALLBACK:
|
---|
2658 | return UINT64_MAX;
|
---|
2659 |
|
---|
2660 | case STAMTYPE_U8:
|
---|
2661 | case STAMTYPE_U8_RESET:
|
---|
2662 | case STAMTYPE_X8:
|
---|
2663 | case STAMTYPE_X8_RESET:
|
---|
2664 | return pNode->Data.u8;
|
---|
2665 |
|
---|
2666 | case STAMTYPE_U16:
|
---|
2667 | case STAMTYPE_U16_RESET:
|
---|
2668 | case STAMTYPE_X16:
|
---|
2669 | case STAMTYPE_X16_RESET:
|
---|
2670 | return pNode->Data.u16;
|
---|
2671 |
|
---|
2672 | case STAMTYPE_U32:
|
---|
2673 | case STAMTYPE_U32_RESET:
|
---|
2674 | case STAMTYPE_X32:
|
---|
2675 | case STAMTYPE_X32_RESET:
|
---|
2676 | return pNode->Data.u32;
|
---|
2677 |
|
---|
2678 | case STAMTYPE_U64:
|
---|
2679 | case STAMTYPE_U64_RESET:
|
---|
2680 | case STAMTYPE_X64:
|
---|
2681 | case STAMTYPE_X64_RESET:
|
---|
2682 | return pNode->Data.u64;
|
---|
2683 |
|
---|
2684 | case STAMTYPE_BOOL:
|
---|
2685 | case STAMTYPE_BOOL_RESET:
|
---|
2686 | return pNode->Data.f;
|
---|
2687 |
|
---|
2688 | default:
|
---|
2689 | AssertMsgFailed(("%d\n", pNode->enmType));
|
---|
2690 | RT_FALL_THRU();
|
---|
2691 | case STAMTYPE_INVALID:
|
---|
2692 | return UINT64_MAX;
|
---|
2693 | }
|
---|
2694 | }
|
---|
2695 |
|
---|
2696 |
|
---|
2697 | /*static*/ uint64_t
|
---|
2698 | VBoxDbgStatsModel::getValueOrAvgAsUInt(PCDBGGUISTATSNODE pNode)
|
---|
2699 | {
|
---|
2700 | switch (pNode->enmType)
|
---|
2701 | {
|
---|
2702 | case STAMTYPE_COUNTER:
|
---|
2703 | return pNode->Data.Counter.c;
|
---|
2704 |
|
---|
2705 | case STAMTYPE_PROFILE:
|
---|
2706 | case STAMTYPE_PROFILE_ADV:
|
---|
2707 | if (pNode->Data.Profile.cPeriods)
|
---|
2708 | return pNode->Data.Profile.cTicks / pNode->Data.Profile.cPeriods;
|
---|
2709 | return 0;
|
---|
2710 |
|
---|
2711 | case STAMTYPE_RATIO_U32:
|
---|
2712 | case STAMTYPE_RATIO_U32_RESET:
|
---|
2713 | return RT_MAKE_U64(pNode->Data.RatioU32.u32A, pNode->Data.RatioU32.u32B);
|
---|
2714 |
|
---|
2715 | case STAMTYPE_CALLBACK:
|
---|
2716 | return UINT64_MAX;
|
---|
2717 |
|
---|
2718 | case STAMTYPE_U8:
|
---|
2719 | case STAMTYPE_U8_RESET:
|
---|
2720 | case STAMTYPE_X8:
|
---|
2721 | case STAMTYPE_X8_RESET:
|
---|
2722 | return pNode->Data.u8;
|
---|
2723 |
|
---|
2724 | case STAMTYPE_U16:
|
---|
2725 | case STAMTYPE_U16_RESET:
|
---|
2726 | case STAMTYPE_X16:
|
---|
2727 | case STAMTYPE_X16_RESET:
|
---|
2728 | return pNode->Data.u16;
|
---|
2729 |
|
---|
2730 | case STAMTYPE_U32:
|
---|
2731 | case STAMTYPE_U32_RESET:
|
---|
2732 | case STAMTYPE_X32:
|
---|
2733 | case STAMTYPE_X32_RESET:
|
---|
2734 | return pNode->Data.u32;
|
---|
2735 |
|
---|
2736 | case STAMTYPE_U64:
|
---|
2737 | case STAMTYPE_U64_RESET:
|
---|
2738 | case STAMTYPE_X64:
|
---|
2739 | case STAMTYPE_X64_RESET:
|
---|
2740 | return pNode->Data.u64;
|
---|
2741 |
|
---|
2742 | case STAMTYPE_BOOL:
|
---|
2743 | case STAMTYPE_BOOL_RESET:
|
---|
2744 | return pNode->Data.f;
|
---|
2745 |
|
---|
2746 | default:
|
---|
2747 | AssertMsgFailed(("%d\n", pNode->enmType));
|
---|
2748 | RT_FALL_THRU();
|
---|
2749 | case STAMTYPE_INVALID:
|
---|
2750 | return UINT64_MAX;
|
---|
2751 | }
|
---|
2752 | }
|
---|
2753 |
|
---|
2754 |
|
---|
2755 | /*static*/ QString
|
---|
2756 | VBoxDbgStatsModel::strMinValue(PCDBGGUISTATSNODE pNode)
|
---|
2757 | {
|
---|
2758 | char sz[128];
|
---|
2759 |
|
---|
2760 | switch (pNode->enmType)
|
---|
2761 | {
|
---|
2762 | case STAMTYPE_PROFILE:
|
---|
2763 | case STAMTYPE_PROFILE_ADV:
|
---|
2764 | if (pNode->Data.Profile.cPeriods)
|
---|
2765 | return formatNumber(sz, pNode->Data.Profile.cTicksMin);
|
---|
2766 | return "0"; /* cTicksMin is set to UINT64_MAX */
|
---|
2767 | default:
|
---|
2768 | return "";
|
---|
2769 | }
|
---|
2770 | }
|
---|
2771 |
|
---|
2772 |
|
---|
2773 | /*static*/ uint64_t
|
---|
2774 | VBoxDbgStatsModel::getMinValueAsUInt(PCDBGGUISTATSNODE pNode)
|
---|
2775 | {
|
---|
2776 | switch (pNode->enmType)
|
---|
2777 | {
|
---|
2778 | case STAMTYPE_PROFILE:
|
---|
2779 | case STAMTYPE_PROFILE_ADV:
|
---|
2780 | if (pNode->Data.Profile.cPeriods)
|
---|
2781 | return pNode->Data.Profile.cTicksMin;
|
---|
2782 | return 0; /* cTicksMin is set to UINT64_MAX */
|
---|
2783 | default:
|
---|
2784 | return UINT64_MAX;
|
---|
2785 | }
|
---|
2786 | }
|
---|
2787 |
|
---|
2788 |
|
---|
2789 | /*static*/ QString
|
---|
2790 | VBoxDbgStatsModel::strAvgValue(PCDBGGUISTATSNODE pNode)
|
---|
2791 | {
|
---|
2792 | char sz[128];
|
---|
2793 |
|
---|
2794 | switch (pNode->enmType)
|
---|
2795 | {
|
---|
2796 | case STAMTYPE_PROFILE:
|
---|
2797 | case STAMTYPE_PROFILE_ADV:
|
---|
2798 | if (pNode->Data.Profile.cPeriods)
|
---|
2799 | return formatNumber(sz, pNode->Data.Profile.cTicks / pNode->Data.Profile.cPeriods);
|
---|
2800 | return "0";
|
---|
2801 | default:
|
---|
2802 | return "";
|
---|
2803 | }
|
---|
2804 | }
|
---|
2805 |
|
---|
2806 |
|
---|
2807 | /*static*/ uint64_t
|
---|
2808 | VBoxDbgStatsModel::getAvgValueAsUInt(PCDBGGUISTATSNODE pNode)
|
---|
2809 | {
|
---|
2810 | switch (pNode->enmType)
|
---|
2811 | {
|
---|
2812 | case STAMTYPE_PROFILE:
|
---|
2813 | case STAMTYPE_PROFILE_ADV:
|
---|
2814 | if (pNode->Data.Profile.cPeriods)
|
---|
2815 | return pNode->Data.Profile.cTicks / pNode->Data.Profile.cPeriods;
|
---|
2816 | return 0;
|
---|
2817 | default:
|
---|
2818 | return UINT64_MAX;
|
---|
2819 | }
|
---|
2820 | }
|
---|
2821 |
|
---|
2822 |
|
---|
2823 |
|
---|
2824 | /*static*/ QString
|
---|
2825 | VBoxDbgStatsModel::strMaxValue(PCDBGGUISTATSNODE pNode)
|
---|
2826 | {
|
---|
2827 | char sz[128];
|
---|
2828 |
|
---|
2829 | switch (pNode->enmType)
|
---|
2830 | {
|
---|
2831 | case STAMTYPE_PROFILE:
|
---|
2832 | case STAMTYPE_PROFILE_ADV:
|
---|
2833 | return formatNumber(sz, pNode->Data.Profile.cTicksMax);
|
---|
2834 | default:
|
---|
2835 | return "";
|
---|
2836 | }
|
---|
2837 | }
|
---|
2838 |
|
---|
2839 |
|
---|
2840 | /*static*/ uint64_t
|
---|
2841 | VBoxDbgStatsModel::getMaxValueAsUInt(PCDBGGUISTATSNODE pNode)
|
---|
2842 | {
|
---|
2843 | switch (pNode->enmType)
|
---|
2844 | {
|
---|
2845 | case STAMTYPE_PROFILE:
|
---|
2846 | case STAMTYPE_PROFILE_ADV:
|
---|
2847 | return pNode->Data.Profile.cTicksMax;
|
---|
2848 | default:
|
---|
2849 | return UINT64_MAX;
|
---|
2850 | }
|
---|
2851 | }
|
---|
2852 |
|
---|
2853 |
|
---|
2854 | /*static*/ QString
|
---|
2855 | VBoxDbgStatsModel::strTotalValue(PCDBGGUISTATSNODE pNode)
|
---|
2856 | {
|
---|
2857 | char sz[128];
|
---|
2858 |
|
---|
2859 | switch (pNode->enmType)
|
---|
2860 | {
|
---|
2861 | case STAMTYPE_PROFILE:
|
---|
2862 | case STAMTYPE_PROFILE_ADV:
|
---|
2863 | return formatNumber(sz, pNode->Data.Profile.cTicks);
|
---|
2864 | default:
|
---|
2865 | return "";
|
---|
2866 | }
|
---|
2867 | }
|
---|
2868 |
|
---|
2869 |
|
---|
2870 | /*static*/ uint64_t
|
---|
2871 | VBoxDbgStatsModel::getTotalValueAsUInt(PCDBGGUISTATSNODE pNode)
|
---|
2872 | {
|
---|
2873 | switch (pNode->enmType)
|
---|
2874 | {
|
---|
2875 | case STAMTYPE_PROFILE:
|
---|
2876 | case STAMTYPE_PROFILE_ADV:
|
---|
2877 | return pNode->Data.Profile.cTicks;
|
---|
2878 | default:
|
---|
2879 | return UINT64_MAX;
|
---|
2880 | }
|
---|
2881 | }
|
---|
2882 |
|
---|
2883 |
|
---|
2884 | /*static*/ QString
|
---|
2885 | VBoxDbgStatsModel::strDeltaValue(PCDBGGUISTATSNODE pNode)
|
---|
2886 | {
|
---|
2887 | switch (pNode->enmType)
|
---|
2888 | {
|
---|
2889 | case STAMTYPE_PROFILE:
|
---|
2890 | case STAMTYPE_PROFILE_ADV:
|
---|
2891 | case STAMTYPE_COUNTER:
|
---|
2892 | case STAMTYPE_RATIO_U32:
|
---|
2893 | case STAMTYPE_RATIO_U32_RESET:
|
---|
2894 | case STAMTYPE_U8:
|
---|
2895 | case STAMTYPE_U8_RESET:
|
---|
2896 | case STAMTYPE_X8:
|
---|
2897 | case STAMTYPE_X8_RESET:
|
---|
2898 | case STAMTYPE_U16:
|
---|
2899 | case STAMTYPE_U16_RESET:
|
---|
2900 | case STAMTYPE_X16:
|
---|
2901 | case STAMTYPE_X16_RESET:
|
---|
2902 | case STAMTYPE_U32:
|
---|
2903 | case STAMTYPE_U32_RESET:
|
---|
2904 | case STAMTYPE_X32:
|
---|
2905 | case STAMTYPE_X32_RESET:
|
---|
2906 | case STAMTYPE_U64:
|
---|
2907 | case STAMTYPE_U64_RESET:
|
---|
2908 | case STAMTYPE_X64:
|
---|
2909 | case STAMTYPE_X64_RESET:
|
---|
2910 | case STAMTYPE_BOOL:
|
---|
2911 | case STAMTYPE_BOOL_RESET:
|
---|
2912 | if (pNode->i64Delta)
|
---|
2913 | {
|
---|
2914 | char sz[128];
|
---|
2915 | return formatNumberSigned(sz, pNode->i64Delta, true /*fPositivePlus*/);
|
---|
2916 | }
|
---|
2917 | return "0";
|
---|
2918 | case STAMTYPE_INTERNAL_SUM:
|
---|
2919 | case STAMTYPE_INTERNAL_PCT_OF_SUM:
|
---|
2920 | case STAMTYPE_END:
|
---|
2921 | AssertFailed(); RT_FALL_THRU();
|
---|
2922 | case STAMTYPE_CALLBACK:
|
---|
2923 | case STAMTYPE_INVALID:
|
---|
2924 | break;
|
---|
2925 | }
|
---|
2926 | return "";
|
---|
2927 | }
|
---|
2928 |
|
---|
2929 |
|
---|
2930 | QVariant
|
---|
2931 | VBoxDbgStatsModel::data(const QModelIndex &a_rIndex, int a_eRole) const
|
---|
2932 | {
|
---|
2933 | unsigned iCol = a_rIndex.column();
|
---|
2934 | AssertMsgReturn(iCol < DBGGUI_STATS_COLUMNS, ("%d\n", iCol), QVariant());
|
---|
2935 | Log4(("Model::data(%p(%d,%d), %d)\n", nodeFromIndex(a_rIndex), iCol, a_rIndex.row(), a_eRole));
|
---|
2936 |
|
---|
2937 | if (a_eRole == Qt::DisplayRole)
|
---|
2938 | {
|
---|
2939 | PDBGGUISTATSNODE pNode = nodeFromIndex(a_rIndex);
|
---|
2940 | AssertReturn(pNode, QVariant());
|
---|
2941 |
|
---|
2942 | switch (iCol)
|
---|
2943 | {
|
---|
2944 | case 0:
|
---|
2945 | if (!pNode->pFilter)
|
---|
2946 | return QString(pNode->pszName);
|
---|
2947 | return QString(pNode->pszName) + " (*)";
|
---|
2948 | case 1:
|
---|
2949 | return strUnit(pNode);
|
---|
2950 | case 2:
|
---|
2951 | return strValueTimes(pNode);
|
---|
2952 | case 3:
|
---|
2953 | return strDeltaValue(pNode);
|
---|
2954 | case 4:
|
---|
2955 | return strMinValue(pNode);
|
---|
2956 | case 5:
|
---|
2957 | return strAvgValue(pNode);
|
---|
2958 | case 6:
|
---|
2959 | return strMaxValue(pNode);
|
---|
2960 | case 7:
|
---|
2961 | return strTotalValue(pNode);
|
---|
2962 | case 8:
|
---|
2963 | return pNode->pDescStr ? QString(*pNode->pDescStr) : QString("");
|
---|
2964 | default:
|
---|
2965 | AssertCompile(DBGGUI_STATS_COLUMNS == 9);
|
---|
2966 | return QVariant();
|
---|
2967 | }
|
---|
2968 | }
|
---|
2969 | else if (a_eRole == Qt::TextAlignmentRole)
|
---|
2970 | switch (iCol)
|
---|
2971 | {
|
---|
2972 | case 0:
|
---|
2973 | case 1:
|
---|
2974 | return QVariant();
|
---|
2975 | case 2:
|
---|
2976 | case 3:
|
---|
2977 | case 4:
|
---|
2978 | case 5:
|
---|
2979 | case 6:
|
---|
2980 | case 7:
|
---|
2981 | return (int)(Qt::AlignRight | Qt::AlignVCenter);
|
---|
2982 | case 8:
|
---|
2983 | return QVariant();
|
---|
2984 | default:
|
---|
2985 | AssertCompile(DBGGUI_STATS_COLUMNS == 9);
|
---|
2986 | return QVariant(); /* bug */
|
---|
2987 | }
|
---|
2988 | return QVariant();
|
---|
2989 | }
|
---|
2990 |
|
---|
2991 |
|
---|
2992 | /*static*/ void
|
---|
2993 | VBoxDbgStatsModel::stringifyNodeNoRecursion(PDBGGUISTATSNODE a_pNode, QString &a_rString, size_t a_cchNameWidth)
|
---|
2994 | {
|
---|
2995 | /*
|
---|
2996 | * Get the path, padding it to 32-chars and add it to the string.
|
---|
2997 | */
|
---|
2998 | char szBuf[1024];
|
---|
2999 | ssize_t off = getNodePath(a_pNode, szBuf, sizeof(szBuf) - 2);
|
---|
3000 | AssertReturnVoid(off >= 0);
|
---|
3001 | szBuf[off++] = ' ';
|
---|
3002 | ssize_t cchPadding = (ssize_t)(a_cchNameWidth - a_pNode->cchName);
|
---|
3003 | if (off < 32 && 32 - off > cchPadding)
|
---|
3004 | cchPadding = 32 - off;
|
---|
3005 | if (cchPadding > 0)
|
---|
3006 | {
|
---|
3007 | if (off + (size_t)cchPadding + 1 >= sizeof(szBuf))
|
---|
3008 | cchPadding = sizeof(szBuf) - off - 1;
|
---|
3009 | if (cchPadding > 0)
|
---|
3010 | {
|
---|
3011 | memset(&szBuf[off], ' ', cchPadding);
|
---|
3012 | off += (size_t)cchPadding;
|
---|
3013 | }
|
---|
3014 | }
|
---|
3015 | szBuf[off] = '\0';
|
---|
3016 | a_rString += szBuf;
|
---|
3017 |
|
---|
3018 | /*
|
---|
3019 | * The following is derived from stamR3PrintOne, except
|
---|
3020 | * we print to szBuf, do no visibility checks and can skip
|
---|
3021 | * the path bit.
|
---|
3022 | */
|
---|
3023 | switch (a_pNode->enmType)
|
---|
3024 | {
|
---|
3025 | case STAMTYPE_COUNTER:
|
---|
3026 | RTStrPrintf(szBuf, sizeof(szBuf), "%'11llu %s", a_pNode->Data.Counter.c, a_pNode->pszUnit);
|
---|
3027 | break;
|
---|
3028 |
|
---|
3029 | case STAMTYPE_PROFILE:
|
---|
3030 | case STAMTYPE_PROFILE_ADV:
|
---|
3031 | {
|
---|
3032 | uint64_t u64 = a_pNode->Data.Profile.cPeriods ? a_pNode->Data.Profile.cPeriods : 1;
|
---|
3033 | RTStrPrintf(szBuf, sizeof(szBuf),
|
---|
3034 | "%'11llu %s (%'14llu ticks, %'9llu times, max %'12llu, min %'9lld)",
|
---|
3035 | a_pNode->Data.Profile.cTicks / u64, a_pNode->pszUnit,
|
---|
3036 | a_pNode->Data.Profile.cTicks, a_pNode->Data.Profile.cPeriods,
|
---|
3037 | a_pNode->Data.Profile.cTicksMax, a_pNode->Data.Profile.cTicksMin);
|
---|
3038 | break;
|
---|
3039 | }
|
---|
3040 |
|
---|
3041 | case STAMTYPE_RATIO_U32:
|
---|
3042 | case STAMTYPE_RATIO_U32_RESET:
|
---|
3043 | RTStrPrintf(szBuf, sizeof(szBuf),
|
---|
3044 | "%'8u:%-'8u %s",
|
---|
3045 | a_pNode->Data.RatioU32.u32A, a_pNode->Data.RatioU32.u32B, a_pNode->pszUnit);
|
---|
3046 | break;
|
---|
3047 |
|
---|
3048 | case STAMTYPE_CALLBACK:
|
---|
3049 | if (a_pNode->Data.pStr)
|
---|
3050 | a_rString += *a_pNode->Data.pStr;
|
---|
3051 | RTStrPrintf(szBuf, sizeof(szBuf), " %s", a_pNode->pszUnit);
|
---|
3052 | break;
|
---|
3053 |
|
---|
3054 | case STAMTYPE_U8:
|
---|
3055 | case STAMTYPE_U8_RESET:
|
---|
3056 | RTStrPrintf(szBuf, sizeof(szBuf), "%11u %s", a_pNode->Data.u8, a_pNode->pszUnit);
|
---|
3057 | break;
|
---|
3058 |
|
---|
3059 | case STAMTYPE_X8:
|
---|
3060 | case STAMTYPE_X8_RESET:
|
---|
3061 | RTStrPrintf(szBuf, sizeof(szBuf), "%11x %s", a_pNode->Data.u8, a_pNode->pszUnit);
|
---|
3062 | break;
|
---|
3063 |
|
---|
3064 | case STAMTYPE_U16:
|
---|
3065 | case STAMTYPE_U16_RESET:
|
---|
3066 | RTStrPrintf(szBuf, sizeof(szBuf), "%'11u %s", a_pNode->Data.u16, a_pNode->pszUnit);
|
---|
3067 | break;
|
---|
3068 |
|
---|
3069 | case STAMTYPE_X16:
|
---|
3070 | case STAMTYPE_X16_RESET:
|
---|
3071 | RTStrPrintf(szBuf, sizeof(szBuf), "%11x %s", a_pNode->Data.u16, a_pNode->pszUnit);
|
---|
3072 | break;
|
---|
3073 |
|
---|
3074 | case STAMTYPE_U32:
|
---|
3075 | case STAMTYPE_U32_RESET:
|
---|
3076 | RTStrPrintf(szBuf, sizeof(szBuf), "%'11u %s", a_pNode->Data.u32, a_pNode->pszUnit);
|
---|
3077 | break;
|
---|
3078 |
|
---|
3079 | case STAMTYPE_X32:
|
---|
3080 | case STAMTYPE_X32_RESET:
|
---|
3081 | RTStrPrintf(szBuf, sizeof(szBuf), "%11x %s", a_pNode->Data.u32, a_pNode->pszUnit);
|
---|
3082 | break;
|
---|
3083 |
|
---|
3084 | case STAMTYPE_U64:
|
---|
3085 | case STAMTYPE_U64_RESET:
|
---|
3086 | RTStrPrintf(szBuf, sizeof(szBuf), "%'11llu %s", a_pNode->Data.u64, a_pNode->pszUnit);
|
---|
3087 | break;
|
---|
3088 |
|
---|
3089 | case STAMTYPE_X64:
|
---|
3090 | case STAMTYPE_X64_RESET:
|
---|
3091 | RTStrPrintf(szBuf, sizeof(szBuf), "%'11llx %s", a_pNode->Data.u64, a_pNode->pszUnit);
|
---|
3092 | break;
|
---|
3093 |
|
---|
3094 | case STAMTYPE_BOOL:
|
---|
3095 | case STAMTYPE_BOOL_RESET:
|
---|
3096 | RTStrPrintf(szBuf, sizeof(szBuf), "%s %s", a_pNode->Data.f ? "true " : "false ", a_pNode->pszUnit);
|
---|
3097 | break;
|
---|
3098 |
|
---|
3099 | default:
|
---|
3100 | AssertMsgFailed(("enmType=%d\n", a_pNode->enmType));
|
---|
3101 | return;
|
---|
3102 | }
|
---|
3103 |
|
---|
3104 | a_rString += szBuf;
|
---|
3105 | }
|
---|
3106 |
|
---|
3107 |
|
---|
3108 | /*static*/ void
|
---|
3109 | VBoxDbgStatsModel::stringifyNode(PDBGGUISTATSNODE a_pNode, QString &a_rString, size_t a_cchNameWidth)
|
---|
3110 | {
|
---|
3111 | /* this node (if it has data) */
|
---|
3112 | if (a_pNode->enmType != STAMTYPE_INVALID)
|
---|
3113 | {
|
---|
3114 | if (!a_rString.isEmpty())
|
---|
3115 | a_rString += "\n";
|
---|
3116 | stringifyNodeNoRecursion(a_pNode, a_rString, a_cchNameWidth);
|
---|
3117 | }
|
---|
3118 |
|
---|
3119 | /* the children */
|
---|
3120 | uint32_t const cChildren = a_pNode->cChildren;
|
---|
3121 | a_cchNameWidth = 0;
|
---|
3122 | for (uint32_t i = 0; i < cChildren; i++)
|
---|
3123 | if (a_cchNameWidth < a_pNode->papChildren[i]->cchName)
|
---|
3124 | a_cchNameWidth = a_pNode->papChildren[i]->cchName;
|
---|
3125 | for (uint32_t i = 0; i < cChildren; i++)
|
---|
3126 | stringifyNode(a_pNode->papChildren[i], a_rString, a_cchNameWidth);
|
---|
3127 | }
|
---|
3128 |
|
---|
3129 |
|
---|
3130 | void
|
---|
3131 | VBoxDbgStatsModel::stringifyTree(QModelIndex &a_rRoot, QString &a_rString) const
|
---|
3132 | {
|
---|
3133 | PDBGGUISTATSNODE pRoot = a_rRoot.isValid() ? nodeFromIndex(a_rRoot) : m_pRoot;
|
---|
3134 | if (pRoot)
|
---|
3135 | stringifyNode(pRoot, a_rString, 0);
|
---|
3136 | }
|
---|
3137 |
|
---|
3138 |
|
---|
3139 | void
|
---|
3140 | VBoxDbgStatsModel::loadFilterConfig(const char *a_pszConfig)
|
---|
3141 | {
|
---|
3142 | /* Skip empty stuff. */
|
---|
3143 | if (!a_pszConfig)
|
---|
3144 | return;
|
---|
3145 | a_pszConfig = RTStrStripL(a_pszConfig);
|
---|
3146 | if (!*a_pszConfig)
|
---|
3147 | return;
|
---|
3148 |
|
---|
3149 | /*
|
---|
3150 | * The list elements are separated by colons. Paths must start with '/' to
|
---|
3151 | * be accepted as such.
|
---|
3152 | *
|
---|
3153 | * Example: "/;min=123;max=9348;name='.*cmp.*';/CPUM;"
|
---|
3154 | */
|
---|
3155 | char * const pszDup = RTStrDup(a_pszConfig);
|
---|
3156 | AssertReturnVoid(pszDup);
|
---|
3157 | char *psz = pszDup;
|
---|
3158 | const char *pszPath = NULL;
|
---|
3159 | VBoxGuiStatsFilterData Data;
|
---|
3160 | do
|
---|
3161 | {
|
---|
3162 | /* Split out this item, strip it and move 'psz' to the next one. */
|
---|
3163 | char *pszItem = psz;
|
---|
3164 | psz = strchr(psz, ';');
|
---|
3165 | if (psz)
|
---|
3166 | *psz++ = '\0';
|
---|
3167 | else
|
---|
3168 | psz = strchr(psz, '\0');
|
---|
3169 | pszItem = RTStrStrip(pszItem);
|
---|
3170 |
|
---|
3171 | /* Is it a path or a variable=value pair. */
|
---|
3172 | if (*pszItem == '/')
|
---|
3173 | {
|
---|
3174 | if (pszPath && !Data.isAllDefaults())
|
---|
3175 | m_FilterHash[QString(pszPath)] = Data.duplicate();
|
---|
3176 | Data.reset();
|
---|
3177 | pszPath = pszItem;
|
---|
3178 | }
|
---|
3179 | else
|
---|
3180 | {
|
---|
3181 | /* Split out the value, if any. */
|
---|
3182 | char *pszValue = strchr(pszItem, '=');
|
---|
3183 | if (pszValue)
|
---|
3184 | {
|
---|
3185 | *pszValue++ = '\0';
|
---|
3186 | pszValue = RTStrStripL(pszValue);
|
---|
3187 | RTStrStripR(pszItem);
|
---|
3188 |
|
---|
3189 | /* Switch on the variable name. */
|
---|
3190 | uint64_t const uValue = RTStrToUInt64(pszValue);
|
---|
3191 | if (strcmp(pszItem, "min") == 0)
|
---|
3192 | Data.uMinValue = uValue;
|
---|
3193 | else if (strcmp(pszItem, "max") == 0)
|
---|
3194 | Data.uMaxValue = uValue != 0 ? uValue : UINT64_MAX;
|
---|
3195 | else if (strcmp(pszItem, "name") == 0)
|
---|
3196 | {
|
---|
3197 | if (!Data.pRegexName)
|
---|
3198 | Data.pRegexName = new QRegularExpression(QString(pszValue));
|
---|
3199 | else
|
---|
3200 | Data.pRegexName->setPattern(QString(pszValue));
|
---|
3201 | if (!Data.pRegexName->isValid())
|
---|
3202 | {
|
---|
3203 | delete Data.pRegexName;
|
---|
3204 | Data.pRegexName = NULL;
|
---|
3205 | }
|
---|
3206 | }
|
---|
3207 | }
|
---|
3208 | /* else: Currently no variables w/o values. */
|
---|
3209 | }
|
---|
3210 | } while (*psz != '\0');
|
---|
3211 |
|
---|
3212 | /* Add the final entry, if any. */
|
---|
3213 | if (pszPath && !Data.isAllDefaults())
|
---|
3214 | m_FilterHash[QString(pszPath)] = Data.duplicate();
|
---|
3215 |
|
---|
3216 | RTStrFree(pszDup);
|
---|
3217 | }
|
---|
3218 |
|
---|
3219 |
|
---|
3220 |
|
---|
3221 |
|
---|
3222 |
|
---|
3223 | /*
|
---|
3224 | *
|
---|
3225 | * V B o x D b g S t a t s M o d e l V M
|
---|
3226 | * V B o x D b g S t a t s M o d e l V M
|
---|
3227 | * V B o x D b g S t a t s M o d e l V M
|
---|
3228 | *
|
---|
3229 | *
|
---|
3230 | */
|
---|
3231 |
|
---|
3232 |
|
---|
3233 | VBoxDbgStatsModelVM::VBoxDbgStatsModelVM(VBoxDbgGui *a_pDbgGui, QString &a_rPatStr, const char *a_pszConfig,
|
---|
3234 | PCVMMR3VTABLE a_pVMM, QObject *a_pParent /*= NULL*/)
|
---|
3235 | : VBoxDbgStatsModel(a_pszConfig, a_pParent), VBoxDbgBase(a_pDbgGui), m_pVMM(a_pVMM)
|
---|
3236 | {
|
---|
3237 | /*
|
---|
3238 | * Create a model containing the STAM entries matching the pattern.
|
---|
3239 | * (The original idea was to get everything and rely on some hide/visible
|
---|
3240 | * flag that it turned out didn't exist.)
|
---|
3241 | */
|
---|
3242 | PDBGGUISTATSNODE pTree = createNewTree(a_rPatStr);
|
---|
3243 | setRootNode(pTree);
|
---|
3244 | }
|
---|
3245 |
|
---|
3246 |
|
---|
3247 | VBoxDbgStatsModelVM::~VBoxDbgStatsModelVM()
|
---|
3248 | {
|
---|
3249 | /* nothing to do here. */
|
---|
3250 | }
|
---|
3251 |
|
---|
3252 |
|
---|
3253 | bool
|
---|
3254 | VBoxDbgStatsModelVM::updateStatsByPattern(const QString &a_rPatStr, PDBGGUISTATSNODE a_pSubTree /*= NULL*/)
|
---|
3255 | {
|
---|
3256 | /** @todo the way we update this stuff is independent of the source (XML, file, STAM), our only
|
---|
3257 | * ASSUMPTION is that the input is strictly ordered by (fully slashed) name. So, all this stuff
|
---|
3258 | * should really move up into the parent class. */
|
---|
3259 | bool fRc = updatePrepare(a_pSubTree);
|
---|
3260 | if (fRc)
|
---|
3261 | {
|
---|
3262 | int rc = stamEnum(a_rPatStr, updateCallback, this);
|
---|
3263 | fRc = updateDone(RT_SUCCESS(rc), a_pSubTree);
|
---|
3264 | }
|
---|
3265 | return fRc;
|
---|
3266 | }
|
---|
3267 |
|
---|
3268 |
|
---|
3269 | void
|
---|
3270 | VBoxDbgStatsModelVM::resetStatsByPattern(QString const &a_rPatStr)
|
---|
3271 | {
|
---|
3272 | stamReset(a_rPatStr);
|
---|
3273 | }
|
---|
3274 |
|
---|
3275 |
|
---|
3276 | /*static*/ DECLCALLBACK(int)
|
---|
3277 | VBoxDbgStatsModelVM::createNewTreeCallback(const char *pszName, STAMTYPE enmType, void *pvSample, STAMUNIT enmUnit,
|
---|
3278 | const char *pszUnit, STAMVISIBILITY enmVisibility, const char *pszDesc, void *pvUser)
|
---|
3279 | {
|
---|
3280 | CreateNewTreeCallbackArgs_T * const pArgs = (CreateNewTreeCallbackArgs_T *)pvUser;
|
---|
3281 | Log3(("createNewTreeCallback: %s\n", pszName));
|
---|
3282 | RT_NOREF(enmUnit);
|
---|
3283 |
|
---|
3284 | /*
|
---|
3285 | * Skip the ones which shouldn't be visible in the GUI.
|
---|
3286 | */
|
---|
3287 | if (enmVisibility == STAMVISIBILITY_NOT_GUI)
|
---|
3288 | return 0;
|
---|
3289 |
|
---|
3290 | /*
|
---|
3291 | * Perform a mkdir -p like operation till we've walked / created the entire path down
|
---|
3292 | * to the node specfied node. Remember the last node as that will be the one we will
|
---|
3293 | * stuff the data into.
|
---|
3294 | */
|
---|
3295 | AssertReturn(*pszName == '/' && pszName[1] != '/', VERR_INTERNAL_ERROR);
|
---|
3296 | PDBGGUISTATSNODE pNode = pArgs->pRoot;
|
---|
3297 | const char *pszCur = pszName + 1;
|
---|
3298 | while (*pszCur)
|
---|
3299 | {
|
---|
3300 | /* find the end of this component. */
|
---|
3301 | const char *pszNext = strchr(pszCur, '/');
|
---|
3302 | if (!pszNext)
|
---|
3303 | pszNext = strchr(pszCur, '\0');
|
---|
3304 | size_t cchCur = pszNext - pszCur;
|
---|
3305 |
|
---|
3306 | /* Create it if it doesn't exist (it will be last if it exists). */
|
---|
3307 | if ( !pNode->cChildren
|
---|
3308 | || strncmp(pNode->papChildren[pNode->cChildren - 1]->pszName, pszCur, cchCur)
|
---|
3309 | || pNode->papChildren[pNode->cChildren - 1]->pszName[cchCur])
|
---|
3310 | {
|
---|
3311 | pNode = pArgs->pThis->createAndInsertNode(pNode, pszCur, pszNext - pszCur, UINT32_MAX, pszName, pszNext - pszName);
|
---|
3312 | if (!pNode)
|
---|
3313 | return VERR_NO_MEMORY;
|
---|
3314 | }
|
---|
3315 | else
|
---|
3316 | pNode = pNode->papChildren[pNode->cChildren - 1];
|
---|
3317 |
|
---|
3318 | /* Advance */
|
---|
3319 | pszCur = *pszNext ? pszNext + 1 : pszNext;
|
---|
3320 | }
|
---|
3321 |
|
---|
3322 | /*
|
---|
3323 | * Save the data.
|
---|
3324 | */
|
---|
3325 | return initNode(pNode, enmType, pvSample, pszUnit, pszDesc);
|
---|
3326 | }
|
---|
3327 |
|
---|
3328 |
|
---|
3329 | PDBGGUISTATSNODE
|
---|
3330 | VBoxDbgStatsModelVM::createNewTree(QString &a_rPatStr)
|
---|
3331 | {
|
---|
3332 | PDBGGUISTATSNODE pRoot = createRootNode();
|
---|
3333 | if (pRoot)
|
---|
3334 | {
|
---|
3335 | CreateNewTreeCallbackArgs_T Args = { pRoot, this };
|
---|
3336 | int rc = stamEnum(a_rPatStr, createNewTreeCallback, &Args);
|
---|
3337 | if (RT_SUCCESS(rc))
|
---|
3338 | return pRoot;
|
---|
3339 |
|
---|
3340 | /* failed, cleanup. */
|
---|
3341 | destroyTree(pRoot);
|
---|
3342 | }
|
---|
3343 |
|
---|
3344 | return NULL;
|
---|
3345 | }
|
---|
3346 |
|
---|
3347 |
|
---|
3348 |
|
---|
3349 |
|
---|
3350 |
|
---|
3351 |
|
---|
3352 |
|
---|
3353 |
|
---|
3354 | /*
|
---|
3355 | *
|
---|
3356 | * V B o x D b g S t a t s S o r t F i l e P r o x y M o d e l
|
---|
3357 | * V B o x D b g S t a t s S o r t F i l e P r o x y M o d e l
|
---|
3358 | * V B o x D b g S t a t s S o r t F i l e P r o x y M o d e l
|
---|
3359 | *
|
---|
3360 | *
|
---|
3361 | */
|
---|
3362 |
|
---|
3363 | #ifdef VBOXDBG_WITH_SORTED_AND_FILTERED_STATS
|
---|
3364 |
|
---|
3365 | VBoxDbgStatsSortFileProxyModel::VBoxDbgStatsSortFileProxyModel(QObject *a_pParent)
|
---|
3366 | : QSortFilterProxyModel(a_pParent)
|
---|
3367 | , m_fShowUnusedRows(false)
|
---|
3368 | {
|
---|
3369 |
|
---|
3370 | }
|
---|
3371 |
|
---|
3372 |
|
---|
3373 | bool
|
---|
3374 | VBoxDbgStatsSortFileProxyModel::filterAcceptsRow(int a_iSrcRow, const QModelIndex &a_rSrcParent) const
|
---|
3375 | {
|
---|
3376 | /*
|
---|
3377 | * Locate the node.
|
---|
3378 | */
|
---|
3379 | PDBGGUISTATSNODE pParent = nodeFromSrcIndex(a_rSrcParent);
|
---|
3380 | if (pParent)
|
---|
3381 | {
|
---|
3382 | if ((unsigned)a_iSrcRow < pParent->cChildren)
|
---|
3383 | {
|
---|
3384 | PDBGGUISTATSNODE const pNode = pParent->papChildren[a_iSrcRow];
|
---|
3385 | if (pNode) /* paranoia */
|
---|
3386 | {
|
---|
3387 | /*
|
---|
3388 | * Apply the global unused-row filter.
|
---|
3389 | */
|
---|
3390 | if (!m_fShowUnusedRows)
|
---|
3391 | {
|
---|
3392 | /* Only relevant for leaf nodes. */
|
---|
3393 | if (pNode->cChildren == 0)
|
---|
3394 | {
|
---|
3395 | if (pNode->enmState != kDbgGuiStatsNodeState_kInvalid)
|
---|
3396 | {
|
---|
3397 | if (pNode->i64Delta == 0)
|
---|
3398 | {
|
---|
3399 | /* Is the cached statistics value zero? */
|
---|
3400 | switch (pNode->enmType)
|
---|
3401 | {
|
---|
3402 | case STAMTYPE_COUNTER:
|
---|
3403 | if (pNode->Data.Counter.c != 0)
|
---|
3404 | break;
|
---|
3405 | return false;
|
---|
3406 |
|
---|
3407 | case STAMTYPE_PROFILE:
|
---|
3408 | case STAMTYPE_PROFILE_ADV:
|
---|
3409 | if (pNode->Data.Profile.cPeriods)
|
---|
3410 | break;
|
---|
3411 | return false;
|
---|
3412 |
|
---|
3413 | case STAMTYPE_RATIO_U32:
|
---|
3414 | case STAMTYPE_RATIO_U32_RESET:
|
---|
3415 | if (pNode->Data.RatioU32.u32A || pNode->Data.RatioU32.u32B)
|
---|
3416 | break;
|
---|
3417 | return false;
|
---|
3418 |
|
---|
3419 | case STAMTYPE_CALLBACK:
|
---|
3420 | if (pNode->Data.pStr && !pNode->Data.pStr->isEmpty())
|
---|
3421 | break;
|
---|
3422 | return false;
|
---|
3423 |
|
---|
3424 | case STAMTYPE_U8:
|
---|
3425 | case STAMTYPE_U8_RESET:
|
---|
3426 | case STAMTYPE_X8:
|
---|
3427 | case STAMTYPE_X8_RESET:
|
---|
3428 | if (pNode->Data.u8)
|
---|
3429 | break;
|
---|
3430 | return false;
|
---|
3431 |
|
---|
3432 | case STAMTYPE_U16:
|
---|
3433 | case STAMTYPE_U16_RESET:
|
---|
3434 | case STAMTYPE_X16:
|
---|
3435 | case STAMTYPE_X16_RESET:
|
---|
3436 | if (pNode->Data.u16)
|
---|
3437 | break;
|
---|
3438 | return false;
|
---|
3439 |
|
---|
3440 | case STAMTYPE_U32:
|
---|
3441 | case STAMTYPE_U32_RESET:
|
---|
3442 | case STAMTYPE_X32:
|
---|
3443 | case STAMTYPE_X32_RESET:
|
---|
3444 | if (pNode->Data.u32)
|
---|
3445 | break;
|
---|
3446 | return false;
|
---|
3447 |
|
---|
3448 | case STAMTYPE_U64:
|
---|
3449 | case STAMTYPE_U64_RESET:
|
---|
3450 | case STAMTYPE_X64:
|
---|
3451 | case STAMTYPE_X64_RESET:
|
---|
3452 | if (pNode->Data.u64)
|
---|
3453 | break;
|
---|
3454 | return false;
|
---|
3455 |
|
---|
3456 | case STAMTYPE_BOOL:
|
---|
3457 | case STAMTYPE_BOOL_RESET:
|
---|
3458 | /* not possible to detect */
|
---|
3459 | return false;
|
---|
3460 |
|
---|
3461 | case STAMTYPE_INVALID:
|
---|
3462 | break;
|
---|
3463 |
|
---|
3464 | default:
|
---|
3465 | AssertMsgFailedBreak(("enmType=%d\n", pNode->enmType));
|
---|
3466 | }
|
---|
3467 | }
|
---|
3468 | }
|
---|
3469 | else
|
---|
3470 | return false;
|
---|
3471 | }
|
---|
3472 | }
|
---|
3473 |
|
---|
3474 | /*
|
---|
3475 | * Look for additional filtering rules among the ancestors.
|
---|
3476 | */
|
---|
3477 | if (VBoxGuiStatsFilterData::s_cInstances > 0 /* quick & dirty optimization */)
|
---|
3478 | {
|
---|
3479 | VBoxGuiStatsFilterData const *pFilter = pParent->pFilter;
|
---|
3480 | while (!pFilter && (pParent = pParent->pParent) != NULL)
|
---|
3481 | pFilter = pParent->pFilter;
|
---|
3482 | if (pFilter)
|
---|
3483 | {
|
---|
3484 | if (pFilter->uMinValue > 0 || pFilter->uMaxValue != UINT64_MAX)
|
---|
3485 | {
|
---|
3486 | uint64_t const uValue = VBoxDbgStatsModel::getValueTimesAsUInt(pNode);
|
---|
3487 | if ( uValue < pFilter->uMinValue
|
---|
3488 | || uValue > pFilter->uMaxValue)
|
---|
3489 | return false;
|
---|
3490 | }
|
---|
3491 | if (pFilter->pRegexName)
|
---|
3492 | {
|
---|
3493 | if (!pFilter->pRegexName->match(pNode->pszName).hasMatch())
|
---|
3494 | return false;
|
---|
3495 | }
|
---|
3496 | }
|
---|
3497 | }
|
---|
3498 | }
|
---|
3499 | }
|
---|
3500 | }
|
---|
3501 | return true;
|
---|
3502 | }
|
---|
3503 |
|
---|
3504 |
|
---|
3505 | bool
|
---|
3506 | VBoxDbgStatsSortFileProxyModel::lessThan(const QModelIndex &a_rSrcLeft, const QModelIndex &a_rSrcRight) const
|
---|
3507 | {
|
---|
3508 | PCDBGGUISTATSNODE const pLeft = nodeFromSrcIndex(a_rSrcLeft);
|
---|
3509 | PCDBGGUISTATSNODE const pRight = nodeFromSrcIndex(a_rSrcRight);
|
---|
3510 | if (pLeft == pRight)
|
---|
3511 | return false;
|
---|
3512 | if (pLeft && pRight)
|
---|
3513 | {
|
---|
3514 | if (pLeft->pParent == pRight->pParent)
|
---|
3515 | {
|
---|
3516 | switch (a_rSrcLeft.column())
|
---|
3517 | {
|
---|
3518 | case 0:
|
---|
3519 | return RTStrCmp(pLeft->pszName, pRight->pszName) < 0;
|
---|
3520 | case 1:
|
---|
3521 | return RTStrCmp(pLeft->pszUnit, pRight->pszUnit) < 0;
|
---|
3522 | case 2:
|
---|
3523 | return VBoxDbgStatsModel::getValueTimesAsUInt(pLeft) < VBoxDbgStatsModel::getValueTimesAsUInt(pRight);
|
---|
3524 | case 3:
|
---|
3525 | return pLeft->i64Delta < pRight->i64Delta;
|
---|
3526 | case 4:
|
---|
3527 | return VBoxDbgStatsModel::getMinValueAsUInt(pLeft) < VBoxDbgStatsModel::getMinValueAsUInt(pRight);
|
---|
3528 | case 5:
|
---|
3529 | return VBoxDbgStatsModel::getAvgValueAsUInt(pLeft) < VBoxDbgStatsModel::getAvgValueAsUInt(pRight);
|
---|
3530 | case 6:
|
---|
3531 | return VBoxDbgStatsModel::getMaxValueAsUInt(pLeft) < VBoxDbgStatsModel::getMaxValueAsUInt(pRight);
|
---|
3532 | case 7:
|
---|
3533 | return VBoxDbgStatsModel::getTotalValueAsUInt(pLeft) < VBoxDbgStatsModel::getTotalValueAsUInt(pRight);
|
---|
3534 | case 8:
|
---|
3535 | if (pLeft->pDescStr == pRight->pDescStr)
|
---|
3536 | return false;
|
---|
3537 | if (!pLeft->pDescStr)
|
---|
3538 | return true;
|
---|
3539 | if (!pRight->pDescStr)
|
---|
3540 | return false;
|
---|
3541 | return *pLeft->pDescStr < *pRight->pDescStr;
|
---|
3542 | default:
|
---|
3543 | AssertCompile(DBGGUI_STATS_COLUMNS == 9);
|
---|
3544 | return true;
|
---|
3545 | }
|
---|
3546 | }
|
---|
3547 | return false;
|
---|
3548 | }
|
---|
3549 | return !pLeft;
|
---|
3550 | }
|
---|
3551 |
|
---|
3552 |
|
---|
3553 | void
|
---|
3554 | VBoxDbgStatsSortFileProxyModel::setShowUnusedRows(bool a_fHide)
|
---|
3555 | {
|
---|
3556 | if (a_fHide != m_fShowUnusedRows)
|
---|
3557 | {
|
---|
3558 | m_fShowUnusedRows = a_fHide;
|
---|
3559 | invalidateRowsFilter();
|
---|
3560 | }
|
---|
3561 | }
|
---|
3562 |
|
---|
3563 |
|
---|
3564 | void
|
---|
3565 | VBoxDbgStatsSortFileProxyModel::notifyFilterChanges()
|
---|
3566 | {
|
---|
3567 | invalidateRowsFilter();
|
---|
3568 | }
|
---|
3569 |
|
---|
3570 |
|
---|
3571 | void
|
---|
3572 | VBoxDbgStatsSortFileProxyModel::stringifyTree(QModelIndex const &a_rRoot, QString &a_rString, size_t a_cchNameWidth) const
|
---|
3573 | {
|
---|
3574 | /* The node itself. */
|
---|
3575 | PDBGGUISTATSNODE pNode = nodeFromProxyIndex(a_rRoot);
|
---|
3576 | if (pNode)
|
---|
3577 | {
|
---|
3578 | if (pNode->enmType != STAMTYPE_INVALID)
|
---|
3579 | {
|
---|
3580 | if (!a_rString.isEmpty())
|
---|
3581 | a_rString += "\n";
|
---|
3582 | VBoxDbgStatsModel::stringifyNodeNoRecursion(pNode, a_rString, a_cchNameWidth);
|
---|
3583 | }
|
---|
3584 | }
|
---|
3585 |
|
---|
3586 | /* The children. */
|
---|
3587 | int const cChildren = rowCount(a_rRoot);
|
---|
3588 | if (cChildren > 0)
|
---|
3589 | {
|
---|
3590 | a_cchNameWidth = 0;
|
---|
3591 | for (int iChild = 0; iChild < cChildren; iChild++)
|
---|
3592 | {
|
---|
3593 | QModelIndex const ChildIdx = index(iChild, 0, a_rRoot);
|
---|
3594 | pNode = nodeFromProxyIndex(ChildIdx);
|
---|
3595 | if (pNode && a_cchNameWidth < pNode->cchName)
|
---|
3596 | a_cchNameWidth = pNode->cchName;
|
---|
3597 | }
|
---|
3598 |
|
---|
3599 | for (int iChild = 0; iChild < cChildren; iChild++)
|
---|
3600 | {
|
---|
3601 | QModelIndex const ChildIdx = index(iChild, 0, a_rRoot);
|
---|
3602 | stringifyTree(ChildIdx, a_rString, a_cchNameWidth);
|
---|
3603 | }
|
---|
3604 | }
|
---|
3605 | }
|
---|
3606 |
|
---|
3607 | #endif /* VBOXDBG_WITH_SORTED_AND_FILTERED_STATS */
|
---|
3608 |
|
---|
3609 |
|
---|
3610 |
|
---|
3611 | /*
|
---|
3612 | *
|
---|
3613 | * V B o x D b g S t a t s V i e w
|
---|
3614 | * V B o x D b g S t a t s V i e w
|
---|
3615 | * V B o x D b g S t a t s V i e w
|
---|
3616 | *
|
---|
3617 | *
|
---|
3618 | */
|
---|
3619 |
|
---|
3620 |
|
---|
3621 | VBoxDbgStatsView::VBoxDbgStatsView(VBoxDbgGui *a_pDbgGui, VBoxDbgStatsModel *a_pVBoxModel,
|
---|
3622 | VBoxDbgStatsSortFileProxyModel *a_pProxyModel, VBoxDbgStats *a_pParent/* = NULL*/)
|
---|
3623 | : QTreeView(a_pParent)
|
---|
3624 | , VBoxDbgBase(a_pDbgGui)
|
---|
3625 | , m_pVBoxModel(a_pVBoxModel)
|
---|
3626 | , m_pProxyModel(a_pProxyModel)
|
---|
3627 | , m_pModel(NULL)
|
---|
3628 | , m_PatStr()
|
---|
3629 | , m_pParent(a_pParent)
|
---|
3630 | , m_pLeafMenu(NULL)
|
---|
3631 | , m_pBranchMenu(NULL)
|
---|
3632 | , m_pViewMenu(NULL)
|
---|
3633 | , m_pCurMenu(NULL)
|
---|
3634 | , m_CurIndex()
|
---|
3635 | {
|
---|
3636 | /*
|
---|
3637 | * Set the model and view defaults.
|
---|
3638 | */
|
---|
3639 | setRootIsDecorated(true);
|
---|
3640 | if (a_pProxyModel)
|
---|
3641 | {
|
---|
3642 | m_pModel = a_pProxyModel;
|
---|
3643 | a_pProxyModel->setSourceModel(a_pVBoxModel);
|
---|
3644 | }
|
---|
3645 | else
|
---|
3646 | m_pModel = a_pVBoxModel;
|
---|
3647 | setModel(m_pModel);
|
---|
3648 | QModelIndex RootIdx = myGetRootIndex(); /* This should really be QModelIndex(), but Qt on darwin does wrong things then. */
|
---|
3649 | setRootIndex(RootIdx);
|
---|
3650 | setItemsExpandable(true);
|
---|
3651 | setAlternatingRowColors(true);
|
---|
3652 | setSelectionBehavior(SelectRows);
|
---|
3653 | setSelectionMode(SingleSelection);
|
---|
3654 | if (a_pProxyModel)
|
---|
3655 | setSortingEnabled(true);
|
---|
3656 |
|
---|
3657 | /*
|
---|
3658 | * Create and setup the actions.
|
---|
3659 | */
|
---|
3660 | m_pExpandAct = new QAction("Expand Tree", this);
|
---|
3661 | m_pCollapseAct = new QAction("Collapse Tree", this);
|
---|
3662 | m_pRefreshAct = new QAction("&Refresh", this);
|
---|
3663 | m_pResetAct = new QAction("Rese&t", this);
|
---|
3664 | m_pCopyAct = new QAction("&Copy", this);
|
---|
3665 | m_pToLogAct = new QAction("To &Log", this);
|
---|
3666 | m_pToRelLogAct = new QAction("T&o Release Log", this);
|
---|
3667 | m_pAdjColumnsAct = new QAction("&Adjust Columns", this);
|
---|
3668 | #ifdef VBOXDBG_WITH_SORTED_AND_FILTERED_STATS
|
---|
3669 | m_pFilterAct = new QAction("&Filter...", this);
|
---|
3670 | #endif
|
---|
3671 |
|
---|
3672 | m_pCopyAct->setShortcut(QKeySequence::Copy);
|
---|
3673 | m_pExpandAct->setShortcut(QKeySequence("Ctrl+E"));
|
---|
3674 | m_pCollapseAct->setShortcut(QKeySequence("Ctrl+D"));
|
---|
3675 | m_pRefreshAct->setShortcut(QKeySequence("Ctrl+R"));
|
---|
3676 | m_pResetAct->setShortcut(QKeySequence("Alt+R"));
|
---|
3677 | m_pToLogAct->setShortcut(QKeySequence("Ctrl+Z"));
|
---|
3678 | m_pToRelLogAct->setShortcut(QKeySequence("Alt+Z"));
|
---|
3679 | m_pAdjColumnsAct->setShortcut(QKeySequence("Ctrl+A"));
|
---|
3680 | #ifdef VBOXDBG_WITH_SORTED_AND_FILTERED_STATS
|
---|
3681 | //m_pFilterAct->setShortcut(QKeySequence("Ctrl+?"));
|
---|
3682 | #endif
|
---|
3683 |
|
---|
3684 | addAction(m_pCopyAct);
|
---|
3685 | addAction(m_pExpandAct);
|
---|
3686 | addAction(m_pCollapseAct);
|
---|
3687 | addAction(m_pRefreshAct);
|
---|
3688 | addAction(m_pResetAct);
|
---|
3689 | addAction(m_pToLogAct);
|
---|
3690 | addAction(m_pToRelLogAct);
|
---|
3691 | addAction(m_pAdjColumnsAct);
|
---|
3692 | #ifdef VBOXDBG_WITH_SORTED_AND_FILTERED_STATS
|
---|
3693 | addAction(m_pFilterAct);
|
---|
3694 | #endif
|
---|
3695 |
|
---|
3696 | connect(m_pExpandAct, SIGNAL(triggered(bool)), this, SLOT(actExpand()));
|
---|
3697 | connect(m_pCollapseAct, SIGNAL(triggered(bool)), this, SLOT(actCollapse()));
|
---|
3698 | connect(m_pRefreshAct, SIGNAL(triggered(bool)), this, SLOT(actRefresh()));
|
---|
3699 | connect(m_pResetAct, SIGNAL(triggered(bool)), this, SLOT(actReset()));
|
---|
3700 | connect(m_pCopyAct, SIGNAL(triggered(bool)), this, SLOT(actCopy()));
|
---|
3701 | connect(m_pToLogAct, SIGNAL(triggered(bool)), this, SLOT(actToLog()));
|
---|
3702 | connect(m_pToRelLogAct, SIGNAL(triggered(bool)), this, SLOT(actToRelLog()));
|
---|
3703 | connect(m_pAdjColumnsAct, SIGNAL(triggered(bool)), this, SLOT(actAdjColumns()));
|
---|
3704 | #ifdef VBOXDBG_WITH_SORTED_AND_FILTERED_STATS
|
---|
3705 | connect(m_pFilterAct, SIGNAL(triggered(bool)), this, SLOT(actFilter()));
|
---|
3706 | #endif
|
---|
3707 |
|
---|
3708 |
|
---|
3709 | /*
|
---|
3710 | * Create the menus and populate them.
|
---|
3711 | */
|
---|
3712 | setContextMenuPolicy(Qt::DefaultContextMenu);
|
---|
3713 |
|
---|
3714 | m_pLeafMenu = new QMenu();
|
---|
3715 | m_pLeafMenu->addAction(m_pCopyAct);
|
---|
3716 | m_pLeafMenu->addAction(m_pRefreshAct);
|
---|
3717 | m_pLeafMenu->addAction(m_pResetAct);
|
---|
3718 | m_pLeafMenu->addAction(m_pToLogAct);
|
---|
3719 | m_pLeafMenu->addAction(m_pToRelLogAct);
|
---|
3720 |
|
---|
3721 | m_pBranchMenu = new QMenu(this);
|
---|
3722 | m_pBranchMenu->addAction(m_pCopyAct);
|
---|
3723 | m_pBranchMenu->addAction(m_pRefreshAct);
|
---|
3724 | m_pBranchMenu->addAction(m_pResetAct);
|
---|
3725 | m_pBranchMenu->addAction(m_pToLogAct);
|
---|
3726 | m_pBranchMenu->addAction(m_pToRelLogAct);
|
---|
3727 | m_pBranchMenu->addSeparator();
|
---|
3728 | m_pBranchMenu->addAction(m_pExpandAct);
|
---|
3729 | m_pBranchMenu->addAction(m_pCollapseAct);
|
---|
3730 | #ifdef VBOXDBG_WITH_SORTED_AND_FILTERED_STATS
|
---|
3731 | m_pBranchMenu->addSeparator();
|
---|
3732 | m_pBranchMenu->addAction(m_pFilterAct);
|
---|
3733 | #endif
|
---|
3734 |
|
---|
3735 | m_pViewMenu = new QMenu();
|
---|
3736 | m_pViewMenu->addAction(m_pCopyAct);
|
---|
3737 | m_pViewMenu->addAction(m_pRefreshAct);
|
---|
3738 | m_pViewMenu->addAction(m_pResetAct);
|
---|
3739 | m_pViewMenu->addAction(m_pToLogAct);
|
---|
3740 | m_pViewMenu->addAction(m_pToRelLogAct);
|
---|
3741 | m_pViewMenu->addSeparator();
|
---|
3742 | m_pViewMenu->addAction(m_pExpandAct);
|
---|
3743 | m_pViewMenu->addAction(m_pCollapseAct);
|
---|
3744 | m_pViewMenu->addSeparator();
|
---|
3745 | m_pViewMenu->addAction(m_pAdjColumnsAct);
|
---|
3746 | #ifdef VBOXDBG_WITH_SORTED_AND_FILTERED_STATS
|
---|
3747 | m_pViewMenu->addAction(m_pFilterAct);
|
---|
3748 | #endif
|
---|
3749 |
|
---|
3750 | /* the header menu */
|
---|
3751 | QHeaderView *pHdrView = header();
|
---|
3752 | pHdrView->setContextMenuPolicy(Qt::CustomContextMenu);
|
---|
3753 | connect(pHdrView, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(headerContextMenuRequested(const QPoint &)));
|
---|
3754 | }
|
---|
3755 |
|
---|
3756 |
|
---|
3757 | VBoxDbgStatsView::~VBoxDbgStatsView()
|
---|
3758 | {
|
---|
3759 | m_pParent = NULL;
|
---|
3760 | m_pCurMenu = NULL;
|
---|
3761 | m_CurIndex = QModelIndex();
|
---|
3762 |
|
---|
3763 | #define DELETE_IT(m) if (m) { delete m; m = NULL; } else do {} while (0)
|
---|
3764 | DELETE_IT(m_pProxyModel);
|
---|
3765 | DELETE_IT(m_pVBoxModel);
|
---|
3766 |
|
---|
3767 | DELETE_IT(m_pLeafMenu);
|
---|
3768 | DELETE_IT(m_pBranchMenu);
|
---|
3769 | DELETE_IT(m_pViewMenu);
|
---|
3770 |
|
---|
3771 | DELETE_IT(m_pExpandAct);
|
---|
3772 | DELETE_IT(m_pCollapseAct);
|
---|
3773 | DELETE_IT(m_pRefreshAct);
|
---|
3774 | DELETE_IT(m_pResetAct);
|
---|
3775 | DELETE_IT(m_pCopyAct);
|
---|
3776 | DELETE_IT(m_pToLogAct);
|
---|
3777 | DELETE_IT(m_pToRelLogAct);
|
---|
3778 | DELETE_IT(m_pAdjColumnsAct);
|
---|
3779 | DELETE_IT(m_pFilterAct);
|
---|
3780 | #undef DELETE_IT
|
---|
3781 | }
|
---|
3782 |
|
---|
3783 |
|
---|
3784 | void
|
---|
3785 | VBoxDbgStatsView::updateStats(const QString &rPatStr)
|
---|
3786 | {
|
---|
3787 | m_PatStr = rPatStr;
|
---|
3788 | if (m_pVBoxModel->updateStatsByPattern(rPatStr))
|
---|
3789 | setRootIndex(myGetRootIndex()); /* hack */
|
---|
3790 | }
|
---|
3791 |
|
---|
3792 |
|
---|
3793 | void
|
---|
3794 | VBoxDbgStatsView::setShowUnusedRows(bool a_fHide)
|
---|
3795 | {
|
---|
3796 | #ifdef VBOXDBG_WITH_SORTED_AND_FILTERED_STATS
|
---|
3797 | if (m_pProxyModel)
|
---|
3798 | m_pProxyModel->setShowUnusedRows(a_fHide);
|
---|
3799 | #else
|
---|
3800 | RT_NOREF_PV(a_fHide);
|
---|
3801 | #endif
|
---|
3802 | }
|
---|
3803 |
|
---|
3804 |
|
---|
3805 | void
|
---|
3806 | VBoxDbgStatsView::resizeColumnsToContent()
|
---|
3807 | {
|
---|
3808 | for (int i = 0; i <= 8; i++)
|
---|
3809 | {
|
---|
3810 | resizeColumnToContents(i);
|
---|
3811 | /* Some extra room for distinguishing numbers better in Value, Min, Avg, Max, Total, dInt columns. */
|
---|
3812 | if (i >= 2 && i <= 7)
|
---|
3813 | setColumnWidth(i, columnWidth(i) + 10);
|
---|
3814 | }
|
---|
3815 | }
|
---|
3816 |
|
---|
3817 |
|
---|
3818 | /*static*/ bool
|
---|
3819 | VBoxDbgStatsView::expandMatchingCallback(PDBGGUISTATSNODE pNode, QModelIndex const &a_rIndex,
|
---|
3820 | const char *pszFullName, void *pvUser)
|
---|
3821 | {
|
---|
3822 | VBoxDbgStatsView *pThis = (VBoxDbgStatsView *)pvUser;
|
---|
3823 |
|
---|
3824 | QModelIndex ParentIndex; /* this isn't 100% optimal */
|
---|
3825 | if (pThis->m_pProxyModel)
|
---|
3826 | {
|
---|
3827 | QModelIndex const ProxyIndex = pThis->m_pProxyModel->mapFromSource(a_rIndex);
|
---|
3828 |
|
---|
3829 | ParentIndex = pThis->m_pModel->parent(ProxyIndex);
|
---|
3830 | }
|
---|
3831 | else
|
---|
3832 | {
|
---|
3833 | pThis->setExpanded(a_rIndex, true);
|
---|
3834 |
|
---|
3835 | ParentIndex = pThis->m_pModel->parent(a_rIndex);
|
---|
3836 | }
|
---|
3837 | while (ParentIndex.isValid() && !pThis->isExpanded(ParentIndex))
|
---|
3838 | {
|
---|
3839 | pThis->setExpanded(ParentIndex, true);
|
---|
3840 | ParentIndex = pThis->m_pModel->parent(ParentIndex);
|
---|
3841 | }
|
---|
3842 |
|
---|
3843 | RT_NOREF(pNode, pszFullName);
|
---|
3844 | return true;
|
---|
3845 | }
|
---|
3846 |
|
---|
3847 |
|
---|
3848 | void
|
---|
3849 | VBoxDbgStatsView::expandMatching(const QString &rPatStr)
|
---|
3850 | {
|
---|
3851 | m_pVBoxModel->iterateStatsByPattern(rPatStr, expandMatchingCallback, this);
|
---|
3852 | }
|
---|
3853 |
|
---|
3854 |
|
---|
3855 | void
|
---|
3856 | VBoxDbgStatsView::setSubTreeExpanded(QModelIndex const &a_rIndex, bool a_fExpanded)
|
---|
3857 | {
|
---|
3858 | int cRows = m_pModel->rowCount(a_rIndex);
|
---|
3859 | if (a_rIndex.model())
|
---|
3860 | for (int i = 0; i < cRows; i++)
|
---|
3861 | setSubTreeExpanded(a_rIndex.model()->index(i, 0, a_rIndex), a_fExpanded);
|
---|
3862 | setExpanded(a_rIndex, a_fExpanded);
|
---|
3863 | }
|
---|
3864 |
|
---|
3865 |
|
---|
3866 | void
|
---|
3867 | VBoxDbgStatsView::contextMenuEvent(QContextMenuEvent *a_pEvt)
|
---|
3868 | {
|
---|
3869 | /*
|
---|
3870 | * Get the selected item.
|
---|
3871 | * If it's a mouse event select the item under the cursor (if any).
|
---|
3872 | */
|
---|
3873 | QModelIndex Idx;
|
---|
3874 | if (a_pEvt->reason() == QContextMenuEvent::Mouse)
|
---|
3875 | {
|
---|
3876 | Idx = indexAt(a_pEvt->pos());
|
---|
3877 | if (Idx.isValid())
|
---|
3878 | setCurrentIndex(Idx);
|
---|
3879 | }
|
---|
3880 | else
|
---|
3881 | {
|
---|
3882 | QModelIndexList SelIdx = selectedIndexes();
|
---|
3883 | if (!SelIdx.isEmpty())
|
---|
3884 | Idx = SelIdx.at(0);
|
---|
3885 | }
|
---|
3886 |
|
---|
3887 | /*
|
---|
3888 | * Popup the corresponding menu.
|
---|
3889 | */
|
---|
3890 | QMenu *pMenu;
|
---|
3891 | if (!Idx.isValid())
|
---|
3892 | pMenu = m_pViewMenu;
|
---|
3893 | else if (m_pModel->hasChildren(Idx))
|
---|
3894 | pMenu = m_pBranchMenu;
|
---|
3895 | else
|
---|
3896 | pMenu = m_pLeafMenu;
|
---|
3897 | if (pMenu)
|
---|
3898 | {
|
---|
3899 | m_pRefreshAct->setEnabled(!Idx.isValid() || Idx == myGetRootIndex());
|
---|
3900 | m_CurIndex = Idx;
|
---|
3901 | m_pCurMenu = pMenu;
|
---|
3902 |
|
---|
3903 | pMenu->exec(a_pEvt->globalPos());
|
---|
3904 |
|
---|
3905 | m_pCurMenu = NULL;
|
---|
3906 | m_CurIndex = QModelIndex();
|
---|
3907 | if (m_pRefreshAct)
|
---|
3908 | m_pRefreshAct->setEnabled(true);
|
---|
3909 | }
|
---|
3910 | a_pEvt->accept();
|
---|
3911 | }
|
---|
3912 |
|
---|
3913 |
|
---|
3914 | QModelIndex
|
---|
3915 | VBoxDbgStatsView::myGetRootIndex(void) const
|
---|
3916 | {
|
---|
3917 | if (!m_pProxyModel)
|
---|
3918 | return m_pVBoxModel->getRootIndex();
|
---|
3919 | return m_pProxyModel->mapFromSource(m_pVBoxModel->getRootIndex());
|
---|
3920 | }
|
---|
3921 |
|
---|
3922 |
|
---|
3923 | void
|
---|
3924 | VBoxDbgStatsView::headerContextMenuRequested(const QPoint &a_rPos)
|
---|
3925 | {
|
---|
3926 | /*
|
---|
3927 | * Show the view menu.
|
---|
3928 | */
|
---|
3929 | if (m_pViewMenu)
|
---|
3930 | {
|
---|
3931 | m_pRefreshAct->setEnabled(true);
|
---|
3932 | m_CurIndex = myGetRootIndex();
|
---|
3933 | m_pCurMenu = m_pViewMenu;
|
---|
3934 |
|
---|
3935 | m_pViewMenu->exec(header()->mapToGlobal(a_rPos));
|
---|
3936 |
|
---|
3937 | m_pCurMenu = NULL;
|
---|
3938 | m_CurIndex = QModelIndex();
|
---|
3939 | if (m_pRefreshAct)
|
---|
3940 | m_pRefreshAct->setEnabled(true);
|
---|
3941 | }
|
---|
3942 | }
|
---|
3943 |
|
---|
3944 |
|
---|
3945 | void
|
---|
3946 | VBoxDbgStatsView::actExpand()
|
---|
3947 | {
|
---|
3948 | QModelIndex Idx = m_pCurMenu ? m_CurIndex : currentIndex();
|
---|
3949 | if (Idx.isValid())
|
---|
3950 | setSubTreeExpanded(Idx, true /* a_fExpanded */);
|
---|
3951 | }
|
---|
3952 |
|
---|
3953 |
|
---|
3954 | void
|
---|
3955 | VBoxDbgStatsView::actCollapse()
|
---|
3956 | {
|
---|
3957 | QModelIndex Idx = m_pCurMenu ? m_CurIndex : currentIndex();
|
---|
3958 | if (Idx.isValid())
|
---|
3959 | setSubTreeExpanded(Idx, false /* a_fExpanded */);
|
---|
3960 | }
|
---|
3961 |
|
---|
3962 |
|
---|
3963 | void
|
---|
3964 | VBoxDbgStatsView::actRefresh()
|
---|
3965 | {
|
---|
3966 | QModelIndex Idx = m_pCurMenu ? m_CurIndex : currentIndex();
|
---|
3967 | if (!Idx.isValid() || Idx == myGetRootIndex())
|
---|
3968 | {
|
---|
3969 | if (m_pVBoxModel->updateStatsByPattern(m_PatStr))
|
---|
3970 | setRootIndex(myGetRootIndex()); /* hack */
|
---|
3971 | }
|
---|
3972 | else
|
---|
3973 | {
|
---|
3974 | if (m_pProxyModel)
|
---|
3975 | Idx = m_pProxyModel->mapToSource(Idx);
|
---|
3976 | m_pVBoxModel->updateStatsByIndex(Idx);
|
---|
3977 | }
|
---|
3978 | }
|
---|
3979 |
|
---|
3980 |
|
---|
3981 | void
|
---|
3982 | VBoxDbgStatsView::actReset()
|
---|
3983 | {
|
---|
3984 | QModelIndex Idx = m_pCurMenu ? m_CurIndex : currentIndex();
|
---|
3985 | if (!Idx.isValid() || Idx == myGetRootIndex())
|
---|
3986 | m_pVBoxModel->resetStatsByPattern(m_PatStr);
|
---|
3987 | else
|
---|
3988 | {
|
---|
3989 | if (m_pProxyModel)
|
---|
3990 | Idx = m_pProxyModel->mapToSource(Idx);
|
---|
3991 | m_pVBoxModel->resetStatsByIndex(Idx);
|
---|
3992 | }
|
---|
3993 | }
|
---|
3994 |
|
---|
3995 |
|
---|
3996 | void
|
---|
3997 | VBoxDbgStatsView::actCopy()
|
---|
3998 | {
|
---|
3999 | QModelIndex Idx = m_pCurMenu ? m_CurIndex : currentIndex();
|
---|
4000 |
|
---|
4001 | QString String;
|
---|
4002 | if (m_pProxyModel)
|
---|
4003 | m_pProxyModel->stringifyTree(Idx, String);
|
---|
4004 | else
|
---|
4005 | m_pVBoxModel->stringifyTree(Idx, String);
|
---|
4006 |
|
---|
4007 | QClipboard *pClipboard = QApplication::clipboard();
|
---|
4008 | if (pClipboard)
|
---|
4009 | pClipboard->setText(String, QClipboard::Clipboard);
|
---|
4010 | }
|
---|
4011 |
|
---|
4012 |
|
---|
4013 | void
|
---|
4014 | VBoxDbgStatsView::actToLog()
|
---|
4015 | {
|
---|
4016 | QModelIndex Idx = m_pCurMenu ? m_CurIndex : currentIndex();
|
---|
4017 |
|
---|
4018 | QString String;
|
---|
4019 | if (m_pProxyModel)
|
---|
4020 | m_pProxyModel->stringifyTree(Idx, String);
|
---|
4021 | else
|
---|
4022 | m_pVBoxModel->stringifyTree(Idx, String);
|
---|
4023 |
|
---|
4024 | QByteArray SelfByteArray = String.toUtf8();
|
---|
4025 | RTLogPrintf("%s\n", SelfByteArray.constData());
|
---|
4026 | }
|
---|
4027 |
|
---|
4028 |
|
---|
4029 | void
|
---|
4030 | VBoxDbgStatsView::actToRelLog()
|
---|
4031 | {
|
---|
4032 | QModelIndex Idx = m_pCurMenu ? m_CurIndex : currentIndex();
|
---|
4033 |
|
---|
4034 | QString String;
|
---|
4035 | if (m_pProxyModel)
|
---|
4036 | m_pProxyModel->stringifyTree(Idx, String);
|
---|
4037 | else
|
---|
4038 | m_pVBoxModel->stringifyTree(Idx, String);
|
---|
4039 |
|
---|
4040 | QByteArray SelfByteArray = String.toUtf8();
|
---|
4041 | RTLogRelPrintf("%s\n", SelfByteArray.constData());
|
---|
4042 | }
|
---|
4043 |
|
---|
4044 |
|
---|
4045 | void
|
---|
4046 | VBoxDbgStatsView::actAdjColumns()
|
---|
4047 | {
|
---|
4048 | resizeColumnsToContent();
|
---|
4049 | }
|
---|
4050 |
|
---|
4051 |
|
---|
4052 | void
|
---|
4053 | VBoxDbgStatsView::actFilter()
|
---|
4054 | {
|
---|
4055 | #ifdef VBOXDBG_WITH_SORTED_AND_FILTERED_STATS
|
---|
4056 | /*
|
---|
4057 | * Get the node it applies to.
|
---|
4058 | */
|
---|
4059 | QModelIndex Idx = m_pCurMenu ? m_CurIndex : currentIndex();
|
---|
4060 | if (!Idx.isValid())
|
---|
4061 | Idx = myGetRootIndex();
|
---|
4062 | Idx = m_pProxyModel->mapToSource(Idx);
|
---|
4063 | PDBGGUISTATSNODE pNode = m_pVBoxModel->nodeFromIndex(Idx);
|
---|
4064 | if (pNode)
|
---|
4065 | {
|
---|
4066 | /*
|
---|
4067 | * Display dialog (modal).
|
---|
4068 | */
|
---|
4069 | VBoxDbgStatsFilterDialog Dialog(this, pNode);
|
---|
4070 | if (Dialog.exec() == QDialog::Accepted)
|
---|
4071 | {
|
---|
4072 | /** @todo it is possible that pNode is invalid now! */
|
---|
4073 | VBoxGuiStatsFilterData * const pOldFilter = pNode->pFilter;
|
---|
4074 | pNode->pFilter = Dialog.dupFilterData();
|
---|
4075 | if (pOldFilter)
|
---|
4076 | delete pOldFilter;
|
---|
4077 | m_pProxyModel->notifyFilterChanges();
|
---|
4078 | }
|
---|
4079 | }
|
---|
4080 | #endif
|
---|
4081 | }
|
---|
4082 |
|
---|
4083 |
|
---|
4084 |
|
---|
4085 |
|
---|
4086 |
|
---|
4087 |
|
---|
4088 | /*
|
---|
4089 | *
|
---|
4090 | * V B o x D b g S t a t s F i l t e r D i a l o g
|
---|
4091 | * V B o x D b g S t a t s F i l t e r D i a l o g
|
---|
4092 | * V B o x D b g S t a t s F i l t e r D i a l o g
|
---|
4093 | *
|
---|
4094 | *
|
---|
4095 | */
|
---|
4096 |
|
---|
4097 | /* static */ QRegularExpression const VBoxDbgStatsFilterDialog::s_UInt64ValidatorRegExp("^([0-9]*|0[Xx][0-9a-fA-F]*)$");
|
---|
4098 |
|
---|
4099 |
|
---|
4100 | /*static*/ QLineEdit *
|
---|
4101 | VBoxDbgStatsFilterDialog::createUInt64LineEdit(uint64_t uValue)
|
---|
4102 | {
|
---|
4103 | QLineEdit *pRet = new QLineEdit;
|
---|
4104 | if (uValue == 0 || uValue == UINT64_MAX)
|
---|
4105 | pRet->setText("");
|
---|
4106 | else
|
---|
4107 | pRet->setText(QString().number(uValue));
|
---|
4108 | pRet->setValidator(new QRegularExpressionValidator(s_UInt64ValidatorRegExp));
|
---|
4109 | return pRet;
|
---|
4110 | }
|
---|
4111 |
|
---|
4112 |
|
---|
4113 | VBoxDbgStatsFilterDialog::VBoxDbgStatsFilterDialog(QWidget *a_pParent, PCDBGGUISTATSNODE a_pNode)
|
---|
4114 | : QDialog(a_pParent)
|
---|
4115 | {
|
---|
4116 | /* Set the window title. */
|
---|
4117 | static char s_szTitlePfx[] = "Filtering - ";
|
---|
4118 | char szTitle[1024 + 128];
|
---|
4119 | memcpy(szTitle, s_szTitlePfx, sizeof(s_szTitlePfx));
|
---|
4120 | VBoxDbgStatsModel::getNodePath(a_pNode, &szTitle[sizeof(s_szTitlePfx) - 1], sizeof(szTitle) - sizeof(s_szTitlePfx));
|
---|
4121 | setWindowTitle(szTitle);
|
---|
4122 |
|
---|
4123 |
|
---|
4124 | /* Copy the old data if any. */
|
---|
4125 | VBoxGuiStatsFilterData const * const pOldFilter = a_pNode->pFilter;
|
---|
4126 | if (pOldFilter)
|
---|
4127 | {
|
---|
4128 | m_Data.uMinValue = pOldFilter->uMinValue;
|
---|
4129 | m_Data.uMaxValue = pOldFilter->uMaxValue;
|
---|
4130 | if (pOldFilter->pRegexName)
|
---|
4131 | m_Data.pRegexName = new QRegularExpression(*pOldFilter->pRegexName);
|
---|
4132 | }
|
---|
4133 |
|
---|
4134 | /* Configure the dialog... */
|
---|
4135 | QVBoxLayout *pMainLayout = new QVBoxLayout(this);
|
---|
4136 |
|
---|
4137 | /* The value / average range: */
|
---|
4138 | QGroupBox *pValueAvgGrpBox = new QGroupBox("Value / Average");
|
---|
4139 | QGridLayout *pValAvgLayout = new QGridLayout;
|
---|
4140 | QLabel *pLabel = new QLabel("Min");
|
---|
4141 | m_pValueAvgMin = createUInt64LineEdit(m_Data.uMinValue);
|
---|
4142 | pLabel->setBuddy(m_pValueAvgMin);
|
---|
4143 | pValAvgLayout->addWidget(pLabel, 0, 0);
|
---|
4144 | pValAvgLayout->addWidget(m_pValueAvgMin, 0, 1);
|
---|
4145 |
|
---|
4146 | pLabel = new QLabel("Max");
|
---|
4147 | m_pValueAvgMax = createUInt64LineEdit(m_Data.uMaxValue);
|
---|
4148 | pLabel->setBuddy(m_pValueAvgMax);
|
---|
4149 | pValAvgLayout->addWidget(pLabel, 1, 0);
|
---|
4150 | pValAvgLayout->addWidget(m_pValueAvgMax, 1, 1);
|
---|
4151 |
|
---|
4152 | pValueAvgGrpBox->setLayout(pValAvgLayout);
|
---|
4153 | pMainLayout->addWidget(pValueAvgGrpBox);
|
---|
4154 |
|
---|
4155 | /* The name filter. */
|
---|
4156 | QGroupBox *pNameGrpBox = new QGroupBox("Name RegExp");
|
---|
4157 | QHBoxLayout *pNameLayout = new QHBoxLayout();
|
---|
4158 | m_pNameRegExp = new QLineEdit;
|
---|
4159 | if (m_Data.pRegexName)
|
---|
4160 | m_pNameRegExp->setText(m_Data.pRegexName->pattern());
|
---|
4161 | else
|
---|
4162 | m_pNameRegExp->setText("");
|
---|
4163 | m_pNameRegExp->setToolTip("Regular expression matching basenames (no parent) to show.");
|
---|
4164 | pNameLayout->addWidget(m_pNameRegExp);
|
---|
4165 | pNameGrpBox->setLayout(pNameLayout);
|
---|
4166 | pMainLayout->addWidget(pNameGrpBox);
|
---|
4167 |
|
---|
4168 | /* Buttons. */
|
---|
4169 | QDialogButtonBox *pButtonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
|
---|
4170 | pButtonBox->button(QDialogButtonBox::Ok)->setDefault(true);
|
---|
4171 | connect(pButtonBox, &QDialogButtonBox::rejected, this, &VBoxDbgStatsFilterDialog::reject);
|
---|
4172 | connect(pButtonBox, &QDialogButtonBox::accepted, this, &VBoxDbgStatsFilterDialog::validateAndAccept);
|
---|
4173 | pMainLayout->addWidget(pButtonBox);
|
---|
4174 | }
|
---|
4175 |
|
---|
4176 |
|
---|
4177 | VBoxDbgStatsFilterDialog::~VBoxDbgStatsFilterDialog()
|
---|
4178 | {
|
---|
4179 | /* anything? */
|
---|
4180 | }
|
---|
4181 |
|
---|
4182 |
|
---|
4183 | VBoxGuiStatsFilterData *
|
---|
4184 | VBoxDbgStatsFilterDialog::dupFilterData(void) const
|
---|
4185 | {
|
---|
4186 | if (m_Data.isAllDefaults())
|
---|
4187 | return NULL;
|
---|
4188 | return m_Data.duplicate();
|
---|
4189 | }
|
---|
4190 |
|
---|
4191 |
|
---|
4192 | uint64_t
|
---|
4193 | VBoxDbgStatsFilterDialog::validateUInt64Field(QLineEdit const *a_pField, uint64_t a_uDefault,
|
---|
4194 | const char *a_pszField, QStringList *a_pLstErrors)
|
---|
4195 | {
|
---|
4196 | QString Str = a_pField->text().trimmed();
|
---|
4197 | if (!Str.isEmpty())
|
---|
4198 | {
|
---|
4199 | QByteArray const StrAsUtf8 = Str.toUtf8();
|
---|
4200 | const char * const pszString = StrAsUtf8.constData();
|
---|
4201 | uint64_t uValue = a_uDefault;
|
---|
4202 | int vrc = RTStrToUInt64Full(pszString, 0, &uValue);
|
---|
4203 | if (vrc == VINF_SUCCESS)
|
---|
4204 | return uValue;
|
---|
4205 | char szMsg[128];
|
---|
4206 | RTStrPrintf(szMsg, sizeof(szMsg), "Invalid %s value: %Rrc - ", a_pszField, vrc);
|
---|
4207 | a_pLstErrors->append(QString(szMsg) + Str);
|
---|
4208 | }
|
---|
4209 |
|
---|
4210 | return a_uDefault;
|
---|
4211 | }
|
---|
4212 |
|
---|
4213 |
|
---|
4214 | void
|
---|
4215 | VBoxDbgStatsFilterDialog::validateAndAccept()
|
---|
4216 | {
|
---|
4217 | QStringList LstErrors;
|
---|
4218 |
|
---|
4219 | /* The numeric fields. */
|
---|
4220 | m_Data.uMinValue = validateUInt64Field(m_pValueAvgMin, 0, "minimum value/avg", &LstErrors);
|
---|
4221 | m_Data.uMaxValue = validateUInt64Field(m_pValueAvgMax, UINT64_MAX, "maximum value/avg", &LstErrors);
|
---|
4222 |
|
---|
4223 | /* The name regexp. */
|
---|
4224 | QString Str = m_pNameRegExp->text().trimmed();
|
---|
4225 | if (!Str.isEmpty())
|
---|
4226 | {
|
---|
4227 | if (!m_Data.pRegexName)
|
---|
4228 | m_Data.pRegexName = new QRegularExpression();
|
---|
4229 | m_Data.pRegexName->setPattern(Str);
|
---|
4230 | if (!m_Data.pRegexName->isValid())
|
---|
4231 | LstErrors.append("Invalid regular expression");
|
---|
4232 | }
|
---|
4233 | else if (m_Data.pRegexName)
|
---|
4234 | {
|
---|
4235 | delete m_Data.pRegexName;
|
---|
4236 | m_Data.pRegexName = NULL;
|
---|
4237 | }
|
---|
4238 |
|
---|
4239 | /* Dismiss the dialog if everything is fine, otherwise complain and keep it open. */
|
---|
4240 | if (LstErrors.isEmpty())
|
---|
4241 | emit accept();
|
---|
4242 | else
|
---|
4243 | {
|
---|
4244 | QMessageBox MsgBox(QMessageBox::Critical, "Invalid input", LstErrors.join("\n"), QMessageBox::Ok);
|
---|
4245 | MsgBox.exec();
|
---|
4246 | }
|
---|
4247 | }
|
---|
4248 |
|
---|
4249 |
|
---|
4250 |
|
---|
4251 |
|
---|
4252 |
|
---|
4253 | /*
|
---|
4254 | *
|
---|
4255 | * V B o x D b g S t a t s
|
---|
4256 | * V B o x D b g S t a t s
|
---|
4257 | * V B o x D b g S t a t s
|
---|
4258 | *
|
---|
4259 | *
|
---|
4260 | */
|
---|
4261 |
|
---|
4262 |
|
---|
4263 | VBoxDbgStats::VBoxDbgStats(VBoxDbgGui *a_pDbgGui, const char *pszFilter /*= NULL*/, const char *pszExpand /*= NULL*/,
|
---|
4264 | const char *pszConfig /*= NULL*/, unsigned uRefreshRate/* = 0*/, QWidget *pParent/* = NULL*/)
|
---|
4265 | : VBoxDbgBaseWindow(a_pDbgGui, pParent, "Statistics")
|
---|
4266 | , m_PatStr(pszFilter), m_pPatCB(NULL), m_uRefreshRate(0), m_pTimer(NULL), m_pView(NULL)
|
---|
4267 | {
|
---|
4268 | /* Delete dialog on close: */
|
---|
4269 | setAttribute(Qt::WA_DeleteOnClose);
|
---|
4270 |
|
---|
4271 | /*
|
---|
4272 | * On top, a horizontal box with the pattern field, buttons and refresh interval.
|
---|
4273 | */
|
---|
4274 | QHBoxLayout *pHLayout = new QHBoxLayout;
|
---|
4275 |
|
---|
4276 | QLabel *pLabel = new QLabel(" Pattern ");
|
---|
4277 | pHLayout->addWidget(pLabel);
|
---|
4278 | pLabel->setMaximumSize(pLabel->sizeHint());
|
---|
4279 | pLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
---|
4280 |
|
---|
4281 | m_pPatCB = new QComboBox();
|
---|
4282 | pHLayout->addWidget(m_pPatCB);
|
---|
4283 | if (!m_PatStr.isEmpty())
|
---|
4284 | m_pPatCB->addItem(m_PatStr);
|
---|
4285 | m_pPatCB->setDuplicatesEnabled(false);
|
---|
4286 | m_pPatCB->setEditable(true);
|
---|
4287 | m_pPatCB->setCompleter(0);
|
---|
4288 | connect(m_pPatCB, SIGNAL(textActivated(const QString &)), this, SLOT(apply(const QString &)));
|
---|
4289 |
|
---|
4290 | QPushButton *pPB = new QPushButton("&All");
|
---|
4291 | pHLayout->addWidget(pPB);
|
---|
4292 | pPB->setMaximumSize(pPB->sizeHint());
|
---|
4293 | connect(pPB, SIGNAL(clicked()), this, SLOT(applyAll()));
|
---|
4294 |
|
---|
4295 | pLabel = new QLabel(" Interval ");
|
---|
4296 | pHLayout->addWidget(pLabel);
|
---|
4297 | pLabel->setMaximumSize(pLabel->sizeHint());
|
---|
4298 | pLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
---|
4299 |
|
---|
4300 | QSpinBox *pSB = new QSpinBox();
|
---|
4301 | pHLayout->addWidget(pSB);
|
---|
4302 | pSB->setMinimum(0);
|
---|
4303 | pSB->setMaximum(60);
|
---|
4304 | pSB->setSingleStep(1);
|
---|
4305 | pSB->setValue(uRefreshRate);
|
---|
4306 | pSB->setSuffix(" s");
|
---|
4307 | pSB->setWrapping(false);
|
---|
4308 | pSB->setButtonSymbols(QSpinBox::PlusMinus);
|
---|
4309 | pSB->setMaximumSize(pSB->sizeHint());
|
---|
4310 | connect(pSB, SIGNAL(valueChanged(int)), this, SLOT(setRefresh(int)));
|
---|
4311 |
|
---|
4312 | #ifdef VBOXDBG_WITH_SORTED_AND_FILTERED_STATS
|
---|
4313 | QCheckBox *pCheckBox = new QCheckBox("Show unused");
|
---|
4314 | pHLayout->addWidget(pCheckBox);
|
---|
4315 | pCheckBox->setMaximumSize(pCheckBox->sizeHint());
|
---|
4316 | connect(pCheckBox, SIGNAL(stateChanged(int)), this, SLOT(sltShowUnusedRowsChanged(int)));
|
---|
4317 | #endif
|
---|
4318 |
|
---|
4319 | /*
|
---|
4320 | * Create the tree view and setup the layout.
|
---|
4321 | */
|
---|
4322 | VBoxDbgStatsModelVM *pModel = new VBoxDbgStatsModelVM(a_pDbgGui, m_PatStr, pszConfig, a_pDbgGui->getVMMFunctionTable());
|
---|
4323 | #ifdef VBOXDBG_WITH_SORTED_AND_FILTERED_STATS
|
---|
4324 | VBoxDbgStatsSortFileProxyModel *pProxyModel = new VBoxDbgStatsSortFileProxyModel(this);
|
---|
4325 | m_pView = new VBoxDbgStatsView(a_pDbgGui, pModel, pProxyModel, this);
|
---|
4326 | pCheckBox->setCheckState(pProxyModel->isShowingUnusedRows() ? Qt::Checked : Qt::Unchecked);
|
---|
4327 | #else
|
---|
4328 | m_pView = new VBoxDbgStatsView(a_pDbgGui, pModel, NULL, this);
|
---|
4329 | #endif
|
---|
4330 |
|
---|
4331 | QWidget *pHBox = new QWidget;
|
---|
4332 | pHBox->setLayout(pHLayout);
|
---|
4333 |
|
---|
4334 | QVBoxLayout *pVLayout = new QVBoxLayout;
|
---|
4335 | pVLayout->addWidget(pHBox);
|
---|
4336 | pVLayout->addWidget(m_pView);
|
---|
4337 | setLayout(pVLayout);
|
---|
4338 |
|
---|
4339 | /*
|
---|
4340 | * Resize the columns.
|
---|
4341 | * Seems this has to be done with all nodes expanded.
|
---|
4342 | */
|
---|
4343 | m_pView->expandAll();
|
---|
4344 | m_pView->resizeColumnsToContent();
|
---|
4345 | m_pView->collapseAll();
|
---|
4346 |
|
---|
4347 | if (pszExpand && *pszExpand)
|
---|
4348 | m_pView->expandMatching(QString(pszExpand));
|
---|
4349 |
|
---|
4350 | /*
|
---|
4351 | * Create a refresh timer and start it.
|
---|
4352 | */
|
---|
4353 | m_pTimer = new QTimer(this);
|
---|
4354 | connect(m_pTimer, SIGNAL(timeout()), this, SLOT(refresh()));
|
---|
4355 | setRefresh(uRefreshRate);
|
---|
4356 |
|
---|
4357 | /*
|
---|
4358 | * And some shortcuts.
|
---|
4359 | */
|
---|
4360 | m_pFocusToPat = new QAction("", this);
|
---|
4361 | m_pFocusToPat->setShortcut(QKeySequence("Ctrl+L"));
|
---|
4362 | addAction(m_pFocusToPat);
|
---|
4363 | connect(m_pFocusToPat, SIGNAL(triggered(bool)), this, SLOT(actFocusToPat()));
|
---|
4364 | }
|
---|
4365 |
|
---|
4366 |
|
---|
4367 | VBoxDbgStats::~VBoxDbgStats()
|
---|
4368 | {
|
---|
4369 | if (m_pTimer)
|
---|
4370 | {
|
---|
4371 | delete m_pTimer;
|
---|
4372 | m_pTimer = NULL;
|
---|
4373 | }
|
---|
4374 |
|
---|
4375 | if (m_pPatCB)
|
---|
4376 | {
|
---|
4377 | delete m_pPatCB;
|
---|
4378 | m_pPatCB = NULL;
|
---|
4379 | }
|
---|
4380 |
|
---|
4381 | if (m_pView)
|
---|
4382 | {
|
---|
4383 | delete m_pView;
|
---|
4384 | m_pView = NULL;
|
---|
4385 | }
|
---|
4386 | }
|
---|
4387 |
|
---|
4388 |
|
---|
4389 | void
|
---|
4390 | VBoxDbgStats::closeEvent(QCloseEvent *a_pCloseEvt)
|
---|
4391 | {
|
---|
4392 | a_pCloseEvt->accept();
|
---|
4393 | }
|
---|
4394 |
|
---|
4395 |
|
---|
4396 | void
|
---|
4397 | VBoxDbgStats::apply(const QString &Str)
|
---|
4398 | {
|
---|
4399 | m_PatStr = Str;
|
---|
4400 | refresh();
|
---|
4401 | }
|
---|
4402 |
|
---|
4403 |
|
---|
4404 | void
|
---|
4405 | VBoxDbgStats::applyAll()
|
---|
4406 | {
|
---|
4407 | apply("");
|
---|
4408 | }
|
---|
4409 |
|
---|
4410 |
|
---|
4411 |
|
---|
4412 | void
|
---|
4413 | VBoxDbgStats::refresh()
|
---|
4414 | {
|
---|
4415 | m_pView->updateStats(m_PatStr);
|
---|
4416 | }
|
---|
4417 |
|
---|
4418 |
|
---|
4419 | void
|
---|
4420 | VBoxDbgStats::setRefresh(int iRefresh)
|
---|
4421 | {
|
---|
4422 | if ((unsigned)iRefresh != m_uRefreshRate)
|
---|
4423 | {
|
---|
4424 | if (!m_uRefreshRate || iRefresh)
|
---|
4425 | m_pTimer->start(iRefresh * 1000);
|
---|
4426 | else
|
---|
4427 | m_pTimer->stop();
|
---|
4428 | m_uRefreshRate = iRefresh;
|
---|
4429 | }
|
---|
4430 | }
|
---|
4431 |
|
---|
4432 |
|
---|
4433 | void
|
---|
4434 | VBoxDbgStats::actFocusToPat()
|
---|
4435 | {
|
---|
4436 | if (!m_pPatCB->hasFocus())
|
---|
4437 | m_pPatCB->setFocus(Qt::ShortcutFocusReason);
|
---|
4438 | }
|
---|
4439 |
|
---|
4440 |
|
---|
4441 | void
|
---|
4442 | VBoxDbgStats::sltShowUnusedRowsChanged(int a_iState)
|
---|
4443 | {
|
---|
4444 | #ifdef VBOXDBG_WITH_SORTED_AND_FILTERED_STATS
|
---|
4445 | m_pView->setShowUnusedRows(a_iState != Qt::Unchecked);
|
---|
4446 | #else
|
---|
4447 | RT_NOREF_PV(a_iState);
|
---|
4448 | #endif
|
---|
4449 | }
|
---|
4450 |
|
---|