Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(673)

Side by Side Diff: base/trace_event/heap_profiler_type_name_deduplicator.cc

Issue 2698003002: Heap Profiler: Avoid splitting PartitionAlloc / BlinkGC type names by comma (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/trace_event/heap_profiler_type_name_deduplicator.h" 5 #include "base/trace_event/heap_profiler_type_name_deduplicator.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/json/string_escape.h" 12 #include "base/json/string_escape.h"
13 #include "base/strings/string_split.h" 13 #include "base/strings/string_split.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "base/trace_event/memory_usage_estimator.h" 15 #include "base/trace_event/memory_usage_estimator.h"
16 #include "base/trace_event/trace_event.h" 16 #include "base/trace_event/trace_event.h"
17 #include "base/trace_event/trace_event_memory_overhead.h" 17 #include "base/trace_event/trace_event_memory_overhead.h"
18 18
19 namespace base { 19 namespace base {
20 namespace trace_event { 20 namespace trace_event {
21 21
22 namespace { 22 namespace {
23 23
24 // If |type_name| is file name then extract directory name. Or if |type_name| is 24 // If |type_name| is file name then extract directory name. Or if |type_name| is
25 // category name, then disambiguate multple categories and remove 25 // category name, then disambiguate multple categories and remove
26 // "disabled-by-default" prefix if present. 26 // "disabled-by-default" prefix if present.
27 StringPiece ExtractCategoryFromTypeName(const char* type_name) { 27 StringPiece ExtractCategoryFromTypeName(const char* type_name) {
28 StringPiece result(type_name); 28 StringPiece result(type_name);
29 size_t last_seperator = result.find_last_of("\\/"); 29 size_t last_separator = result.find_last_of("\\/");
Primiano Tucci (use gerrit) 2017/05/09 09:04:12 LOL, how much damage did a typo + code/paste :)
30 30
31 // If |type_name| was a not a file path, the seperator will not be found, so 31 // If |type_name| was a not a file path, the separator will not be found, so
32 // the whole type name is returned. 32 // the whole type name is returned.
33 if (last_seperator == StringPiece::npos) { 33 if (last_separator == StringPiece::npos) {
34 // |type_name| is C++ typename if its reporting allocator is
35 // partition_alloc or blink_gc. In this case, we should not split
36 // |type_name| by ',', because of function types and template types.
37 // e.g. WTF::HashMap<WTF::AtomicString, WTF::AtomicString>,
38 // void (*)(void*, void*), and so on. So if |type_name| contains
39 if (result.find_last_of(")>") != StringPiece::npos)
40 return result;
41
34 // Use the first the category name if it has ",". 42 // Use the first the category name if it has ",".
35 size_t first_comma_position = result.find(','); 43 size_t first_comma_position = result.find(',');
36 if (first_comma_position != StringPiece::npos) 44 if (first_comma_position != StringPiece::npos)
37 result = result.substr(0, first_comma_position); 45 result = result.substr(0, first_comma_position);
38 if (result.starts_with(TRACE_DISABLED_BY_DEFAULT(""))) 46 if (result.starts_with(TRACE_DISABLED_BY_DEFAULT("")))
39 result.remove_prefix(sizeof(TRACE_DISABLED_BY_DEFAULT("")) - 1); 47 result.remove_prefix(sizeof(TRACE_DISABLED_BY_DEFAULT("")) - 1);
40 return result; 48 return result;
41 } 49 }
42 50
43 // Remove the file name from the path. 51 // Remove the file name from the path.
44 result.remove_suffix(result.length() - last_seperator); 52 result.remove_suffix(result.length() - last_separator);
45 53
46 // Remove the parent directory references. 54 // Remove the parent directory references.
47 const char kParentDirectory[] = ".."; 55 const char kParentDirectory[] = "..";
48 const size_t kParentDirectoryLength = 3; // '../' or '..\'. 56 const size_t kParentDirectoryLength = 3; // '../' or '..\'.
49 while (result.starts_with(kParentDirectory)) { 57 while (result.starts_with(kParentDirectory)) {
50 result.remove_prefix(kParentDirectoryLength); 58 result.remove_prefix(kParentDirectoryLength);
51 } 59 }
52 return result; 60 return result;
53 } 61 }
54 62
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 114
107 void TypeNameDeduplicator::EstimateTraceMemoryOverhead( 115 void TypeNameDeduplicator::EstimateTraceMemoryOverhead(
108 TraceEventMemoryOverhead* overhead) { 116 TraceEventMemoryOverhead* overhead) {
109 size_t memory_usage = EstimateMemoryUsage(type_ids_); 117 size_t memory_usage = EstimateMemoryUsage(type_ids_);
110 overhead->Add(TraceEventMemoryOverhead::kHeapProfilerTypeNameDeduplicator, 118 overhead->Add(TraceEventMemoryOverhead::kHeapProfilerTypeNameDeduplicator,
111 sizeof(TypeNameDeduplicator) + memory_usage); 119 sizeof(TypeNameDeduplicator) + memory_usage);
112 } 120 }
113 121
114 } // namespace trace_event 122 } // namespace trace_event
115 } // namespace base 123 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698