| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/tracked_objects.h" | 5 #include "base/tracked_objects.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 if (too_late_to_create) { | 124 if (too_late_to_create) { |
| 125 delete registry; | 125 delete registry; |
| 126 registry = NULL; | 126 registry = NULL; |
| 127 } else { | 127 } else { |
| 128 tls_index_.Set(registry); | 128 tls_index_.Set(registry); |
| 129 } | 129 } |
| 130 } | 130 } |
| 131 return registry; | 131 return registry; |
| 132 } | 132 } |
| 133 | 133 |
| 134 // Do mininimal fixups for searching function names. | |
| 135 static std::string UnescapeQuery(const std::string& query) { | |
| 136 std::string result; | |
| 137 for (size_t i = 0; i < query.size(); i++) { | |
| 138 char next = query[i]; | |
| 139 if ('%' == next && i + 2 < query.size()) { | |
| 140 std::string hex = query.substr(i + 1, 2); | |
| 141 char replacement = '\0'; | |
| 142 // Only bother with "<", ">", and " ". | |
| 143 if (LowerCaseEqualsASCII(hex, "3c")) | |
| 144 replacement ='<'; | |
| 145 else if (LowerCaseEqualsASCII(hex, "3e")) | |
| 146 replacement = '>'; | |
| 147 else if (hex == "20") | |
| 148 replacement = ' '; | |
| 149 if (replacement) { | |
| 150 next = replacement; | |
| 151 i += 2; | |
| 152 } | |
| 153 } | |
| 154 result.push_back(next); | |
| 155 } | |
| 156 return result; | |
| 157 } | |
| 158 | |
| 159 // static | 134 // static |
| 160 void ThreadData::WriteHTML(const std::string& query, std::string* output) { | 135 void ThreadData::WriteHTML(const std::string& query, std::string* output) { |
| 161 if (!ThreadData::IsActive()) | 136 if (!ThreadData::IsActive()) |
| 162 return; // Not yet initialized. | 137 return; // Not yet initialized. |
| 163 | 138 |
| 164 DCHECK(ThreadData::current()); | 139 DCHECK(ThreadData::current()); |
| 165 | |
| 166 output->append("<html><head><title>About Tasks"); | |
| 167 std::string escaped_query = UnescapeQuery(query); | |
| 168 if (!escaped_query.empty()) | |
| 169 output->append(" - " + escaped_query); | |
| 170 output->append("</title></head><body><pre>"); | |
| 171 | |
| 172 DataCollector collected_data; // Gather data. | 140 DataCollector collected_data; // Gather data. |
| 173 collected_data.AddListOfLivingObjects(); // Add births that are still alive. | 141 collected_data.AddListOfLivingObjects(); // Add births that are still alive. |
| 174 | 142 |
| 175 // Data Gathering is complete. Now to sort/process/render. | 143 // Data Gathering is complete. Now to sort/process/render. |
| 176 DataCollector::Collection* collection = collected_data.collection(); | 144 DataCollector::Collection* collection = collected_data.collection(); |
| 177 | 145 |
| 178 // Create filtering and sort comparison object. | 146 // Create filtering and sort comparison object. |
| 179 Comparator comparator; | 147 Comparator comparator; |
| 180 comparator.ParseQuery(escaped_query); | 148 comparator.ParseQuery(query); |
| 181 | 149 |
| 182 // Filter out acceptable (matching) instances. | 150 // Filter out acceptable (matching) instances. |
| 183 DataCollector::Collection match_array; | 151 DataCollector::Collection match_array; |
| 184 for (DataCollector::Collection::iterator it = collection->begin(); | 152 for (DataCollector::Collection::iterator it = collection->begin(); |
| 185 it != collection->end(); ++it) { | 153 it != collection->end(); ++it) { |
| 186 if (comparator.Acceptable(*it)) | 154 if (comparator.Acceptable(*it)) |
| 187 match_array.push_back(*it); | 155 match_array.push_back(*it); |
| 188 } | 156 } |
| 189 | 157 |
| 190 comparator.Sort(&match_array); | 158 comparator.Sort(&match_array); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 215 " of lifetime events." | 183 " of lifetime events." |
| 216 "</ul>" | 184 "</ul>" |
| 217 " The data can be reset to zero (discarding all births, deaths, etc.) using" | 185 " The data can be reset to zero (discarding all births, deaths, etc.) using" |
| 218 " <b>about:tasks/reset</b>. The existing stats will be displayed, but the" | 186 " <b>about:tasks/reset</b>. The existing stats will be displayed, but the" |
| 219 " internal stats will be set to zero, and start accumulating afresh. This" | 187 " internal stats will be set to zero, and start accumulating afresh. This" |
| 220 " option is very helpful if you only wish to consider tasks created after" | 188 " option is very helpful if you only wish to consider tasks created after" |
| 221 " some point in time.<br><br>" | 189 " some point in time.<br><br>" |
| 222 "If you wish to monitor Renderer events, be sure to run in --single-process" | 190 "If you wish to monitor Renderer events, be sure to run in --single-process" |
| 223 " mode."; | 191 " mode."; |
| 224 output->append(help_string); | 192 output->append(help_string); |
| 225 output->append("</body></html>"); | |
| 226 } | 193 } |
| 227 | 194 |
| 228 // static | 195 // static |
| 229 void ThreadData::WriteHTMLTotalAndSubtotals( | 196 void ThreadData::WriteHTMLTotalAndSubtotals( |
| 230 const DataCollector::Collection& match_array, | 197 const DataCollector::Collection& match_array, |
| 231 const Comparator& comparator, | 198 const Comparator& comparator, |
| 232 std::string* output) { | 199 std::string* output) { |
| 233 if (!match_array.size()) { | 200 if (!match_array.size()) { |
| 234 output->append("There were no tracked matches."); | 201 output->append("There were no tracked matches."); |
| 235 } else { | 202 } else { |
| (...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1048 (combined_selectors_ & BIRTH_THREAD) ? "*" : | 1015 (combined_selectors_ & BIRTH_THREAD) ? "*" : |
| 1049 sample.birth().birth_thread()->ThreadName().c_str(), | 1016 sample.birth().birth_thread()->ThreadName().c_str(), |
| 1050 (combined_selectors_ & DEATH_THREAD) ? "*" : | 1017 (combined_selectors_ & DEATH_THREAD) ? "*" : |
| 1051 sample.DeathThreadName().c_str()); | 1018 sample.DeathThreadName().c_str()); |
| 1052 sample.birth().location().Write(!(combined_selectors_ & BIRTH_FILE), | 1019 sample.birth().location().Write(!(combined_selectors_ & BIRTH_FILE), |
| 1053 !(combined_selectors_ & BIRTH_FUNCTION), | 1020 !(combined_selectors_ & BIRTH_FUNCTION), |
| 1054 output); | 1021 output); |
| 1055 } | 1022 } |
| 1056 | 1023 |
| 1057 } // namespace tracked_objects | 1024 } // namespace tracked_objects |
| OLD | NEW |