VBoxDbgStatsQt4.cpp revision 4d4f336b656d46f8d301603114bb99ce635aafc0
/* $Id$ */
/** @file
* VBox Debugger GUI - Statistics.
*/
/*
* Copyright (C) 2006-2010 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_DBGG
#include "VBoxDbgStatsQt4.h"
#include <QLocale>
#include <QPushButton>
#include <QSpinBox>
#include <QLabel>
#include <QClipboard>
#include <QApplication>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QKeySequence>
#include <QAction>
#include <QContextMenuEvent>
#include <QHeaderView>
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/** The number of column. */
#define DBGGUI_STATS_COLUMNS 9
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/**
* The state of a statistics sample node.
*
* This is used for two pass refresh (1. get data, 2. update the view) and
* for saving the result of a diff.
*/
typedef enum DBGGUISTATSNODESTATE
{
/** The typical invalid zeroth entry. */
/** The node is the root node. */
/** The node is visible. */
/** The node should be refreshed. */
/** diff: The node equals. */
/** diff: The node in set 1 is less than the one in set 2. */
/** diff: The node in set 1 is greater than the one in set 2. */
/** diff: The node is only in set 1. */
/** diff: The node is only in set 2. */
/** The end of the valid state values. */
/**
* A tree node representing a statistic sample.
*
* The nodes carry a reference to the parent and to its position among its
* siblings. Both of these need updating when the grand parent or parent adds a
* new child. This will hopefully not be too expensive but rather pay off when
* we need to create a parent index.
*/
typedef struct DBGGUISTATSNODE
{
/** Pointer to the parent. */
/** Array of pointers to the child nodes. */
/** The number of children. */
/** Our index among the parent's children. */
/** The unit. */
/** The data type.
* For filler nodes not containing data, this will be set to STAMTYPE_INVALID. */
/** The data at last update. */
union
{
/** STAMTYPE_COUNTER. */
/** STAMTYPE_PROFILE. */
/** STAMTYPE_PROFILE_ADV. */
/** STAMTYPE_RATIO_U32. */
/** STAMTYPE_U8 & STAMTYPE_U8_RESET. */
/** STAMTYPE_U16 & STAMTYPE_U16_RESET. */
/** STAMTYPE_U32 & STAMTYPE_U32_RESET. */
/** STAMTYPE_U64 & STAMTYPE_U64_RESET. */
/** STAMTYPE_BOOL and STAMTYPE_BOOL_RESET. */
bool f;
/** STAMTYPE_CALLBACK. */
} Data;
/** The delta. */
/** The name. */
char *pszName;
/** The length of the name. */
/** The description string. */
/** The node state. */
/**
* Recursion stack.
*/
typedef struct DBGGUISTATSSTACK
{
/** The top stack entry. */
/** The stack array. */
struct DBGGUISTATSSTACKENTRY
{
/** The node. */
/** The current child. */
} a[32];
/**
* The item model for the statistics tree view.
*
* This manages the DBGGUISTATSNODE trees.
*/
class VBoxDbgStatsModel : public QAbstractItemModel
{
protected:
/** The root of the sample tree. */
private:
/** Next update child. This is UINT32_MAX when invalid. */
/** Pointer to the node m_szUpdateParent represent and m_iUpdateChild refers to. */
/** The length of the path. */
/** The path to the current update parent, including a trailing slash. */
char m_szUpdateParent[1024];
bool m_fUpdateInsertRemove;
public:
/**
* Constructor.
*
* @param a_pParent The parent object. See QAbstractItemModel in the Qt
* docs for details.
*/
/**
* Destructor.
*
* This will free all the data the model holds.
*/
virtual ~VBoxDbgStatsModel();
/**
* Updates the data matching the specified pattern.
*
* This will should invoke updatePrep, updateCallback and updateDone.
*
* It is vitally important that updateCallback is fed the data in the right
* order. The code make very definite ASSUMPTIONS about the ordering being
* strictly sorted and taking the slash into account when doing so.
*
* @returns true if we reset the model and it's necessary to set the root index.
* @param a_rPatStr The selection pattern.
*
* @remarks The default implementation is an empty stub.
*/
/**
* Similar to updateStatsByPattern, except that it only works on a sub-tree and
* will not remove anything that's outside that tree.
*
* @param a_rIndex The sub-tree root. Invalid index means root.
*
* @todo Create a default implementation using updateStatsByPattern.
*/
/**
* Reset the stats matching the specified pattern.
*
* @param a_rPatStr The selection pattern.
*
* @remarks The default implementation is an empty stub.
*/
/**
* Reset the stats of a sub-tree.
*
* @param a_rIndex The sub-tree root. Invalid index means root.
* @param a_fSubTree Whether to reset the sub-tree as well. Default is true.
*
* @remarks The default implementation makes use of resetStatsByPattern
*/
/**
* Gets the model index of the root node.
*
* @returns root index.
*/
QModelIndex getRootIndex(void) const;
protected:
/**
* Set the root node.
*
* This will free all the current data before taking the ownership of the new
* root node and its children.
*
* @param a_pRoot The new root node.
*/
/** Creates the root node. */
static PDBGGUISTATSNODE createRootNode(void);
/** Creates and insert a node under the given parent. */
static PDBGGUISTATSNODE createAndInsertNode(PDBGGUISTATSNODE pParent, const char *pszName, size_t cchName, uint32_t iPosition);
/** Creates and insert a node under the given parent with correct Qt
* signalling. */
PDBGGUISTATSNODE createAndInsert(PDBGGUISTATSNODE pParent, const char *pszName, size_t cchName, uint32_t iPosition);
/**
* Resets the node to a pristine state.
*
* @param pNode The node.
*/
/**
* Initializes a pristine node.
*/
static int initNode(PDBGGUISTATSNODE pNode, STAMTYPE enmType, void *pvSample, STAMUNIT enmUnit, const char *pszDesc);
/**
* Updates (or reinitializes if you like) a node.
*/
static void updateNode(PDBGGUISTATSNODE pNode, STAMTYPE enmType, void *pvSample, STAMUNIT enmUnit, const char *pszDesc);
/**
* Called by updateStatsByPattern(), makes the necessary preparations.
*
* @returns Success indicator.
*/
bool updatePrepare(void);
/**
* Called by updateStatsByPattern(), finalizes the update.
*
* @return See updateStatsByPattern().
*
* @param a_fSuccess Whether the update was successful or not.
*
*/
bool updateDone(bool a_fSuccess);
/**
* updateCallback() worker taking care of in-tree inserts and removals.
*
* @returns The current node.
* @param pszName The name of the tree element to update.
*/
/**
* updateCallback() worker taking care of tail insertions.
*
* @returns The current node.
* @param pszName The name of the tree element to update.
*/
/**
* updateCallback() worker that advances the update state to the next data node
* in anticipation of the next updateCallback call.
*
* @returns The current node.
* @param pNode The current node.
*/
/** Callback used by updateStatsByPattern() and updateStatsByIndex() to feed
* changes.
* @copydoc FNSTAMR3ENUM */
static DECLCALLBACK(int) updateCallback(const char *pszName, STAMTYPE enmType, void *pvSample, STAMUNIT enmUnit,
/**
* Calculates the full path of a node.
*
* @returns Number of bytes returned, negative value on buffer overflow
*
* @param pNode The node.
* @param psz The output buffer.
* @param cch The size of the buffer.
*/
/**
* Check if the first node is an ancestor to the second one.
*
* @param pAncestor The first node, the alleged ancestor.
* @param pDescendant The second node, the alleged descendant.
*/
/**
* Advance to the next node in the tree.
*
* @returns Pointer to the next node, NULL if we've reached the end or
* was handed a NULL node.
* @param pNode The current node.
*/
/**
* Advance to the next node in the tree that contains data.
*
* @returns Pointer to the next data node, NULL if we've reached the end or
* was handed a NULL node.
* @param pNode The current node.
*/
/**
* Advance to the previous node in the tree.
*
* @returns Pointer to the previous node, NULL if we've reached the end or
* was handed a NULL node.
* @param pNode The current node.
*/
/**
* Advance to the previous node in the tree that contains data.
*
* @returns Pointer to the previous data node, NULL if we've reached the end or
* was handed a NULL node.
* @param pNode The current node.
*/
/**
* Removes a node from the tree.
*
* @returns pNode.
* @param pNode The node.
*/
/**
* Removes a node from the tree and destroys it and all its descendants.
*
* @param pNode The node.
*/
/** Removes a node from the tree and destroys it and all its descendants
* performing the required Qt signalling. */
/**
* Destroys a statistics tree.
*
* @param a_pRoot The root of the tree. NULL is fine.
*/
/**
* Stringifies exactly one node, no children.
*
* This is for logging and clipboard.
*
* @param a_pNode The node.
* @param a_rString The string to append the stringified node to.
*/
/**
* Stringifies a node and its children.
*
* This is for logging and clipboard.
*
* @param a_pNode The node.
* @param a_rString The string to append the stringified node to.
*/
public:
/**
* Converts the specified tree to string.
*
* This is for logging and clipboard.
*
* @param a_rRoot Where to start. Use QModelIndex() to start at the root.
* @param a_rString Where to return to return the string dump.
*/
/**
* Dumps the given (sub-)tree as XML.
*
* @param a_rRoot Where to start. Use QModelIndex() to start at the root.
* @param a_rString Where to return to return the XML dump.
*/
/**
* Puts the stringified tree on the clipboard.
*
* @param a_rRoot Where to start. Use QModelIndex() to start at the root.
*/
protected:
/** Worker for logTree. */
public:
/** Logs a (sub-)tree.
*
* @param a_rRoot Where to start. Use QModelIndex() to start at the root.
* @param a_fReleaseLog Whether to use the release log (true) or the debug log (false).
*/
protected:
/** Gets the unit. */
/** Gets the minimum value. */
/** Gets the average value. */
/** Gets the maximum value. */
/** Gets the total value. */
/** Gets the delta value. */
/**
* Destroys a node and all its children.
*
* @param a_pNode The node to destroy.
*/
/**
* Converts an index to a node pointer.
*
* @returns Pointer to the node, NULL if invalid reference.
* @param a_rIndex Reference to the index
*/
{
return NULL;
}
public:
/** @name Overridden QAbstractItemModel methods
* @{ */
///virtual void sort(int a_iColumn, Qt::SortOrder a_eOrder);
/** @} */
};
/**
* Model using the VM / STAM interface as data source.
*/
{
public:
/**
* Constructor.
*
* @param a_pDbgGui Pointer to the debugger gui object.
* @param a_rPatStr The selection pattern.
* @param a_pParent The parent object. NULL is fine.
*/
/** Destructor */
virtual ~VBoxDbgStatsModelVM();
protected:
/**
* Enumeration callback used by createNewTree.
*/
static DECLCALLBACK(int) createNewTreeCallback(const char *pszName, STAMTYPE enmType, void *pvSample, STAMUNIT enmUnit,
/**
* Constructs a new statistics tree by query data from the VM.
*
* @returns Pointer to the root of the tree we've constructed. This will be NULL
* if the STAM API throws an error or we run out of memory.
* @param a_rPatStr The selection pattern.
*/
};
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
/**
* Formats a number into a 64-byte buffer.
*/
{
static const char s_szDigits[] = "0123456789";
psz += 63;
*psz-- = '\0';
unsigned cDigits = 0;
for (;;)
{
u64 /= 10;
if (!u64)
break;
psz--;
if (!(++cDigits % 3))
*psz-- = ',';
}
return psz;
}
/**
* Formats a number into a 64-byte buffer.
* (18 446 744 073 709 551 615)
*/
{
static const char s_szDigits[] = "0123456789";
psz += 63;
*psz-- = '\0';
unsigned cDigits = 0;
for (;;)
{
u64 /= 10;
if (!u64)
break;
psz--;
if (!(++cDigits % 3))
*psz-- = ',';
}
if (fNegative)
*--psz = '-';
return psz;
}
/**
* Formats a unsigned hexadecimal number into a into a 64-byte buffer.
*/
{
static const char s_szDigits[] = "0123456789abcdef";
psz += 63;
*psz-- = '\0';
unsigned cDigits = 0;
for (;;)
{
u64 /= 16;
++cDigits;
break;
psz--;
if (!(cDigits % 8))
*psz-- = '\'';
}
return psz;
}
#if 0/* unused */
/**
* Formats a sort key number.
*/
{
static const char s_szDigits[] = "0123456789abcdef";
/* signed */
*psz++ = '+';
/* 16 hex digits */
unsigned i = 16;
while (i-- > 0)
{
if (u64)
{
u64 /= 16;
}
else
psz[i] = '0';
}
}
#endif
#if 0/* unused */
/**
* Formats a sort key number.
*/
{
static const char s_szDigits[] = "0123456789abcdef";
/* signed */
if (i64 >= 0)
{
*psz++ = '+';
}
else
{
*psz++ = '-';
}
/* 16 hex digits */
unsigned i = 16;
while (i-- > 0)
{
if (u64)
{
u64 /= 16;
}
else
psz[i] = '0';
}
}
#endif
/*
*
* V B o x D b g S t a t s M o d e l
* V B o x D b g S t a t s M o d e l
* V B o x D b g S t a t s M o d e l
*
*
*/
{
}
{
}
/*static*/ void
{
if (!a_pRoot)
return;
}
/* static*/ void
{
/* destroy all our children */
while (i-- > 0)
{
}
/* free the resources we're using */
{
}
{
}
#ifdef VBOX_STRICT
/* poison it. */
a_pNode->papChildren++;
#endif
/* Finally ourselves */
}
/*static*/ PDBGGUISTATSNODE
VBoxDbgStatsModel::createRootNode(void)
{
if (!pRoot)
return NULL;
return pRoot;
}
/*static*/ PDBGGUISTATSNODE
VBoxDbgStatsModel::createAndInsertNode(PDBGGUISTATSNODE pParent, const char *pszName, size_t cchName, uint32_t iPosition)
{
/*
* Create it.
*/
if (!pNode)
return NULL;
/*
* Do we need to expand the array?
*/
{
void *pvNew = RTMemRealloc(pParent->papChildren, sizeof(*pParent->papChildren) * (pParent->cChildren + 32));
if (!pvNew)
{
return NULL;
}
}
/*
* Insert it.
*/
/* Last. */
else
{
/* Shift all the items after ours. */
{
}
}
/* Insert ours */
return pNode;
}
VBoxDbgStatsModel::createAndInsert(PDBGGUISTATSNODE pParent, const char *pszName, size_t cchName, uint32_t iPosition)
{
else
{
}
return pNode;
}
/*static*/ PDBGGUISTATSNODE
{
if (pParent)
{
{
}
#ifdef VBOX_STRICT /* poison */
#endif
}
return pNode;
}
/*static*/ void
{
}
void
{
else
{
/*
* Removing is fun since the docs are imprecise as to how persistent
* indexes are updated (or aren't). So, let try a few different ideas
* and see which works.
*/
#if 1
/* destroy the children first with the appropriate begin/endRemoveRows signals. */
{
/* get top element */
{
/* push */
}
else
{
/* pop and destroy all the children. */
if (i)
{
while (i-- > 0)
}
}
}
/* finally the node it self. */
#elif 0
/* This ain't working, leaves invalid indexes behind. */
#else
/* Force reset() of the model after the update. */
m_fUpdateInsertRemove = true;
#endif
}
}
/*static*/ void
{
/* free and reinit the data. */
{
}
/* free the description. */
{
}
}
/*static*/ int
VBoxDbgStatsModel::initNode(PDBGGUISTATSNODE pNode, STAMTYPE enmType, void *pvSample, STAMUNIT enmUnit, const char *pszDesc)
{
/*
* Copy the data.
*/
if (pszDesc)
pNode->pDescStr = new QString(pszDesc); /* ignore allocation failure (well, at least up to the point we can ignore it) */
switch (enmType)
{
case STAMTYPE_COUNTER:
break;
case STAMTYPE_PROFILE:
case STAMTYPE_PROFILE_ADV:
break;
case STAMTYPE_RATIO_U32:
case STAMTYPE_RATIO_U32_RESET:
break;
case STAMTYPE_CALLBACK:
{
break;
}
case STAMTYPE_U8:
case STAMTYPE_U8_RESET:
case STAMTYPE_X8:
case STAMTYPE_X8_RESET:
break;
case STAMTYPE_U16:
case STAMTYPE_U16_RESET:
case STAMTYPE_X16:
case STAMTYPE_X16_RESET:
break;
case STAMTYPE_U32:
case STAMTYPE_U32_RESET:
case STAMTYPE_X32:
case STAMTYPE_X32_RESET:
break;
case STAMTYPE_U64:
case STAMTYPE_U64_RESET:
case STAMTYPE_X64:
case STAMTYPE_X64_RESET:
break;
case STAMTYPE_BOOL:
case STAMTYPE_BOOL_RESET:
break;
default:
break;
}
return VINF_SUCCESS;
}
/*static*/ void
VBoxDbgStatsModel::updateNode(PDBGGUISTATSNODE pNode, STAMTYPE enmType, void *pvSample, STAMUNIT enmUnit, const char *pszDesc)
{
/*
* Reset and init the node if the type changed.
*/
{
}
else
{
/*
* ASSUME that only the sample value will change and that the unit, visibility
* and description remains the same.
*/
switch (enmType)
{
case STAMTYPE_COUNTER:
{
{
}
break;
}
case STAMTYPE_PROFILE:
case STAMTYPE_PROFILE_ADV:
{
{
}
break;
}
case STAMTYPE_RATIO_U32:
case STAMTYPE_RATIO_U32_RESET:
{
{
{
}
}
else
{
if (iDeltaA >= 0)
else
}
break;
}
case STAMTYPE_CALLBACK:
{
{
}
{
}
break;
}
case STAMTYPE_U8:
case STAMTYPE_U8_RESET:
case STAMTYPE_X8:
case STAMTYPE_X8_RESET:
{
{
}
break;
}
case STAMTYPE_U16:
case STAMTYPE_U16_RESET:
case STAMTYPE_X16:
case STAMTYPE_X16_RESET:
{
{
}
break;
}
case STAMTYPE_U32:
case STAMTYPE_U32_RESET:
case STAMTYPE_X32:
case STAMTYPE_X32_RESET:
{
{
}
break;
}
case STAMTYPE_U64:
case STAMTYPE_U64_RESET:
case STAMTYPE_X64:
case STAMTYPE_X64_RESET:
{
{
}
break;
}
case STAMTYPE_BOOL:
case STAMTYPE_BOOL_RESET:
{
{
}
break;
}
default:
break;
}
}
}
/*static*/ ssize_t
{
{
/* root - don't add it's slash! */
off = 0;
*psz = '\0';
}
else
{
if (off >= 0)
{
}
}
return off;
}
/*static*/ bool
{
while (pDescendant)
{
if (pDescendant == pAncestor)
return true;
}
return false;
}
/*static*/ PDBGGUISTATSNODE
{
if (!pNode)
return NULL;
/* descend to children. */
return pNode->papChildren[0];
if (!pParent)
return NULL;
/* next sibling. */
/* ascend and advanced to a parent's sibiling. */
for (;;)
{
if (!pParent)
return NULL;
}
}
/*static*/ PDBGGUISTATSNODE
{
do
while ( pNode
return pNode;
}
/*static*/ PDBGGUISTATSNODE
{
if (!pNode)
return NULL;
if (!pParent)
return NULL;
/* previous sibling's latest descendant (better expression anyone?). */
{
return pNode;
}
/* ascend to the parent. */
return pParent;
}
/*static*/ PDBGGUISTATSNODE
{
do
while ( pNode
return pNode;
}
#if 0
/*static*/ PDBGGUISTATSNODE
{
/** @todo */
return NULL;
}
#endif
#if 0
/*static*/ PDBGGUISTATSNODE
{
/** @todo */
return NULL;
}
#endif
#if 0
/*static*/ PDBGGUISTATSNODE
{
/** @todo */
return NULL;
}
#endif
{
/*
* We might be inserting a new node between pPrev and pNode
* or we might be removing one or more nodes. Either case is
* handled in the same rough way.
*
* Might consider optimizing insertion at some later point since this
* is a normal occurrence (dynamic statistics in PATM, IOM, MM, ++).
*/
/*
* Start with the current parent node and look for a common ancestor
* hoping that this is faster than going from the root (saves lookup).
*/
{
break;
}
/*
* modifying m_szUpdateParent as we go along.
*/
{
/* Find the end of this component. */
if (!pszEnd)
/* Add the name to the path. */
{
/* first child */
}
else
{
/* binary search. */
for (;;)
{
int iDiff;
if (!iDiff)
if (iDiff > 0)
{
iStart = i + 1;
{
break;
}
}
else if (iDiff < 0)
{
iLast = i - 1;
{
break;
}
}
else
{
break;
}
}
}
}
/*
* Remove all the nodes between pNode and pPrev but keep all
* of pNode's ancestors (or it'll get orphaned).
*/
{
{
}
}
/*
* Remove the data from all ancestors of pNode that it doesn't
* share them pPrev.
*/
if (pPrev)
{
{
}
}
/*
* Finally, adjust the globals (szUpdateParent is one level too deep).
*/
return pNode;
}
{
/*
* Insert it at the end of the tree.
*
* Do the same as we're doing down in createNewTreeCallback, walk from the
* root and create whatever we need.
*/
while (*pszCur)
{
/* Find the end of this component. */
if (!pszNext)
/* Create it if it doesn't exist (it will be last if it exists). */
{
}
else
/* Advance */
}
return pNode;
}
void
{
/*
* Advance to the next node with data.
*
* ASSUMES a leaf *must* have data and again we're ASSUMING the sorting
* on slash separated sub-strings.
*/
if (m_iUpdateChild != UINT32_MAX)
{
#ifdef VBOX_STRICT
#endif
{
/* descend to the first child. */
}
{
/* next sibling or one if its descendants. */
}
else
{
/* move up and down- / on-wards */
for (;;)
{
/* ascend */
if (!pParent)
{
m_szUpdateParent[0] = '\0';
m_cchUpdateParent = 0;
break;
}
/* try advance */
{
break;
}
}
}
/* descend to a node containing data and finalize the globals. (ASSUMES leaf has data.) */
if (m_iUpdateChild != UINT32_MAX)
{
{
}
}
}
/* else: we're at the end */
}
/*static*/ DECLCALLBACK(int)
VBoxDbgStatsModel::updateCallback(const char *pszName, STAMTYPE enmType, void *pvSample, STAMUNIT enmUnit,
{
/*
* Skip the ones which shouldn't be visible in the GUI.
*/
if (enmVisibility == STAMVISIBILITY_NOT_GUI)
return 0;
/*
* The default assumption is that nothing has changed.
* For now we'll reset the model when ever something changes.
*/
{
/* got it! */;
else
{
if (!pNode)
return VERR_NO_MEMORY;
}
}
else
{
/* append */
if (!pNode)
return VERR_NO_MEMORY;
}
/*
* Perform the update and advance to the next one.
*/
return VINF_SUCCESS;
}
bool
VBoxDbgStatsModel::updatePrepare(void)
{
/*
* Find the first child with data and set it up as the 'next'
* node to be updated.
*/
if (pFirst)
{
}
else
{
m_szUpdateParent[0] = '\0';
m_cchUpdateParent = 0;
}
/*
* Set the flag and signal possible layout change.
*/
m_fUpdateInsertRemove = false;
/* emit layoutAboutToBeChanged(); - debug this, it gets stuck... */
return true;
}
bool
{
/*
* Remove any nodes following the last in the update (unless the update failed).
*/
if ( a_fSuccess
&& m_iUpdateChild != UINT32_MAX)
{
if (!pLast)
{
/* nuking the whole tree. */
m_fUpdateInsertRemove = true;
}
else
{
{
}
}
}
/*
* We're done making layout changes (if I understood it correctly), so,
* signal this and then see what to do next. If we did too many removals
* we'll just reset the whole shebang.
*/
{
/* emit layoutChanged(); - hrmpf, doesn't work reliably... */
reset();
}
else
{
/*
* Send dataChanged events.
*
* We do this here instead of from the updateCallback because it reduces
* the clutter in that method and allow us to emit bulk signals in an
* easier way because we can traverse the tree in a different fashion.
*/
{
/* get top element */
{
/* push */
}
else
{
/* pop */
/* do the actual work. */
iChild = 0;
{
/* skip to the first needing updating. */
iChild++;
break;
/* any subsequent nodes that also needs refreshing? */
{
QModelIndex BottomRight = createIndex(iChild - 1, DBGGUI_STATS_COLUMNS - 1, pNode->papChildren[iChild - 1]);
/* emit the refresh signal */
}
else
{
/* emit the refresh signal */
}
}
}
}
/* emit layoutChanged(); - hrmpf, doesn't work reliably... */
}
return m_fUpdateInsertRemove;
}
bool
{
/* stub */
return false;
}
void
{
/** @todo implement this based on updateStatsByPattern. */
}
void
{
/* stub */
}
void
{
{
if (fSubTree)
{
/* everything from the root down. */
}
}
else if (pNode)
{
/* the node pattern. */
AssertReturnVoid(cch >= 0);
/* the sub-tree pattern. */
{
*psz++ = '|';
*psz++ = '/';
*psz++ = '*';
*psz++ = '\0';
}
}
}
VBoxDbgStatsModel::getRootIndex(void) const
{
if (!m_pRoot)
return QModelIndex();
return createIndex(0, 0, m_pRoot);
}
void
{
reset();
}
{
return fFlags;
}
int
{
return DBGGUI_STATS_COLUMNS;
}
int
{
}
bool
{
}
{
if (!pParent)
{
|| iRow
|| (unsigned)iColumn < DBGGUI_STATS_COLUMNS)
{
return QModelIndex();
}
/* root */
}
{
Log(("index: iRow=%d >= cChildren=%u (iColumn=%d)\n", iRow, (unsigned)pParent->cChildren, iColumn));
return QModelIndex(); /* bug? */
}
if ((unsigned)iColumn >= DBGGUI_STATS_COLUMNS)
{
return QModelIndex(); /* bug? */
}
}
{
if (!pChild)
{
Log(("parent: invalid child\n"));
return QModelIndex(); /* bug */
}
if (!pParent)
return QModelIndex(); /* ultimate root */
}
{
switch (a_iSection)
{
case 0: return tr("Name");
default:
return QVariant(); /* bug */
}
switch (a_iSection)
{
case 0:
case 1:
return QVariant();
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
return QVariant();
default:
return QVariant(); /* bug */
}
return QVariant();
}
/*static*/ QString
{
return "";
}
/*static*/ QString
{
char sz[128];
{
case STAMTYPE_COUNTER:
case STAMTYPE_PROFILE:
case STAMTYPE_PROFILE_ADV:
return "0";
case STAMTYPE_RATIO_U32:
case STAMTYPE_RATIO_U32_RESET:
{
*psz++ = ':';
return psz;
}
case STAMTYPE_CALLBACK:
case STAMTYPE_U8:
case STAMTYPE_U8_RESET:
case STAMTYPE_X8:
case STAMTYPE_X8_RESET:
case STAMTYPE_U16:
case STAMTYPE_U16_RESET:
case STAMTYPE_X16:
case STAMTYPE_X16_RESET:
case STAMTYPE_U32:
case STAMTYPE_U32_RESET:
case STAMTYPE_X32:
case STAMTYPE_X32_RESET:
case STAMTYPE_U64:
case STAMTYPE_U64_RESET:
case STAMTYPE_X64:
case STAMTYPE_X64_RESET:
case STAMTYPE_BOOL:
case STAMTYPE_BOOL_RESET:
default:
case STAMTYPE_INVALID:
return "";
}
}
/*static*/ QString
{
char sz[128];
{
case STAMTYPE_PROFILE:
case STAMTYPE_PROFILE_ADV:
return "0";
default:
return "";
}
}
/*static*/ QString
{
char sz[128];
{
case STAMTYPE_PROFILE:
case STAMTYPE_PROFILE_ADV:
return "0";
default:
return "";
}
}
/*static*/ QString
{
char sz[128];
{
case STAMTYPE_PROFILE:
case STAMTYPE_PROFILE_ADV:
return "0";
default:
return "";
}
}
/*static*/ QString
{
char sz[128];
{
case STAMTYPE_PROFILE:
case STAMTYPE_PROFILE_ADV:
return "0";
default:
return "";
}
}
/*static*/ QString
{
char sz[128];
{
case STAMTYPE_PROFILE:
case STAMTYPE_PROFILE_ADV:
return "0";
/* fall thru */
case STAMTYPE_COUNTER:
case STAMTYPE_RATIO_U32:
case STAMTYPE_RATIO_U32_RESET:
case STAMTYPE_U8:
case STAMTYPE_U8_RESET:
case STAMTYPE_X8:
case STAMTYPE_X8_RESET:
case STAMTYPE_U16:
case STAMTYPE_U16_RESET:
case STAMTYPE_X16:
case STAMTYPE_X16_RESET:
case STAMTYPE_U32:
case STAMTYPE_U32_RESET:
case STAMTYPE_X32:
case STAMTYPE_X32_RESET:
case STAMTYPE_U64:
case STAMTYPE_U64_RESET:
case STAMTYPE_X64:
case STAMTYPE_X64_RESET:
case STAMTYPE_BOOL:
case STAMTYPE_BOOL_RESET:
default:
return "";
}
}
{
if (iCol >= DBGGUI_STATS_COLUMNS)
return QVariant();
{
if (!pNode)
return QVariant();
switch (iCol)
{
case 0:
case 1:
case 2:
return strValueTimes(pNode);
case 3:
return strMinValue(pNode);
case 4:
return strAvgValue(pNode);
case 5:
return strMaxValue(pNode);
case 6:
return strTotalValue(pNode);
case 7:
return strDeltaValue(pNode);
case 8:
default:
return QVariant();
}
}
switch (iCol)
{
case 0:
case 1:
return QVariant();
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
return QVariant();
default:
return QVariant(); /* bug */
}
return QVariant();
}
/*static*/ void
{
/*
* Get the path, padding it to 32-chars and add it to the string.
*/
char szBuf[1024];
AssertReturnVoid(off >= 0);
if (off < 32)
{
off = 32;
}
/*
* The following is derived from stamR3PrintOne, except
* we print to szBuf, do no visibility checks and can skip
* the path bit.
*/
{
case STAMTYPE_COUNTER:
RTStrPrintf(szBuf, sizeof(szBuf), "%8llu %s", a_pNode->Data.Counter.c, STAMR3GetUnit(a_pNode->enmUnit));
break;
case STAMTYPE_PROFILE:
case STAMTYPE_PROFILE_ADV:
{
"%8llu %s (%12llu ticks, %7llu times, max %9llu, min %7lld)",
a_pNode->Data.Profile.cTicks, a_pNode->Data.Profile.cPeriods, a_pNode->Data.Profile.cTicksMax, a_pNode->Data.Profile.cTicksMin);
break;
}
case STAMTYPE_RATIO_U32:
case STAMTYPE_RATIO_U32_RESET:
"%8u:%-8u %s",
break;
case STAMTYPE_CALLBACK:
break;
case STAMTYPE_U8:
case STAMTYPE_U8_RESET:
break;
case STAMTYPE_X8:
case STAMTYPE_X8_RESET:
break;
case STAMTYPE_U16:
case STAMTYPE_U16_RESET:
break;
case STAMTYPE_X16:
case STAMTYPE_X16_RESET:
break;
case STAMTYPE_U32:
case STAMTYPE_U32_RESET:
break;
case STAMTYPE_X32:
case STAMTYPE_X32_RESET:
break;
case STAMTYPE_U64:
case STAMTYPE_U64_RESET:
break;
case STAMTYPE_X64:
case STAMTYPE_X64_RESET:
break;
case STAMTYPE_BOOL:
case STAMTYPE_BOOL_RESET:
RTStrPrintf(szBuf, sizeof(szBuf), "%s %s", a_pNode->Data.f ? "true " : "false ", STAMR3GetUnit(a_pNode->enmUnit));
break;
default:
return;
}
}
/*static*/ void
{
/* this node (if it has data) */
{
a_rString += "\n";
}
/* the children */
}
void
{
if (pRoot)
}
void
{
if (pClipboard)
}
/*static*/ void
{
/* this node (if it has data) */
{
if (a_fReleaseLog)
else
}
/* the children */
}
void
{
if (pRoot)
}
/*
*
* V B o x D b g S t a t s M o d e l V M
* V B o x D b g S t a t s M o d e l V M
* V B o x D b g S t a t s M o d e l V M
*
*
*/
VBoxDbgStatsModelVM::VBoxDbgStatsModelVM(VBoxDbgGui *a_pDbgGui, QString &a_rPatStr, QObject *a_pParent)
{
/*
* Create a model containing the STAM entries matching the pattern.
* flag that it turned out didn't exist.)
*/
}
{
/* nothing to do here. */
}
bool
{
/** @todo the way we update this stuff is independent of the source (XML, file, STAM), our only
* ASSUMPTION is that the input is strictly ordered by (fully slashed) name. So, all this stuff
* should really move up into the parent class. */
bool fRc = updatePrepare();
if (fRc)
{
}
return fRc;
}
void
{
}
/*static*/ DECLCALLBACK(int)
VBoxDbgStatsModelVM::createNewTreeCallback(const char *pszName, STAMTYPE enmType, void *pvSample, STAMUNIT enmUnit,
{
/*
* Skip the ones which shouldn't be visible in the GUI.
*/
if (enmVisibility == STAMVISIBILITY_NOT_GUI)
return 0;
/*
* Perform a mkdir -p like operation till we've walked / created the entire path down
* to the node specfied node. Remember the last node as that will be the one we will
* stuff the data into.
*/
while (*pszCur)
{
/* find the end of this component. */
if (!pszNext)
/* Create it if it doesn't exist (it will be last if it exists). */
{
if (!pNode)
return VERR_NO_MEMORY;
}
else
/* Advance */
}
/*
* Save the data.
*/
}
{
if (pRoot)
{
if (RT_SUCCESS(rc))
return pRoot;
/* failed, cleanup. */
}
return NULL;
}
/*
*
* V B o x D b g S t a t s V i e w
* V B o x D b g S t a t s V i e w
* V B o x D b g S t a t s V i e w
*
*
*/
VBoxDbgStatsView::VBoxDbgStatsView(VBoxDbgGui *a_pDbgGui, VBoxDbgStatsModel *a_pModel, VBoxDbgStats *a_pParent/* = NULL*/)
: QTreeView(a_pParent), VBoxDbgBase(a_pDbgGui), m_pModel(a_pModel), m_PatStr(), m_pParent(a_pParent),
{
/*
* Set the model and view defaults.
*/
setRootIsDecorated(true);
QModelIndex RootIdx = m_pModel->getRootIndex(); /* This should really be QModelIndex(), but Qt on darwin does wrong things then. */
setItemsExpandable(true);
setAlternatingRowColors(true);
/// @todo sorting setSortingEnabled(true);
/*
* Create and setup the actions.
*/
/*
* Create the menus and populate them.
*/
m_pLeafMenu = new QMenu();
m_pBranchMenu = new QMenu(this);
m_pViewMenu = new QMenu();
/* the header menu */
connect(pHdrView, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(headerContextMenuRequested(const QPoint &)));
}
{
m_pCurMenu = NULL;
m_CurIndex = QModelIndex();
}
void
{
}
void
{
for (int i = 0; i <= 8; i++)
}
void
{
for (int i = 0; i < cRows; i++)
}
void
{
/*
* Get the selected item.
* If it's a mouse event select the item under the cursor (if any).
*/
{
}
else
{
}
/*
* Popup the corresponding menu.
*/
pMenu = m_pViewMenu;
else
pMenu = m_pLeafMenu;
if (pMenu)
{
m_CurIndex = Idx;
m_pCurMenu = pMenu;
m_pCurMenu = NULL;
m_CurIndex = QModelIndex();
if (m_pRefreshAct)
m_pRefreshAct->setEnabled(true);
}
}
void
{
/*
* Show the view menu.
*/
if (m_pViewMenu)
{
m_pRefreshAct->setEnabled(true);
m_pCurMenu = NULL;
m_CurIndex = QModelIndex();
if (m_pRefreshAct)
m_pRefreshAct->setEnabled(true);
}
}
void
{
}
void
{
}
void
{
{
}
else
}
void
{
else
}
void
{
}
void
{
}
void
{
}
void
{
}
/*
*
* V B o x D b g S t a t s
* V B o x D b g S t a t s
* V B o x D b g S t a t s
*
*
*/
VBoxDbgStats::VBoxDbgStats(VBoxDbgGui *a_pDbgGui, const char *pszPat/* = NULL*/, unsigned uRefreshRate/* = 0*/, QWidget *pParent/* = NULL*/)
: VBoxDbgBaseWindow(a_pDbgGui, pParent), m_PatStr(pszPat), m_pPatCB(NULL), m_uRefreshRate(0), m_pTimer(NULL), m_pView(NULL)
{
setWindowTitle("VBoxDbg - Statistics");
/*
* On top, a horizontal box with the pattern field, buttons and refresh interval.
*/
m_pPatCB->setAutoCompletion(false);
m_pPatCB->setDuplicatesEnabled(false);
m_pPatCB->setEditable(true);
pSB->setMinimum(0);
pSB->setWrapping(false);
/*
* Create the tree view and setup the layout.
*/
/*
* Resize the columns.
* Seems this has to be done with all nodes expanded.
*/
m_pView->collapseAll();
/*
* Create a refresh timer and start it.
*/
/*
* And some shortcuts.
*/
}
{
if (m_pTimer)
{
delete m_pTimer;
}
if (m_pPatCB)
{
delete m_pPatCB;
}
if (m_pView)
{
delete m_pView;
}
}
void
{
a_pCloseEvt->accept();
delete this;
}
void
{
refresh();
}
void
{
apply("");
}
void
{
}
void
{
if ((unsigned)iRefresh != m_uRefreshRate)
{
if (!m_uRefreshRate || iRefresh)
else
}
}
void
{
}