summaryrefslogtreecommitdiff
path: root/base/trace_event/heap_profiler_type_name_deduplicator.cc
diff options
context:
space:
mode:
Diffstat (limited to 'base/trace_event/heap_profiler_type_name_deduplicator.cc')
-rw-r--r--base/trace_event/heap_profiler_type_name_deduplicator.cc28
1 files changed, 18 insertions, 10 deletions
diff --git a/base/trace_event/heap_profiler_type_name_deduplicator.cc b/base/trace_event/heap_profiler_type_name_deduplicator.cc
index 055f86abf0..a6dab51ad2 100644
--- a/base/trace_event/heap_profiler_type_name_deduplicator.cc
+++ b/base/trace_event/heap_profiler_type_name_deduplicator.cc
@@ -10,7 +10,10 @@
#include <utility>
#include "base/json/string_escape.h"
+#include "base/strings/string_split.h"
#include "base/strings/stringprintf.h"
+#include "base/trace_event/memory_usage_estimator.h"
+#include "base/trace_event/trace_event.h"
#include "base/trace_event/trace_event_memory_overhead.h"
namespace base {
@@ -18,16 +21,24 @@ namespace trace_event {
namespace {
-// Extract directory name if |type_name| was file name. Otherwise, return
-// |type_name|.
-StringPiece ExtractDirNameFromFileName(const char* type_name) {
+// If |type_name| is file name then extract directory name. Or if |type_name| is
+// category name, then disambiguate multple categories and remove
+// "disabled-by-default" prefix if present.
+StringPiece ExtractCategoryFromTypeName(const char* type_name) {
StringPiece result(type_name);
size_t last_seperator = result.find_last_of("\\/");
// If |type_name| was a not a file path, the seperator will not be found, so
// the whole type name is returned.
- if (last_seperator == StringPiece::npos)
+ if (last_seperator == StringPiece::npos) {
+ // Use the first the category name if it has ",".
+ size_t first_comma_position = result.find(',');
+ if (first_comma_position != StringPiece::npos)
+ result = result.substr(0, first_comma_position);
+ if (result.starts_with(TRACE_DISABLED_BY_DEFAULT("")))
+ result.remove_prefix(sizeof(TRACE_DISABLED_BY_DEFAULT("")) - 1);
return result;
+ }
// Remove the file name from the path.
result.remove_suffix(result.length() - last_seperator);
@@ -82,7 +93,7 @@ void TypeNameDeduplicator::AppendAsTraceFormat(std::string* out) const {
// TODO(ssid): crbug.com/594803 the type name is misused for file name in
// some cases.
- StringPiece type_info = ExtractDirNameFromFileName(it->first);
+ StringPiece type_info = ExtractCategoryFromTypeName(it->first);
// |EscapeJSONString| appends, it does not overwrite |buffer|.
bool put_in_quotes = true;
@@ -95,12 +106,9 @@ void TypeNameDeduplicator::AppendAsTraceFormat(std::string* out) const {
void TypeNameDeduplicator::EstimateTraceMemoryOverhead(
TraceEventMemoryOverhead* overhead) {
- // The size here is only an estimate; it fails to take into account the size
- // of the tree nodes for the map, but as an estimate this should be fine.
- size_t map_size = type_ids_.size() * sizeof(std::pair<const char*, int>);
-
+ size_t memory_usage = EstimateMemoryUsage(type_ids_);
overhead->Add("TypeNameDeduplicator",
- sizeof(TypeNameDeduplicator) + map_size);
+ sizeof(TypeNameDeduplicator) + memory_usage);
}
} // namespace trace_event