PageRenderTime 26ms CodeModel.GetById 16ms app.highlight 7ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/llcommon/llallocator.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 134 lines | 75 code | 19 blank | 40 comment | 3 complexity | a0de6d917014de4ca626315f3ec017f1 MD5 | raw file
  1/** 
  2 * @file llallocator.cpp
  3 * @brief Implementation of the LLAllocator class.
  4 *
  5 * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#include "linden_common.h"
 28#include "llallocator.h"
 29
 30#if LL_USE_TCMALLOC
 31
 32#include "google/heap-profiler.h"
 33#include "google/commandlineflags_public.h"
 34
 35DECLARE_bool(heap_profile_use_stack_trace);
 36//DECLARE_double(tcmalloc_release_rate);
 37
 38// static
 39void LLAllocator::pushMemType(S32 type)
 40{
 41    if(isProfiling())
 42    {
 43    	PushMemType(type);
 44    }
 45}
 46
 47// static
 48S32 LLAllocator::popMemType()
 49{
 50    if (isProfiling())
 51    {
 52    	return PopMemType();
 53    }
 54    else
 55    {
 56        return -1;
 57    }
 58}
 59
 60void LLAllocator::setProfilingEnabled(bool should_enable)
 61{
 62    // NULL disables dumping to disk
 63    static char const * const PREFIX = NULL;
 64    if(should_enable)
 65    {
 66		HeapProfilerSetUseStackTrace(false);
 67        HeapProfilerStart(PREFIX);
 68    }
 69    else
 70    {
 71        HeapProfilerStop();
 72    }
 73}
 74
 75// static
 76bool LLAllocator::isProfiling()
 77{
 78    return IsHeapProfilerRunning();
 79}
 80
 81std::string LLAllocator::getRawProfile()
 82{
 83    // *TODO - fix google-perftools to accept an buffer to avoid this
 84    // malloc-copy-free cycle.
 85    char * buffer = GetHeapProfile();
 86    std::string ret = buffer;
 87    free(buffer);
 88    return ret;
 89}
 90
 91#else // LL_USE_TCMALLOC
 92
 93//
 94// stub implementations for when tcmalloc is disabled
 95//
 96
 97// static
 98void LLAllocator::pushMemType(S32 type)
 99{
100}
101
102// static
103S32 LLAllocator::popMemType()
104{
105    return -1;
106}
107
108void LLAllocator::setProfilingEnabled(bool should_enable)
109{
110}
111
112// static
113bool LLAllocator::isProfiling()
114{
115    return false;
116}
117
118std::string LLAllocator::getRawProfile()
119{
120    return std::string();
121}
122
123#endif // LL_USE_TCMALLOC
124
125LLAllocatorHeapProfile const & LLAllocator::getProfile()
126{
127    mProf.mLines.clear();
128
129    // *TODO - avoid making all these extra copies of things...
130    std::string prof_text = getRawProfile();
131    //std::cout << prof_text << std::endl;
132    mProf.parse(prof_text);
133    return mProf;
134}