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

Side by Side Diff: base/tracked.h

Issue 7039020: Tag all tracked objects, including Tasks, with the program counter at the site of FROM_HERE. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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
« no previous file with comments | « base/message_loop.cc ('k') | base/tracked.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 //------------------------------------------------------------------------------ 5 //------------------------------------------------------------------------------
6 // Tracked is the base class for all tracked objects. During construction, it 6 // Tracked is the base class for all tracked objects. During construction, it
7 // registers the fact that an instance was created, and at destruction time, it 7 // registers the fact that an instance was created, and at destruction time, it
8 // records that event. The instance may be tagged with a name, which is refered 8 // records that event. The instance may be tagged with a name, which is refered
9 // to as its Location. The Location is a file and line number, most 9 // to as its Location. The Location is a file and line number, most
10 // typically indicated where the object was constructed. In some cases, as the 10 // typically indicated where the object was constructed. In some cases, as the
(...skipping 23 matching lines...) Expand all
34 34
35 //------------------------------------------------------------------------------ 35 //------------------------------------------------------------------------------
36 // Location provides basic info where of an object was constructed, or was 36 // Location provides basic info where of an object was constructed, or was
37 // significantly brought to life. 37 // significantly brought to life.
38 38
39 class BASE_API Location { 39 class BASE_API Location {
40 public: 40 public:
41 // Constructor should be called with a long-lived char*, such as __FILE__. 41 // Constructor should be called with a long-lived char*, such as __FILE__.
42 // It assumes the provided value will persist as a global constant, and it 42 // It assumes the provided value will persist as a global constant, and it
43 // will not make a copy of it. 43 // will not make a copy of it.
44 Location(const char* function_name, const char* file_name, int line_number); 44 Location(const char* function_name,
45 const char* file_name,
46 int line_number,
47 const void* program_counter);
45 48
46 // Provide a default constructor for easy of debugging. 49 // Provide a default constructor for easy of debugging.
47 Location(); 50 Location();
48 51
49 // Comparison operator for insertion into a std::map<> hash tables. 52 // Comparison operator for insertion into a std::map<> hash tables.
50 // All we need is *some* (any) hashing distinction. Strings should already 53 // All we need is *some* (any) hashing distinction. Strings should already
51 // be unique, so we don't bother with strcmp or such. 54 // be unique, so we don't bother with strcmp or such.
52 // Use line number as the primary key (because it is fast, and usually gets us 55 // Use line number as the primary key (because it is fast, and usually gets us
53 // a difference), and then pointers as secondary keys (just to get some 56 // a difference), and then pointers as secondary keys (just to get some
54 // distinctions). 57 // distinctions).
55 bool operator < (const Location& other) const { 58 bool operator < (const Location& other) const {
56 if (line_number_ != other.line_number_) 59 if (line_number_ != other.line_number_)
57 return line_number_ < other.line_number_; 60 return line_number_ < other.line_number_;
58 if (file_name_ != other.file_name_) 61 if (file_name_ != other.file_name_)
59 return file_name_ < other.file_name_; 62 return file_name_ < other.file_name_;
60 return function_name_ < other.function_name_; 63 return function_name_ < other.function_name_;
61 } 64 }
62 65
63 const char* function_name() const { return function_name_; } 66 const char* function_name() const { return function_name_; }
64 const char* file_name() const { return file_name_; } 67 const char* file_name() const { return file_name_; }
65 int line_number() const { return line_number_; } 68 int line_number() const { return line_number_; }
69 const void* program_counter() const { return program_counter_; }
66 70
67 void Write(bool display_filename, bool display_function_name, 71 void Write(bool display_filename, bool display_function_name,
68 std::string* output) const; 72 std::string* output) const;
69 73
70 // Write function_name_ in HTML with '<' and '>' properly encoded. 74 // Write function_name_ in HTML with '<' and '>' properly encoded.
71 void WriteFunctionName(std::string* output) const; 75 void WriteFunctionName(std::string* output) const;
72 76
73 private: 77 private:
74 const char* const function_name_; 78 const char* const function_name_;
75 const char* const file_name_; 79 const char* const file_name_;
76 const int line_number_; 80 const int line_number_;
81 const void* const program_counter_;
77 }; 82 };
78 83
84 BASE_API const void* GetProgramCounterRegister();
darin (slow to review) 2011/05/19 21:00:03 nit: maybe just call this GetProgramCounter()... R
apatrick_chromium 2011/05/19 21:09:45 Done.
79 85
80 //------------------------------------------------------------------------------ 86 //------------------------------------------------------------------------------
81 // Define a macro to record the current source location. 87 // Define a macro to record the current source location.
82 88
83 #define FROM_HERE tracked_objects::Location(__FUNCTION__, __FILE__, __LINE__) 89 #define FROM_HERE tracked_objects::Location( \
90 __FUNCTION__, \
91 __FILE__, \
92 __LINE__, \
93 tracked_objects::GetProgramCounterRegister()) \
84 94
85 95
86 //------------------------------------------------------------------------------ 96 //------------------------------------------------------------------------------
87 97
88 98
89 class Births; 99 class Births;
90 100
91 class BASE_API Tracked { 101 class BASE_API Tracked {
92 public: 102 public:
93 Tracked(); 103 Tracked();
94 virtual ~Tracked(); 104 virtual ~Tracked();
95 105
96 // Used to record the FROM_HERE location of a caller. 106 // Used to record the FROM_HERE location of a caller.
97 void SetBirthPlace(const Location& from_here); 107 void SetBirthPlace(const Location& from_here);
98 const Location GetBirthPlace() const; 108 const Location GetBirthPlace() const;
99 109
100 // When a task sits around a long time, such as in a timer, or object watcher, 110 // When a task sits around a long time, such as in a timer, or object watcher,
101 // this method should be called when the task becomes active, and its 111 // this method should be called when the task becomes active, and its
102 // significant lifetime begins (and its waiting to be woken up has passed). 112 // significant lifetime begins (and its waiting to be woken up has passed).
103 void ResetBirthTime(); 113 void ResetBirthTime();
104 114
105 bool MissingBirthplace() const; 115 bool MissingBirthplace() const;
106 116
107 #if defined(TRACK_ALL_TASK_OBJECTS) 117 #if defined(TRACK_ALL_TASK_OBJECTS)
108 base::TimeTicks tracked_birth_time() const { return tracked_birth_time_; } 118 base::TimeTicks tracked_birth_time() const { return tracked_birth_time_; }
109 #else 119 #else
110 base::TimeTicks tracked_birth_time() const { return base::TimeTicks::Now(); } 120 base::TimeTicks tracked_birth_time() const { return base::TimeTicks::Now(); }
111 #endif // defined(TRACK_ALL_TASK_OBJECTS) 121 #endif // defined(TRACK_ALL_TASK_OBJECTS)
112 122
123 // Returns null if SetBirthPlace has not been called.
124 const void* get_birth_program_counter() const {
125 return birth_program_counter_;
126 }
127
113 private: 128 private:
114 #if defined(TRACK_ALL_TASK_OBJECTS) 129 #if defined(TRACK_ALL_TASK_OBJECTS)
115 130
116 // Pointer to instance were counts of objects with the same birth location 131 // Pointer to instance were counts of objects with the same birth location
117 // (on the same thread) are stored. 132 // (on the same thread) are stored.
118 Births* tracked_births_; 133 Births* tracked_births_;
119 // The time this object was constructed. If its life consisted of a long 134 // The time this object was constructed. If its life consisted of a long
120 // waiting period, and then it became active, then this value is generally 135 // waiting period, and then it became active, then this value is generally
121 // reset before the object begins it active life. 136 // reset before the object begins it active life.
122 base::TimeTicks tracked_birth_time_; 137 base::TimeTicks tracked_birth_time_;
123 138
124 #endif // defined(TRACK_ALL_TASK_OBJECTS) 139 #endif // defined(TRACK_ALL_TASK_OBJECTS)
125 140
141 const void* birth_program_counter_;
142
126 DISALLOW_COPY_AND_ASSIGN(Tracked); 143 DISALLOW_COPY_AND_ASSIGN(Tracked);
127 }; 144 };
128 145
129 } // namespace tracked_objects 146 } // namespace tracked_objects
130 147
131 #endif // BASE_TRACKED_H_ 148 #endif // BASE_TRACKED_H_
OLDNEW
« no previous file with comments | « base/message_loop.cc ('k') | base/tracked.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698