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 #include "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #if defined(COMPILER_MSVC) | 7 #if defined(COMPILER_MSVC) |
8 // MSDN says to #include <intrin.h>, but that breaks the VS2005 build. | 8 // MSDN says to #include <intrin.h>, but that breaks the VS2005 build. |
9 extern "C" { | 9 extern "C" { |
10 void* _ReturnAddress(); | 10 void* _ReturnAddress(); |
11 } | 11 } |
12 #endif | 12 #endif |
13 | 13 |
14 #include "base/tracked.h" | 14 #include "base/tracked.h" |
15 | 15 |
16 #include "base/string_number_conversions.h" | |
16 #include "base/stringprintf.h" | 17 #include "base/stringprintf.h" |
17 #include "base/tracked_objects.h" | 18 #include "base/tracked_objects.h" |
18 | 19 |
19 using base::TimeTicks; | 20 using base::TimeTicks; |
20 | 21 |
21 namespace tracked_objects { | 22 namespace tracked_objects { |
22 | 23 |
23 //------------------------------------------------------------------------------ | 24 //------------------------------------------------------------------------------ |
24 | 25 |
25 Location::Location(const char* function_name, | 26 Location::Location(const char* file_line, |
26 const char* file_name, | 27 const char* function_name, |
27 int line_number, | |
28 const void* program_counter) | 28 const void* program_counter) |
29 : function_name_(function_name), | 29 : file_line_(file_line), |
30 file_name_(file_name), | 30 function_name_(function_name), |
31 line_number_(line_number), | |
32 program_counter_(program_counter) { | 31 program_counter_(program_counter) { |
33 } | 32 } |
34 | 33 |
35 Location::Location() | 34 Location::Location() |
36 : function_name_("Unknown"), | 35 : file_line_("Unknown:-1"), |
37 file_name_("Unknown"), | 36 function_name_("Unknown"), |
38 line_number_(-1), | |
39 program_counter_(NULL) { | 37 program_counter_(NULL) { |
40 } | 38 } |
41 | 39 |
40 const base::StringPiece Location::file_name() const { | |
41 base::StringPiece file_line(file_line_); | |
42 return file_line.substr(0, file_line.find_last_of(':')); | |
43 } | |
44 | |
45 int Location::line_number() const { | |
46 base::StringPiece file_line(file_line_); | |
47 base::StringPiece::size_type colon1 = file_line.find_last_of(':'); | |
48 int line_num = 0; | |
49 base::StringToInt(file_line.substr(colon1).as_string(), &line_num); | |
50 return line_num; | |
51 } | |
52 | |
53 const base::StringPiece Location::function_name() const { | |
54 return base::StringPiece(function_name_); | |
joth
2011/09/15 10:38:09
nit: is there any point returning this as a string
jbates
2011/09/15 16:48:33
I went back and forth on this one -- I was on the
| |
55 } | |
56 | |
42 void Location::Write(bool display_filename, bool display_function_name, | 57 void Location::Write(bool display_filename, bool display_function_name, |
43 std::string* output) const { | 58 std::string* output) const { |
44 base::StringAppendF(output, "%s[%d] ", | 59 base::StringAppendF(output, "%s[%d] ", |
45 display_filename ? file_name_ : "line", | 60 display_filename ? file_name().as_string().c_str() : "line", |
46 line_number_); | 61 line_number()); |
47 | 62 |
48 if (display_function_name) { | 63 if (display_function_name) { |
49 WriteFunctionName(output); | 64 WriteFunctionName(output); |
50 output->push_back(' '); | 65 output->push_back(' '); |
51 } | 66 } |
52 } | 67 } |
53 | 68 |
54 void Location::WriteFunctionName(std::string* output) const { | 69 void Location::WriteFunctionName(std::string* output) const { |
55 // Translate "<" to "<" for HTML safety. | 70 // Translate "<" to "<" for HTML safety. |
56 // TODO(jar): Support ASCII or html for logging in ASCII. | 71 // TODO(jar): Support ASCII or html for logging in ASCII. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 #if !defined(TRACK_ALL_TASK_OBJECTS) | 104 #if !defined(TRACK_ALL_TASK_OBJECTS) |
90 | 105 |
91 Tracked::Tracked() : birth_program_counter_(NULL) {} | 106 Tracked::Tracked() : birth_program_counter_(NULL) {} |
92 Tracked::~Tracked() {} | 107 Tracked::~Tracked() {} |
93 | 108 |
94 void Tracked::SetBirthPlace(const Location& from_here) { | 109 void Tracked::SetBirthPlace(const Location& from_here) { |
95 birth_program_counter_ = from_here.program_counter(); | 110 birth_program_counter_ = from_here.program_counter(); |
96 } | 111 } |
97 | 112 |
98 const Location Tracked::GetBirthPlace() const { | 113 const Location Tracked::GetBirthPlace() const { |
99 static Location kNone("NoFunctionName", "NeedToSetBirthPlace", -1, NULL); | 114 static Location kNone("NeedToSetBirthPlace:-1", "NoFunctionName", NULL); |
100 return kNone; | 115 return kNone; |
101 } | 116 } |
102 bool Tracked::MissingBirthPlace() const { return false; } | 117 bool Tracked::MissingBirthPlace() const { return false; } |
103 void Tracked::ResetBirthTime() {} | 118 void Tracked::ResetBirthTime() {} |
104 | 119 |
105 #else | 120 #else |
106 | 121 |
107 Tracked::Tracked() | 122 Tracked::Tracked() |
108 : tracked_births_(NULL), | 123 : tracked_births_(NULL), |
109 tracked_birth_time_(TimeTicks::Now()) { | 124 tracked_birth_time_(TimeTicks::Now()) { |
(...skipping 13 matching lines...) Expand all Loading... | |
123 tracked_births_->ForgetBirth(); | 138 tracked_births_->ForgetBirth(); |
124 ThreadData* current_thread_data = ThreadData::current(); | 139 ThreadData* current_thread_data = ThreadData::current(); |
125 if (!current_thread_data) | 140 if (!current_thread_data) |
126 return; // Shutdown started, and this thread wasn't registered. | 141 return; // Shutdown started, and this thread wasn't registered. |
127 tracked_births_ = current_thread_data->TallyABirth(from_here); | 142 tracked_births_ = current_thread_data->TallyABirth(from_here); |
128 | 143 |
129 birth_program_counter_ = from_here.program_counter(); | 144 birth_program_counter_ = from_here.program_counter(); |
130 } | 145 } |
131 | 146 |
132 const Location Tracked::GetBirthPlace() const { | 147 const Location Tracked::GetBirthPlace() const { |
133 static Location kNone("UnknownFunctionName", "UnknownFile", -1, NULL); | 148 static Location kNone; |
134 return tracked_births_ ? tracked_births_->location() : kNone; | 149 return tracked_births_ ? tracked_births_->location() : kNone; |
135 } | 150 } |
136 | 151 |
137 void Tracked::ResetBirthTime() { | 152 void Tracked::ResetBirthTime() { |
138 tracked_birth_time_ = TimeTicks::Now(); | 153 tracked_birth_time_ = TimeTicks::Now(); |
139 } | 154 } |
140 | 155 |
141 bool Tracked::MissingBirthPlace() const { | 156 bool Tracked::MissingBirthPlace() const { |
142 return !tracked_births_ || tracked_births_->location().line_number() == -1; | 157 return !tracked_births_ || |
158 tracked_births_->location().program_counter() == NULL; | |
143 } | 159 } |
144 | 160 |
145 #endif // !defined(TRACK_ALL_TASK_OBJECTS) | 161 #endif // !defined(TRACK_ALL_TASK_OBJECTS) |
146 | 162 |
147 } // namespace tracked_objects | 163 } // namespace tracked_objects |
OLD | NEW |