Skip to content

Commit

Permalink
Added debugging ccmd "varstats" - print detailed statistical info
Browse files Browse the repository at this point in the history
about the PathDirectory used for the console variable database.
  • Loading branch information
danij-deng committed Aug 14, 2011
1 parent d173a2e commit d30a76c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
5 changes: 4 additions & 1 deletion doomsday/engine/api/dd_share.h
Expand Up @@ -1261,9 +1261,12 @@ typedef enum {
CVT_BYTE,
CVT_INT,
CVT_FLOAT,
CVT_CHARPTR // ptr points to a char*, which points to the string.
CVT_CHARPTR, // ptr points to a char*, which points to the string.
CVARTYPE_COUNT
} cvartype_t;

#define VALID_CVARTYPE(val) ((val) >= CVT_NULL && (val) <= CVARTYPE_COUNT)

/**
* Console variable template. Used with Con_AddVariable.
*/
Expand Down
3 changes: 3 additions & 0 deletions doomsday/engine/data/cphelp.txt
Expand Up @@ -533,6 +533,9 @@ inf = Params: uicolor (object) (red) (green) (blue)\nFor example, 'uicolor text
desc = Unload the current game or one or more data files.
inf = Params: unload (name) ...\nFor example, 'unload mylevel.wad'.

[varstats]
desc = Show detailed statistics for console variables.

[version]
desc = Show detailed version information.

Expand Down
2 changes: 2 additions & 0 deletions doomsday/engine/portable/include/con_main.h
Expand Up @@ -97,6 +97,8 @@ typedef struct cvar_s {
void (*notifyChanged)(void);
} cvar_t;

static const ddstring_t* CVar_TypeName(cvartype_t type);

/// @return Type of the variable.
cvartype_t CVar_Type(const cvar_t* var);

Expand Down
37 changes: 37 additions & 0 deletions doomsday/engine/portable/src/con_data.c
Expand Up @@ -56,6 +56,7 @@ D_CMD(HelpWhat);
D_CMD(ListAliases);
D_CMD(ListCmds);
D_CMD(ListVars);
D_CMD(VarStats);

// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------

Expand Down Expand Up @@ -97,6 +98,7 @@ void Con_DataRegister(void)
C_CMD("listaliases", NULL, ListAliases);
C_CMD("listcmds", NULL, ListCmds);
C_CMD("listvars", NULL, ListVars);
C_CMD("varstats", NULL, VarStats);
}

static int markStringVariableFreed(struct pathdirectory_node_s* node, void* paramaters)
Expand Down Expand Up @@ -415,6 +417,18 @@ static void updateKnownWords(void)
knownWordsNeedUpdate = false;
}

static const ddstring_t* CVar_TypeName(cvartype_t type)
{
static const ddstring_t names[CVARTYPE_COUNT] = {
{ "invalid" },
{ "CVT_BYTE" },
{ "CVT_INT" },
{ "CVT_FLOAT" },
{ "CVT_CHATPTR"},
};
return &names[(VALID_CVARTYPE(type)? type : 0)];
}

cvartype_t CVar_Type(const cvar_t* var)
{
assert(NULL != var);
Expand Down Expand Up @@ -1537,6 +1551,29 @@ D_CMD(ListVars)
return true;
}

D_CMD(VarStats)
{
cvartype_t type;
countvariableparams_t p;
Con_FPrintf(CBLF_YELLOW, "Console Variable Statistics:\n");
p.hidden = false;
p.ignoreHidden = false;
for(type = CVT_BYTE; type < CVARTYPE_COUNT; ++type)
{
p.count = 0;
p.type = type;
PathDirectory_Iterate2_Const(cvarDirectory, PCF_NO_BRANCH, NULL, PATHDIRECTORY_PATHHASH_SIZE, countVariable, &p);
Con_Printf("%12s: %u\n", Str_Text(CVar_TypeName(type)), p.count);
}
p.count = 0;
p.type = -1;
p.hidden = true;
PathDirectory_Iterate2_Const(cvarDirectory, PCF_NO_BRANCH, NULL, PATHDIRECTORY_PATHHASH_SIZE, countVariable, &p);
Con_Printf(" Total: %u\n Hidden: %u\n\n", cvarCount, p.count);
PathDirectory_PrintHashDistribution(cvarDirectory);
return true;
}

D_CMD(ListAliases)
{
uint numPrinted = 0;
Expand Down

0 comments on commit d30a76c

Please sign in to comment.