Chromium Code Reviews| 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 21 matching lines...) Expand all Loading... | |
| 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, Sa mpler* sampler, int interval_in_useconds) | 45 ProfilerEventsProcessor::ProfilerEventsProcessor(ProfileGenerator* generator, Sa mpler* sampler, int interval_in_useconds) |
| 49 : Thread(Thread::Options("v8:ProfEvntProc", kProfilerStackSize)), | 46 : Thread(Thread::Options("v8:ProfEvntProc", kProfilerStackSize)), |
| 50 generator_(generator), | 47 generator_(generator), |
| 51 sampler_(sampler), | 48 sampler_(sampler), |
| 52 running_(true), | 49 running_(true), |
| 53 interval_in_useconds_(interval_in_useconds), | 50 interval_in_useconds_(interval_in_useconds), |
| 54 ticks_buffer_(sizeof(TickSampleEventRecord), | 51 ticks_buffer_is_empty_(true), |
|
Jakob Kummerow
2012/09/04 11:25:18
You should still initialize ticks_buffer_(NULL) to
rogulenko
2012/09/04 13:14:55
Did you mean that you would like ticks_buffer_ to
Jakob Kummerow
2012/09/04 13:36:22
Ah, sorry, somehow I thought it was one already. I
| |
| 55 kTickSamplesBufferChunkSize, | |
| 56 kTickSamplesBufferChunksCount), | |
| 57 enqueue_order_(0) { | 52 enqueue_order_(0) { |
| 58 } | 53 } |
| 59 | 54 |
| 60 | 55 |
| 61 void ProfilerEventsProcessor::CallbackCreateEvent(Logger::LogEventsAndTags tag, | 56 void ProfilerEventsProcessor::CallbackCreateEvent(Logger::LogEventsAndTags tag, |
| 62 const char* prefix, | 57 const char* prefix, |
| 63 String* name, | 58 String* name, |
| 64 Address start) { | 59 Address start) { |
| 65 if (FilterOutCodeCreateEvent(tag)) return; | 60 if (FilterOutCodeCreateEvent(tag)) return; |
| 66 CodeEventsContainer evt_rec; | 61 CodeEventsContainer evt_rec; |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 #undef PROFILER_TYPE_CASE | 196 #undef PROFILER_TYPE_CASE |
| 202 default: return true; // Skip record. | 197 default: return true; // Skip record. |
| 203 } | 198 } |
| 204 *dequeue_order = record.generic.order; | 199 *dequeue_order = record.generic.order; |
| 205 return true; | 200 return true; |
| 206 } | 201 } |
| 207 return false; | 202 return false; |
| 208 } | 203 } |
| 209 | 204 |
| 210 | 205 |
| 211 bool ProfilerEventsProcessor::ProcessTicks(int64_t stop_time, unsigned dequeue_o rder) { | 206 bool ProfilerEventsProcessor::ProcessTicks(unsigned dequeue_order) { |
| 212 while (stop_time == -1 || OS::Ticks() < stop_time) { | 207 while (true) { |
| 213 if (!ticks_from_vm_buffer_.IsEmpty() | 208 if (!ticks_from_vm_buffer_.IsEmpty() |
| 214 && ticks_from_vm_buffer_.Peek()->order == dequeue_order) { | 209 && ticks_from_vm_buffer_.Peek()->order == dequeue_order) { |
| 215 TickSampleEventRecord record; | 210 TickSampleEventRecord record; |
| 216 ticks_from_vm_buffer_.Dequeue(&record); | 211 ticks_from_vm_buffer_.Dequeue(&record); |
| 217 generator_->RecordTickSample(record.sample); | 212 generator_->RecordTickSample(record.sample); |
| 218 } | 213 } |
| 219 | 214 |
| 220 const TickSampleEventRecord* rec = | 215 if (ticks_buffer_is_empty_) return !ticks_from_vm_buffer_.IsEmpty(); |
| 221 TickSampleEventRecord::cast(ticks_buffer_.StartDequeue()); | 216 if (ticks_buffer_.order == dequeue_order) { |
|
Jakob Kummerow
2012/09/04 11:25:18
Does it still make sense to have a dequeue_order s
rogulenko
2012/09/04 13:14:55
ProfilerEventsProcessor has two queues. One to kee
| |
| 222 if (rec == NULL) return !ticks_from_vm_buffer_.IsEmpty(); | |
| 223 // Make a local copy of tick sample record to ensure that it won't | |
| 224 // be modified as we are processing it. This is possible as the | |
| 225 // sampler writes w/o any sync to the queue, so if the processor | |
| 226 // will get far behind, a record may be modified right under its | |
| 227 // feet. | |
| 228 TickSampleEventRecord record = *rec; | |
| 229 if (record.order == dequeue_order) { | |
| 230 // A paranoid check to make sure that we don't get a memory overrun | 217 // A paranoid check to make sure that we don't get a memory overrun |
| 231 // in case of frames_count having a wild value. | 218 // in case of frames_count having a wild value. |
| 232 if (record.sample.frames_count < 0 | 219 if (ticks_buffer_.sample.frames_count < 0 |
| 233 || record.sample.frames_count > TickSample::kMaxFramesCount) | 220 || ticks_buffer_.sample.frames_count > TickSample::kMaxFramesCount) |
| 234 record.sample.frames_count = 0; | 221 ticks_buffer_.sample.frames_count = 0; |
|
Jakob Kummerow
2012/09/04 11:25:18
{} around the conditional block please
| |
| 235 generator_->RecordTickSample(record.sample); | 222 generator_->RecordTickSample(ticks_buffer_.sample); |
| 236 ticks_buffer_.FinishDequeue(); | 223 ticks_buffer_is_empty_ = true; |
| 237 } else { | 224 } else { |
| 238 return true; | 225 return true; |
| 239 } | 226 } |
| 240 } | 227 } |
| 241 return false; | |
| 242 } | 228 } |
| 243 | 229 |
| 244 | 230 |
| 245 void ProfilerEventsProcessor::ProcessEventsQueue(int64_t stop_time, unsigned* de queue_order) { | 231 void ProfilerEventsProcessor::ProcessEventsQueue(int64_t stop_time, unsigned* de queue_order) { |
| 246 while (OS::Ticks() < stop_time) { | 232 while (OS::Ticks() < stop_time) { |
| 247 // Process ticks until we have any. | 233 // Process ticks until we have any. |
| 248 if (ProcessTicks(stop_time, *dequeue_order)) { | 234 if (ProcessTicks(*dequeue_order)) { |
| 249 // All ticks of the current dequeue_order are processed, | 235 // All ticks of the current dequeue_order are processed, |
| 250 // proceed to the next code event. | 236 // proceed to the next code event. |
| 251 ProcessCodeEvent(dequeue_order); | 237 ProcessCodeEvent(dequeue_order); |
| 252 } | 238 } |
| 253 } | 239 } |
| 254 } | 240 } |
| 255 | 241 |
| 256 | 242 |
| 257 void ProfilerEventsProcessor::Run() { | 243 void ProfilerEventsProcessor::Run() { |
| 258 unsigned dequeue_order = 0; | 244 unsigned dequeue_order = 0; |
| 259 | 245 |
| 260 while (running_) { | 246 while (running_) { |
| 261 int64_t stop_time = OS::Ticks() + interval_in_useconds_; | 247 int64_t stop_time = OS::Ticks() + interval_in_useconds_; |
| 262 sampler_->DoSample(); | 248 sampler_->DoSample(); |
| 263 ProcessEventsQueue(stop_time, &dequeue_order); | 249 ProcessEventsQueue(stop_time, &dequeue_order); |
| 264 } | 250 } |
| 265 | |
| 266 // Process remaining tick events. | |
| 267 ticks_buffer_.FlushResidualRecords(); | |
| 268 // Perform processing until we have tick events, skip remaining code events. | |
| 269 while (ProcessTicks(-1, dequeue_order) && ProcessCodeEvent(&dequeue_order)) { } | |
| 270 } | 251 } |
| 271 | 252 |
| 272 | 253 |
| 273 void CpuProfiler::StartProfiling(const char* title) { | 254 void CpuProfiler::StartProfiling(const char* title) { |
| 274 ASSERT(Isolate::Current()->cpu_profiler() != NULL); | 255 ASSERT(Isolate::Current()->cpu_profiler() != NULL); |
| 275 Isolate::Current()->cpu_profiler()->StartCollectingProfile(title); | 256 Isolate::Current()->cpu_profiler()->StartCollectingProfile(title); |
| 276 } | 257 } |
| 277 | 258 |
| 278 | 259 |
| 279 void CpuProfiler::StartProfiling(String* title) { | 260 void CpuProfiler::StartProfiling(String* title) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 | 295 |
| 315 | 296 |
| 316 CpuProfile* CpuProfiler::FindProfile(Object* security_token, unsigned uid) { | 297 CpuProfile* CpuProfiler::FindProfile(Object* security_token, unsigned uid) { |
| 317 ASSERT(Isolate::Current()->cpu_profiler() != NULL); | 298 ASSERT(Isolate::Current()->cpu_profiler() != NULL); |
| 318 CpuProfiler* profiler = Isolate::Current()->cpu_profiler(); | 299 CpuProfiler* profiler = Isolate::Current()->cpu_profiler(); |
| 319 const int token = profiler->token_enumerator_->GetTokenId(security_token); | 300 const int token = profiler->token_enumerator_->GetTokenId(security_token); |
| 320 return profiler->profiles_->GetProfile(token, uid); | 301 return profiler->profiles_->GetProfile(token, uid); |
| 321 } | 302 } |
| 322 | 303 |
| 323 | 304 |
| 324 TickSample* CpuProfiler::TickSampleEvent(Isolate* isolate) { | 305 TickSample* CpuProfiler::StartTickSampleEvent(Isolate* isolate) { |
| 325 if (CpuProfiler::is_profiling(isolate)) { | 306 if (CpuProfiler::is_profiling(isolate)) { |
| 326 return isolate->cpu_profiler()->processor_->TickSampleEvent(); | 307 return isolate->cpu_profiler()->processor_->StartTickSampleEvent(); |
| 327 } else { | 308 } else { |
| 328 return NULL; | 309 return NULL; |
| 329 } | 310 } |
| 330 } | 311 } |
| 331 | 312 |
| 332 | 313 |
| 314 void CpuProfiler::FinishTickSampleEvent(Isolate* isolate) { | |
| 315 if (CpuProfiler::is_profiling(isolate)) { | |
| 316 isolate->cpu_profiler()->processor_->FinishTickSampleEvent(); | |
| 317 } | |
| 318 } | |
| 319 | |
| 320 | |
| 333 void CpuProfiler::DeleteAllProfiles() { | 321 void CpuProfiler::DeleteAllProfiles() { |
| 334 Isolate* isolate = Isolate::Current(); | 322 Isolate* isolate = Isolate::Current(); |
| 335 ASSERT(isolate->cpu_profiler() != NULL); | 323 ASSERT(isolate->cpu_profiler() != NULL); |
| 336 if (is_profiling(isolate)) { | 324 if (is_profiling(isolate)) { |
| 337 isolate->cpu_profiler()->StopProcessor(); | 325 isolate->cpu_profiler()->StopProcessor(); |
| 338 } | 326 } |
| 339 isolate->cpu_profiler()->ResetProfiles(); | 327 isolate->cpu_profiler()->ResetProfiles(); |
| 340 } | 328 } |
| 341 | 329 |
| 342 | 330 |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 584 | 572 |
| 585 void CpuProfiler::TearDown() { | 573 void CpuProfiler::TearDown() { |
| 586 Isolate* isolate = Isolate::Current(); | 574 Isolate* isolate = Isolate::Current(); |
| 587 if (isolate->cpu_profiler() != NULL) { | 575 if (isolate->cpu_profiler() != NULL) { |
| 588 delete isolate->cpu_profiler(); | 576 delete isolate->cpu_profiler(); |
| 589 } | 577 } |
| 590 isolate->set_cpu_profiler(NULL); | 578 isolate->set_cpu_profiler(NULL); |
| 591 } | 579 } |
| 592 | 580 |
| 593 } } // namespace v8::internal | 581 } } // namespace v8::internal |
| OLD | NEW |