Chromium Code Reviews| Index: base/trace_event/heap_profiler_type_name_deduplicator.cc |
| diff --git a/base/trace_event/heap_profiler_type_name_deduplicator.cc b/base/trace_event/heap_profiler_type_name_deduplicator.cc |
| index e7f57c8ae0ebd853404eb3bfd2da792d8547b05a..8f3d446d232091acb5f6284e5d01126151c60aa8 100644 |
| --- a/base/trace_event/heap_profiler_type_name_deduplicator.cc |
| +++ b/base/trace_event/heap_profiler_type_name_deduplicator.cc |
| @@ -9,6 +9,7 @@ |
| #include <string> |
| #include <utility> |
| +#include "base/files/file_path.h" |
| #include "base/json/string_escape.h" |
| #include "base/strings/stringprintf.h" |
| #include "base/trace_event/trace_event_memory_overhead.h" |
| @@ -16,6 +17,31 @@ |
| namespace base { |
| namespace trace_event { |
| +namespace { |
| + |
| +// Extract category name from the file name. |
| +std::string ExtractTypeInfo(const std::string& type_name) { |
|
Primiano Tucci (use gerrit)
2016/03/25 01:56:31
I think the arg of this should be const char*, if
ssid
2016/03/28 18:14:49
Done.
|
| + std::vector<FilePath::StringType> folder_names; |
| + FilePath(FILE_PATH_LITERAL(type_name)).DirName().GetComponents(&folder_names); |
| + |
| + // If |type_name| is a not a file path the directory will be empty, then |
| + // return the type name. |
| + if (folder_names.empty()) |
| + return type_name; |
| + |
| + // Remove the parent directory references - '..'. |
| + while (folder_names.begin()->find(FilePath::kParentDirectory) != |
| + std::string::npos) { |
| + folder_names.erase(folder_names.begin()); |
| + } |
| + std::string type_info; |
| + for (std::string folder : folder_names) |
|
Primiano Tucci (use gerrit)
2016/03/25 01:56:31
tip for next times, const std::string& would have
ssid
2016/03/28 18:14:49
Thanks.
|
| + type_info += folder + "/"; |
| + return type_info; |
| +} |
| + |
| +} // namespace |
| + |
| TypeNameDeduplicator::TypeNameDeduplicator() { |
| // A null pointer has type ID 0 ("unknown type"); |
| type_ids_.insert(std::make_pair(nullptr, 0)); |
| @@ -53,9 +79,12 @@ void TypeNameDeduplicator::AppendAsTraceFormat(std::string* out) const { |
| // a dictionary. |
| SStringPrintf(&buffer, ",\"%d\":", it->second); |
| + // TODO(ssid): crbug.com/594803 the type name is misused for category name. |
| + std::string type_info = ExtractTypeInfo(it->first); |
| + |
| // |EscapeJSONString| appends, it does not overwrite |buffer|. |
| bool put_in_quotes = true; |
| - EscapeJSONString(it->first, put_in_quotes, &buffer); |
| + EscapeJSONString(type_info, put_in_quotes, &buffer); |
| out->append(buffer); |
| } |