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..da4dc0d11f14d80a35f7a51c0e47b48c6f5d53a2 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,32 @@ |
namespace base { |
namespace trace_event { |
+namespace { |
+ |
+// Extract category name from the file name. |
+StringPiece ExtractDirNameFromTaskContext(const char* type_name) { |
petrcermak
2016/03/29 12:49:05
The comment, method name and argument name all dis
ssid
2016/03/29 18:32:45
wdyt now?
petrcermak
2016/03/29 18:42:13
I think it's much better, but the comment is now "
ssid
2016/03/29 23:04:18
Done.
|
+ StringPiece result = type_name; |
+ size_t last_seperator = result.find_last_of(FilePath::kSeparators); |
+ |
+ // If |type_name| is a not a file path the seperator will not be found. |
petrcermak
2016/03/29 12:49:05
nit: add a comma after "path"
ssid
2016/03/29 18:32:45
Done.
|
+ // return the type name. |
petrcermak
2016/03/29 12:49:05
This is not a sentence, I suggest merging it with
ssid
2016/03/29 18:32:45
Done.
|
+ if (last_seperator == StringPiece::npos) |
+ return result; |
+ |
+ // Remove the file name from the path. |
+ result.remove_suffix(result.length() - last_seperator); |
+ |
+ // Remove the parent directory references - '..'. |
+ while (result.starts_with(FilePath::kParentDirectory)) { |
+ size_t parent_seperator = result.find_first_of(FilePath::kSeparators); |
+ DCHECK_NE(StringPiece::npos, parent_seperator); |
+ result.remove_prefix(parent_seperator + 1); |
+ } |
+ return result; |
+} |
+ |
+} // namespace |
+ |
TypeNameDeduplicator::TypeNameDeduplicator() { |
// A null pointer has type ID 0 ("unknown type"); |
type_ids_.insert(std::make_pair(nullptr, 0)); |
@@ -53,9 +80,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. |
+ StringPiece type_info = ExtractDirNameFromTaskContext(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); |
} |