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

Side by Side Diff: runtime/vm/profiler.cc

Issue 2955493002: Allocate the profiler sample buffer and zone segments with virtual memory instead of malloc. (Closed)
Patch Set: . Created 3 years, 6 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 | « runtime/vm/profiler.h ('k') | runtime/vm/virtual_memory_fuchsia.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/address_sanitizer.h" 5 #include "platform/address_sanitizer.h"
6 #include "platform/memory_sanitizer.h" 6 #include "platform/memory_sanitizer.h"
7 #include "platform/utils.h" 7 #include "platform/utils.h"
8 8
9 #include "vm/allocation.h" 9 #include "vm/allocation.h"
10 #include "vm/atomic.h" 10 #include "vm/atomic.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 122
123 123
124 uword* Sample::GetPCArray() const { 124 uword* Sample::GetPCArray() const {
125 return reinterpret_cast<uword*>(reinterpret_cast<uintptr_t>(this) + 125 return reinterpret_cast<uword*>(reinterpret_cast<uintptr_t>(this) +
126 sizeof(*this)); 126 sizeof(*this));
127 } 127 }
128 128
129 129
130 SampleBuffer::SampleBuffer(intptr_t capacity) { 130 SampleBuffer::SampleBuffer(intptr_t capacity) {
131 ASSERT(Sample::instance_size() > 0); 131 ASSERT(Sample::instance_size() > 0);
132 samples_ = 132
133 reinterpret_cast<Sample*>(calloc(capacity, Sample::instance_size())); 133 const intptr_t size = Utils::RoundUp(capacity * Sample::instance_size(),
134 VirtualMemory::PageSize());
135 const bool kNotExecutable = false;
136 memory_ = VirtualMemory::Reserve(size);
137 if ((memory_ == NULL) || !memory_->Commit(kNotExecutable, "dart-profiler")) {
138 OUT_OF_MEMORY();
139 }
140
141 samples_ = reinterpret_cast<Sample*>(memory_->address());
142 capacity_ = capacity;
143 cursor_ = 0;
144
134 if (FLAG_trace_profiler) { 145 if (FLAG_trace_profiler) {
135 OS::Print("Profiler holds %" Pd " samples\n", capacity); 146 OS::Print("Profiler holds %" Pd " samples\n", capacity);
136 OS::Print("Profiler sample is %" Pd " bytes\n", Sample::instance_size()); 147 OS::Print("Profiler sample is %" Pd " bytes\n", Sample::instance_size());
137 OS::Print("Profiler memory usage = %" Pd " bytes\n", 148 OS::Print("Profiler memory usage = %" Pd " bytes\n", size);
138 capacity * Sample::instance_size());
139 } 149 }
140 capacity_ = capacity;
141 cursor_ = 0;
142 } 150 }
143 151
144 152
153 SampleBuffer::~SampleBuffer() {
154 delete memory_;
155 }
156
157
145 Sample* SampleBuffer::At(intptr_t idx) const { 158 Sample* SampleBuffer::At(intptr_t idx) const {
146 ASSERT(idx >= 0); 159 ASSERT(idx >= 0);
147 ASSERT(idx < capacity_); 160 ASSERT(idx < capacity_);
148 intptr_t offset = idx * Sample::instance_size(); 161 intptr_t offset = idx * Sample::instance_size();
149 uint8_t* samples = reinterpret_cast<uint8_t*>(samples_); 162 uint8_t* samples = reinterpret_cast<uint8_t*>(samples_);
150 return reinterpret_cast<Sample*>(samples + offset); 163 return reinterpret_cast<Sample*>(samples + offset);
151 } 164 }
152 165
153 166
154 intptr_t SampleBuffer::ReserveSampleSlot() { 167 intptr_t SampleBuffer::ReserveSampleSlot() {
(...skipping 1453 matching lines...) Expand 10 before | Expand all | Expand 10 after
1608 1621
1609 1622
1610 ProcessedSampleBuffer::ProcessedSampleBuffer() 1623 ProcessedSampleBuffer::ProcessedSampleBuffer()
1611 : code_lookup_table_(new CodeLookupTable(Thread::Current())) { 1624 : code_lookup_table_(new CodeLookupTable(Thread::Current())) {
1612 ASSERT(code_lookup_table_ != NULL); 1625 ASSERT(code_lookup_table_ != NULL);
1613 } 1626 }
1614 1627
1615 #endif // !PRODUCT 1628 #endif // !PRODUCT
1616 1629
1617 } // namespace dart 1630 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/profiler.h ('k') | runtime/vm/virtual_memory_fuchsia.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698