| OLD | NEW |
| 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 28 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 namespace v8 { | 40 namespace v8 { |
| 41 namespace internal { | 41 namespace internal { |
| 42 | 42 |
| 43 static const int kProfilerStackSize = 64 * KB; | 43 static const int kProfilerStackSize = 64 * KB; |
| 44 | 44 |
| 45 | 45 |
| 46 ProfilerEventsProcessor::ProfilerEventsProcessor( | 46 ProfilerEventsProcessor::ProfilerEventsProcessor( |
| 47 ProfileGenerator* generator, | 47 ProfileGenerator* generator, |
| 48 Sampler* sampler, | 48 Sampler* sampler, |
| 49 TimeDelta period) | 49 int period_in_useconds) |
| 50 : Thread(Thread::Options("v8:ProfEvntProc", kProfilerStackSize)), | 50 : Thread(Thread::Options("v8:ProfEvntProc", kProfilerStackSize)), |
| 51 generator_(generator), | 51 generator_(generator), |
| 52 sampler_(sampler), | 52 sampler_(sampler), |
| 53 running_(true), | 53 running_(true), |
| 54 period_(period), | 54 period_in_useconds_(period_in_useconds), |
| 55 last_code_event_id_(0), last_processed_code_event_id_(0) { | 55 last_code_event_id_(0), last_processed_code_event_id_(0) { |
| 56 } | 56 } |
| 57 | 57 |
| 58 | 58 |
| 59 void ProfilerEventsProcessor::Enqueue(const CodeEventsContainer& event) { | 59 void ProfilerEventsProcessor::Enqueue(const CodeEventsContainer& event) { |
| 60 event.generic.order = ++last_code_event_id_; | 60 event.generic.order = ++last_code_event_id_; |
| 61 events_buffer_.Enqueue(event); | 61 events_buffer_.Enqueue(event); |
| 62 } | 62 } |
| 63 | 63 |
| 64 | 64 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 const TickSampleEventRecord* record = ticks_buffer_.StartDequeue(); | 117 const TickSampleEventRecord* record = ticks_buffer_.StartDequeue(); |
| 118 if (record == NULL) return !ticks_from_vm_buffer_.IsEmpty(); | 118 if (record == NULL) return !ticks_from_vm_buffer_.IsEmpty(); |
| 119 if (record->order != last_processed_code_event_id_) return true; | 119 if (record->order != last_processed_code_event_id_) return true; |
| 120 generator_->RecordTickSample(record->sample); | 120 generator_->RecordTickSample(record->sample); |
| 121 ticks_buffer_.FinishDequeue(); | 121 ticks_buffer_.FinishDequeue(); |
| 122 } | 122 } |
| 123 } | 123 } |
| 124 | 124 |
| 125 | 125 |
| 126 void ProfilerEventsProcessor::ProcessEventsAndDoSample() { | 126 void ProfilerEventsProcessor::ProcessEventsAndDoSample() { |
| 127 ElapsedTimer timer; | 127 int64_t stop_time = OS::Ticks() + period_in_useconds_; |
| 128 timer.Start(); | |
| 129 // Keep processing existing events until we need to do next sample. | 128 // Keep processing existing events until we need to do next sample. |
| 130 while (!timer.HasExpired(period_)) { | 129 while (OS::Ticks() < stop_time) { |
| 131 if (ProcessTicks()) { | 130 if (ProcessTicks()) { |
| 132 // All ticks of the current dequeue_order are processed, | 131 // All ticks of the current dequeue_order are processed, |
| 133 // proceed to the next code event. | 132 // proceed to the next code event. |
| 134 ProcessCodeEvent(); | 133 ProcessCodeEvent(); |
| 135 } | 134 } |
| 136 } | 135 } |
| 137 // Schedule next sample. sampler_ is NULL in tests. | 136 // Schedule next sample. sampler_ is NULL in tests. |
| 138 if (sampler_) sampler_->DoSample(); | 137 if (sampler_) sampler_->DoSample(); |
| 139 } | 138 } |
| 140 | 139 |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 | 427 |
| 429 void CpuProfiler::StartProcessorIfNotStarted() { | 428 void CpuProfiler::StartProcessorIfNotStarted() { |
| 430 if (processor_ == NULL) { | 429 if (processor_ == NULL) { |
| 431 Logger* logger = isolate_->logger(); | 430 Logger* logger = isolate_->logger(); |
| 432 // Disable logging when using the new implementation. | 431 // Disable logging when using the new implementation. |
| 433 saved_logging_nesting_ = logger->logging_nesting_; | 432 saved_logging_nesting_ = logger->logging_nesting_; |
| 434 logger->logging_nesting_ = 0; | 433 logger->logging_nesting_ = 0; |
| 435 generator_ = new ProfileGenerator(profiles_); | 434 generator_ = new ProfileGenerator(profiles_); |
| 436 Sampler* sampler = logger->sampler(); | 435 Sampler* sampler = logger->sampler(); |
| 437 processor_ = new ProfilerEventsProcessor( | 436 processor_ = new ProfilerEventsProcessor( |
| 438 generator_, sampler, | 437 generator_, sampler, FLAG_cpu_profiler_sampling_interval); |
| 439 TimeDelta::FromMicroseconds(FLAG_cpu_profiler_sampling_interval)); | |
| 440 is_profiling_ = true; | 438 is_profiling_ = true; |
| 441 // Enumerate stuff we already have in the heap. | 439 // Enumerate stuff we already have in the heap. |
| 442 ASSERT(isolate_->heap()->HasBeenSetUp()); | 440 ASSERT(isolate_->heap()->HasBeenSetUp()); |
| 443 if (!FLAG_prof_browser_mode) { | 441 if (!FLAG_prof_browser_mode) { |
| 444 logger->LogCodeObjects(); | 442 logger->LogCodeObjects(); |
| 445 } | 443 } |
| 446 logger->LogCompiledFunctions(); | 444 logger->LogCompiledFunctions(); |
| 447 logger->LogAccessorCallbacks(); | 445 logger->LogAccessorCallbacks(); |
| 448 LogBuiltins(); | 446 LogBuiltins(); |
| 449 // Enable stack sampling. | 447 // Enable stack sampling. |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 ReportBuiltinEventRecord* rec = &evt_rec.ReportBuiltinEventRecord_; | 511 ReportBuiltinEventRecord* rec = &evt_rec.ReportBuiltinEventRecord_; |
| 514 Builtins::Name id = static_cast<Builtins::Name>(i); | 512 Builtins::Name id = static_cast<Builtins::Name>(i); |
| 515 rec->start = builtins->builtin(id)->address(); | 513 rec->start = builtins->builtin(id)->address(); |
| 516 rec->builtin_id = id; | 514 rec->builtin_id = id; |
| 517 processor_->Enqueue(evt_rec); | 515 processor_->Enqueue(evt_rec); |
| 518 } | 516 } |
| 519 } | 517 } |
| 520 | 518 |
| 521 | 519 |
| 522 } } // namespace v8::internal | 520 } } // namespace v8::internal |
| OLD | NEW |