OLD | NEW |
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 |
11 // object's significance is refined (for example, a Task object is augmented to | 11 // object's significance is refined (for example, a Task object is augmented to |
12 // do additonal things), its Location may be redefined to that later location. | 12 // do additonal things), its Location may be redefined to that later location. |
13 | 13 |
14 // Tracking includes (for each instance) recording the birth thread, death | 14 // Tracking includes (for each instance) recording the birth thread, death |
15 // thread, and duration of life (from construction to destruction). All this | 15 // thread, and duration of life (from construction to destruction). All this |
16 // data is accumulated and filtered for review at about:objects. | 16 // data is accumulated and filtered for review at about:objects. |
17 | 17 |
18 #ifndef BASE_TRACKED_H_ | 18 #ifndef BASE_TRACKED_H_ |
19 #define BASE_TRACKED_H_ | 19 #define BASE_TRACKED_H_ |
20 #pragma once | 20 #pragma once |
21 | 21 |
22 #include <string> | 22 #include <string> |
23 | 23 |
24 #include "base/base_api.h" | 24 #include "base/base_export.h" |
25 #include "base/time.h" | 25 #include "base/time.h" |
26 | 26 |
27 #ifndef NDEBUG | 27 #ifndef NDEBUG |
28 #ifndef TRACK_ALL_TASK_OBJECTS | 28 #ifndef TRACK_ALL_TASK_OBJECTS |
29 #define TRACK_ALL_TASK_OBJECTS | 29 #define TRACK_ALL_TASK_OBJECTS |
30 #endif // TRACK_ALL_TASK_OBJECTS | 30 #endif // TRACK_ALL_TASK_OBJECTS |
31 #endif // NDEBUG | 31 #endif // NDEBUG |
32 | 32 |
33 namespace tracked_objects { | 33 namespace tracked_objects { |
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_EXPORT 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, | 44 Location(const char* function_name, |
45 const char* file_name, | 45 const char* file_name, |
46 int line_number, | 46 int line_number, |
47 const void* program_counter); | 47 const void* program_counter); |
48 | 48 |
49 // Provide a default constructor for easy of debugging. | 49 // Provide a default constructor for easy of debugging. |
(...skipping 24 matching lines...) Expand all Loading... |
74 // Write function_name_ in HTML with '<' and '>' properly encoded. | 74 // Write function_name_ in HTML with '<' and '>' properly encoded. |
75 void WriteFunctionName(std::string* output) const; | 75 void WriteFunctionName(std::string* output) const; |
76 | 76 |
77 private: | 77 private: |
78 const char* const function_name_; | 78 const char* const function_name_; |
79 const char* const file_name_; | 79 const char* const file_name_; |
80 const int line_number_; | 80 const int line_number_; |
81 const void* const program_counter_; | 81 const void* const program_counter_; |
82 }; | 82 }; |
83 | 83 |
84 BASE_API const void* GetProgramCounter(); | 84 BASE_EXPORT const void* GetProgramCounter(); |
85 | 85 |
86 //------------------------------------------------------------------------------ | 86 //------------------------------------------------------------------------------ |
87 // Define a macro to record the current source location. | 87 // Define a macro to record the current source location. |
88 | 88 |
89 #define FROM_HERE tracked_objects::Location( \ | 89 #define FROM_HERE tracked_objects::Location( \ |
90 __FUNCTION__, \ | 90 __FUNCTION__, \ |
91 __FILE__, \ | 91 __FILE__, \ |
92 __LINE__, \ | 92 __LINE__, \ |
93 tracked_objects::GetProgramCounter()) \ | 93 tracked_objects::GetProgramCounter()) \ |
94 | 94 |
95 | 95 |
96 //------------------------------------------------------------------------------ | 96 //------------------------------------------------------------------------------ |
97 | 97 |
98 | 98 |
99 class Births; | 99 class Births; |
100 | 100 |
101 class BASE_API Tracked { | 101 class BASE_EXPORT Tracked { |
102 public: | 102 public: |
103 Tracked(); | 103 Tracked(); |
104 virtual ~Tracked(); | 104 virtual ~Tracked(); |
105 | 105 |
106 // Used to record the FROM_HERE location of a caller. | 106 // Used to record the FROM_HERE location of a caller. |
107 void SetBirthPlace(const Location& from_here); | 107 void SetBirthPlace(const Location& from_here); |
108 const Location GetBirthPlace() const; | 108 const Location GetBirthPlace() const; |
109 | 109 |
110 // 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, |
111 // 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 |
(...skipping 27 matching lines...) Expand all Loading... |
139 #endif // defined(TRACK_ALL_TASK_OBJECTS) | 139 #endif // defined(TRACK_ALL_TASK_OBJECTS) |
140 | 140 |
141 const void* birth_program_counter_; | 141 const void* birth_program_counter_; |
142 | 142 |
143 DISALLOW_COPY_AND_ASSIGN(Tracked); | 143 DISALLOW_COPY_AND_ASSIGN(Tracked); |
144 }; | 144 }; |
145 | 145 |
146 } // namespace tracked_objects | 146 } // namespace tracked_objects |
147 | 147 |
148 #endif // BASE_TRACKED_H_ | 148 #endif // BASE_TRACKED_H_ |
OLD | NEW |