Checkpoint on a utility helper class. Basically, if you have a class that you want to count the numbers of instances, you do this:
class Foo
#ifdef TRACK_OBJECT_USAGE
: public InstanceCounter<Foo>
#endif
Then, use this macro somewhere in the class body:
SUPPORT_OBJECT_ANALYTICS(Foo)
Lastly, add whatever information you want to trace out to the function ObjectAnalytics::DumpStatistics().
Here's a sample of the output of what I've instrumented so far:
-----------------------------------------------------------
Object Usage Stats
CardPrimitive current count: 7899
CardPrimitive current byte usage: 2053740
CardPrimitive max count: 7908
CardPrimitive max byte usage: 2056080
MTGCard current count: 13973
MTGCard current byte usage: 670704
MTGCard max count: 13982
MTGCard max byte usage: 671136
MTGCardInstance current count: 180
MTGCardInstance current byte usage: 172080
MTGCardInstance max count: 189
MTGCardInstance max byte usage: 180684
-----------------------------------------------------------
This commit is contained in:
@@ -8,6 +8,8 @@
|
||||
|
||||
using std::string;
|
||||
|
||||
SUPPORT_OBJECT_ANALYTICS(CardPrimitive)
|
||||
|
||||
CardPrimitive::CardPrimitive()
|
||||
{
|
||||
init();
|
||||
@@ -44,6 +46,10 @@ CardPrimitive::CardPrimitive(CardPrimitive * source)
|
||||
alias = source->alias;
|
||||
}
|
||||
|
||||
CardPrimitive::~CardPrimitive()
|
||||
{
|
||||
}
|
||||
|
||||
int CardPrimitive::init()
|
||||
{
|
||||
basicAbilities.clear();
|
||||
|
||||
@@ -268,6 +268,11 @@ void GameApp::LoadGameStates()
|
||||
void GameApp::Destroy()
|
||||
{
|
||||
LOG("==Destroying GameApp==");
|
||||
|
||||
#ifdef TRACK_OBJECT_USAGE
|
||||
ObjectAnalytics::DumpStatistics();
|
||||
#endif
|
||||
|
||||
for (int i = GAME_STATE_MENU; i <= GAME_STATE_MAX - 1; i++)
|
||||
{
|
||||
if (mGameStates[i])
|
||||
|
||||
@@ -245,6 +245,10 @@ void GameStateDuel::End()
|
||||
{
|
||||
DebugTrace("Ending GameStateDuel");
|
||||
|
||||
#ifdef TRACK_OBJECT_USAGE
|
||||
ObjectAnalytics::DumpStatistics();
|
||||
#endif
|
||||
|
||||
JRenderer::GetInstance()->EnableVSync(false);
|
||||
if (!premadeDeck && mPlayers[0] && mPlayers[1])
|
||||
{ // save the stats for the game
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
|
||||
using std::string;
|
||||
|
||||
SUPPORT_OBJECT_ANALYTICS(MTGCard)
|
||||
|
||||
MTGCard::MTGCard()
|
||||
{
|
||||
init();
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
SUPPORT_OBJECT_ANALYTICS(MTGCardInstance)
|
||||
|
||||
MTGCardInstance MTGCardInstance::AnyCard = MTGCardInstance();
|
||||
MTGCardInstance MTGCardInstance::NoCard = MTGCardInstance();
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
|
||||
#include "ObjectAnalytics.h"
|
||||
|
||||
#include "CardPrimitive.h"
|
||||
#include "DebugRoutines.h"
|
||||
#include "MTGCard.h"
|
||||
#include "MTGCardInstance.h"
|
||||
|
||||
namespace ObjectAnalytics
|
||||
{
|
||||
void DumpStatistics()
|
||||
{
|
||||
#ifdef TRACK_OBJECT_USAGE
|
||||
|
||||
DebugTrace("-----------------------------------------------------------");
|
||||
DebugTrace("Object Usage Stats" << std::endl);
|
||||
DebugTrace("CardPrimitive current count: " << InstanceCounter<CardPrimitive>::GetCurrentObjectCount());
|
||||
DebugTrace("CardPrimitive current byte usage: " << InstanceCounter<CardPrimitive>::GetCurrentByteCount());
|
||||
DebugTrace("CardPrimitive max count: " << InstanceCounter<CardPrimitive>::GetMaximumObjectCount());
|
||||
DebugTrace("CardPrimitive max byte usage: " << InstanceCounter<CardPrimitive>::GetMaximumByteCount() << std::endl);
|
||||
|
||||
DebugTrace("MTGCard current count: " << InstanceCounter<MTGCard>::GetCurrentObjectCount());
|
||||
DebugTrace("MTGCard current byte usage: " << InstanceCounter<MTGCard>::GetCurrentByteCount());
|
||||
DebugTrace("MTGCard max count: " << InstanceCounter<MTGCard>::GetMaximumObjectCount());
|
||||
DebugTrace("MTGCard max byte usage: " << InstanceCounter<MTGCard>::GetMaximumByteCount() << std::endl);
|
||||
|
||||
DebugTrace("MTGCardInstance current count: " << InstanceCounter<MTGCardInstance>::GetCurrentObjectCount());
|
||||
DebugTrace("MTGCardInstance current byte usage: " << InstanceCounter<MTGCardInstance>::GetCurrentByteCount());
|
||||
DebugTrace("MTGCardInstance max count: " << InstanceCounter<MTGCardInstance>::GetMaximumObjectCount());
|
||||
DebugTrace("MTGCardInstance max byte usage: " << InstanceCounter<MTGCardInstance>::GetMaximumByteCount() << std::endl);
|
||||
|
||||
DebugTrace("-----------------------------------------------------------");
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user