summaryrefslogtreecommitdiff
path: root/src/heap-profile-table.h
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/heap-profile-table.h
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/heap-profile-table.h')
-rw-r--r--src/heap-profile-table.h47
1 files changed, 35 insertions, 12 deletions
diff --git a/src/heap-profile-table.h b/src/heap-profile-table.h
index 416b8bc..968ff90 100644
--- a/src/heap-profile-table.h
+++ b/src/heap-profile-table.h
@@ -37,6 +37,7 @@
#include "addressmap-inl.h"
#include "base/basictypes.h"
+#include "base/logging.h" // for RawFD
// Table to maintain a heap profile data inside,
// i.e. the set of currently active heap memory allocations.
@@ -51,8 +52,8 @@ class HeapProfileTable {
// Extension to be used for heap pforile files.
static const char kFileExt[];
- // Longest stack trace we record.
- static const int kMaxStackDepth = 32;
+ // Longest stack trace we record. Defined in the .cc file.
+ static const int kMaxStackDepth;
// data types ----------------------------
@@ -75,6 +76,8 @@ class HeapProfileTable {
size_t object_size; // size of the allocation
const void* const* call_stack; // call stack that made the allocation call
int stack_depth; // depth of call_stack
+ bool live;
+ bool ignored;
};
// Info we return about an allocation context.
@@ -126,6 +129,11 @@ class HeapProfileTable {
// also makes all allocations non-live.
bool MarkAsLive(const void* ptr);
+ // If "ptr" points to a recorded allocation, mark it as "ignored".
+ // Ignored objects are treated like other objects, except that they
+ // are skipped in heap checking reports.
+ void MarkAsIgnored(const void* ptr);
+
// Return current total (de)allocation statistics.
const Stats& total() const { return total_; }
@@ -165,6 +173,7 @@ class HeapProfileTable {
// and write the sums of allocated byte and object counts in the dump
// to *alloc_bytes and *alloc_objects.
// dump_alloc_addresses controls if object addresses are dumped.
+ // Ignores any objects that have the "ignore" bit set.
bool DumpNonLiveProfile(const char* file_name,
bool dump_alloc_addresses,
Stats* profile_stats) const;
@@ -189,17 +198,32 @@ class HeapProfileTable {
struct AllocValue {
// Access to the stack-trace bucket
Bucket* bucket() const {
- return reinterpret_cast<Bucket*>(bucket_rep & ~uintptr_t(1));
+ return reinterpret_cast<Bucket*>(bucket_rep & ~uintptr_t(kMask));
}
// This also does set_live(false).
void set_bucket(Bucket* b) { bucket_rep = reinterpret_cast<uintptr_t>(b); }
size_t bytes; // Number of bytes in this allocation
+
// Access to the allocation liveness flag (for leak checking)
- bool live() const { return bucket_rep & 1; }
- void set_live(bool l) { bucket_rep = (bucket_rep & ~uintptr_t(1)) | l; }
+ bool live() const { return bucket_rep & kLive; }
+ void set_live(bool l) {
+ bucket_rep = (bucket_rep & ~uintptr_t(kLive)) | (l ? kLive : 0);
+ }
+
+ // Should this allocation be ignored if it looks like a leak?
+ bool ignore() const { return bucket_rep & kIgnore; }
+ void set_ignore(bool r) {
+ bucket_rep = (bucket_rep & ~uintptr_t(kIgnore)) | (r ? kIgnore : 0);
+ }
+
private:
- uintptr_t bucket_rep; // Bucket* with the lower bit being the "live" flag:
- // pointers point to at least 4-byte aligned storage.
+ // We store a few bits in the bottom bits of bucket_rep.
+ // (Alignment is at least four, so we have at least two bits.)
+ static const int kLive = 1;
+ static const int kIgnore = 2;
+ static const int kMask = kLive | kIgnore;
+
+ uintptr_t bucket_rep;
};
// helper for FindInsideAlloc
@@ -209,11 +233,11 @@ class HeapProfileTable {
// Arguments that need to be passed DumpNonLiveIterator callback below.
struct DumpArgs {
- int fd; // file to write to
+ RawFD fd; // file to write to
bool dump_alloc_addresses; // if we are dumping allocation's addresses
Stats* profile_stats; // stats to update
- DumpArgs(int a, bool b, Stats* d)
+ DumpArgs(RawFD a, bool b, Stats* d)
: fd(a), dump_alloc_addresses(b), profile_stats(d) { }
};
@@ -240,6 +264,8 @@ class HeapProfileTable {
info.object_size = v->bytes;
info.call_stack = v->bucket()->stack;
info.stack_depth = v->bucket()->depth;
+ info.live = v->live();
+ info.ignored = v->ignore();
callback(ptr, info);
}
@@ -255,9 +281,6 @@ class HeapProfileTable {
// data ----------------------------
- // Size for table_.
- static const int kHashTableSize = 179999;
-
// Memory (de)allocator that we use.
Allocator alloc_;
DeAllocator dealloc_;