Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: base/debug/trace_memory.h

Issue 15418002: Record Chrome trace events in tcmalloc heap profiles (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase, cleanup Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef BASE_DEBUG_TRACE_MEMORY_H_
6 #define BASE_DEBUG_TRACE_MEMORY_H_
7
8 #include "base/base_export.h"
9 #include "base/debug/trace_event_impl.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/timer.h"
13
14 namespace base {
15
16 class MessageLoopProxy;
17
18 namespace debug {
19
20 // Watches for chrome://tracing to be enabled or disabled. When tracing is
21 // enabled, also enables tcmalloc heap profiling. This class is the preferred
22 // way to turn trace-base heap memory profiling on and off.
23 class BASE_EXPORT TraceMemoryTraceLogObserver
24 : public TraceLog::EnabledStateObserver {
25 public:
26 // |message_loop_proxy| must be a proxy to the primary thread for the client
27 // process, e.g. the UI thread in a browser.
28 TraceMemoryTraceLogObserver(
29 scoped_refptr<MessageLoopProxy> message_loop_proxy);
30 virtual ~TraceMemoryTraceLogObserver();
31
32 // base::debug::TraceLog::EnabledStateChangedObserver overrides:
33 virtual void OnTraceLogEnabled() OVERRIDE;
34 virtual void OnTraceLogDisabled() OVERRIDE;
35
36 // Starts heap memory profiling.
37 void StartProfiling();
38
39 // Ends heap memory profiling.
40 void StopProfiling();
41
42 bool IsTimerRunningForTest() const;
dsinclair 2013/06/18 15:30:15 If this is only for test, can we make it private a
James Cook 2013/06/29 00:02:42 Done.
43
44 private:
45 // Ensures the observer starts and stops tracing on the primary thread.
46 scoped_refptr<MessageLoopProxy> message_loop_proxy_;
47
48 // Timer to schedule memory profile dumps.
49 RepeatingTimer<TraceMemoryTraceLogObserver> dump_timer_;
50
51 WeakPtrFactory<TraceMemoryTraceLogObserver> weak_factory_;
52
53 DISALLOW_COPY_AND_ASSIGN(TraceMemoryTraceLogObserver);
54 };
55
56 //////////////////////////////////////////////////////////////////////////////
57
58 // A scoped context for memory tracing. Pushes the category onto a stack for
59 // recording by tcmalloc heap profiling.
60 class BASE_EXPORT ScopedTraceMemory {
61 public:
62 ScopedTraceMemory(const char* category);
dsinclair 2013/06/18 15:30:15 The memory for category, does that need to be stat
James Cook 2013/06/29 00:02:42 Added clarifying comment and changed to |name|, si
63 ~ScopedTraceMemory();
64
65 // Testing interface:
66 static int GetStackIndexForTest();
67 static const char* GetItemForTest(int index);
68 };
69
70 } // namespace debug
71 } // namespace base
72
73 // Make local variables with unique names based on the line number. Note that
74 // the extra level of redirection is needed.
75 #define INTERNAL_TRACE_MEMORY_ID3(line) trace_memory_unique_##line
76 #define INTERNAL_TRACE_MEMORY_ID2(line) INTERNAL_TRACE_MEMORY_ID3(line)
77 #define INTERNAL_TRACE_MEMORY_ID INTERNAL_TRACE_MEMORY_ID2(__LINE__)
78
79 // Generates a unique local variable name.
80 // TODO(jamescook): Make it record both category and name.
dsinclair 2013/06/18 15:30:15 You'll need to be careful when you add category in
James Cook 2013/06/29 00:02:42 OK. For now I'm only recording the name, but we'l
81 #define TRACE_MEMORY(category, name) \
82 base::debug::ScopedTraceMemory INTERNAL_TRACE_MEMORY_ID(name);
83
84 // A special trace name that allows us to ignore memory allocations inside
85 // the memory dump system itself. The allocations are recorded, but the
86 // visualizer skips them. Must match the value in heap.js.
87 #define TRACE_MEMORY_IGNORE "trace-memory-ignore"
88
89 #endif // BASE_DEBUG_TRACE_MEMORY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698