//------------------------------------------------------------------------------// Tracked is the base class for all tracked objects. During construction, it// registers the fact that an instance was created, and at destruction time, it// records that event. The instance may be tagged with a name, which is refered// to as its Location. The Location is a file and line number, most// typically indicated where the object was constructed. In some cases, as the// object's significance is refined (for example, a Task object is augmented to// do additonal things), its Location may be redefined to that later location.// Tracking includes (for each instance) recording the birth thread, death// thread, and duration of life (from construction to destruction). All this// data is accumulated and filtered for review at about:objects.
信息跟踪收集,用于统计分析的工具
下面的代码是不是很熟悉,FROM_HERE
message_loop->PostTask(FROM_HERE,...)#define FROM_HERE tracked_objects::Location(__FUNCTION__, __FILE__, __LINE__)
构造函数如下:
class Location { public: // Constructor should be called with a long-lived char*, such as __FILE__. // It assumes the provided value will persist as a global constant, and it // will not make a copy of it. Location(const char* function_name, const char* file_name, int line_number) : function_name_(function_name), file_name_(file_name), line_number_(line_number) { }}
记录了函数名,文件名,行号
不过,只有在调试模式,才会有比较详细的统计信息
#ifndef NDEBUG#ifndef TRACK_ALL_TASK_OBJECTS#define TRACK_ALL_TASK_OBJECTS#endif // TRACK_ALL_TASK_OBJECTS#endif // NDEBUG
调试模式下,多了一个没见过的ThreadData,可以分析分析
Tracked::Tracked() : tracked_births_(NULL), tracked_birth_time_(Time::Now()) { if (!ThreadData::IsActive()) return; SetBirthPlace(Location("NoFunctionName", "NeedToSetBirthPlace", -1));}