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 11065034: Rollback trunk to bleeding_edge revision 12524 (Closed) Base URL: https://v8.googlecode.com/svn/trunk
Patch Set: Created 8 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « src/cpu-profiler.h ('k') | src/cpu-profiler-inl.h » ('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 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,
46 Sampler* sampler,
47 int period_in_useconds)
49 : Thread(Thread::Options("v8:ProfEvntProc", kProfilerStackSize)), 48 : Thread(Thread::Options("v8:ProfEvntProc", kProfilerStackSize)),
50 generator_(generator), 49 generator_(generator),
50 sampler_(sampler),
51 running_(true), 51 running_(true),
52 ticks_buffer_(sizeof(TickSampleEventRecord), 52 period_in_useconds_(period_in_useconds),
53 kTickSamplesBufferChunkSize, 53 ticks_buffer_is_empty_(true),
54 kTickSamplesBufferChunksCount), 54 ticks_buffer_is_initialized_(false),
55 enqueue_order_(0) { 55 enqueue_order_(0) {
56 } 56 }
57 57
58 58
59 void ProfilerEventsProcessor::CallbackCreateEvent(Logger::LogEventsAndTags tag, 59 void ProfilerEventsProcessor::CallbackCreateEvent(Logger::LogEventsAndTags tag,
60 const char* prefix, 60 const char* prefix,
61 String* name, 61 String* name,
62 Address start) { 62 Address start) {
63 if (FilterOutCodeCreateEvent(tag)) return; 63 if (FilterOutCodeCreateEvent(tag)) return;
64 CodeEventsContainer evt_rec; 64 CodeEventsContainer evt_rec;
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 208
209 bool ProfilerEventsProcessor::ProcessTicks(unsigned dequeue_order) { 209 bool ProfilerEventsProcessor::ProcessTicks(unsigned dequeue_order) {
210 while (true) { 210 while (true) {
211 if (!ticks_from_vm_buffer_.IsEmpty() 211 if (!ticks_from_vm_buffer_.IsEmpty()
212 && ticks_from_vm_buffer_.Peek()->order == dequeue_order) { 212 && ticks_from_vm_buffer_.Peek()->order == dequeue_order) {
213 TickSampleEventRecord record; 213 TickSampleEventRecord record;
214 ticks_from_vm_buffer_.Dequeue(&record); 214 ticks_from_vm_buffer_.Dequeue(&record);
215 generator_->RecordTickSample(record.sample); 215 generator_->RecordTickSample(record.sample);
216 } 216 }
217 217
218 const TickSampleEventRecord* rec = 218 if (ticks_buffer_is_empty_) return !ticks_from_vm_buffer_.IsEmpty();
219 TickSampleEventRecord::cast(ticks_buffer_.StartDequeue()); 219 if (ticks_buffer_.order == dequeue_order) {
220 if (rec == NULL) return !ticks_from_vm_buffer_.IsEmpty();
221 // Make a local copy of tick sample record to ensure that it won't
222 // be modified as we are processing it. This is possible as the
223 // sampler writes w/o any sync to the queue, so if the processor
224 // will get far behind, a record may be modified right under its
225 // feet.
226 TickSampleEventRecord record = *rec;
227 if (record.order == dequeue_order) {
228 // 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
229 // in case of frames_count having a wild value. 221 // in case of frames_count having a wild value.
230 if (record.sample.frames_count < 0 222 if (ticks_buffer_.sample.frames_count < 0
231 || record.sample.frames_count > TickSample::kMaxFramesCount) 223 || ticks_buffer_.sample.frames_count > TickSample::kMaxFramesCount) {
232 record.sample.frames_count = 0; 224 ticks_buffer_.sample.frames_count = 0;
233 generator_->RecordTickSample(record.sample); 225 }
234 ticks_buffer_.FinishDequeue(); 226 generator_->RecordTickSample(ticks_buffer_.sample);
227 ticks_buffer_is_empty_ = true;
228 ticks_buffer_is_initialized_ = false;
235 } else { 229 } else {
236 return true; 230 return true;
237 } 231 }
238 } 232 }
239 } 233 }
240 234
241 235
236 void ProfilerEventsProcessor::ProcessEventsQueue(int64_t stop_time,
237 unsigned* dequeue_order) {
238 while (OS::Ticks() < stop_time) {
239 if (ProcessTicks(*dequeue_order)) {
240 // All ticks of the current dequeue_order are processed,
241 // proceed to the next code event.
242 ProcessCodeEvent(dequeue_order);
243 }
244 }
245 }
246
247
242 void ProfilerEventsProcessor::Run() { 248 void ProfilerEventsProcessor::Run() {
243 unsigned dequeue_order = 0; 249 unsigned dequeue_order = 0;
244 250
245 while (running_) { 251 while (running_) {
246 // Process ticks until we have any. 252 int64_t stop_time = OS::Ticks() + period_in_useconds_;
247 if (ProcessTicks(dequeue_order)) { 253 if (sampler_ != NULL) {
248 // All ticks of the current dequeue_order are processed, 254 sampler_->DoSample();
249 // proceed to the next code event.
250 ProcessCodeEvent(&dequeue_order);
251 } 255 }
252 YieldCPU(); 256 ProcessEventsQueue(stop_time, &dequeue_order);
253 } 257 }
254 258
255 // Process remaining tick events.
256 ticks_buffer_.FlushResidualRecords();
257 // Perform processing until we have tick events, skip remaining code events.
258 while (ProcessTicks(dequeue_order) && ProcessCodeEvent(&dequeue_order)) { } 259 while (ProcessTicks(dequeue_order) && ProcessCodeEvent(&dequeue_order)) { }
259 } 260 }
260 261
261 262
262 void CpuProfiler::StartProfiling(const char* title) { 263 void CpuProfiler::StartProfiling(const char* title) {
263 ASSERT(Isolate::Current()->cpu_profiler() != NULL); 264 ASSERT(Isolate::Current()->cpu_profiler() != NULL);
264 Isolate::Current()->cpu_profiler()->StartCollectingProfile(title); 265 Isolate::Current()->cpu_profiler()->StartCollectingProfile(title);
265 } 266 }
266 267
267 268
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 304
304 305
305 CpuProfile* CpuProfiler::FindProfile(Object* security_token, unsigned uid) { 306 CpuProfile* CpuProfiler::FindProfile(Object* security_token, unsigned uid) {
306 ASSERT(Isolate::Current()->cpu_profiler() != NULL); 307 ASSERT(Isolate::Current()->cpu_profiler() != NULL);
307 CpuProfiler* profiler = Isolate::Current()->cpu_profiler(); 308 CpuProfiler* profiler = Isolate::Current()->cpu_profiler();
308 const int token = profiler->token_enumerator_->GetTokenId(security_token); 309 const int token = profiler->token_enumerator_->GetTokenId(security_token);
309 return profiler->profiles_->GetProfile(token, uid); 310 return profiler->profiles_->GetProfile(token, uid);
310 } 311 }
311 312
312 313
313 TickSample* CpuProfiler::TickSampleEvent(Isolate* isolate) { 314 TickSample* CpuProfiler::StartTickSampleEvent(Isolate* isolate) {
314 if (CpuProfiler::is_profiling(isolate)) { 315 if (CpuProfiler::is_profiling(isolate)) {
315 return isolate->cpu_profiler()->processor_->TickSampleEvent(); 316 return isolate->cpu_profiler()->processor_->StartTickSampleEvent();
316 } else { 317 } else {
317 return NULL; 318 return NULL;
318 } 319 }
319 } 320 }
320 321
321 322
323 void CpuProfiler::FinishTickSampleEvent(Isolate* isolate) {
324 if (CpuProfiler::is_profiling(isolate)) {
325 isolate->cpu_profiler()->processor_->FinishTickSampleEvent();
326 }
327 }
328
329
322 void CpuProfiler::DeleteAllProfiles() { 330 void CpuProfiler::DeleteAllProfiles() {
323 Isolate* isolate = Isolate::Current(); 331 Isolate* isolate = Isolate::Current();
324 ASSERT(isolate->cpu_profiler() != NULL); 332 ASSERT(isolate->cpu_profiler() != NULL);
325 if (is_profiling(isolate)) { 333 if (is_profiling(isolate)) {
326 isolate->cpu_profiler()->StopProcessor(); 334 isolate->cpu_profiler()->StopProcessor();
327 } 335 }
328 isolate->cpu_profiler()->ResetProfiles(); 336 isolate->cpu_profiler()->ResetProfiles();
329 } 337 }
330 338
331 339
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 487
480 void CpuProfiler::StartCollectingProfile(String* title) { 488 void CpuProfiler::StartCollectingProfile(String* title) {
481 StartCollectingProfile(profiles_->GetName(title)); 489 StartCollectingProfile(profiles_->GetName(title));
482 } 490 }
483 491
484 492
485 void CpuProfiler::StartProcessorIfNotStarted() { 493 void CpuProfiler::StartProcessorIfNotStarted() {
486 if (processor_ == NULL) { 494 if (processor_ == NULL) {
487 Isolate* isolate = Isolate::Current(); 495 Isolate* isolate = Isolate::Current();
488 496
497 Sampler* sampler = isolate->logger()->sampler();
489 // Disable logging when using the new implementation. 498 // Disable logging when using the new implementation.
490 saved_logging_nesting_ = isolate->logger()->logging_nesting_; 499 saved_logging_nesting_ = isolate->logger()->logging_nesting_;
491 isolate->logger()->logging_nesting_ = 0; 500 isolate->logger()->logging_nesting_ = 0;
492 generator_ = new ProfileGenerator(profiles_); 501 generator_ = new ProfileGenerator(profiles_);
493 processor_ = new ProfilerEventsProcessor(generator_); 502 processor_ = new ProfilerEventsProcessor(generator_,
503 sampler,
504 FLAG_cpu_profiler_sampling_period);
494 NoBarrier_Store(&is_profiling_, true); 505 NoBarrier_Store(&is_profiling_, true);
495 processor_->Start();
496 // Enumerate stuff we already have in the heap. 506 // Enumerate stuff we already have in the heap.
497 if (isolate->heap()->HasBeenSetUp()) { 507 if (isolate->heap()->HasBeenSetUp()) {
498 if (!FLAG_prof_browser_mode) { 508 if (!FLAG_prof_browser_mode) {
499 bool saved_log_code_flag = FLAG_log_code; 509 bool saved_log_code_flag = FLAG_log_code;
500 FLAG_log_code = true; 510 FLAG_log_code = true;
501 isolate->logger()->LogCodeObjects(); 511 isolate->logger()->LogCodeObjects();
502 FLAG_log_code = saved_log_code_flag; 512 FLAG_log_code = saved_log_code_flag;
503 } 513 }
504 isolate->logger()->LogCompiledFunctions(); 514 isolate->logger()->LogCompiledFunctions();
505 isolate->logger()->LogAccessorCallbacks(); 515 isolate->logger()->LogAccessorCallbacks();
506 } 516 }
507 // Enable stack sampling. 517 // Enable stack sampling.
508 Sampler* sampler = reinterpret_cast<Sampler*>(isolate->logger()->ticker_);
509 if (!sampler->IsActive()) { 518 if (!sampler->IsActive()) {
510 sampler->Start(); 519 sampler->Start();
511 need_to_stop_sampler_ = true; 520 need_to_stop_sampler_ = true;
512 } 521 }
513 sampler->IncreaseProfilingDepth(); 522 sampler->IncreaseProfilingDepth();
523 processor_->Start();
514 } 524 }
515 } 525 }
516 526
517 527
518 CpuProfile* CpuProfiler::StopCollectingProfile(const char* title) { 528 CpuProfile* CpuProfiler::StopCollectingProfile(const char* title) {
519 const double actual_sampling_rate = generator_->actual_sampling_rate(); 529 const double actual_sampling_rate = generator_->actual_sampling_rate();
520 StopProcessorIfLastProfile(title); 530 StopProcessorIfLastProfile(title);
521 CpuProfile* result = 531 CpuProfile* result =
522 profiles_->StopProfiling(TokenEnumerator::kNoSecurityToken, 532 profiles_->StopProfiling(TokenEnumerator::kNoSecurityToken,
523 title, 533 title,
(...skipping 14 matching lines...) Expand all
538 return profiles_->StopProfiling(token, profile_title, actual_sampling_rate); 548 return profiles_->StopProfiling(token, profile_title, actual_sampling_rate);
539 } 549 }
540 550
541 551
542 void CpuProfiler::StopProcessorIfLastProfile(const char* title) { 552 void CpuProfiler::StopProcessorIfLastProfile(const char* title) {
543 if (profiles_->IsLastProfile(title)) StopProcessor(); 553 if (profiles_->IsLastProfile(title)) StopProcessor();
544 } 554 }
545 555
546 556
547 void CpuProfiler::StopProcessor() { 557 void CpuProfiler::StopProcessor() {
558 NoBarrier_Store(&is_profiling_, false);
559 processor_->Stop();
560 processor_->Join();
548 Logger* logger = Isolate::Current()->logger(); 561 Logger* logger = Isolate::Current()->logger();
549 Sampler* sampler = reinterpret_cast<Sampler*>(logger->ticker_); 562 Sampler* sampler = logger->sampler();
550 sampler->DecreaseProfilingDepth(); 563 sampler->DecreaseProfilingDepth();
551 if (need_to_stop_sampler_) { 564 if (need_to_stop_sampler_) {
552 sampler->Stop(); 565 sampler->Stop();
553 need_to_stop_sampler_ = false; 566 need_to_stop_sampler_ = false;
554 } 567 }
555 NoBarrier_Store(&is_profiling_, false);
556 processor_->Stop();
557 processor_->Join();
558 delete processor_; 568 delete processor_;
559 delete generator_; 569 delete generator_;
560 processor_ = NULL; 570 processor_ = NULL;
561 generator_ = NULL; 571 generator_ = NULL;
562 logger->logging_nesting_ = saved_logging_nesting_; 572 logger->logging_nesting_ = saved_logging_nesting_;
563 } 573 }
564 574
565 575
566 void CpuProfiler::SetUp() { 576 void CpuProfiler::SetUp() {
567 Isolate* isolate = Isolate::Current(); 577 Isolate* isolate = Isolate::Current();
568 if (isolate->cpu_profiler() == NULL) { 578 if (isolate->cpu_profiler() == NULL) {
569 isolate->set_cpu_profiler(new CpuProfiler()); 579 isolate->set_cpu_profiler(new CpuProfiler());
570 } 580 }
571 } 581 }
572 582
573 583
574 void CpuProfiler::TearDown() { 584 void CpuProfiler::TearDown() {
575 Isolate* isolate = Isolate::Current(); 585 Isolate* isolate = Isolate::Current();
576 if (isolate->cpu_profiler() != NULL) { 586 if (isolate->cpu_profiler() != NULL) {
577 delete isolate->cpu_profiler(); 587 delete isolate->cpu_profiler();
578 } 588 }
579 isolate->set_cpu_profiler(NULL); 589 isolate->set_cpu_profiler(NULL);
580 } 590 }
581 591
582 } } // namespace v8::internal 592 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/cpu-profiler.h ('k') | src/cpu-profiler-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698