Memory consumption in statistics floater

This commit is contained in:
Siana Gearz
2012-03-01 13:49:47 +01:00
parent ab26e1008f
commit 251b0fa5c0
5 changed files with 84 additions and 6 deletions

View File

@@ -18,14 +18,76 @@
#include "llviewerprecompiledheaders.h"
#include "sgmemstat.h"
#if 0
bool SGMemStat::haveStat() {
return false;
return false;
}
F32 SGMemStat::getMalloc() {
return 0.f;
return 0.f;
}
U32 SGMemStat::getNumObjects() {
return 0;
return 0;
}
std::string SGMemStat::getPrintableStat() {
return std::string();
}
#else
extern "C" {
typedef void (*MallocExtension_GetStats_t)(char* buffer, int buffer_length);
typedef int (*MallocExtension_GetNumericProperty_t)(const char* property, size_t* value);
//typedef int (*MallocExtension_SetNumericProperty_t)(const char* property, size_t value);
}
static MallocExtension_GetNumericProperty_t MallocExtension_GetNumericProperty = 0;
static MallocExtension_GetStats_t MallocExtension_GetStats = 0;
static void initialize() {
static bool initialized = false;
if (!initialized) {
apr_dso_handle_t* hprog;// = (apr_dso_handle_t*)dlopen(0,0);
LLAPRPool pool;
pool.create();
apr_dso_load(&hprog, 0, pool());
apr_dso_sym((apr_dso_handle_sym_t*)&MallocExtension_GetNumericProperty,
hprog, "MallocExtension_GetNumericProperty");
apr_dso_sym((apr_dso_handle_sym_t*)&MallocExtension_GetStats,
hprog, "MallocExtension_GetStats");
initialized = true;
}
}
bool SGMemStat::haveStat() {
initialize();
return MallocExtension_GetNumericProperty;
}
F32 SGMemStat::getMalloc() {
if(MallocExtension_GetNumericProperty) {
size_t value;
MallocExtension_GetNumericProperty("generic.current_allocated_bytes", &value);
return value;
}
else return 0.0f;
}
U32 SGMemStat::getNumObjects() {
return 0;
}
std::string SGMemStat::getPrintableStat() {
initialize();
if (MallocExtension_GetStats) {
char buffer[4096];
buffer[4095] = 0;
MallocExtension_GetStats(buffer, 4095);
return std::string(buffer);
}
else return std::string();
}
#endif