| OLD | NEW |
| 1 // Copyright (c) 2006-2008 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/time.h" | 25 #include "base/time.h" |
| 25 | 26 |
| 26 #ifndef NDEBUG | 27 #ifndef NDEBUG |
| 27 #ifndef TRACK_ALL_TASK_OBJECTS | 28 #ifndef TRACK_ALL_TASK_OBJECTS |
| 28 #define TRACK_ALL_TASK_OBJECTS | 29 #define TRACK_ALL_TASK_OBJECTS |
| 29 #endif // TRACK_ALL_TASK_OBJECTS | 30 #endif // TRACK_ALL_TASK_OBJECTS |
| 30 #endif // NDEBUG | 31 #endif // NDEBUG |
| 31 | 32 |
| 32 namespace tracked_objects { | 33 namespace tracked_objects { |
| 33 | 34 |
| 34 //------------------------------------------------------------------------------ | 35 //------------------------------------------------------------------------------ |
| 35 // 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 |
| 36 // significantly brought to life. | 37 // significantly brought to life. |
| 37 | 38 |
| 38 class Location { | 39 class BASE_API Location { |
| 39 public: | 40 public: |
| 40 // 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__. |
| 41 // 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 |
| 42 // will not make a copy of it. | 43 // will not make a copy of it. |
| 43 Location(const char* function_name, const char* file_name, int line_number); | 44 Location(const char* function_name, const char* file_name, int line_number); |
| 44 | 45 |
| 45 // Provide a default constructor for easy of debugging. | 46 // Provide a default constructor for easy of debugging. |
| 46 Location(); | 47 Location(); |
| 47 | 48 |
| 48 // Comparison operator for insertion into a std::map<> hash tables. | 49 // Comparison operator for insertion into a std::map<> hash tables. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 // Define a macro to record the current source location. | 81 // Define a macro to record the current source location. |
| 81 | 82 |
| 82 #define FROM_HERE tracked_objects::Location(__FUNCTION__, __FILE__, __LINE__) | 83 #define FROM_HERE tracked_objects::Location(__FUNCTION__, __FILE__, __LINE__) |
| 83 | 84 |
| 84 | 85 |
| 85 //------------------------------------------------------------------------------ | 86 //------------------------------------------------------------------------------ |
| 86 | 87 |
| 87 | 88 |
| 88 class Births; | 89 class Births; |
| 89 | 90 |
| 90 class Tracked { | 91 class BASE_API Tracked { |
| 91 public: | 92 public: |
| 92 Tracked(); | 93 Tracked(); |
| 93 virtual ~Tracked(); | 94 virtual ~Tracked(); |
| 94 | 95 |
| 95 // Used to record the FROM_HERE location of a caller. | 96 // Used to record the FROM_HERE location of a caller. |
| 96 void SetBirthPlace(const Location& from_here); | 97 void SetBirthPlace(const Location& from_here); |
| 97 const Location GetBirthPlace() const; | 98 const Location GetBirthPlace() const; |
| 98 | 99 |
| 99 // When a task sits around a long time, such as in a timer, or object watcher, | 100 // When a task sits around a long time, such as in a timer, or object watcher, |
| 100 // this method should be called when the task becomes active, and its | 101 // this method should be called when the task becomes active, and its |
| (...skipping 20 matching lines...) Expand all Loading... |
| 121 base::TimeTicks tracked_birth_time_; | 122 base::TimeTicks tracked_birth_time_; |
| 122 | 123 |
| 123 #endif // defined(TRACK_ALL_TASK_OBJECTS) | 124 #endif // defined(TRACK_ALL_TASK_OBJECTS) |
| 124 | 125 |
| 125 DISALLOW_COPY_AND_ASSIGN(Tracked); | 126 DISALLOW_COPY_AND_ASSIGN(Tracked); |
| 126 }; | 127 }; |
| 127 | 128 |
| 128 } // namespace tracked_objects | 129 } // namespace tracked_objects |
| 129 | 130 |
| 130 #endif // BASE_TRACKED_H_ | 131 #endif // BASE_TRACKED_H_ |
| OLD | NEW |