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

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

Issue 1249643007: Align base::Pickle allocations to 4k boundaries (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@accounting_fix
Patch Set: Nits test Created 5 years, 5 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
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/trace_event_memory_overhead.h" 5 #include "base/trace_event/trace_event_memory_overhead.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bits.h"
9 #include "base/memory/ref_counted_memory.h" 10 #include "base/memory/ref_counted_memory.h"
10 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
11 #include "base/trace_event/memory_allocator_dump.h" 12 #include "base/trace_event/memory_allocator_dump.h"
12 #include "base/trace_event/process_memory_dump.h" 13 #include "base/trace_event/process_memory_dump.h"
13 #include "base/values.h" 14 #include "base/values.h"
14 15
15 namespace {
16 size_t RoundUp(size_t size, size_t alignment) {
17 return (size + alignment - 1) & ~(alignment - 1);
18 }
19 } // namespace
20
21 namespace base { 16 namespace base {
22 namespace trace_event { 17 namespace trace_event {
23 18
24 TraceEventMemoryOverhead::TraceEventMemoryOverhead() { 19 TraceEventMemoryOverhead::TraceEventMemoryOverhead() {
25 } 20 }
26 21
27 TraceEventMemoryOverhead::~TraceEventMemoryOverhead() { 22 TraceEventMemoryOverhead::~TraceEventMemoryOverhead() {
28 } 23 }
29 24
30 void TraceEventMemoryOverhead::AddOrCreateInternal( 25 void TraceEventMemoryOverhead::AddOrCreateInternal(
(...skipping 23 matching lines...) Expand all
54 size_t allocated_size_in_bytes, 49 size_t allocated_size_in_bytes,
55 size_t resident_size_in_bytes) { 50 size_t resident_size_in_bytes) {
56 AddOrCreateInternal(object_type, 1, allocated_size_in_bytes, 51 AddOrCreateInternal(object_type, 1, allocated_size_in_bytes,
57 resident_size_in_bytes); 52 resident_size_in_bytes);
58 } 53 }
59 54
60 void TraceEventMemoryOverhead::AddString(const std::string& str) { 55 void TraceEventMemoryOverhead::AddString(const std::string& str) {
61 // The number below are empirical and mainly based on profiling of real-world 56 // The number below are empirical and mainly based on profiling of real-world
62 // std::string implementations: 57 // std::string implementations:
63 // - even short string end up malloc()-inc at least 32 bytes. 58 // - even short string end up malloc()-inc at least 32 bytes.
64 // - longer stings seem to malloc() multiples of 16 bytes. 59 // - longer strings seem to malloc() multiples of 16 bytes.
65 Add("std::string", 60 const size_t capacity = bits::Align(str.capacity(), 16);
66 sizeof(std::string) + std::max<size_t>(RoundUp(str.capacity(), 16), 32u)); 61 Add("std::string", sizeof(std::string) + std::max<size_t>(capacity, 32u));
67 } 62 }
68 63
69 void TraceEventMemoryOverhead::AddRefCountedString( 64 void TraceEventMemoryOverhead::AddRefCountedString(
70 const RefCountedString& str) { 65 const RefCountedString& str) {
71 Add("RefCountedString", sizeof(RefCountedString)); 66 Add("RefCountedString", sizeof(RefCountedString));
72 AddString(str.data()); 67 AddString(str.data());
73 } 68 }
74 69
75 void TraceEventMemoryOverhead::AddValue(const Value& value) { 70 void TraceEventMemoryOverhead::AddValue(const Value& value) {
76 switch (value.GetType()) { 71 switch (value.GetType()) {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 it.second.allocated_size_in_bytes); 147 it.second.allocated_size_in_bytes);
153 mad->AddScalar("resident_size", MemoryAllocatorDump::kUnitsBytes, 148 mad->AddScalar("resident_size", MemoryAllocatorDump::kUnitsBytes,
154 it.second.resident_size_in_bytes); 149 it.second.resident_size_in_bytes);
155 mad->AddScalar(MemoryAllocatorDump::kNameObjectsCount, 150 mad->AddScalar(MemoryAllocatorDump::kNameObjectsCount,
156 MemoryAllocatorDump::kUnitsObjects, it.second.count); 151 MemoryAllocatorDump::kUnitsObjects, it.second.count);
157 } 152 }
158 } 153 }
159 154
160 } // namespace trace_event 155 } // namespace trace_event
161 } // namespace base 156 } // namespace base
OLDNEW
« base/bits_unittest.cc ('K') | « base/trace_event/trace_event_argument.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698