| 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 | 145 |
| 146 // Process remaining tick events. | 146 // Process remaining tick events. |
| 147 ticks_buffer_.FlushResidualRecords(); | 147 ticks_buffer_.FlushResidualRecords(); |
| 148 // Perform processing until we have tick events, skip remaining code events. | 148 // Perform processing until we have tick events, skip remaining code events. |
| 149 while (ProcessTicks(dequeue_order) && ProcessCodeEvent(&dequeue_order)) { } | 149 while (ProcessTicks(dequeue_order) && ProcessCodeEvent(&dequeue_order)) { } |
| 150 } | 150 } |
| 151 | 151 |
| 152 | 152 |
| 153 int CpuProfiler::GetProfilesCount() { | 153 int CpuProfiler::GetProfilesCount() { |
| 154 // The count of profiles doesn't depend on a security token. | 154 // The count of profiles doesn't depend on a security token. |
| 155 return profiles_->Profiles(TokenEnumerator::kNoSecurityToken)->length(); | 155 return profiles_->profiles()->length(); |
| 156 } | 156 } |
| 157 | 157 |
| 158 | 158 |
| 159 CpuProfile* CpuProfiler::GetProfile(Object* security_token, int index) { | 159 CpuProfile* CpuProfiler::GetProfile(int index) { |
| 160 const int token = token_enumerator_->GetTokenId(security_token); | 160 return profiles_->profiles()->at(index); |
| 161 return profiles_->Profiles(token)->at(index); | |
| 162 } | 161 } |
| 163 | 162 |
| 164 | 163 |
| 165 CpuProfile* CpuProfiler::FindProfile(Object* security_token, unsigned uid) { | |
| 166 const int token = token_enumerator_->GetTokenId(security_token); | |
| 167 return profiles_->GetProfile(token, uid); | |
| 168 } | |
| 169 | |
| 170 | |
| 171 TickSample* CpuProfiler::TickSampleEvent() { | 164 TickSample* CpuProfiler::TickSampleEvent() { |
| 172 if (is_profiling_) return processor_->TickSampleEvent(); | 165 if (is_profiling_) return processor_->TickSampleEvent(); |
| 173 return NULL; | 166 return NULL; |
| 174 } | 167 } |
| 175 | 168 |
| 176 | 169 |
| 177 void CpuProfiler::DeleteAllProfiles() { | 170 void CpuProfiler::DeleteAllProfiles() { |
| 178 if (is_profiling_) StopProcessor(); | 171 if (is_profiling_) StopProcessor(); |
| 179 ResetProfiles(); | 172 ResetProfiles(); |
| 180 } | 173 } |
| 181 | 174 |
| 182 | 175 |
| 183 void CpuProfiler::DeleteProfile(CpuProfile* profile) { | 176 void CpuProfiler::DeleteProfile(CpuProfile* profile) { |
| 184 profiles_->RemoveProfile(profile); | 177 profiles_->RemoveProfile(profile); |
| 185 delete profile; | 178 delete profile; |
| 186 } | 179 } |
| 187 | 180 |
| 188 | 181 |
| 189 bool CpuProfiler::HasDetachedProfiles() { | |
| 190 return profiles_->HasDetachedProfiles(); | |
| 191 } | |
| 192 | |
| 193 | |
| 194 static bool FilterOutCodeCreateEvent(Logger::LogEventsAndTags tag) { | 182 static bool FilterOutCodeCreateEvent(Logger::LogEventsAndTags tag) { |
| 195 return FLAG_prof_browser_mode | 183 return FLAG_prof_browser_mode |
| 196 && (tag != Logger::CALLBACK_TAG | 184 && (tag != Logger::CALLBACK_TAG |
| 197 && tag != Logger::FUNCTION_TAG | 185 && tag != Logger::FUNCTION_TAG |
| 198 && tag != Logger::LAZY_COMPILE_TAG | 186 && tag != Logger::LAZY_COMPILE_TAG |
| 199 && tag != Logger::REG_EXP_TAG | 187 && tag != Logger::REG_EXP_TAG |
| 200 && tag != Logger::SCRIPT_TAG); | 188 && tag != Logger::SCRIPT_TAG); |
| 201 } | 189 } |
| 202 | 190 |
| 203 | 191 |
| 204 void CpuProfiler::CallbackEvent(Name* name, Address entry_point) { | 192 void CpuProfiler::CallbackEvent(Name* name, Address entry_point) { |
| 205 if (FilterOutCodeCreateEvent(Logger::CALLBACK_TAG)) return; | 193 if (FilterOutCodeCreateEvent(Logger::CALLBACK_TAG)) return; |
| 206 CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION); | 194 CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION); |
| 207 CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_; | 195 CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_; |
| 208 rec->start = entry_point; | 196 rec->start = entry_point; |
| 209 rec->entry = profiles_->NewCodeEntry( | 197 rec->entry = profiles_->NewCodeEntry( |
| 210 Logger::CALLBACK_TAG, | 198 Logger::CALLBACK_TAG, |
| 211 profiles_->GetName(name), | 199 profiles_->GetName(name)); |
| 212 TokenEnumerator::kInheritsSecurityToken); | |
| 213 rec->size = 1; | 200 rec->size = 1; |
| 214 rec->shared = NULL; | 201 rec->shared = NULL; |
| 215 processor_->Enqueue(evt_rec); | 202 processor_->Enqueue(evt_rec); |
| 216 } | 203 } |
| 217 | 204 |
| 218 | 205 |
| 219 void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, | 206 void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, |
| 220 Code* code, | 207 Code* code, |
| 221 const char* name) { | 208 const char* name) { |
| 222 if (FilterOutCodeCreateEvent(tag)) return; | 209 if (FilterOutCodeCreateEvent(tag)) return; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 SharedFunctionInfo* shared, | 260 SharedFunctionInfo* shared, |
| 274 CompilationInfo* info, | 261 CompilationInfo* info, |
| 275 String* source, int line) { | 262 String* source, int line) { |
| 276 if (FilterOutCodeCreateEvent(tag)) return; | 263 if (FilterOutCodeCreateEvent(tag)) return; |
| 277 CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION); | 264 CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION); |
| 278 CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_; | 265 CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_; |
| 279 rec->start = code->address(); | 266 rec->start = code->address(); |
| 280 rec->entry = profiles_->NewCodeEntry( | 267 rec->entry = profiles_->NewCodeEntry( |
| 281 tag, | 268 tag, |
| 282 profiles_->GetFunctionName(shared->DebugName()), | 269 profiles_->GetFunctionName(shared->DebugName()), |
| 283 TokenEnumerator::kNoSecurityToken, | |
| 284 CodeEntry::kEmptyNamePrefix, | 270 CodeEntry::kEmptyNamePrefix, |
| 285 profiles_->GetName(source), | 271 profiles_->GetName(source), |
| 286 line); | 272 line); |
| 287 if (info) { | 273 if (info) { |
| 288 rec->entry->set_no_frame_ranges(info->ReleaseNoFrameRanges()); | 274 rec->entry->set_no_frame_ranges(info->ReleaseNoFrameRanges()); |
| 289 } | 275 } |
| 290 ASSERT(Script::cast(shared->script())); | 276 ASSERT(Script::cast(shared->script())); |
| 291 Script* script = Script::cast(shared->script()); | 277 Script* script = Script::cast(shared->script()); |
| 292 rec->entry->set_script_id(script->id()->value()); | 278 rec->entry->set_script_id(script->id()->value()); |
| 293 rec->size = code->ExecutableSize(); | 279 rec->size = code->ExecutableSize(); |
| 294 rec->shared = shared->address(); | 280 rec->shared = shared->address(); |
| 295 processor_->Enqueue(evt_rec); | 281 processor_->Enqueue(evt_rec); |
| 296 } | 282 } |
| 297 | 283 |
| 298 | 284 |
| 299 void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, | 285 void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, |
| 300 Code* code, | 286 Code* code, |
| 301 int args_count) { | 287 int args_count) { |
| 302 if (FilterOutCodeCreateEvent(tag)) return; | 288 if (FilterOutCodeCreateEvent(tag)) return; |
| 303 CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION); | 289 CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION); |
| 304 CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_; | 290 CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_; |
| 305 rec->start = code->address(); | 291 rec->start = code->address(); |
| 306 rec->entry = profiles_->NewCodeEntry( | 292 rec->entry = profiles_->NewCodeEntry( |
| 307 tag, | 293 tag, |
| 308 profiles_->GetName(args_count), | 294 profiles_->GetName(args_count), |
| 309 TokenEnumerator::kInheritsSecurityToken, | |
| 310 "args_count: "); | 295 "args_count: "); |
| 311 rec->size = code->ExecutableSize(); | 296 rec->size = code->ExecutableSize(); |
| 312 rec->shared = NULL; | 297 rec->shared = NULL; |
| 313 processor_->Enqueue(evt_rec); | 298 processor_->Enqueue(evt_rec); |
| 314 } | 299 } |
| 315 | 300 |
| 316 | 301 |
| 317 void CpuProfiler::CodeMoveEvent(Address from, Address to) { | 302 void CpuProfiler::CodeMoveEvent(Address from, Address to) { |
| 318 CodeEventsContainer evt_rec(CodeEventRecord::CODE_MOVE); | 303 CodeEventsContainer evt_rec(CodeEventRecord::CODE_MOVE); |
| 319 CodeMoveEventRecord* rec = &evt_rec.CodeMoveEventRecord_; | 304 CodeMoveEventRecord* rec = &evt_rec.CodeMoveEventRecord_; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 338 | 323 |
| 339 | 324 |
| 340 void CpuProfiler::GetterCallbackEvent(Name* name, Address entry_point) { | 325 void CpuProfiler::GetterCallbackEvent(Name* name, Address entry_point) { |
| 341 if (FilterOutCodeCreateEvent(Logger::CALLBACK_TAG)) return; | 326 if (FilterOutCodeCreateEvent(Logger::CALLBACK_TAG)) return; |
| 342 CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION); | 327 CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION); |
| 343 CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_; | 328 CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_; |
| 344 rec->start = entry_point; | 329 rec->start = entry_point; |
| 345 rec->entry = profiles_->NewCodeEntry( | 330 rec->entry = profiles_->NewCodeEntry( |
| 346 Logger::CALLBACK_TAG, | 331 Logger::CALLBACK_TAG, |
| 347 profiles_->GetName(name), | 332 profiles_->GetName(name), |
| 348 TokenEnumerator::kInheritsSecurityToken, | |
| 349 "get "); | 333 "get "); |
| 350 rec->size = 1; | 334 rec->size = 1; |
| 351 rec->shared = NULL; | 335 rec->shared = NULL; |
| 352 processor_->Enqueue(evt_rec); | 336 processor_->Enqueue(evt_rec); |
| 353 } | 337 } |
| 354 | 338 |
| 355 | 339 |
| 356 void CpuProfiler::RegExpCodeCreateEvent(Code* code, String* source) { | 340 void CpuProfiler::RegExpCodeCreateEvent(Code* code, String* source) { |
| 357 if (FilterOutCodeCreateEvent(Logger::REG_EXP_TAG)) return; | 341 if (FilterOutCodeCreateEvent(Logger::REG_EXP_TAG)) return; |
| 358 CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION); | 342 CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION); |
| 359 CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_; | 343 CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_; |
| 360 rec->start = code->address(); | 344 rec->start = code->address(); |
| 361 rec->entry = profiles_->NewCodeEntry( | 345 rec->entry = profiles_->NewCodeEntry( |
| 362 Logger::REG_EXP_TAG, | 346 Logger::REG_EXP_TAG, |
| 363 profiles_->GetName(source), | 347 profiles_->GetName(source), |
| 364 TokenEnumerator::kInheritsSecurityToken, | |
| 365 "RegExp: "); | 348 "RegExp: "); |
| 366 rec->size = code->ExecutableSize(); | 349 rec->size = code->ExecutableSize(); |
| 367 processor_->Enqueue(evt_rec); | 350 processor_->Enqueue(evt_rec); |
| 368 } | 351 } |
| 369 | 352 |
| 370 | 353 |
| 371 void CpuProfiler::SetterCallbackEvent(Name* name, Address entry_point) { | 354 void CpuProfiler::SetterCallbackEvent(Name* name, Address entry_point) { |
| 372 if (FilterOutCodeCreateEvent(Logger::CALLBACK_TAG)) return; | 355 if (FilterOutCodeCreateEvent(Logger::CALLBACK_TAG)) return; |
| 373 CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION); | 356 CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION); |
| 374 CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_; | 357 CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_; |
| 375 rec->start = entry_point; | 358 rec->start = entry_point; |
| 376 rec->entry = profiles_->NewCodeEntry( | 359 rec->entry = profiles_->NewCodeEntry( |
| 377 Logger::CALLBACK_TAG, | 360 Logger::CALLBACK_TAG, |
| 378 profiles_->GetName(name), | 361 profiles_->GetName(name), |
| 379 TokenEnumerator::kInheritsSecurityToken, | |
| 380 "set "); | 362 "set "); |
| 381 rec->size = 1; | 363 rec->size = 1; |
| 382 rec->shared = NULL; | 364 rec->shared = NULL; |
| 383 processor_->Enqueue(evt_rec); | 365 processor_->Enqueue(evt_rec); |
| 384 } | 366 } |
| 385 | 367 |
| 386 | 368 |
| 387 CpuProfiler::CpuProfiler(Isolate* isolate) | 369 CpuProfiler::CpuProfiler(Isolate* isolate) |
| 388 : isolate_(isolate), | 370 : isolate_(isolate), |
| 389 profiles_(new CpuProfilesCollection()), | 371 profiles_(new CpuProfilesCollection()), |
| 390 next_profile_uid_(1), | 372 next_profile_uid_(1), |
| 391 token_enumerator_(new TokenEnumerator()), | |
| 392 generator_(NULL), | 373 generator_(NULL), |
| 393 processor_(NULL), | 374 processor_(NULL), |
| 394 need_to_stop_sampler_(false), | 375 need_to_stop_sampler_(false), |
| 395 is_profiling_(false) { | 376 is_profiling_(false) { |
| 396 } | 377 } |
| 397 | 378 |
| 398 | 379 |
| 399 CpuProfiler::CpuProfiler(Isolate* isolate, | 380 CpuProfiler::CpuProfiler(Isolate* isolate, |
| 400 CpuProfilesCollection* test_profiles, | 381 CpuProfilesCollection* test_profiles, |
| 401 ProfileGenerator* test_generator, | 382 ProfileGenerator* test_generator, |
| 402 ProfilerEventsProcessor* test_processor) | 383 ProfilerEventsProcessor* test_processor) |
| 403 : isolate_(isolate), | 384 : isolate_(isolate), |
| 404 profiles_(test_profiles), | 385 profiles_(test_profiles), |
| 405 next_profile_uid_(1), | 386 next_profile_uid_(1), |
| 406 token_enumerator_(new TokenEnumerator()), | |
| 407 generator_(test_generator), | 387 generator_(test_generator), |
| 408 processor_(test_processor), | 388 processor_(test_processor), |
| 409 need_to_stop_sampler_(false), | 389 need_to_stop_sampler_(false), |
| 410 is_profiling_(false) { | 390 is_profiling_(false) { |
| 411 } | 391 } |
| 412 | 392 |
| 413 | 393 |
| 414 CpuProfiler::~CpuProfiler() { | 394 CpuProfiler::~CpuProfiler() { |
| 415 ASSERT(!is_profiling_); | 395 ASSERT(!is_profiling_); |
| 416 delete token_enumerator_; | |
| 417 delete profiles_; | 396 delete profiles_; |
| 418 } | 397 } |
| 419 | 398 |
| 420 | 399 |
| 421 void CpuProfiler::ResetProfiles() { | 400 void CpuProfiler::ResetProfiles() { |
| 422 delete profiles_; | 401 delete profiles_; |
| 423 profiles_ = new CpuProfilesCollection(); | 402 profiles_ = new CpuProfilesCollection(); |
| 424 } | 403 } |
| 425 | 404 |
| 426 void CpuProfiler::StartProfiling(const char* title, bool record_samples) { | 405 void CpuProfiler::StartProfiling(const char* title, bool record_samples) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 need_to_stop_sampler_ = true; | 441 need_to_stop_sampler_ = true; |
| 463 } | 442 } |
| 464 } | 443 } |
| 465 } | 444 } |
| 466 | 445 |
| 467 | 446 |
| 468 CpuProfile* CpuProfiler::StopProfiling(const char* title) { | 447 CpuProfile* CpuProfiler::StopProfiling(const char* title) { |
| 469 if (!is_profiling_) return NULL; | 448 if (!is_profiling_) return NULL; |
| 470 const double actual_sampling_rate = generator_->actual_sampling_rate(); | 449 const double actual_sampling_rate = generator_->actual_sampling_rate(); |
| 471 StopProcessorIfLastProfile(title); | 450 StopProcessorIfLastProfile(title); |
| 472 CpuProfile* result = | 451 CpuProfile* result = profiles_->StopProfiling(title, actual_sampling_rate); |
| 473 profiles_->StopProfiling(TokenEnumerator::kNoSecurityToken, | |
| 474 title, | |
| 475 actual_sampling_rate); | |
| 476 if (result != NULL) { | 452 if (result != NULL) { |
| 477 result->Print(); | 453 result->Print(); |
| 478 } | 454 } |
| 479 return result; | 455 return result; |
| 480 } | 456 } |
| 481 | 457 |
| 482 | 458 |
| 483 CpuProfile* CpuProfiler::StopProfiling(Object* security_token, String* title) { | 459 CpuProfile* CpuProfiler::StopProfiling(String* title) { |
| 484 if (!is_profiling_) return NULL; | 460 if (!is_profiling_) return NULL; |
| 485 const double actual_sampling_rate = generator_->actual_sampling_rate(); | 461 const double actual_sampling_rate = generator_->actual_sampling_rate(); |
| 486 const char* profile_title = profiles_->GetName(title); | 462 const char* profile_title = profiles_->GetName(title); |
| 487 StopProcessorIfLastProfile(profile_title); | 463 StopProcessorIfLastProfile(profile_title); |
| 488 int token = token_enumerator_->GetTokenId(security_token); | 464 return profiles_->StopProfiling(profile_title, actual_sampling_rate); |
| 489 return profiles_->StopProfiling(token, profile_title, actual_sampling_rate); | |
| 490 } | 465 } |
| 491 | 466 |
| 492 | 467 |
| 493 void CpuProfiler::StopProcessorIfLastProfile(const char* title) { | 468 void CpuProfiler::StopProcessorIfLastProfile(const char* title) { |
| 494 if (profiles_->IsLastProfile(title)) StopProcessor(); | 469 if (profiles_->IsLastProfile(title)) StopProcessor(); |
| 495 } | 470 } |
| 496 | 471 |
| 497 | 472 |
| 498 void CpuProfiler::StopProcessor() { | 473 void CpuProfiler::StopProcessor() { |
| 499 Logger* logger = isolate_->logger(); | 474 Logger* logger = isolate_->logger(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 522 ReportBuiltinEventRecord* rec = &evt_rec.ReportBuiltinEventRecord_; | 497 ReportBuiltinEventRecord* rec = &evt_rec.ReportBuiltinEventRecord_; |
| 523 Builtins::Name id = static_cast<Builtins::Name>(i); | 498 Builtins::Name id = static_cast<Builtins::Name>(i); |
| 524 rec->start = builtins->builtin(id)->address(); | 499 rec->start = builtins->builtin(id)->address(); |
| 525 rec->builtin_id = id; | 500 rec->builtin_id = id; |
| 526 processor_->Enqueue(evt_rec); | 501 processor_->Enqueue(evt_rec); |
| 527 } | 502 } |
| 528 } | 503 } |
| 529 | 504 |
| 530 | 505 |
| 531 } } // namespace v8::internal | 506 } } // namespace v8::internal |
| OLD | NEW |