| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 15 matching lines...) Expand all Loading... |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #include "v8.h" | 28 #include "v8.h" |
| 29 | 29 |
| 30 #include "cpu-profiler-inl.h" | 30 #include "cpu-profiler-inl.h" |
| 31 | 31 |
| 32 #ifdef ENABLE_CPP_PROFILES_PROCESSOR | 32 #ifdef ENABLE_CPP_PROFILES_PROCESSOR |
| 33 | 33 |
| 34 #include "log-inl.h" | 34 #include "log-inl.h" |
| 35 | 35 |
| 36 #include "../include/v8-profiler.h" |
| 37 |
| 36 namespace v8 { | 38 namespace v8 { |
| 37 namespace internal { | 39 namespace internal { |
| 38 | 40 |
| 39 static const int kEventsBufferSize = 256*KB; | 41 static const int kEventsBufferSize = 256*KB; |
| 40 static const int kTickSamplesBufferChunkSize = 64*KB; | 42 static const int kTickSamplesBufferChunkSize = 64*KB; |
| 41 static const int kTickSamplesBufferChunksCount = 16; | 43 static const int kTickSamplesBufferChunksCount = 16; |
| 42 | 44 |
| 43 | 45 |
| 44 ProfilerEventsProcessor::ProfilerEventsProcessor(ProfileGenerator* generator) | 46 ProfilerEventsProcessor::ProfilerEventsProcessor(ProfileGenerator* generator) |
| 45 : generator_(generator), | 47 : generator_(generator), |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 void ProfilerEventsProcessor::FunctionMoveEvent(Address from, Address to) { | 151 void ProfilerEventsProcessor::FunctionMoveEvent(Address from, Address to) { |
| 150 CodeMoveEvent(from, to); | 152 CodeMoveEvent(from, to); |
| 151 } | 153 } |
| 152 | 154 |
| 153 | 155 |
| 154 void ProfilerEventsProcessor::FunctionDeleteEvent(Address from) { | 156 void ProfilerEventsProcessor::FunctionDeleteEvent(Address from) { |
| 155 CodeDeleteEvent(from); | 157 CodeDeleteEvent(from); |
| 156 } | 158 } |
| 157 | 159 |
| 158 | 160 |
| 161 void ProfilerEventsProcessor::RegExpCodeCreateEvent( |
| 162 Logger::LogEventsAndTags tag, |
| 163 const char* prefix, |
| 164 String* name, |
| 165 Address start, |
| 166 unsigned size) { |
| 167 CodeEventsContainer evt_rec; |
| 168 CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_; |
| 169 rec->type = CodeEventRecord::CODE_CREATION; |
| 170 rec->order = ++enqueue_order_; |
| 171 rec->start = start; |
| 172 rec->entry = generator_->NewCodeEntry(tag, prefix, name); |
| 173 rec->size = size; |
| 174 events_buffer_.Enqueue(evt_rec); |
| 175 } |
| 176 |
| 177 |
| 159 bool ProfilerEventsProcessor::ProcessCodeEvent(unsigned* dequeue_order) { | 178 bool ProfilerEventsProcessor::ProcessCodeEvent(unsigned* dequeue_order) { |
| 160 if (!events_buffer_.IsEmpty()) { | 179 if (!events_buffer_.IsEmpty()) { |
| 161 CodeEventsContainer record; | 180 CodeEventsContainer record; |
| 162 events_buffer_.Dequeue(&record); | 181 events_buffer_.Dequeue(&record); |
| 163 switch (record.generic.type) { | 182 switch (record.generic.type) { |
| 164 #define PROFILER_TYPE_CASE(type, clss) \ | 183 #define PROFILER_TYPE_CASE(type, clss) \ |
| 165 case CodeEventRecord::type: \ | 184 case CodeEventRecord::type: \ |
| 166 record.clss##_.UpdateCodeMap(generator_->code_map()); \ | 185 record.clss##_.UpdateCodeMap(generator_->code_map()); \ |
| 167 break; | 186 break; |
| 168 | 187 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 tag, comment, code->address(), code->ExecutableSize()); | 299 tag, comment, code->address(), code->ExecutableSize()); |
| 281 } | 300 } |
| 282 | 301 |
| 283 | 302 |
| 284 void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, | 303 void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, |
| 285 Code* code, String* name) { | 304 Code* code, String* name) { |
| 286 singleton_->processor_->CodeCreateEvent( | 305 singleton_->processor_->CodeCreateEvent( |
| 287 tag, | 306 tag, |
| 288 name, | 307 name, |
| 289 Heap::empty_string(), | 308 Heap::empty_string(), |
| 290 CodeEntry::kNoLineNumberInfo, | 309 v8::CpuProfileNode::kNoLineNumberInfo, |
| 291 code->address(), | 310 code->address(), |
| 292 code->ExecutableSize()); | 311 code->ExecutableSize()); |
| 293 } | 312 } |
| 294 | 313 |
| 295 | 314 |
| 296 void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, | 315 void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, |
| 297 Code* code, String* name, | 316 Code* code, String* name, |
| 298 String* source, int line) { | 317 String* source, int line) { |
| 299 singleton_->processor_->CodeCreateEvent( | 318 singleton_->processor_->CodeCreateEvent( |
| 300 tag, | 319 tag, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 } | 361 } |
| 343 | 362 |
| 344 | 363 |
| 345 void CpuProfiler::GetterCallbackEvent(String* name, Address entry_point) { | 364 void CpuProfiler::GetterCallbackEvent(String* name, Address entry_point) { |
| 346 singleton_->processor_->CallbackCreateEvent( | 365 singleton_->processor_->CallbackCreateEvent( |
| 347 Logger::CALLBACK_TAG, "get ", name, entry_point); | 366 Logger::CALLBACK_TAG, "get ", name, entry_point); |
| 348 } | 367 } |
| 349 | 368 |
| 350 | 369 |
| 351 void CpuProfiler::RegExpCodeCreateEvent(Code* code, String* source) { | 370 void CpuProfiler::RegExpCodeCreateEvent(Code* code, String* source) { |
| 352 singleton_->processor_->CodeCreateEvent( | 371 singleton_->processor_->RegExpCodeCreateEvent( |
| 353 Logger::REG_EXP_TAG, | 372 Logger::REG_EXP_TAG, |
| 373 "RegExp: ", |
| 354 source, | 374 source, |
| 355 Heap::empty_string(), | |
| 356 CodeEntry::kNoLineNumberInfo, | |
| 357 code->address(), | 375 code->address(), |
| 358 code->ExecutableSize()); | 376 code->ExecutableSize()); |
| 359 } | 377 } |
| 360 | 378 |
| 361 | 379 |
| 362 void CpuProfiler::SetterCallbackEvent(String* name, Address entry_point) { | 380 void CpuProfiler::SetterCallbackEvent(String* name, Address entry_point) { |
| 363 singleton_->processor_->CallbackCreateEvent( | 381 singleton_->processor_->CallbackCreateEvent( |
| 364 Logger::CALLBACK_TAG, "set ", name, entry_point); | 382 Logger::CALLBACK_TAG, "set ", name, entry_point); |
| 365 } | 383 } |
| 366 | 384 |
| 367 | 385 |
| 368 CpuProfiler::CpuProfiler() | 386 CpuProfiler::CpuProfiler() |
| 369 : profiles_(new CpuProfilesCollection()), | 387 : profiles_(new CpuProfilesCollection()), |
| 370 next_profile_uid_(1), | 388 next_profile_uid_(1), |
| 371 generator_(NULL), | 389 generator_(NULL), |
| 372 processor_(NULL) { | 390 processor_(NULL) { |
| 373 } | 391 } |
| 374 | 392 |
| 375 | 393 |
| 376 CpuProfiler::~CpuProfiler() { | 394 CpuProfiler::~CpuProfiler() { |
| 377 delete profiles_; | 395 delete profiles_; |
| 378 } | 396 } |
| 379 | 397 |
| 380 | 398 |
| 381 void CpuProfiler::StartCollectingProfile(const char* title) { | 399 void CpuProfiler::StartCollectingProfile(const char* title) { |
| 382 if (profiles_->StartProfiling(title, ++next_profile_uid_)) { | 400 if (profiles_->StartProfiling(title, next_profile_uid_++)) { |
| 383 StartProcessorIfNotStarted(); | 401 StartProcessorIfNotStarted(); |
| 384 } | 402 } |
| 385 } | 403 } |
| 386 | 404 |
| 387 | 405 |
| 388 void CpuProfiler::StartCollectingProfile(String* title) { | 406 void CpuProfiler::StartCollectingProfile(String* title) { |
| 389 if (profiles_->StartProfiling(title, ++next_profile_uid_)) { | 407 if (profiles_->StartProfiling(title, next_profile_uid_++)) { |
| 390 StartProcessorIfNotStarted(); | 408 StartProcessorIfNotStarted(); |
| 391 } | 409 } |
| 392 } | 410 } |
| 393 | 411 |
| 394 | 412 |
| 395 void CpuProfiler::StartProcessorIfNotStarted() { | 413 void CpuProfiler::StartProcessorIfNotStarted() { |
| 396 if (processor_ == NULL) { | 414 if (processor_ == NULL) { |
| 397 generator_ = new ProfileGenerator(profiles_); | 415 generator_ = new ProfileGenerator(profiles_); |
| 398 processor_ = new ProfilerEventsProcessor(generator_); | 416 processor_ = new ProfilerEventsProcessor(generator_); |
| 399 processor_->Start(); | 417 processor_->Start(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 void CpuProfiler::TearDown() { | 475 void CpuProfiler::TearDown() { |
| 458 #ifdef ENABLE_CPP_PROFILES_PROCESSOR | 476 #ifdef ENABLE_CPP_PROFILES_PROCESSOR |
| 459 if (singleton_ != NULL) { | 477 if (singleton_ != NULL) { |
| 460 delete singleton_; | 478 delete singleton_; |
| 461 } | 479 } |
| 462 singleton_ = NULL; | 480 singleton_ = NULL; |
| 463 #endif | 481 #endif |
| 464 } | 482 } |
| 465 | 483 |
| 466 } } // namespace v8::internal | 484 } } // namespace v8::internal |
| OLD | NEW |