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

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

Issue 23748003: Cleanup Semaphore class. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Build fix for Mac OS X. Created 7 years, 3 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') | src/sweeper-thread.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 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 } 435 }
436 436
437 437
438 void CodeMap::Print() { 438 void CodeMap::Print() {
439 CodeTreePrinter printer; 439 CodeTreePrinter printer;
440 tree_.ForEach(&printer); 440 tree_.ForEach(&printer);
441 } 441 }
442 442
443 443
444 CpuProfilesCollection::CpuProfilesCollection() 444 CpuProfilesCollection::CpuProfilesCollection()
445 : current_profiles_semaphore_(OS::CreateSemaphore(1)) { 445 : current_profiles_semaphore_(1) {
446 } 446 }
447 447
448 448
449 static void DeleteCodeEntry(CodeEntry** entry_ptr) { 449 static void DeleteCodeEntry(CodeEntry** entry_ptr) {
450 delete *entry_ptr; 450 delete *entry_ptr;
451 } 451 }
452 452
453 453
454 static void DeleteCpuProfile(CpuProfile** profile_ptr) { 454 static void DeleteCpuProfile(CpuProfile** profile_ptr) {
455 delete *profile_ptr; 455 delete *profile_ptr;
456 } 456 }
457 457
458 458
459 CpuProfilesCollection::~CpuProfilesCollection() { 459 CpuProfilesCollection::~CpuProfilesCollection() {
460 delete current_profiles_semaphore_;
461 finished_profiles_.Iterate(DeleteCpuProfile); 460 finished_profiles_.Iterate(DeleteCpuProfile);
462 current_profiles_.Iterate(DeleteCpuProfile); 461 current_profiles_.Iterate(DeleteCpuProfile);
463 code_entries_.Iterate(DeleteCodeEntry); 462 code_entries_.Iterate(DeleteCodeEntry);
464 } 463 }
465 464
466 465
467 bool CpuProfilesCollection::StartProfiling(const char* title, unsigned uid, 466 bool CpuProfilesCollection::StartProfiling(const char* title, unsigned uid,
468 bool record_samples) { 467 bool record_samples) {
469 ASSERT(uid > 0); 468 ASSERT(uid > 0);
470 current_profiles_semaphore_->Wait(); 469 current_profiles_semaphore_.Wait();
471 if (current_profiles_.length() >= kMaxSimultaneousProfiles) { 470 if (current_profiles_.length() >= kMaxSimultaneousProfiles) {
472 current_profiles_semaphore_->Signal(); 471 current_profiles_semaphore_.Signal();
473 return false; 472 return false;
474 } 473 }
475 for (int i = 0; i < current_profiles_.length(); ++i) { 474 for (int i = 0; i < current_profiles_.length(); ++i) {
476 if (strcmp(current_profiles_[i]->title(), title) == 0) { 475 if (strcmp(current_profiles_[i]->title(), title) == 0) {
477 // Ignore attempts to start profile with the same title. 476 // Ignore attempts to start profile with the same title.
478 current_profiles_semaphore_->Signal(); 477 current_profiles_semaphore_.Signal();
479 return false; 478 return false;
480 } 479 }
481 } 480 }
482 current_profiles_.Add(new CpuProfile(title, uid, record_samples)); 481 current_profiles_.Add(new CpuProfile(title, uid, record_samples));
483 current_profiles_semaphore_->Signal(); 482 current_profiles_semaphore_.Signal();
484 return true; 483 return true;
485 } 484 }
486 485
487 486
488 CpuProfile* CpuProfilesCollection::StopProfiling(const char* title) { 487 CpuProfile* CpuProfilesCollection::StopProfiling(const char* title) {
489 const int title_len = StrLength(title); 488 const int title_len = StrLength(title);
490 CpuProfile* profile = NULL; 489 CpuProfile* profile = NULL;
491 current_profiles_semaphore_->Wait(); 490 current_profiles_semaphore_.Wait();
492 for (int i = current_profiles_.length() - 1; i >= 0; --i) { 491 for (int i = current_profiles_.length() - 1; i >= 0; --i) {
493 if (title_len == 0 || strcmp(current_profiles_[i]->title(), title) == 0) { 492 if (title_len == 0 || strcmp(current_profiles_[i]->title(), title) == 0) {
494 profile = current_profiles_.Remove(i); 493 profile = current_profiles_.Remove(i);
495 break; 494 break;
496 } 495 }
497 } 496 }
498 current_profiles_semaphore_->Signal(); 497 current_profiles_semaphore_.Signal();
499 498
500 if (profile == NULL) return NULL; 499 if (profile == NULL) return NULL;
501 profile->CalculateTotalTicksAndSamplingRate(); 500 profile->CalculateTotalTicksAndSamplingRate();
502 finished_profiles_.Add(profile); 501 finished_profiles_.Add(profile);
503 return profile; 502 return profile;
504 } 503 }
505 504
506 505
507 bool CpuProfilesCollection::IsLastProfile(const char* title) { 506 bool CpuProfilesCollection::IsLastProfile(const char* title) {
508 // Called from VM thread, and only it can mutate the list, 507 // Called from VM thread, and only it can mutate the list,
(...skipping 15 matching lines...) Expand all
524 } 523 }
525 UNREACHABLE(); 524 UNREACHABLE();
526 } 525 }
527 526
528 527
529 void CpuProfilesCollection::AddPathToCurrentProfiles( 528 void CpuProfilesCollection::AddPathToCurrentProfiles(
530 const Vector<CodeEntry*>& path) { 529 const Vector<CodeEntry*>& path) {
531 // As starting / stopping profiles is rare relatively to this 530 // As starting / stopping profiles is rare relatively to this
532 // method, we don't bother minimizing the duration of lock holding, 531 // method, we don't bother minimizing the duration of lock holding,
533 // e.g. copying contents of the list to a local vector. 532 // e.g. copying contents of the list to a local vector.
534 current_profiles_semaphore_->Wait(); 533 current_profiles_semaphore_.Wait();
535 for (int i = 0; i < current_profiles_.length(); ++i) { 534 for (int i = 0; i < current_profiles_.length(); ++i) {
536 current_profiles_[i]->AddPath(path); 535 current_profiles_[i]->AddPath(path);
537 } 536 }
538 current_profiles_semaphore_->Signal(); 537 current_profiles_semaphore_.Signal();
539 } 538 }
540 539
541 540
542 CodeEntry* CpuProfilesCollection::NewCodeEntry( 541 CodeEntry* CpuProfilesCollection::NewCodeEntry(
543 Logger::LogEventsAndTags tag, 542 Logger::LogEventsAndTags tag,
544 const char* name, 543 const char* name,
545 const char* name_prefix, 544 const char* name_prefix,
546 const char* resource_name, 545 const char* resource_name,
547 int line_number) { 546 int line_number) {
548 CodeEntry* code_entry = new CodeEntry(tag, 547 CodeEntry* code_entry = new CodeEntry(tag,
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 if (no_symbolized_entries) { 651 if (no_symbolized_entries) {
653 *entry++ = EntryForVMState(sample.state); 652 *entry++ = EntryForVMState(sample.state);
654 } 653 }
655 } 654 }
656 655
657 profiles_->AddPathToCurrentProfiles(entries); 656 profiles_->AddPathToCurrentProfiles(entries);
658 } 657 }
659 658
660 659
661 } } // namespace v8::internal 660 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/profile-generator.h ('k') | src/sweeper-thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698