diff options
Diffstat (limited to 'indra/llcommon')
-rw-r--r-- | indra/llcommon/llapr.cpp | 2 | ||||
-rw-r--r-- | indra/llcommon/llapr.h | 1 | ||||
-rw-r--r-- | indra/llcommon/llerror.cpp | 1 | ||||
-rw-r--r-- | indra/llcommon/llmemory.cpp | 143 | ||||
-rw-r--r-- | indra/llcommon/llmemory.h | 5 | ||||
-rw-r--r-- | indra/llcommon/llthread.cpp | 2 |
6 files changed, 150 insertions, 4 deletions
diff --git a/indra/llcommon/llapr.cpp b/indra/llcommon/llapr.cpp index bf6a4d1b21..8ee939af08 100644 --- a/indra/llcommon/llapr.cpp +++ b/indra/llcommon/llapr.cpp @@ -24,7 +24,7 @@ void ll_init_apr() apr_pool_create(&gAPRPoolp, NULL); // Initialize the logging mutex - apr_thread_mutex_create(&gLogMutexp, APR_THREAD_MUTEX_DEFAULT, gAPRPoolp); + apr_thread_mutex_create(&gLogMutexp, APR_THREAD_MUTEX_UNNESTED, gAPRPoolp); } } diff --git a/indra/llcommon/llapr.h b/indra/llcommon/llapr.h index 1e2d86f814..215df520b0 100644 --- a/indra/llcommon/llapr.h +++ b/indra/llcommon/llapr.h @@ -24,6 +24,7 @@ #include "apr-1/apr_atomic.h" #include "llstring.h" +extern apr_thread_mutex_t* gLogMutexp; /** * @brief initialize the common apr constructs -- apr itself, the diff --git a/indra/llcommon/llerror.cpp b/indra/llcommon/llerror.cpp index 3d9a51ecad..90ea72f24c 100644 --- a/indra/llcommon/llerror.cpp +++ b/indra/llcommon/llerror.cpp @@ -14,7 +14,6 @@ #include "llapp.h" #include "llapr.h" -extern apr_thread_mutex_t *gLogMutexp; #include "llfile.h" #include "llfixedbuffer.h" #include "lllivefile.h" diff --git a/indra/llcommon/llmemory.cpp b/indra/llcommon/llmemory.cpp index 19b8748d2e..ca7e9590f1 100644 --- a/indra/llcommon/llmemory.cpp +++ b/indra/llcommon/llmemory.cpp @@ -8,6 +8,21 @@ #include "linden_common.h" +#if defined(LL_WINDOWS) +# include <windows.h> +# include <psapi.h> +#elif defined(LL_DARWIN) +# include <sys/types.h> +# include <sys/sysctl.h> +# include <mach/task.h> +# include <mach/vm_map.h> +# include <mach/mach_init.h> +# include <mach/vm_region.h> +# include <mach/mach_port.h> +#elif defined(LL_LINUX) +# include <unistd.h> +#endif + #include "llmemory.h" #include "llmemtype.h" @@ -258,3 +273,131 @@ LLRefCount::~LLRefCount() //---------------------------------------------------------------------------- +#if defined(LL_WINDOWS) + +U64 getCurrentRSS() +{ + HANDLE self = GetCurrentProcess(); + PROCESS_MEMORY_COUNTERS counters; + + if (!GetProcessMemoryInfo(self, &counters, sizeof(counters))) + { + llwarns << "GetProcessMemoryInfo failed" << llendl; + return 0; + } + + return counters.WorkingSetSize; +} + +#elif defined(LL_DARWIN) + +static U32 getPageSize() +{ + int ctl[2] = { CTL_HW, HW_PAGESIZE }; + int page_size; + size_t size = sizeof(page_size); + + if (sysctl(ctl, 2, &page_size, &size, NULL, 0) == -1) + { + llwarns << "Couldn't get page size" << llendl; + return 0; + } else { + return page_size; + } +} + +U64 getCurrentRSS() +{ + task_t task = mach_task_self(); + vm_address_t addr = VM_MIN_ADDRESS; + vm_size_t size = 0; + U64 residentPages = 0; + + while (true) + { + mach_msg_type_number_t bcount = VM_REGION_BASIC_INFO_COUNT; + vm_region_basic_info binfo; + mach_port_t bobj; + kern_return_t ret; + + addr += size; + + ret = vm_region(task, &addr, &size, VM_REGION_BASIC_INFO, + (vm_region_info_t) &binfo, &bcount, &bobj); + + if (ret != KERN_SUCCESS) + { + break; + } + + if (bobj != MACH_PORT_NULL) + { + mach_port_deallocate(task, bobj); + } + + mach_msg_type_number_t ecount = VM_REGION_EXTENDED_INFO_COUNT; + vm_region_extended_info einfo; + mach_port_t eobj; + + ret = vm_region(task, &addr, &size, VM_REGION_EXTENDED_INFO, + (vm_region_info_t) &einfo, &ecount, &eobj); + + if (ret != KERN_SUCCESS) + { + llwarns << "vm_region failed" << llendl; + return 0; + } + + if (eobj != MACH_PORT_NULL) + { + mach_port_deallocate(task, eobj); + } + + residentPages += einfo.pages_resident; + } + + return residentPages * getPageSize(); +} + +#elif defined(LL_LINUX) + +U64 getCurrentRSS() +{ + static const char statPath[] = "/proc/self/stat"; + FILE *fp = fopen(statPath, "r"); + U64 rss = 0; + + if (fp == NULL) + { + llwarns << "couldn't open " << statPath << llendl; + goto bail; + } + + // Eee-yew! See Documentation/filesystems/proc.txt in your + // nearest friendly kernel tree for details. + + { + int ret = fscanf(fp, "%*d (%*[^)]) %*c %*d %*d %*d %*d %*d %*d %*d " + "%*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %Lu", + &rss); + if (ret != 1) + { + llwarns << "couldn't parse contents of " << statPath << llendl; + rss = 0; + } + } + + fclose(fp); + +bail: + return rss; +} + +#else + +U64 getCurrentRSS() +{ + return 0; +} + +#endif diff --git a/indra/llcommon/llmemory.h b/indra/llcommon/llmemory.h index 1253d34a7d..e6a8dad83d 100644 --- a/indra/llcommon/llmemory.h +++ b/indra/llcommon/llmemory.h @@ -395,5 +395,8 @@ public: //---------------------------------------------------------------------------- -#endif +// Return the resident set size of the current process, in bytes. +// Return value is zero if not known. +U64 getCurrentRSS(); +#endif diff --git a/indra/llcommon/llthread.cpp b/indra/llcommon/llthread.cpp index b7be8d6a3b..424d503113 100644 --- a/indra/llcommon/llthread.cpp +++ b/indra/llcommon/llthread.cpp @@ -246,7 +246,7 @@ LLMutex::LLMutex(apr_pool_t *poolp) : mIsLocalPool = TRUE; apr_pool_create(&mAPRPoolp, NULL); // Create a subpool for this thread } - apr_thread_mutex_create(&mAPRMutexp, APR_THREAD_MUTEX_DEFAULT, mAPRPoolp); + apr_thread_mutex_create(&mAPRMutexp, APR_THREAD_MUTEX_UNNESTED, mAPRPoolp); } |