OLD | NEW |
---|---|
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 21 matching lines...) Expand all Loading... | |
32 | 32 |
33 //------------------------------------------------------------------------------ | 33 //------------------------------------------------------------------------------ |
34 // Location provides basic info where of an object was constructed, or was | 34 // Location provides basic info where of an object was constructed, or was |
35 // significantly brought to life. | 35 // significantly brought to life. |
36 | 36 |
37 class Location { | 37 class Location { |
38 public: | 38 public: |
39 // Constructor should be called with a long-lived char*, such as __FILE__. | 39 // Constructor should be called with a long-lived char*, such as __FILE__. |
40 // It assumes the provided value will persist as a global constant, and it | 40 // It assumes the provided value will persist as a global constant, and it |
41 // will not make a copy of it. | 41 // will not make a copy of it. |
42 Location(const char* function_name, const char* file_name, int line_number) | 42 Location(const char* function_name, const char* file_name, int line_number); |
43 : function_name_(function_name), | |
44 file_name_(file_name), | |
45 line_number_(line_number) { } | |
46 | 43 |
47 // Provide a default constructor for easy of debugging. | 44 // Provide a default constructor for easy of debugging. |
48 Location() | 45 Location(); |
49 : function_name_("Unknown"), | |
50 file_name_("Unknown"), | |
51 line_number_(-1) { } | |
52 | 46 |
53 // Comparison operator for insertion into a std::map<> hash tables. | 47 // Comparison operator for insertion into a std::map<> hash tables. |
54 // All we need is *some* (any) hashing distinction. Strings should already | 48 // All we need is *some* (any) hashing distinction. Strings should already |
55 // be unique, so we don't bother with strcmp or such. | 49 // be unique, so we don't bother with strcmp or such. |
56 // Use line number as the primary key (because it is fast, and usually gets us | 50 // Use line number as the primary key (because it is fast, and usually gets us |
57 // a difference), and then pointers as secondary keys (just to get some | 51 // a difference), and then pointers as secondary keys (just to get some |
58 // distinctions). | 52 // distinctions). |
59 bool operator < (const Location& other) const { | 53 bool operator < (const Location& other) const; |
Evan Martin
2010/07/15 17:37:33
Comparators being inlined might be important for p
Elliot Glaysher
2010/07/15 18:08:10
I've undone this one. I saw strings and I thought
| |
60 if (line_number_ != other.line_number_) | |
61 return line_number_ < other.line_number_; | |
62 if (file_name_ != other.file_name_) | |
63 return file_name_ < other.file_name_; | |
64 return function_name_ < other.function_name_; | |
65 } | |
66 | 54 |
67 const char* function_name() const { return function_name_; } | 55 const char* function_name() const { return function_name_; } |
68 const char* file_name() const { return file_name_; } | 56 const char* file_name() const { return file_name_; } |
69 int line_number() const { return line_number_; } | 57 int line_number() const { return line_number_; } |
70 | 58 |
71 void Write(bool display_filename, bool display_function_name, | 59 void Write(bool display_filename, bool display_function_name, |
72 std::string* output) const; | 60 std::string* output) const; |
73 | 61 |
74 // Write function_name_ in HTML with '<' and '>' properly encoded. | 62 // Write function_name_ in HTML with '<' and '>' properly encoded. |
75 void WriteFunctionName(std::string* output) const; | 63 void WriteFunctionName(std::string* output) const; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 base::TimeTicks tracked_birth_time_; | 113 base::TimeTicks tracked_birth_time_; |
126 | 114 |
127 #endif // defined(TRACK_ALL_TASK_OBJECTS) | 115 #endif // defined(TRACK_ALL_TASK_OBJECTS) |
128 | 116 |
129 DISALLOW_COPY_AND_ASSIGN(Tracked); | 117 DISALLOW_COPY_AND_ASSIGN(Tracked); |
130 }; | 118 }; |
131 | 119 |
132 } // namespace tracked_objects | 120 } // namespace tracked_objects |
133 | 121 |
134 #endif // BASE_TRACKED_H_ | 122 #endif // BASE_TRACKED_H_ |
OLD | NEW |