summaryrefslogtreecommitdiffstats
path: root/tools/memory_watcher/memory_watcher.h
diff options
context:
space:
mode:
authorjar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-06 21:17:51 +0000
committerjar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-06 21:17:51 +0000
commit0c6854514bc0c543d63f8cbac07360c5c0885592 (patch)
tree02411257153034e09411cfae68da0121a8019cab /tools/memory_watcher/memory_watcher.h
parent7fd41a837aef6af92487dccfcc2819e3de8c6e41 (diff)
downloadchromium_src-0c6854514bc0c543d63f8cbac07360c5c0885592.zip
chromium_src-0c6854514bc0c543d63f8cbac07360c5c0885592.tar.gz
chromium_src-0c6854514bc0c543d63f8cbac07360c5c0885592.tar.bz2
Support running memory watch under vista, plus other tweaks
This version of memory_watcher can run under Vista, even though the recursive calls that it handles are appearing often enough that there is a performance penalty. With this landed, it may be possible for other folks to run the tool, and I can work on improving its performance. This CL also resolves the problem with hanging processes. Although memory reporting can only be done once, and it leaves a pile of memory "hanging around," the browser can be cleanly exited. Tweaks include outputing the aggregate stacks such that the largest stacks appear at the start of the output file. This version avoids ongoing aggregation of stats in favor of only doing the aggregation at dump-time. This probably enhances performance at run-time, although it is hidden (on Vista) by the recursive calling. This also simplifies the tracking code a fair amount. There is some evidence that a small number of duplicate calls are being made to "track" the same memory region, without an intervening free (i.e., call to "untrack"). The code to better diagnose this is currently in place, but ifdef'ed, as it is only useful under a debugger. Exercise of this code (turning a stack-frame list into a human readable stack trace string) currently causes some corruption shortly after it triggers, so I can't leave it on full time. r=mbelshe Review URL: http://codereview.chromium.org/366031 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31299 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/memory_watcher/memory_watcher.h')
-rw-r--r--tools/memory_watcher/memory_watcher.h37
1 files changed, 21 insertions, 16 deletions
diff --git a/tools/memory_watcher/memory_watcher.h b/tools/memory_watcher/memory_watcher.h
index c382cb1..9609ce2 100644
--- a/tools/memory_watcher/memory_watcher.h
+++ b/tools/memory_watcher/memory_watcher.h
@@ -23,6 +23,19 @@ class AllocationStack;
// allocations and frees.
class MemoryWatcher : MemoryObserver {
public:
+ struct StackTrack {
+ CallStack* stack;
+ int count;
+ int size;
+ };
+
+ typedef std::map<int32, AllocationStack*, std::less<int32>,
+ PrivateHookAllocator<int32> > CallStackMap;
+ typedef std::map<int32, StackTrack, std::less<int32>,
+ PrivateHookAllocator<int32> > CallStackIdMap;
+ typedef std::basic_string<char, std::char_traits<char>,
+ PrivateHookAllocator<char> > PrivateAllocatorString;
+
MemoryWatcher();
virtual ~MemoryWatcher();
@@ -49,32 +62,24 @@ class MemoryWatcher : MemoryObserver {
// Unhooks our memory hooks.
void Unhook();
+ // Check to see if this thread is already processing a block, and should not
+ // recurse.
+ bool LockedRecursionDetected() const;
+
// This is for logging.
FILE* file_;
- struct StackTrack {
- CallStack* stack;
- int count;
- int size;
- };
-
bool hooked_; // True when this class has the memory_hooks hooked.
- bool in_track_;
+ // Either 0, or else the threadID for a thread that is actively working on
+ // a stack track. Used to avoid recursive tracking.
+ DWORD active_thread_id_;
+
Lock block_map_lock_;
- typedef std::map<int32, AllocationStack*, std::less<int32>,
- PrivateHookAllocator<int32>> CallStackMap;
- typedef std::map<int32, StackTrack, std::less<int32>,
- PrivateHookAllocator<int32>> CallStackIdMap;
// The block_map provides quick lookups based on the allocation
// pointer. This is important for having fast round trips through
// malloc/free.
CallStackMap *block_map_;
- // The stack_map keeps track of the known CallStacks based on the
- // hash of the CallStack. This is so that we can quickly aggregate
- // like-CallStacks together.
- CallStackIdMap *stack_map_;
- int32 block_map_size_;
// The file name for that log.
std::string file_name_;