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

Side by Side Diff: src/profile-generator.cc

Issue 21105003: Simplify sampling rate calculation (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 4 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/profile-generator.h ('k') | test/cctest/test-cpu-profiler.cc » ('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 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 } 365 }
366 366
367 367
368 void ProfileTree::ShortPrint() { 368 void ProfileTree::ShortPrint() {
369 OS::Print("root: %u %u %.2fms %.2fms\n", 369 OS::Print("root: %u %u %.2fms %.2fms\n",
370 root_->total_ticks(), root_->self_ticks(), 370 root_->total_ticks(), root_->self_ticks(),
371 root_->GetTotalMillis(), root_->GetSelfMillis()); 371 root_->GetTotalMillis(), root_->GetSelfMillis());
372 } 372 }
373 373
374 374
375 CpuProfile::CpuProfile(const char* title, unsigned uid, bool record_samples)
376 : title_(title),
377 uid_(uid),
378 record_samples_(record_samples),
379 start_time_ms_(OS::TimeCurrentMillis()),
loislo 2013/07/29 18:01:27 Can we do that on the first sample?
yurys 2013/07/29 18:13:21 Doing it here should be more fair. With the sampli
380 end_time_ms_(0) {
381 }
382
383
375 void CpuProfile::AddPath(const Vector<CodeEntry*>& path) { 384 void CpuProfile::AddPath(const Vector<CodeEntry*>& path) {
376 ProfileNode* top_frame_node = top_down_.AddPathFromEnd(path); 385 ProfileNode* top_frame_node = top_down_.AddPathFromEnd(path);
377 if (record_samples_) samples_.Add(top_frame_node); 386 if (record_samples_) samples_.Add(top_frame_node);
378 } 387 }
379 388
380 389
381 void CpuProfile::CalculateTotalTicks() { 390 void CpuProfile::CalculateTotalTicksAndSamplingRate() {
391 end_time_ms_ = OS::TimeCurrentMillis();
382 top_down_.CalculateTotalTicks(); 392 top_down_.CalculateTotalTicks();
393
394 double duration = end_time_ms_ - start_time_ms_;
395 if (duration < 1) duration = 1;
396 unsigned ticks = top_down_.root()->total_ticks();
397 double rate = ticks / duration;
398 top_down_.SetTickRatePerMs(rate);
383 } 399 }
384 400
385 401
386 void CpuProfile::SetActualSamplingRate(double actual_sampling_rate) {
387 top_down_.SetTickRatePerMs(actual_sampling_rate);
388 }
389
390
391 void CpuProfile::ShortPrint() { 402 void CpuProfile::ShortPrint() {
392 OS::Print("top down "); 403 OS::Print("top down ");
393 top_down_.ShortPrint(); 404 top_down_.ShortPrint();
394 } 405 }
395 406
396 407
397 void CpuProfile::Print() { 408 void CpuProfile::Print() {
398 OS::Print("[Top down]:\n"); 409 OS::Print("[Top down]:\n");
399 top_down_.Print(); 410 top_down_.Print();
400 } 411 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 current_profiles_semaphore_->Signal(); 533 current_profiles_semaphore_->Signal();
523 return false; 534 return false;
524 } 535 }
525 } 536 }
526 current_profiles_.Add(new CpuProfile(title, uid, record_samples)); 537 current_profiles_.Add(new CpuProfile(title, uid, record_samples));
527 current_profiles_semaphore_->Signal(); 538 current_profiles_semaphore_->Signal();
528 return true; 539 return true;
529 } 540 }
530 541
531 542
532 CpuProfile* CpuProfilesCollection::StopProfiling(const char* title, 543 CpuProfile* CpuProfilesCollection::StopProfiling(const char* title) {
533 double actual_sampling_rate) {
534 const int title_len = StrLength(title); 544 const int title_len = StrLength(title);
535 CpuProfile* profile = NULL; 545 CpuProfile* profile = NULL;
536 current_profiles_semaphore_->Wait(); 546 current_profiles_semaphore_->Wait();
537 for (int i = current_profiles_.length() - 1; i >= 0; --i) { 547 for (int i = current_profiles_.length() - 1; i >= 0; --i) {
538 if (title_len == 0 || strcmp(current_profiles_[i]->title(), title) == 0) { 548 if (title_len == 0 || strcmp(current_profiles_[i]->title(), title) == 0) {
539 profile = current_profiles_.Remove(i); 549 profile = current_profiles_.Remove(i);
540 break; 550 break;
541 } 551 }
542 } 552 }
543 current_profiles_semaphore_->Signal(); 553 current_profiles_semaphore_->Signal();
544 554
545 if (profile == NULL) return NULL; 555 if (profile == NULL) return NULL;
546 profile->CalculateTotalTicks(); 556 profile->CalculateTotalTicksAndSamplingRate();
547 profile->SetActualSamplingRate(actual_sampling_rate);
548 finished_profiles_.Add(profile); 557 finished_profiles_.Add(profile);
549 return profile; 558 return profile;
550 } 559 }
551 560
552 561
553 bool CpuProfilesCollection::IsLastProfile(const char* title) { 562 bool CpuProfilesCollection::IsLastProfile(const char* title) {
554 // Called from VM thread, and only it can mutate the list, 563 // Called from VM thread, and only it can mutate the list,
555 // so no locking is needed here. 564 // so no locking is needed here.
556 if (current_profiles_.length() != 1) return false; 565 if (current_profiles_.length() != 1) return false;
557 return StrLength(title) == 0 566 return StrLength(title) == 0
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 CodeEntry* code_entry = new CodeEntry(tag, 603 CodeEntry* code_entry = new CodeEntry(tag,
595 name, 604 name,
596 name_prefix, 605 name_prefix,
597 resource_name, 606 resource_name,
598 line_number); 607 line_number);
599 code_entries_.Add(code_entry); 608 code_entries_.Add(code_entry);
600 return code_entry; 609 return code_entry;
601 } 610 }
602 611
603 612
604 void SampleRateCalculator::Tick() {
605 if (--wall_time_query_countdown_ == 0)
606 UpdateMeasurements(OS::TimeCurrentMillis());
607 }
608
609
610 void SampleRateCalculator::UpdateMeasurements(double current_time) {
611 if (measurements_count_++ != 0) {
612 const double measured_ticks_per_ms =
613 (kWallTimeQueryIntervalMs * ticks_per_ms_) /
614 (current_time - last_wall_time_);
615 // Update the average value.
616 ticks_per_ms_ +=
617 (measured_ticks_per_ms - ticks_per_ms_) / measurements_count_;
618 // Update the externally accessible result.
619 result_ = static_cast<AtomicWord>(ticks_per_ms_ * kResultScale);
620 }
621 last_wall_time_ = current_time;
622 wall_time_query_countdown_ =
623 static_cast<unsigned>(kWallTimeQueryIntervalMs * ticks_per_ms_);
624 }
625
626
627 const char* const ProfileGenerator::kAnonymousFunctionName = 613 const char* const ProfileGenerator::kAnonymousFunctionName =
628 "(anonymous function)"; 614 "(anonymous function)";
629 const char* const ProfileGenerator::kProgramEntryName = 615 const char* const ProfileGenerator::kProgramEntryName =
630 "(program)"; 616 "(program)";
631 const char* const ProfileGenerator::kGarbageCollectorEntryName = 617 const char* const ProfileGenerator::kGarbageCollectorEntryName =
632 "(garbage collector)"; 618 "(garbage collector)";
633 const char* const ProfileGenerator::kUnresolvedFunctionName = 619 const char* const ProfileGenerator::kUnresolvedFunctionName =
634 "(unresolved function)"; 620 "(unresolved function)";
635 621
636 622
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 if (no_symbolized_entries) { 703 if (no_symbolized_entries) {
718 *entry++ = EntryForVMState(sample.state); 704 *entry++ = EntryForVMState(sample.state);
719 } 705 }
720 } 706 }
721 707
722 profiles_->AddPathToCurrentProfiles(entries); 708 profiles_->AddPathToCurrentProfiles(entries);
723 } 709 }
724 710
725 711
726 } } // namespace v8::internal 712 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/profile-generator.h ('k') | test/cctest/test-cpu-profiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698