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

Side by Side Diff: src/cpu-profiler.cc

Issue 10871039: Replacing circular queue by single buffer in CPU Profiler. (Closed) Base URL: http://git.chromium.org/external/v8.git@profiling
Patch Set: an attempt to fix a test that strangely crashed only once Created 8 years, 3 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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 21 matching lines...) Expand all
32 #include "frames-inl.h" 32 #include "frames-inl.h"
33 #include "hashmap.h" 33 #include "hashmap.h"
34 #include "log-inl.h" 34 #include "log-inl.h"
35 #include "vm-state-inl.h" 35 #include "vm-state-inl.h"
36 36
37 #include "../include/v8-profiler.h" 37 #include "../include/v8-profiler.h"
38 38
39 namespace v8 { 39 namespace v8 {
40 namespace internal { 40 namespace internal {
41 41
42 static const int kEventsBufferSize = 256 * KB;
43 static const int kTickSamplesBufferChunkSize = 64 * KB;
44 static const int kTickSamplesBufferChunksCount = 16;
45 static const int kProfilerStackSize = 64 * KB; 42 static const int kProfilerStackSize = 64 * KB;
46 43
47 44
48 ProfilerEventsProcessor::ProfilerEventsProcessor(ProfileGenerator* generator, 45 ProfilerEventsProcessor::ProfilerEventsProcessor(ProfileGenerator* generator,
49 Sampler* sampler, 46 Sampler* sampler,
50 int period_in_useconds) 47 int period_in_useconds)
51 : Thread(Thread::Options("v8:ProfEvntProc", kProfilerStackSize)), 48 : Thread(Thread::Options("v8:ProfEvntProc", kProfilerStackSize)),
52 generator_(generator), 49 generator_(generator),
53 sampler_(sampler), 50 sampler_(sampler),
54 running_(true), 51 running_(true),
55 period_in_useconds_(period_in_useconds), 52 period_in_useconds_(period_in_useconds),
56 ticks_buffer_(sizeof(TickSampleEventRecord), 53 ticks_buffer_is_empty_(true),
57 kTickSamplesBufferChunkSize, 54 ticks_buffer_is_initialized_(false),
58 kTickSamplesBufferChunksCount),
59 enqueue_order_(0) { 55 enqueue_order_(0) {
60 } 56 }
61 57
62 58
63 void ProfilerEventsProcessor::CallbackCreateEvent(Logger::LogEventsAndTags tag, 59 void ProfilerEventsProcessor::CallbackCreateEvent(Logger::LogEventsAndTags tag,
64 const char* prefix, 60 const char* prefix,
65 String* name, 61 String* name,
66 Address start) { 62 Address start) {
67 if (FilterOutCodeCreateEvent(tag)) return; 63 if (FilterOutCodeCreateEvent(tag)) return;
68 CodeEventsContainer evt_rec; 64 CodeEventsContainer evt_rec;
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 #undef PROFILER_TYPE_CASE 199 #undef PROFILER_TYPE_CASE
204 default: return true; // Skip record. 200 default: return true; // Skip record.
205 } 201 }
206 *dequeue_order = record.generic.order; 202 *dequeue_order = record.generic.order;
207 return true; 203 return true;
208 } 204 }
209 return false; 205 return false;
210 } 206 }
211 207
212 208
213 bool ProfilerEventsProcessor::ProcessTicks(int64_t stop_time, 209 bool ProfilerEventsProcessor::ProcessTicks(unsigned dequeue_order) {
214 unsigned dequeue_order) { 210 while (true) {
215 while (stop_time == -1 || OS::Ticks() < stop_time) {
216 if (!ticks_from_vm_buffer_.IsEmpty() 211 if (!ticks_from_vm_buffer_.IsEmpty()
217 && ticks_from_vm_buffer_.Peek()->order == dequeue_order) { 212 && ticks_from_vm_buffer_.Peek()->order == dequeue_order) {
218 TickSampleEventRecord record; 213 TickSampleEventRecord record;
219 ticks_from_vm_buffer_.Dequeue(&record); 214 ticks_from_vm_buffer_.Dequeue(&record);
220 generator_->RecordTickSample(record.sample); 215 generator_->RecordTickSample(record.sample);
221 } 216 }
222 217
223 const TickSampleEventRecord* rec = 218 if (ticks_buffer_is_empty_) return !ticks_from_vm_buffer_.IsEmpty();
224 TickSampleEventRecord::cast(ticks_buffer_.StartDequeue()); 219 if (ticks_buffer_.order == dequeue_order) {
225 if (rec == NULL) return !ticks_from_vm_buffer_.IsEmpty();
226 // Make a local copy of tick sample record to ensure that it won't
227 // be modified as we are processing it. This is possible as the
228 // sampler writes w/o any sync to the queue, so if the processor
229 // will get far behind, a record may be modified right under its
230 // feet.
231 TickSampleEventRecord record = *rec;
232 if (record.order == dequeue_order) {
233 // A paranoid check to make sure that we don't get a memory overrun 220 // A paranoid check to make sure that we don't get a memory overrun
234 // in case of frames_count having a wild value. 221 // in case of frames_count having a wild value.
235 if (record.sample.frames_count < 0 222 if (ticks_buffer_.sample.frames_count < 0
236 || record.sample.frames_count > TickSample::kMaxFramesCount) 223 || ticks_buffer_.sample.frames_count > TickSample::kMaxFramesCount) {
237 record.sample.frames_count = 0; 224 ticks_buffer_.sample.frames_count = 0;
238 generator_->RecordTickSample(record.sample); 225 }
239 ticks_buffer_.FinishDequeue(); 226 generator_->RecordTickSample(ticks_buffer_.sample);
227 ticks_buffer_is_empty_ = true;
228 ticks_buffer_is_initialized_ = false;
240 } else { 229 } else {
241 return true; 230 return true;
242 } 231 }
243 } 232 }
244 return false;
245 } 233 }
246 234
247 235
248 void ProfilerEventsProcessor::ProcessEventsQueue(int64_t stop_time, 236 void ProfilerEventsProcessor::ProcessEventsQueue(int64_t stop_time,
249 unsigned* dequeue_order) { 237 unsigned* dequeue_order) {
250 while (OS::Ticks() < stop_time) { 238 while (OS::Ticks() < stop_time) {
251 if (ProcessTicks(stop_time, *dequeue_order)) { 239 if (ProcessTicks(*dequeue_order)) {
252 // All ticks of the current dequeue_order are processed, 240 // All ticks of the current dequeue_order are processed,
253 // proceed to the next code event. 241 // proceed to the next code event.
254 ProcessCodeEvent(dequeue_order); 242 ProcessCodeEvent(dequeue_order);
255 } 243 }
256 } 244 }
257 } 245 }
258 246
259 247
260 void ProfilerEventsProcessor::Run() { 248 void ProfilerEventsProcessor::Run() {
261 unsigned dequeue_order = 0; 249 unsigned dequeue_order = 0;
262 250
263 while (running_) { 251 while (running_) {
264 int64_t stop_time = OS::Ticks() + period_in_useconds_; 252 int64_t stop_time = OS::Ticks() + period_in_useconds_;
265 if (sampler_ != NULL) { 253 if (sampler_ != NULL) {
266 sampler_->DoSample(); 254 sampler_->DoSample();
267 } 255 }
268 ProcessEventsQueue(stop_time, &dequeue_order); 256 ProcessEventsQueue(stop_time, &dequeue_order);
269 } 257 }
270 258
271 // Process remaining tick events. 259 while (ProcessTicks(dequeue_order) && ProcessCodeEvent(&dequeue_order)) { }
272 ticks_buffer_.FlushResidualRecords();
273 // Perform processing until we have tick events, skip remaining code events.
274 while (ProcessTicks(-1, dequeue_order) && ProcessCodeEvent(&dequeue_order)) {
275 }
276 } 260 }
277 261
278 262
279 void CpuProfiler::StartProfiling(const char* title) { 263 void CpuProfiler::StartProfiling(const char* title) {
280 ASSERT(Isolate::Current()->cpu_profiler() != NULL); 264 ASSERT(Isolate::Current()->cpu_profiler() != NULL);
281 Isolate::Current()->cpu_profiler()->StartCollectingProfile(title); 265 Isolate::Current()->cpu_profiler()->StartCollectingProfile(title);
282 } 266 }
283 267
284 268
285 void CpuProfiler::StartProfiling(String* title) { 269 void CpuProfiler::StartProfiling(String* title) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 304
321 305
322 CpuProfile* CpuProfiler::FindProfile(Object* security_token, unsigned uid) { 306 CpuProfile* CpuProfiler::FindProfile(Object* security_token, unsigned uid) {
323 ASSERT(Isolate::Current()->cpu_profiler() != NULL); 307 ASSERT(Isolate::Current()->cpu_profiler() != NULL);
324 CpuProfiler* profiler = Isolate::Current()->cpu_profiler(); 308 CpuProfiler* profiler = Isolate::Current()->cpu_profiler();
325 const int token = profiler->token_enumerator_->GetTokenId(security_token); 309 const int token = profiler->token_enumerator_->GetTokenId(security_token);
326 return profiler->profiles_->GetProfile(token, uid); 310 return profiler->profiles_->GetProfile(token, uid);
327 } 311 }
328 312
329 313
330 TickSample* CpuProfiler::TickSampleEvent(Isolate* isolate) { 314 TickSample* CpuProfiler::StartTickSampleEvent(Isolate* isolate) {
331 if (CpuProfiler::is_profiling(isolate)) { 315 if (CpuProfiler::is_profiling(isolate)) {
332 return isolate->cpu_profiler()->processor_->TickSampleEvent(); 316 return isolate->cpu_profiler()->processor_->StartTickSampleEvent();
333 } else { 317 } else {
334 return NULL; 318 return NULL;
335 } 319 }
336 } 320 }
337 321
338 322
323 void CpuProfiler::FinishTickSampleEvent(Isolate* isolate) {
324 if (CpuProfiler::is_profiling(isolate)) {
325 isolate->cpu_profiler()->processor_->FinishTickSampleEvent();
326 }
327 }
328
329
339 void CpuProfiler::DeleteAllProfiles() { 330 void CpuProfiler::DeleteAllProfiles() {
340 Isolate* isolate = Isolate::Current(); 331 Isolate* isolate = Isolate::Current();
341 ASSERT(isolate->cpu_profiler() != NULL); 332 ASSERT(isolate->cpu_profiler() != NULL);
342 if (is_profiling(isolate)) { 333 if (is_profiling(isolate)) {
343 isolate->cpu_profiler()->StopProcessor(); 334 isolate->cpu_profiler()->StopProcessor();
344 } 335 }
345 isolate->cpu_profiler()->ResetProfiles(); 336 isolate->cpu_profiler()->ResetProfiles();
346 } 337 }
347 338
348 339
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 583
593 void CpuProfiler::TearDown() { 584 void CpuProfiler::TearDown() {
594 Isolate* isolate = Isolate::Current(); 585 Isolate* isolate = Isolate::Current();
595 if (isolate->cpu_profiler() != NULL) { 586 if (isolate->cpu_profiler() != NULL) {
596 delete isolate->cpu_profiler(); 587 delete isolate->cpu_profiler();
597 } 588 }
598 isolate->set_cpu_profiler(NULL); 589 isolate->set_cpu_profiler(NULL);
599 } 590 }
600 591
601 } } // namespace v8::internal 592 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698