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

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

Issue 12592002: Revert "Send SIGPROF signals on the profiler event processor thread" (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 9 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/flag-definitions.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 27 matching lines...) Expand all
38 38
39 namespace v8 { 39 namespace v8 {
40 namespace internal { 40 namespace internal {
41 41
42 static const int kEventsBufferSize = 256 * KB; 42 static const int kEventsBufferSize = 256 * KB;
43 static const int kTickSamplesBufferChunkSize = 64 * KB; 43 static const int kTickSamplesBufferChunkSize = 64 * KB;
44 static const int kTickSamplesBufferChunksCount = 16; 44 static const int kTickSamplesBufferChunksCount = 16;
45 static const int kProfilerStackSize = 64 * KB; 45 static const int kProfilerStackSize = 64 * KB;
46 46
47 47
48 ProfilerEventsProcessor::ProfilerEventsProcessor(ProfileGenerator* generator, 48 ProfilerEventsProcessor::ProfilerEventsProcessor(ProfileGenerator* generator)
49 Sampler* sampler,
50 int period_in_useconds)
51 : Thread(Thread::Options("v8:ProfEvntProc", kProfilerStackSize)), 49 : Thread(Thread::Options("v8:ProfEvntProc", kProfilerStackSize)),
52 generator_(generator), 50 generator_(generator),
53 sampler_(sampler),
54 running_(true), 51 running_(true),
55 period_in_useconds_(period_in_useconds),
56 ticks_buffer_(sizeof(TickSampleEventRecord), 52 ticks_buffer_(sizeof(TickSampleEventRecord),
57 kTickSamplesBufferChunkSize, 53 kTickSamplesBufferChunkSize,
58 kTickSamplesBufferChunksCount, 54 kTickSamplesBufferChunksCount),
59 !Sampler::CanSampleOnProfilerEventsProcessorThread()),
60 enqueue_order_(0) { 55 enqueue_order_(0) {
61 } 56 }
62 57
63 58
64 void ProfilerEventsProcessor::CallbackCreateEvent(Logger::LogEventsAndTags tag, 59 void ProfilerEventsProcessor::CallbackCreateEvent(Logger::LogEventsAndTags tag,
65 const char* prefix, 60 const char* prefix,
66 Name* name, 61 Name* name,
67 Address start) { 62 Address start) {
68 if (FilterOutCodeCreateEvent(tag)) return; 63 if (FilterOutCodeCreateEvent(tag)) return;
69 CodeEventsContainer evt_rec; 64 CodeEventsContainer evt_rec;
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 record.sample.frames_count = 0; 232 record.sample.frames_count = 0;
238 generator_->RecordTickSample(record.sample); 233 generator_->RecordTickSample(record.sample);
239 ticks_buffer_.FinishDequeue(); 234 ticks_buffer_.FinishDequeue();
240 } else { 235 } else {
241 return true; 236 return true;
242 } 237 }
243 } 238 }
244 } 239 }
245 240
246 241
247 void ProfilerEventsProcessor::ProcessEventsAndDoSample(
248 unsigned* dequeue_order) {
249 int64_t stop_time = OS::Ticks() + period_in_useconds_;
250 // Keep processing existing events until we need to do next sample.
251 while (OS::Ticks() < stop_time) {
252 if (ProcessTicks(*dequeue_order)) {
253 // All ticks of the current dequeue_order are processed,
254 // proceed to the next code event.
255 ProcessCodeEvent(dequeue_order);
256 }
257 }
258 // Schedule next sample. sampler_ is NULL in tests.
259 if (sampler_)
260 sampler_->DoSample();
261 }
262
263
264 void ProfilerEventsProcessor::ProcessEventsAndYield(unsigned* dequeue_order) {
265 if (ProcessTicks(*dequeue_order)) {
266 // All ticks of the current dequeue_order are processed,
267 // proceed to the next code event.
268 ProcessCodeEvent(dequeue_order);
269 }
270 YieldCPU();
271 }
272
273
274 void ProfilerEventsProcessor::Run() { 242 void ProfilerEventsProcessor::Run() {
275 unsigned dequeue_order = 0; 243 unsigned dequeue_order = 0;
276 244
277 while (running_) { 245 while (running_) {
278 if (Sampler::CanSampleOnProfilerEventsProcessorThread()) { 246 // Process ticks until we have any.
279 ProcessEventsAndDoSample(&dequeue_order); 247 if (ProcessTicks(dequeue_order)) {
280 } else { 248 // All ticks of the current dequeue_order are processed,
281 ProcessEventsAndYield(&dequeue_order); 249 // proceed to the next code event.
250 ProcessCodeEvent(&dequeue_order);
282 } 251 }
252 YieldCPU();
283 } 253 }
284 254
285 // Process remaining tick events. 255 // Process remaining tick events.
286 ticks_buffer_.FlushResidualRecords(); 256 ticks_buffer_.FlushResidualRecords();
287 // Perform processing until we have tick events, skip remaining code events. 257 // Perform processing until we have tick events, skip remaining code events.
288 while (ProcessTicks(dequeue_order) && ProcessCodeEvent(&dequeue_order)) { } 258 while (ProcessTicks(dequeue_order) && ProcessCodeEvent(&dequeue_order)) { }
289 } 259 }
290 260
291 261
292 void CpuProfiler::StartProfiling(const char* title) { 262 void CpuProfiler::StartProfiling(const char* title) {
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 479
510 void CpuProfiler::StartCollectingProfile(String* title) { 480 void CpuProfiler::StartCollectingProfile(String* title) {
511 StartCollectingProfile(profiles_->GetName(title)); 481 StartCollectingProfile(profiles_->GetName(title));
512 } 482 }
513 483
514 484
515 void CpuProfiler::StartProcessorIfNotStarted() { 485 void CpuProfiler::StartProcessorIfNotStarted() {
516 if (processor_ == NULL) { 486 if (processor_ == NULL) {
517 Isolate* isolate = Isolate::Current(); 487 Isolate* isolate = Isolate::Current();
518 488
519 Sampler* sampler = reinterpret_cast<Sampler*>(isolate->logger()->ticker_);
520 // Disable logging when using the new implementation. 489 // Disable logging when using the new implementation.
521 saved_logging_nesting_ = isolate->logger()->logging_nesting_; 490 saved_logging_nesting_ = isolate->logger()->logging_nesting_;
522 isolate->logger()->logging_nesting_ = 0; 491 isolate->logger()->logging_nesting_ = 0;
523 generator_ = new ProfileGenerator(profiles_); 492 generator_ = new ProfileGenerator(profiles_);
524 processor_ = new ProfilerEventsProcessor(generator_, 493 processor_ = new ProfilerEventsProcessor(generator_);
525 sampler,
526 FLAG_cpu_profiler_sampling_period);
527 is_profiling_ = true; 494 is_profiling_ = true;
495 processor_->Start();
528 // Enumerate stuff we already have in the heap. 496 // Enumerate stuff we already have in the heap.
529 if (isolate->heap()->HasBeenSetUp()) { 497 if (isolate->heap()->HasBeenSetUp()) {
530 if (!FLAG_prof_browser_mode) { 498 if (!FLAG_prof_browser_mode) {
531 bool saved_log_code_flag = FLAG_log_code; 499 bool saved_log_code_flag = FLAG_log_code;
532 FLAG_log_code = true; 500 FLAG_log_code = true;
533 isolate->logger()->LogCodeObjects(); 501 isolate->logger()->LogCodeObjects();
534 FLAG_log_code = saved_log_code_flag; 502 FLAG_log_code = saved_log_code_flag;
535 } 503 }
536 isolate->logger()->LogCompiledFunctions(); 504 isolate->logger()->LogCompiledFunctions();
537 isolate->logger()->LogAccessorCallbacks(); 505 isolate->logger()->LogAccessorCallbacks();
538 } 506 }
539 // Enable stack sampling. 507 // Enable stack sampling.
508 Sampler* sampler = reinterpret_cast<Sampler*>(isolate->logger()->ticker_);
540 if (!sampler->IsActive()) { 509 if (!sampler->IsActive()) {
541 sampler->Start(); 510 sampler->Start();
542 need_to_stop_sampler_ = true; 511 need_to_stop_sampler_ = true;
543 } 512 }
544 sampler->SetHasProcessingThread(true);
545 sampler->IncreaseProfilingDepth(); 513 sampler->IncreaseProfilingDepth();
546 processor_->Start();
547 } 514 }
548 } 515 }
549 516
550 517
551 CpuProfile* CpuProfiler::StopCollectingProfile(const char* title) { 518 CpuProfile* CpuProfiler::StopCollectingProfile(const char* title) {
552 const double actual_sampling_rate = generator_->actual_sampling_rate(); 519 const double actual_sampling_rate = generator_->actual_sampling_rate();
553 StopProcessorIfLastProfile(title); 520 StopProcessorIfLastProfile(title);
554 CpuProfile* result = 521 CpuProfile* result =
555 profiles_->StopProfiling(TokenEnumerator::kNoSecurityToken, 522 profiles_->StopProfiling(TokenEnumerator::kNoSecurityToken,
556 title, 523 title,
(...skipping 17 matching lines...) Expand all
574 541
575 void CpuProfiler::StopProcessorIfLastProfile(const char* title) { 542 void CpuProfiler::StopProcessorIfLastProfile(const char* title) {
576 if (profiles_->IsLastProfile(title)) StopProcessor(); 543 if (profiles_->IsLastProfile(title)) StopProcessor();
577 } 544 }
578 545
579 546
580 void CpuProfiler::StopProcessor() { 547 void CpuProfiler::StopProcessor() {
581 Logger* logger = Isolate::Current()->logger(); 548 Logger* logger = Isolate::Current()->logger();
582 Sampler* sampler = reinterpret_cast<Sampler*>(logger->ticker_); 549 Sampler* sampler = reinterpret_cast<Sampler*>(logger->ticker_);
583 sampler->DecreaseProfilingDepth(); 550 sampler->DecreaseProfilingDepth();
584 sampler->SetHasProcessingThread(false);
585 if (need_to_stop_sampler_) { 551 if (need_to_stop_sampler_) {
586 sampler->Stop(); 552 sampler->Stop();
587 need_to_stop_sampler_ = false; 553 need_to_stop_sampler_ = false;
588 } 554 }
589 is_profiling_ = false; 555 is_profiling_ = false;
590 processor_->Stop(); 556 processor_->Stop();
591 processor_->Join(); 557 processor_->Join();
592 delete processor_; 558 delete processor_;
593 delete generator_; 559 delete generator_;
594 processor_ = NULL; 560 processor_ = NULL;
(...skipping 12 matching lines...) Expand all
607 573
608 void CpuProfiler::TearDown() { 574 void CpuProfiler::TearDown() {
609 Isolate* isolate = Isolate::Current(); 575 Isolate* isolate = Isolate::Current();
610 if (isolate->cpu_profiler() != NULL) { 576 if (isolate->cpu_profiler() != NULL) {
611 delete isolate->cpu_profiler(); 577 delete isolate->cpu_profiler();
612 } 578 }
613 isolate->set_cpu_profiler(NULL); 579 isolate->set_cpu_profiler(NULL);
614 } 580 }
615 581
616 } } // namespace v8::internal 582 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/cpu-profiler.h ('k') | src/flag-definitions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698