From 251b0fa5c07487d416400dfea72816d14fb6641a Mon Sep 17 00:00:00 2001 From: Siana Gearz Date: Thu, 1 Mar 2012 13:49:47 +0100 Subject: [PATCH] Memory consumption in statistics floater --- indra/newview/llfloaterstats.cpp | 6 +-- indra/newview/llviewerdisplay.cpp | 2 + indra/newview/llviewerstats.cpp | 12 ++++++ indra/newview/sgmemstat.cpp | 68 +++++++++++++++++++++++++++++-- indra/newview/sgmemstat.h | 2 + 5 files changed, 84 insertions(+), 6 deletions(-) diff --git a/indra/newview/llfloaterstats.cpp b/indra/newview/llfloaterstats.cpp index 84c637f2c..fa71cfb13 100644 --- a/indra/newview/llfloaterstats.cpp +++ b/indra/newview/llfloaterstats.cpp @@ -105,9 +105,9 @@ void LLFloaterStats::buildStats() stat_barp = stat_viewp->addStat("Allocated memory", &(LLViewerStats::getInstance()->mMallocStat), "DebugStatModeMalloc"); stat_barp->setUnitLabel(" MB"); stat_barp->mMinBar = 0.f; - stat_barp->mMaxBar = 4000.f; - stat_barp->mTickSpacing = 100.f; - stat_barp->mLabelSpacing = 200.f; + stat_barp->mMaxBar = 2048.f; + stat_barp->mTickSpacing = 128.f; + stat_barp->mLabelSpacing = 512.f; stat_barp->mPerSec = FALSE; stat_barp->mDisplayMean = FALSE; } diff --git a/indra/newview/llviewerdisplay.cpp b/indra/newview/llviewerdisplay.cpp index 949235013..bf7d50e9f 100644 --- a/indra/newview/llviewerdisplay.cpp +++ b/indra/newview/llviewerdisplay.cpp @@ -83,6 +83,7 @@ #include "llwlparammanager.h" #include "llwaterparammanager.h" #include "llpostprocess.h" +#include "sgmemstat.h" // [RLVa:KB] #include "rlvhandler.h" @@ -229,6 +230,7 @@ void display_stats() U32 memory = (U32)(gMemoryAllocated / (1024*1024)); llinfos << llformat("MEMORY: %d MB", memory) << llendl; llinfos << "THREADS: "<< LLThread::getCount() << llendl; + llinfos << "MALLOC: " << SGMemStat::getPrintableStat() <= mem_stats_freq) + { + LLViewerStats::getInstance()->mMallocStat.addValue(SGMemStat::getMalloc()/1024.f/1024.f); + mem_stats_timer.reset(); + } + } + + #if LL_LCD_COMPILE bool LCDenabled = gLcdScreen->Enabled(); LLViewerStats::getInstance()->setStat(LLViewerStats::ST_LOGITECH_LCD, LCDenabled); diff --git a/indra/newview/sgmemstat.cpp b/indra/newview/sgmemstat.cpp index 27f3cc7cb..0fbe006f6 100644 --- a/indra/newview/sgmemstat.cpp +++ b/indra/newview/sgmemstat.cpp @@ -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 diff --git a/indra/newview/sgmemstat.h b/indra/newview/sgmemstat.h index 8a89e3b0d..1768f66ef 100644 --- a/indra/newview/sgmemstat.h +++ b/indra/newview/sgmemstat.h @@ -26,6 +26,8 @@ F32 getMalloc(); U32 getNumObjects(); +std::string getPrintableStat(); + } #endif