summaryrefslogtreecommitdiff
path: root/src/google
diff options
context:
space:
mode:
authorcsilvers <csilvers@6b5cf1ce-ec42-a296-1ba9-69fdba395a50>2008-12-13 01:35:42 +0000
committercsilvers <csilvers@6b5cf1ce-ec42-a296-1ba9-69fdba395a50>2008-12-13 01:35:42 +0000
commit6fa2a2574ce1c15ac12293e24691d69a41972e54 (patch)
tree606da4a80de5c91721969ade70c4d9a87cb1604a /src/google
parent16191f87ff8dc78295c0f617060460664fc444bd (diff)
downloadgperftools-6fa2a2574ce1c15ac12293e24691d69a41972e54.tar.gz
Thu Dec 11 16:01:32 2008 Google Inc. <opensource@google.com>
* google-perftools: version 1.0rc1 release * Replace API for selectively disabling heap-checker in code (sanjay) * Add a pre-mmap hook (daven, adlr) * Add MallocExtension interface to set memory-releasing rate (fikes) * Augment pprof to allow any string ending in /pprof/profile (csilvers) * PORTING: Rewrite -- and fix -- malloc patching for windows (dvitek) * PORTING: Add nm-pdb and addr2line-pdb for use by pprof (dvitek) * PORTING: Improve cygwin and mingw support (jperkins, csilvers) * PORTING: Fix pprof for mac os x, other pprof improvements (csilvers) * PORTING: Fix some PPC bugs in our locking code (anton.blanchard) * A new unittest, smapling_test, to verify tcmalloc-profiles (csilvers) * Turn off TLS for gcc < 4.1.2, due to a TLS + -fPIC bug (csilvers) * Prefer __builtin_frame_address to assembly for stacktraces (nlewycky) * Separate tcmalloc.cc out into multiple files -- finally! (kash) * Make our locking code work with -fPIC on 32-bit x86 (aruns) * Fix an initialization-ordering bug for tcmalloc/profiling (csilvers) * Use "initial exec" model of TLS to speed up tcmalloc (csilvers) * Enforce 16-byte alignment for tcmalloc, for SSE (sanjay) git-svn-id: http://gperftools.googlecode.com/svn/trunk@60 6b5cf1ce-ec42-a296-1ba9-69fdba395a50
Diffstat (limited to 'src/google')
-rw-r--r--src/google/heap-checker.h121
-rw-r--r--src/google/heap-profiler.h2
-rw-r--r--src/google/malloc_extension.h14
-rw-r--r--src/google/malloc_hook.h31
-rw-r--r--src/google/malloc_hook_c.h11
-rw-r--r--src/google/profiler.h2
-rw-r--r--src/google/stacktrace.h2
7 files changed, 90 insertions, 93 deletions
diff --git a/src/google/heap-checker.h b/src/google/heap-checker.h
index 7390691..af27c4c 100644
--- a/src/google/heap-checker.h
+++ b/src/google/heap-checker.h
@@ -58,7 +58,7 @@
// Annoying stuff for windows -- makes sure clients can import these functions
#ifndef PERFTOOLS_DLL_DECL
-# ifdef WIN32
+# ifdef _WIN32
# define PERFTOOLS_DLL_DECL __declspec(dllimport)
# else
# define PERFTOOLS_DLL_DECL
@@ -170,91 +170,28 @@ class PERFTOOLS_DLL_DECL HeapLeakChecker {
// ----------------------------------------------------------------------- //
// Static helpers to make us ignore certain leaks.
- // NOTE: All calls to DisableChecks* affect all later heap profile generation
- // that happens in our construction and inside of *NoLeaks().
- // They do nothing when heap leak checking is turned off.
-
- // CAVEAT: Disabling via all the DisableChecks* functions happens only
- // up to kMaxStackTrace stack frames (see heap-profile-table.h)
- // down from the stack frame identified by the function.
- // Hence, this disabling will stop working for very deep call stacks
- // and you might see quite wierd leak profile dumps in such cases.
-
- // CAVEAT: Disabling via DisableChecksIn works only with non-strip'ped
- // binaries. It's better not to use this function if at all possible.
+ // Scoped helper class. Should be allocated on the stack inside a
+ // block of code. Any heap allocations done in the code block
+ // covered by the scoped object (including in nested function calls
+ // done by the code block) will not be reported as leaks. This is
+ // the recommended replacement for the GetDisableChecksStart() and
+ // DisableChecksToHereFrom() routines below.
//
- // Register 'pattern' as another variant of a regular expression to match
- // function_name, file_name:line_number, or function_address
- // of function call/return points for which allocations below them should be
- // ignored during heap leak checking.
- // (This becomes a part of pprof's '--ignore' argument.)
- // Usually this should be caled from a REGISTER_HEAPCHECK_CLEANUP
- // in the source file that is causing the leaks being ignored.
- static void DisableChecksIn(const char* pattern);
-
- // A pair of functions to disable heap checking between them.
- // For example
- // ...
- // void* start_address = HeapLeakChecker::GetDisableChecksStart();
- // <do things>
- // HeapLeakChecker::DisableChecksToHereFrom(start_address);
- // ...
- // will disable heap leak checking for everything that happens
- // during any execution of <do things> (including any calls from it),
- // i.e. all objects allocated from there
- // and everything reachable from them will not be considered a leak.
- // Each such pair of function calls must be from the same function,
- // because this disabling works by remembering the range of
- // return program counter addresses for the two calls.
- static void* GetDisableChecksStart();
- static void DisableChecksToHereFrom(const void* start_address);
-
- // ADVICE: Use GetDisableChecksStart, DisableChecksToHereFrom
- // instead of DisableChecksUp|At whenever possible
- // to make the code less fragile under different degrees of inlining.
- // Register the function call point (return program counter address)
- // 'stack_frames' above us for which allocations
- // (everything reachable from them) below it should be
- // ignored during heap leak checking.
- // 'stack_frames' must be >= 1 (in most cases one would use the value of 1).
- // For example
- // void Foo() { // Foo() should not get inlined
- // HeapLeakChecker::DisableChecksUp(1);
- // <do things>
- // }
- // will disable heap leak checking for everything that happens
- // during any execution of <do things> (including any calls from it),
- // i.e. all objects allocated from there
- // and everything reachable from them will not be considered a leak.
- // CAVEAT: If Foo() is inlined this will disable heap leak checking
- // under all processing of all functions Foo() is inlined into.
- // Hence, for potentially inlined functions, use the GetDisableChecksStart,
- // DisableChecksToHereFrom calls instead.
- // (In the above example we store and use the return program counter
- // addresses from Foo to do the disabling.)
- static void DisableChecksUp(int stack_frames);
-
- // Same as DisableChecksUp,
- // but the function return program counter address is given explicitly.
- static void DisableChecksAt(const void* address);
-
- // Tests for checking that DisableChecksUp and DisableChecksAt
- // behaved as expected, for example
- // void Foo() {
- // HeapLeakChecker::DisableChecksUp(1);
- // <do things>
- // }
- // void Bar() {
- // Foo();
- // CHECK(!HeapLeakChecker::HaveDisabledChecksUp(1));
- // // This will fail if Foo() got inlined into Bar()
- // // (due to more aggressive optimization in the (new) compiler)
- // // which breaks the intended behavior of DisableChecksUp(1) in it.
- // <do things>
- // }
- // These return false when heap leak checking is turned off.
- static bool HaveDisabledChecksUp(int stack_frames);
- static bool HaveDisabledChecksAt(const void* address);
+ // Example:
+ // void Foo() {
+ // HeapLeakChecker::Disabler disabler;
+ // ... code that allocates objects whose leaks should be ignored ...
+ // }
+ //
+ // REQUIRES: Destructor runs in same thread as constructor
+ class Disabler {
+ public:
+ Disabler();
+ ~Disabler();
+ private:
+ Disabler(const Disabler&); // disallow copy
+ void operator=(const Disabler&); // and assign
+ };
// Ignore an object located at 'ptr' (can go at the start or into the object)
// as well as all heap objects (transitively) referenced from it
@@ -320,8 +257,18 @@ class PERFTOOLS_DLL_DECL HeapLeakChecker {
void HandleProfile(ProfileType profile_type);
void HandleProfileLocked(ProfileType profile_type);
- // Helper for DisableChecksAt
- static void DisableChecksAtLocked(const void* address);
+ // These used to be public, but they are now deprecated.
+ // Will remove entirely when all internal uses are fixed.
+ // In the meantime, use friendship so the unittest can still test them.
+ static void* GetDisableChecksStart();
+ static void DisableChecksToHereFrom(const void* start_address);
+ static void DisableChecksIn(const char* pattern);
+ friend void RangeDisabledLeaks();
+ friend void NamedTwoDisabledLeaks();
+ friend void* RunNamedDisabledLeaks(void*);
+ friend void TestHeapLeakCheckerNamedDisabling();
+ friend int main(int, char**);
+
// Helper for DisableChecksIn
static void DisableChecksInLocked(const char* pattern);
diff --git a/src/google/heap-profiler.h b/src/google/heap-profiler.h
index 33d7fae..5efaf64 100644
--- a/src/google/heap-profiler.h
+++ b/src/google/heap-profiler.h
@@ -54,7 +54,7 @@
/* Annoying stuff for windows; makes sure clients can import these functions */
#ifndef PERFTOOLS_DLL_DECL
-# ifdef WIN32
+# ifdef _WIN32
# define PERFTOOLS_DLL_DECL __declspec(dllimport)
# else
# define PERFTOOLS_DLL_DECL
diff --git a/src/google/malloc_extension.h b/src/google/malloc_extension.h
index 6be5d87..e1d3425 100644
--- a/src/google/malloc_extension.h
+++ b/src/google/malloc_extension.h
@@ -46,7 +46,7 @@
// Annoying stuff for windows -- makes sure clients can import these functions
#ifndef PERFTOOLS_DLL_DECL
-# ifdef WIN32
+# ifdef _WIN32
# define PERFTOOLS_DLL_DECL __declspec(dllimport)
# else
# define PERFTOOLS_DLL_DECL
@@ -124,7 +124,7 @@ class PERFTOOLS_DLL_DECL MallocExtension {
// "tcmalloc.max_total_thread_cache_bytes"
// Upper limit on total number of bytes stored across all
// per-thread caches. Default: 16MB.
- //
+ //
// "tcmalloc.current_total_thread_cache_bytes"
// Number of bytes used across all thread caches.
// This property is not writable.
@@ -171,6 +171,16 @@ class PERFTOOLS_DLL_DECL MallocExtension {
// tcmalloc.)
virtual void ReleaseFreeMemory();
+ // Sets the rate at which we release unused memory to the system.
+ // Zero means we never release memory back to the system. Increase
+ // this flag to return memory faster; decrease it to return memory
+ // slower. Reasonable rates are in the range [0,10]. (Currently
+ // only implemented in tcmalloc).
+ virtual void SetMemoryReleaseRate(double rate);
+
+ // Gets the release rate. Returns a value < 0 if unknown.
+ virtual double GetMemoryReleaseRate();
+
// The current malloc implementation. Always non-NULL.
static MallocExtension* instance();
diff --git a/src/google/malloc_hook.h b/src/google/malloc_hook.h
index 88d3e77..f2713e9 100644
--- a/src/google/malloc_hook.h
+++ b/src/google/malloc_hook.h
@@ -74,7 +74,7 @@ extern "C" {
// Annoying stuff for windows -- makes sure clients can import these functions
#ifndef PERFTOOLS_DLL_DECL
-# ifdef WIN32
+# ifdef _WIN32
# define PERFTOOLS_DLL_DECL __declspec(dllimport)
# else
# define PERFTOOLS_DLL_DECL
@@ -106,6 +106,22 @@ class PERFTOOLS_DLL_DECL MallocHook {
}
inline static void InvokeDeleteHook(const void* p);
+ // The PreMmapHook is invoked with mmap or mmap64 arguments just
+ // before the call is actually made. Such a hook may be useful
+ // in memory limited contexts, to catch allocations that will exceed
+ // a memory limit, and take outside actions to increase that limit.
+ typedef MallocHook_PreMmapHook PreMmapHook;
+ inline static PreMmapHook GetPreMmapHook();
+ inline static PreMmapHook SetPreMmapHook(PreMmapHook hook) {
+ return MallocHook_SetPreMmapHook(hook);
+ }
+ inline static void InvokePreMmapHook(const void* start,
+ size_t size,
+ int protection,
+ int flags,
+ int fd,
+ off_t offset);
+
// The MmapHook is invoked whenever a region of memory is mapped.
// It may be passed MAP_FAILED if the mmap failed.
typedef MallocHook_MmapHook MmapHook;
@@ -142,6 +158,19 @@ class PERFTOOLS_DLL_DECL MallocHook {
int flags,
const void* new_addr);
+ // The PreSbrkHook is invoked just before sbrk is called -- except when
+ // the increment is 0. This is because sbrk(0) is often called
+ // to get the top of the memory stack, and is not actually a
+ // memory-allocation call. It may be useful in memory-limited contexts,
+ // to catch allocations that will exceed the limit and take outside
+ // actions to increase such a limit.
+ typedef MallocHook_PreSbrkHook PreSbrkHook;
+ inline static PreSbrkHook GetPreSbrkHook();
+ inline static PreSbrkHook SetPreSbrkHook(PreSbrkHook hook) {
+ return MallocHook_SetPreSbrkHook(hook);
+ }
+ inline static void InvokePreSbrkHook(ptrdiff_t increment);
+
// The SbrkHook is invoked whenever sbrk is called -- except when
// the increment is 0. This is because sbrk(0) is often called
// to get the top of the memory stack, and is not actually a
diff --git a/src/google/malloc_hook_c.h b/src/google/malloc_hook_c.h
index 2100f28..c870dae 100644
--- a/src/google/malloc_hook_c.h
+++ b/src/google/malloc_hook_c.h
@@ -56,6 +56,14 @@ MallocHook_NewHook MallocHook_SetNewHook(MallocHook_NewHook hook);
typedef void (*MallocHook_DeleteHook)(const void* ptr);
MallocHook_DeleteHook MallocHook_SetDeleteHook(MallocHook_DeleteHook hook);
+typedef void (*MallocHook_PreMmapHook)(const void *start,
+ size_t size,
+ int protection,
+ int flags,
+ int fd,
+ off_t offset);
+MallocHook_PreMmapHook MallocHook_SetPreMmapHook(MallocHook_PreMmapHook hook);
+
typedef void (*MallocHook_MmapHook)(const void* result,
const void* start,
size_t size,
@@ -76,6 +84,9 @@ typedef void (*MallocHook_MremapHook)(const void* result,
const void* new_addr);
MallocHook_MremapHook MallocHook_SetMremapHook(MallocHook_MremapHook hook);
+typedef void (*MallocHook_PreSbrkHook)(ptrdiff_t increment);
+MallocHook_PreSbrkHook MallocHook_SetPreSbrkHook(MallocHook_PreSbrkHook hook);
+
typedef void (*MallocHook_SbrkHook)(const void* result, ptrdiff_t increment);
MallocHook_SbrkHook MallocHook_SetSbrkHook(MallocHook_SbrkHook hook);
diff --git a/src/google/profiler.h b/src/google/profiler.h
index 0a185d2..be7dbf3 100644
--- a/src/google/profiler.h
+++ b/src/google/profiler.h
@@ -63,7 +63,7 @@
/* Annoying stuff for windows; makes sure clients can import these functions */
#ifndef PERFTOOLS_DLL_DECL
-# ifdef WIN32
+# ifdef _WIN32
# define PERFTOOLS_DLL_DECL __declspec(dllimport)
# else
# define PERFTOOLS_DLL_DECL
diff --git a/src/google/stacktrace.h b/src/google/stacktrace.h
index 1062ed6..598a308 100644
--- a/src/google/stacktrace.h
+++ b/src/google/stacktrace.h
@@ -38,7 +38,7 @@
// Annoying stuff for windows -- makes sure clients can import these functions
#ifndef PERFTOOLS_DLL_DECL
-# ifdef WIN32
+# ifdef _WIN32
# define PERFTOOLS_DLL_DECL __declspec(dllimport)
# else
# define PERFTOOLS_DLL_DECL