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
3 // found in the LICENSE file.
5 #include "base/tracked.h"
7 #include "base/string_util.h"
8 #include "base/tracked_objects.h"
12 namespace tracked_objects
{
14 //------------------------------------------------------------------------------
15 void Location::Write(bool display_filename
, bool display_function_name
,
16 std::string
* output
) const {
17 StringAppendF(output
, "%s[%d] ",
18 display_filename
? file_name_
: "line",
21 if (display_function_name
) {
22 WriteFunctionName(output
);
23 output
->push_back(' ');
27 void Location::WriteFunctionName(std::string
* output
) const {
28 // Translate "<" to "<" for HTML safety.
29 // TODO(jar): Support ASCII or html for logging in ASCII.
30 for (const char *p
= function_name_
; *p
; p
++) {
33 output
->append("<");
37 output
->append(">");
41 output
->push_back(*p
);
47 //------------------------------------------------------------------------------
49 #ifndef TRACK_ALL_TASK_OBJECTS
52 Tracked::~Tracked() {}
53 void Tracked::SetBirthPlace(const Location
& from_here
) {}
54 bool Tracked::MissingBirthplace() const { return false; }
55 void Tracked::ResetBirthTime() {}
59 Tracked::Tracked() : tracked_births_(NULL
), tracked_birth_time_(Time::Now()) {
60 if (!ThreadData::IsActive())
62 SetBirthPlace(Location("NoFunctionName", "NeedToSetBirthPlace", -1));
66 if (!ThreadData::IsActive() || !tracked_births_
)
68 ThreadData::current()->TallyADeath(*tracked_births_
,
69 Time::Now() - tracked_birth_time_
);
72 void Tracked::SetBirthPlace(const Location
& from_here
) {
73 if (!ThreadData::IsActive())
76 tracked_births_
->ForgetBirth();
77 ThreadData
* current_thread_data
= ThreadData::current();
78 if (!current_thread_data
)
79 return; // Shutdown started, and this thread wasn't registered.
80 tracked_births_
= current_thread_data
->TallyABirth(from_here
);
83 void Tracked::ResetBirthTime() {
84 tracked_birth_time_
= Time::Now();
87 bool Tracked::MissingBirthplace() const {
88 return -1 == tracked_births_
->location().line_number();
93 } // namespace tracked_objects