Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: src/cpu-profiler.cc

Issue 12475016: Maintain API compatibility with older versions of V8. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/cpu-profiler.h ('k') | src/execution.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 YieldCPU(); 251 YieldCPU();
252 } 252 }
253 253
254 // Process remaining tick events. 254 // Process remaining tick events.
255 ticks_buffer_.FlushResidualRecords(); 255 ticks_buffer_.FlushResidualRecords();
256 // Perform processing until we have tick events, skip remaining code events. 256 // Perform processing until we have tick events, skip remaining code events.
257 while (ProcessTicks(dequeue_order) && ProcessCodeEvent(&dequeue_order)) { } 257 while (ProcessTicks(dequeue_order) && ProcessCodeEvent(&dequeue_order)) { }
258 } 258 }
259 259
260 260
261 void CpuProfiler::StartProfiling(const char* title) {
262 ASSERT(Isolate::Current()->cpu_profiler() != NULL);
263 Isolate::Current()->cpu_profiler()->StartCollectingProfile(title);
264 }
265
266
267 void CpuProfiler::StartProfiling(String* title) {
268 ASSERT(Isolate::Current()->cpu_profiler() != NULL);
269 Isolate::Current()->cpu_profiler()->StartCollectingProfile(title);
270 }
271
272
273 CpuProfile* CpuProfiler::StopProfiling(const char* title) {
274 Isolate* isolate = Isolate::Current();
275 return is_profiling(isolate) ?
276 isolate->cpu_profiler()->StopCollectingProfile(title) : NULL;
277 }
278
279
280 CpuProfile* CpuProfiler::StopProfiling(Object* security_token, String* title) {
281 Isolate* isolate = Isolate::Current();
282 return is_profiling(isolate) ?
283 isolate->cpu_profiler()->StopCollectingProfile(
284 security_token, title) : NULL;
285 }
286
287
261 int CpuProfiler::GetProfilesCount() { 288 int CpuProfiler::GetProfilesCount() {
289 ASSERT(Isolate::Current()->cpu_profiler() != NULL);
262 // The count of profiles doesn't depend on a security token. 290 // The count of profiles doesn't depend on a security token.
263 return profiles_->Profiles(TokenEnumerator::kNoSecurityToken)->length(); 291 return Isolate::Current()->cpu_profiler()->profiles_->Profiles(
292 TokenEnumerator::kNoSecurityToken)->length();
264 } 293 }
265 294
266 295
267 CpuProfile* CpuProfiler::GetProfile(Object* security_token, int index) { 296 CpuProfile* CpuProfiler::GetProfile(Object* security_token, int index) {
268 const int token = token_enumerator_->GetTokenId(security_token); 297 ASSERT(Isolate::Current()->cpu_profiler() != NULL);
269 return profiles_->Profiles(token)->at(index); 298 CpuProfiler* profiler = Isolate::Current()->cpu_profiler();
299 const int token = profiler->token_enumerator_->GetTokenId(security_token);
300 return profiler->profiles_->Profiles(token)->at(index);
270 } 301 }
271 302
272 303
273 CpuProfile* CpuProfiler::FindProfile(Object* security_token, unsigned uid) { 304 CpuProfile* CpuProfiler::FindProfile(Object* security_token, unsigned uid) {
274 const int token = token_enumerator_->GetTokenId(security_token); 305 ASSERT(Isolate::Current()->cpu_profiler() != NULL);
275 return profiles_->GetProfile(token, uid); 306 CpuProfiler* profiler = Isolate::Current()->cpu_profiler();
307 const int token = profiler->token_enumerator_->GetTokenId(security_token);
308 return profiler->profiles_->GetProfile(token, uid);
276 } 309 }
277 310
278 311
279 TickSample* CpuProfiler::TickSampleEvent() { 312 TickSample* CpuProfiler::TickSampleEvent(Isolate* isolate) {
280 if (is_profiling_) return processor_->TickSampleEvent(); 313 if (CpuProfiler::is_profiling(isolate)) {
281 return NULL; 314 return isolate->cpu_profiler()->processor_->TickSampleEvent();
315 } else {
316 return NULL;
317 }
282 } 318 }
283 319
284 320
285 void CpuProfiler::DeleteAllProfiles() { 321 void CpuProfiler::DeleteAllProfiles() {
286 if (is_profiling_) StopProcessor(); 322 Isolate* isolate = Isolate::Current();
287 ResetProfiles(); 323 ASSERT(isolate->cpu_profiler() != NULL);
324 if (is_profiling(isolate)) {
325 isolate->cpu_profiler()->StopProcessor();
326 }
327 isolate->cpu_profiler()->ResetProfiles();
288 } 328 }
289 329
290 330
291 void CpuProfiler::DeleteProfile(CpuProfile* profile) { 331 void CpuProfiler::DeleteProfile(CpuProfile* profile) {
292 profiles_->RemoveProfile(profile); 332 ASSERT(Isolate::Current()->cpu_profiler() != NULL);
333 Isolate::Current()->cpu_profiler()->profiles_->RemoveProfile(profile);
293 delete profile; 334 delete profile;
294 } 335 }
295 336
296 337
297 bool CpuProfiler::HasDetachedProfiles() { 338 bool CpuProfiler::HasDetachedProfiles() {
298 return profiles_->HasDetachedProfiles(); 339 ASSERT(Isolate::Current()->cpu_profiler() != NULL);
340 return Isolate::Current()->cpu_profiler()->profiles_->HasDetachedProfiles();
299 } 341 }
300 342
301 343
302 void CpuProfiler::CallbackEvent(Name* name, Address entry_point) { 344 void CpuProfiler::CallbackEvent(Name* name, Address entry_point) {
303 processor_->CallbackCreateEvent( 345 Isolate::Current()->cpu_profiler()->processor_->CallbackCreateEvent(
304 Logger::CALLBACK_TAG, CodeEntry::kEmptyNamePrefix, name, entry_point); 346 Logger::CALLBACK_TAG, CodeEntry::kEmptyNamePrefix, name, entry_point);
305 } 347 }
306 348
307 349
308 void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, 350 void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag,
309 Code* code, const char* comment) { 351 Code* code, const char* comment) {
310 processor_->CodeCreateEvent( 352 Isolate::Current()->cpu_profiler()->processor_->CodeCreateEvent(
311 tag, comment, code->address(), code->ExecutableSize()); 353 tag, comment, code->address(), code->ExecutableSize());
312 } 354 }
313 355
314 356
315 void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, 357 void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag,
316 Code* code, Name* name) { 358 Code* code, Name* name) {
317 processor_->CodeCreateEvent( 359 Isolate* isolate = Isolate::Current();
360 isolate->cpu_profiler()->processor_->CodeCreateEvent(
318 tag, 361 tag,
319 name, 362 name,
320 isolate_->heap()->empty_string(), 363 isolate->heap()->empty_string(),
321 v8::CpuProfileNode::kNoLineNumberInfo, 364 v8::CpuProfileNode::kNoLineNumberInfo,
322 code->address(), 365 code->address(),
323 code->ExecutableSize(), 366 code->ExecutableSize(),
324 NULL); 367 NULL);
325 } 368 }
326 369
327 370
328 void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, 371 void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag,
329 Code* code, 372 Code* code,
330 SharedFunctionInfo* shared, 373 SharedFunctionInfo* shared,
331 Name* name) { 374 Name* name) {
332 processor_->CodeCreateEvent( 375 Isolate* isolate = Isolate::Current();
376 isolate->cpu_profiler()->processor_->CodeCreateEvent(
333 tag, 377 tag,
334 name, 378 name,
335 isolate_->heap()->empty_string(), 379 isolate->heap()->empty_string(),
336 v8::CpuProfileNode::kNoLineNumberInfo, 380 v8::CpuProfileNode::kNoLineNumberInfo,
337 code->address(), 381 code->address(),
338 code->ExecutableSize(), 382 code->ExecutableSize(),
339 shared->address()); 383 shared->address());
340 } 384 }
341 385
342 386
343 void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, 387 void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag,
344 Code* code, 388 Code* code,
345 SharedFunctionInfo* shared, 389 SharedFunctionInfo* shared,
346 String* source, int line) { 390 String* source, int line) {
347 processor_->CodeCreateEvent( 391 Isolate::Current()->cpu_profiler()->processor_->CodeCreateEvent(
348 tag, 392 tag,
349 shared->DebugName(), 393 shared->DebugName(),
350 source, 394 source,
351 line, 395 line,
352 code->address(), 396 code->address(),
353 code->ExecutableSize(), 397 code->ExecutableSize(),
354 shared->address()); 398 shared->address());
355 } 399 }
356 400
357 401
358 void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, 402 void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag,
359 Code* code, int args_count) { 403 Code* code, int args_count) {
360 processor_->CodeCreateEvent( 404 Isolate::Current()->cpu_profiler()->processor_->CodeCreateEvent(
361 tag, 405 tag,
362 args_count, 406 args_count,
363 code->address(), 407 code->address(),
364 code->ExecutableSize()); 408 code->ExecutableSize());
365 } 409 }
366 410
367 411
368 void CpuProfiler::CodeMoveEvent(Address from, Address to) { 412 void CpuProfiler::CodeMoveEvent(Address from, Address to) {
369 processor_->CodeMoveEvent(from, to); 413 Isolate::Current()->cpu_profiler()->processor_->CodeMoveEvent(from, to);
370 } 414 }
371 415
372 416
373 void CpuProfiler::CodeDeleteEvent(Address from) { 417 void CpuProfiler::CodeDeleteEvent(Address from) {
374 } 418 }
375 419
376 420
377 void CpuProfiler::SharedFunctionInfoMoveEvent(Address from, Address to) { 421 void CpuProfiler::SharedFunctionInfoMoveEvent(Address from, Address to) {
378 processor_->SharedFunctionInfoMoveEvent(from, to); 422 CpuProfiler* profiler = Isolate::Current()->cpu_profiler();
423 profiler->processor_->SharedFunctionInfoMoveEvent(from, to);
379 } 424 }
380 425
381 426
382 void CpuProfiler::GetterCallbackEvent(Name* name, Address entry_point) { 427 void CpuProfiler::GetterCallbackEvent(Name* name, Address entry_point) {
383 processor_->CallbackCreateEvent( 428 Isolate::Current()->cpu_profiler()->processor_->CallbackCreateEvent(
384 Logger::CALLBACK_TAG, "get ", name, entry_point); 429 Logger::CALLBACK_TAG, "get ", name, entry_point);
385 } 430 }
386 431
387 432
388 void CpuProfiler::RegExpCodeCreateEvent(Code* code, String* source) { 433 void CpuProfiler::RegExpCodeCreateEvent(Code* code, String* source) {
389 processor_->RegExpCodeCreateEvent( 434 Isolate::Current()->cpu_profiler()->processor_->RegExpCodeCreateEvent(
390 Logger::REG_EXP_TAG, 435 Logger::REG_EXP_TAG,
391 "RegExp: ", 436 "RegExp: ",
392 source, 437 source,
393 code->address(), 438 code->address(),
394 code->ExecutableSize()); 439 code->ExecutableSize());
395 } 440 }
396 441
397 442
398 void CpuProfiler::SetterCallbackEvent(Name* name, Address entry_point) { 443 void CpuProfiler::SetterCallbackEvent(Name* name, Address entry_point) {
399 processor_->CallbackCreateEvent( 444 Isolate::Current()->cpu_profiler()->processor_->CallbackCreateEvent(
400 Logger::CALLBACK_TAG, "set ", name, entry_point); 445 Logger::CALLBACK_TAG, "set ", name, entry_point);
401 } 446 }
402 447
403 448
404 CpuProfiler::CpuProfiler(Isolate* isolate) 449 CpuProfiler::CpuProfiler()
405 : isolate_(isolate), 450 : profiles_(new CpuProfilesCollection()),
406 profiles_(new CpuProfilesCollection()),
407 next_profile_uid_(1), 451 next_profile_uid_(1),
408 token_enumerator_(new TokenEnumerator()), 452 token_enumerator_(new TokenEnumerator()),
409 generator_(NULL), 453 generator_(NULL),
410 processor_(NULL), 454 processor_(NULL),
411 need_to_stop_sampler_(false), 455 need_to_stop_sampler_(false),
412 is_profiling_(false) { 456 is_profiling_(false) {
413 } 457 }
414 458
415 459
416 CpuProfiler::~CpuProfiler() { 460 CpuProfiler::~CpuProfiler() {
417 delete token_enumerator_; 461 delete token_enumerator_;
418 delete profiles_; 462 delete profiles_;
419 } 463 }
420 464
421 465
422 void CpuProfiler::ResetProfiles() { 466 void CpuProfiler::ResetProfiles() {
423 delete profiles_; 467 delete profiles_;
424 profiles_ = new CpuProfilesCollection(); 468 profiles_ = new CpuProfilesCollection();
425 } 469 }
426 470
427 void CpuProfiler::StartProfiling(const char* title, bool record_samples) { 471 void CpuProfiler::StartCollectingProfile(const char* title) {
428 if (profiles_->StartProfiling(title, next_profile_uid_++, record_samples)) { 472 if (profiles_->StartProfiling(title, next_profile_uid_++)) {
429 StartProcessorIfNotStarted(); 473 StartProcessorIfNotStarted();
430 } 474 }
431 processor_->AddCurrentStack(); 475 processor_->AddCurrentStack();
432 } 476 }
433 477
434 478
435 void CpuProfiler::StartProfiling(String* title, bool record_samples) { 479 void CpuProfiler::StartCollectingProfile(String* title) {
436 StartProfiling(profiles_->GetName(title), record_samples); 480 StartCollectingProfile(profiles_->GetName(title));
437 } 481 }
438 482
439 483
440 void CpuProfiler::StartProcessorIfNotStarted() { 484 void CpuProfiler::StartProcessorIfNotStarted() {
441 if (processor_ == NULL) { 485 if (processor_ == NULL) {
486 Isolate* isolate = Isolate::Current();
487
442 // Disable logging when using the new implementation. 488 // Disable logging when using the new implementation.
443 saved_logging_nesting_ = isolate_->logger()->logging_nesting_; 489 saved_logging_nesting_ = isolate->logger()->logging_nesting_;
444 isolate_->logger()->logging_nesting_ = 0; 490 isolate->logger()->logging_nesting_ = 0;
445 generator_ = new ProfileGenerator(profiles_); 491 generator_ = new ProfileGenerator(profiles_);
446 processor_ = new ProfilerEventsProcessor(generator_); 492 processor_ = new ProfilerEventsProcessor(generator_);
447 is_profiling_ = true; 493 is_profiling_ = true;
448 processor_->Start(); 494 processor_->Start();
449 // Enumerate stuff we already have in the heap. 495 // Enumerate stuff we already have in the heap.
450 if (isolate_->heap()->HasBeenSetUp()) { 496 if (isolate->heap()->HasBeenSetUp()) {
451 if (!FLAG_prof_browser_mode) { 497 if (!FLAG_prof_browser_mode) {
452 bool saved_log_code_flag = FLAG_log_code; 498 bool saved_log_code_flag = FLAG_log_code;
453 FLAG_log_code = true; 499 FLAG_log_code = true;
454 isolate_->logger()->LogCodeObjects(); 500 isolate->logger()->LogCodeObjects();
455 FLAG_log_code = saved_log_code_flag; 501 FLAG_log_code = saved_log_code_flag;
456 } 502 }
457 isolate_->logger()->LogCompiledFunctions(); 503 isolate->logger()->LogCompiledFunctions();
458 isolate_->logger()->LogAccessorCallbacks(); 504 isolate->logger()->LogAccessorCallbacks();
459 } 505 }
460 // Enable stack sampling. 506 // Enable stack sampling.
461 Sampler* sampler = reinterpret_cast<Sampler*>(isolate_->logger()->ticker_); 507 Sampler* sampler = reinterpret_cast<Sampler*>(isolate->logger()->ticker_);
462 if (!sampler->IsActive()) { 508 if (!sampler->IsActive()) {
463 sampler->Start(); 509 sampler->Start();
464 need_to_stop_sampler_ = true; 510 need_to_stop_sampler_ = true;
465 } 511 }
466 sampler->IncreaseProfilingDepth(); 512 sampler->IncreaseProfilingDepth();
467 } 513 }
468 } 514 }
469 515
470 516
471 CpuProfile* CpuProfiler::StopProfiling(const char* title) { 517 CpuProfile* CpuProfiler::StopCollectingProfile(const char* title) {
472 if (!is_profiling_) return NULL;
473 const double actual_sampling_rate = generator_->actual_sampling_rate(); 518 const double actual_sampling_rate = generator_->actual_sampling_rate();
474 StopProcessorIfLastProfile(title); 519 StopProcessorIfLastProfile(title);
475 CpuProfile* result = 520 CpuProfile* result =
476 profiles_->StopProfiling(TokenEnumerator::kNoSecurityToken, 521 profiles_->StopProfiling(TokenEnumerator::kNoSecurityToken,
477 title, 522 title,
478 actual_sampling_rate); 523 actual_sampling_rate);
479 if (result != NULL) { 524 if (result != NULL) {
480 result->Print(); 525 result->Print();
481 } 526 }
482 return result; 527 return result;
483 } 528 }
484 529
485 530
486 CpuProfile* CpuProfiler::StopProfiling(Object* security_token, String* title) { 531 CpuProfile* CpuProfiler::StopCollectingProfile(Object* security_token,
487 if (!is_profiling_) return NULL; 532 String* title) {
488 const double actual_sampling_rate = generator_->actual_sampling_rate(); 533 const double actual_sampling_rate = generator_->actual_sampling_rate();
489 const char* profile_title = profiles_->GetName(title); 534 const char* profile_title = profiles_->GetName(title);
490 StopProcessorIfLastProfile(profile_title); 535 StopProcessorIfLastProfile(profile_title);
491 int token = token_enumerator_->GetTokenId(security_token); 536 int token = token_enumerator_->GetTokenId(security_token);
492 return profiles_->StopProfiling(token, profile_title, actual_sampling_rate); 537 return profiles_->StopProfiling(token, profile_title, actual_sampling_rate);
493 } 538 }
494 539
495 540
496 void CpuProfiler::StopProcessorIfLastProfile(const char* title) { 541 void CpuProfiler::StopProcessorIfLastProfile(const char* title) {
497 if (profiles_->IsLastProfile(title)) StopProcessor(); 542 if (profiles_->IsLastProfile(title)) StopProcessor();
498 } 543 }
499 544
500 545
501 void CpuProfiler::StopProcessor() { 546 void CpuProfiler::StopProcessor() {
502 Logger* logger = isolate_->logger(); 547 Logger* logger = Isolate::Current()->logger();
503 Sampler* sampler = reinterpret_cast<Sampler*>(logger->ticker_); 548 Sampler* sampler = reinterpret_cast<Sampler*>(logger->ticker_);
504 sampler->DecreaseProfilingDepth(); 549 sampler->DecreaseProfilingDepth();
505 if (need_to_stop_sampler_) { 550 if (need_to_stop_sampler_) {
506 sampler->Stop(); 551 sampler->Stop();
507 need_to_stop_sampler_ = false; 552 need_to_stop_sampler_ = false;
508 } 553 }
509 is_profiling_ = false; 554 is_profiling_ = false;
510 processor_->Stop(); 555 processor_->Stop();
511 processor_->Join(); 556 processor_->Join();
512 delete processor_; 557 delete processor_;
513 delete generator_; 558 delete generator_;
514 processor_ = NULL; 559 processor_ = NULL;
515 generator_ = NULL; 560 generator_ = NULL;
516 logger->logging_nesting_ = saved_logging_nesting_; 561 logger->logging_nesting_ = saved_logging_nesting_;
517 } 562 }
518 563
519 564
565 void CpuProfiler::SetUp() {
566 Isolate* isolate = Isolate::Current();
567 if (isolate->cpu_profiler() == NULL) {
568 isolate->set_cpu_profiler(new CpuProfiler());
569 }
570 }
571
572
573 void CpuProfiler::TearDown() {
574 Isolate* isolate = Isolate::Current();
575 if (isolate->cpu_profiler() != NULL) {
576 delete isolate->cpu_profiler();
577 }
578 isolate->set_cpu_profiler(NULL);
579 }
580
520 } } // namespace v8::internal 581 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/cpu-profiler.h ('k') | src/execution.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698