OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/cpu-profiler-inl.h" | 7 #include "src/cpu-profiler-inl.h" |
8 | 8 |
9 #include "src/compiler.h" | 9 #include "src/compiler.h" |
10 #include "src/frames-inl.h" | 10 #include "src/frames-inl.h" |
11 #include "src/hashmap.h" | 11 #include "src/hashmap.h" |
12 #include "src/log-inl.h" | 12 #include "src/log-inl.h" |
13 #include "src/vm-state-inl.h" | 13 #include "src/vm-state-inl.h" |
14 | 14 |
15 #include "include/v8-profiler.h" | 15 #include "include/v8-profiler.h" |
16 | 16 |
17 namespace v8 { | 17 namespace v8 { |
18 namespace internal { | 18 namespace internal { |
19 | 19 |
20 static const int kProfilerStackSize = 64 * KB; | 20 static const int kProfilerStackSize = 64 * KB; |
21 | 21 |
22 | 22 |
23 ProfilerEventsProcessor::ProfilerEventsProcessor( | 23 ProfilerEventsProcessor::ProfilerEventsProcessor( |
24 ProfileGenerator* generator, | 24 ProfileGenerator* generator, |
25 Sampler* sampler, | 25 Sampler* sampler, |
26 TimeDelta period) | 26 base::TimeDelta period) |
27 : Thread(Thread::Options("v8:ProfEvntProc", kProfilerStackSize)), | 27 : Thread(Thread::Options("v8:ProfEvntProc", kProfilerStackSize)), |
28 generator_(generator), | 28 generator_(generator), |
29 sampler_(sampler), | 29 sampler_(sampler), |
30 running_(true), | 30 running_(true), |
31 period_(period), | 31 period_(period), |
32 last_code_event_id_(0), last_processed_code_event_id_(0) { | 32 last_code_event_id_(0), last_processed_code_event_id_(0) { |
33 } | 33 } |
34 | 34 |
35 | 35 |
36 void ProfilerEventsProcessor::Enqueue(const CodeEventsContainer& event) { | 36 void ProfilerEventsProcessor::Enqueue(const CodeEventsContainer& event) { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 return FoundSampleForNextCodeEvent; | 101 return FoundSampleForNextCodeEvent; |
102 } | 102 } |
103 generator_->RecordTickSample(record->sample); | 103 generator_->RecordTickSample(record->sample); |
104 ticks_buffer_.Remove(); | 104 ticks_buffer_.Remove(); |
105 return OneSampleProcessed; | 105 return OneSampleProcessed; |
106 } | 106 } |
107 | 107 |
108 | 108 |
109 void ProfilerEventsProcessor::Run() { | 109 void ProfilerEventsProcessor::Run() { |
110 while (running_) { | 110 while (running_) { |
111 ElapsedTimer timer; | 111 base::ElapsedTimer timer; |
112 timer.Start(); | 112 timer.Start(); |
113 // Keep processing existing events until we need to do next sample. | 113 // Keep processing existing events until we need to do next sample. |
114 do { | 114 do { |
115 if (FoundSampleForNextCodeEvent == ProcessOneSample()) { | 115 if (FoundSampleForNextCodeEvent == ProcessOneSample()) { |
116 // All ticks of the current last_processed_code_event_id_ are | 116 // All ticks of the current last_processed_code_event_id_ are |
117 // processed, proceed to the next code event. | 117 // processed, proceed to the next code event. |
118 ProcessCodeEvent(); | 118 ProcessCodeEvent(); |
119 } | 119 } |
120 } while (!timer.HasExpired(period_)); | 120 } while (!timer.HasExpired(period_)); |
121 | 121 |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 profiles_->GetName(name), | 366 profiles_->GetName(name), |
367 "set "); | 367 "set "); |
368 rec->size = 1; | 368 rec->size = 1; |
369 rec->shared = NULL; | 369 rec->shared = NULL; |
370 processor_->Enqueue(evt_rec); | 370 processor_->Enqueue(evt_rec); |
371 } | 371 } |
372 | 372 |
373 | 373 |
374 CpuProfiler::CpuProfiler(Isolate* isolate) | 374 CpuProfiler::CpuProfiler(Isolate* isolate) |
375 : isolate_(isolate), | 375 : isolate_(isolate), |
376 sampling_interval_(TimeDelta::FromMicroseconds( | 376 sampling_interval_(base::TimeDelta::FromMicroseconds( |
377 FLAG_cpu_profiler_sampling_interval)), | 377 FLAG_cpu_profiler_sampling_interval)), |
378 profiles_(new CpuProfilesCollection(isolate->heap())), | 378 profiles_(new CpuProfilesCollection(isolate->heap())), |
379 generator_(NULL), | 379 generator_(NULL), |
380 processor_(NULL), | 380 processor_(NULL), |
381 is_profiling_(false) { | 381 is_profiling_(false) { |
382 } | 382 } |
383 | 383 |
384 | 384 |
385 CpuProfiler::CpuProfiler(Isolate* isolate, | 385 CpuProfiler::CpuProfiler(Isolate* isolate, |
386 CpuProfilesCollection* test_profiles, | 386 CpuProfilesCollection* test_profiles, |
387 ProfileGenerator* test_generator, | 387 ProfileGenerator* test_generator, |
388 ProfilerEventsProcessor* test_processor) | 388 ProfilerEventsProcessor* test_processor) |
389 : isolate_(isolate), | 389 : isolate_(isolate), |
390 sampling_interval_(TimeDelta::FromMicroseconds( | 390 sampling_interval_(base::TimeDelta::FromMicroseconds( |
391 FLAG_cpu_profiler_sampling_interval)), | 391 FLAG_cpu_profiler_sampling_interval)), |
392 profiles_(test_profiles), | 392 profiles_(test_profiles), |
393 generator_(test_generator), | 393 generator_(test_generator), |
394 processor_(test_processor), | 394 processor_(test_processor), |
395 is_profiling_(false) { | 395 is_profiling_(false) { |
396 } | 396 } |
397 | 397 |
398 | 398 |
399 CpuProfiler::~CpuProfiler() { | 399 CpuProfiler::~CpuProfiler() { |
400 ASSERT(!is_profiling_); | 400 ASSERT(!is_profiling_); |
401 delete profiles_; | 401 delete profiles_; |
402 } | 402 } |
403 | 403 |
404 | 404 |
405 void CpuProfiler::set_sampling_interval(TimeDelta value) { | 405 void CpuProfiler::set_sampling_interval(base::TimeDelta value) { |
406 ASSERT(!is_profiling_); | 406 ASSERT(!is_profiling_); |
407 sampling_interval_ = value; | 407 sampling_interval_ = value; |
408 } | 408 } |
409 | 409 |
410 | 410 |
411 void CpuProfiler::ResetProfiles() { | 411 void CpuProfiler::ResetProfiles() { |
412 delete profiles_; | 412 delete profiles_; |
413 profiles_ = new CpuProfilesCollection(isolate()->heap()); | 413 profiles_ = new CpuProfilesCollection(isolate()->heap()); |
414 } | 414 } |
415 | 415 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 ReportBuiltinEventRecord* rec = &evt_rec.ReportBuiltinEventRecord_; | 503 ReportBuiltinEventRecord* rec = &evt_rec.ReportBuiltinEventRecord_; |
504 Builtins::Name id = static_cast<Builtins::Name>(i); | 504 Builtins::Name id = static_cast<Builtins::Name>(i); |
505 rec->start = builtins->builtin(id)->address(); | 505 rec->start = builtins->builtin(id)->address(); |
506 rec->builtin_id = id; | 506 rec->builtin_id = id; |
507 processor_->Enqueue(evt_rec); | 507 processor_->Enqueue(evt_rec); |
508 } | 508 } |
509 } | 509 } |
510 | 510 |
511 | 511 |
512 } } // namespace v8::internal | 512 } } // namespace v8::internal |
OLD | NEW |