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

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

Issue 2769001: Factor out StringsStorage from CpuProfilesCollection. (Closed)
Patch Set: Comments addressed Created 10 years, 6 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
« no previous file with comments | « src/profile-generator.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 void TokenEnumerator::TokenRemoved(Object** token_location) { 79 void TokenEnumerator::TokenRemoved(Object** token_location) {
80 for (int i = 0; i < token_locations_.length(); ++i) { 80 for (int i = 0; i < token_locations_.length(); ++i) {
81 if (token_locations_[i] == token_location && !token_removed_[i]) { 81 if (token_locations_[i] == token_location && !token_removed_[i]) {
82 token_removed_[i] = true; 82 token_removed_[i] = true;
83 return; 83 return;
84 } 84 }
85 } 85 }
86 } 86 }
87 87
88 88
89 StringsStorage::StringsStorage()
90 : names_(StringsMatch) {
91 }
92
93
94 StringsStorage::~StringsStorage() {
95 for (HashMap::Entry* p = names_.Start();
96 p != NULL;
97 p = names_.Next(p)) {
98 DeleteArray(reinterpret_cast<const char*>(p->value));
99 }
100 }
101
102
103 const char* StringsStorage::GetName(String* name) {
104 if (name->IsString()) {
105 char* c_name =
106 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL).Detach();
107 HashMap::Entry* cache_entry = names_.Lookup(c_name, name->Hash(), true);
108 if (cache_entry->value == NULL) {
109 // New entry added.
110 cache_entry->value = c_name;
111 } else {
112 DeleteArray(c_name);
113 }
114 return reinterpret_cast<const char*>(cache_entry->value);
115 }
116 return "";
117 }
118
119
89 const char* CodeEntry::kEmptyNamePrefix = ""; 120 const char* CodeEntry::kEmptyNamePrefix = "";
90 unsigned CodeEntry::next_call_uid_ = 1; 121 unsigned CodeEntry::next_call_uid_ = 1;
91 122
92 123
93 void CodeEntry::CopyData(const CodeEntry& source) { 124 void CodeEntry::CopyData(const CodeEntry& source) {
94 call_uid_ = source.call_uid_; 125 call_uid_ = source.call_uid_;
95 tag_ = source.tag_; 126 tag_ = source.tag_;
96 name_prefix_ = source.name_prefix_; 127 name_prefix_ = source.name_prefix_;
97 name_ = source.name_; 128 name_ = source.name_;
98 resource_name_ = source.resource_name_; 129 resource_name_ = source.resource_name_;
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 } 462 }
432 463
433 464
434 void CodeMap::Print() { 465 void CodeMap::Print() {
435 CodeTreePrinter printer; 466 CodeTreePrinter printer;
436 tree_.ForEach(&printer); 467 tree_.ForEach(&printer);
437 } 468 }
438 469
439 470
440 CpuProfilesCollection::CpuProfilesCollection() 471 CpuProfilesCollection::CpuProfilesCollection()
441 : function_and_resource_names_(StringsMatch), 472 : profiles_uids_(UidsMatch),
442 profiles_uids_(UidsMatch),
443 current_profiles_semaphore_(OS::CreateSemaphore(1)) { 473 current_profiles_semaphore_(OS::CreateSemaphore(1)) {
444 // Create list of unabridged profiles. 474 // Create list of unabridged profiles.
445 profiles_by_token_.Add(new List<CpuProfile*>()); 475 profiles_by_token_.Add(new List<CpuProfile*>());
446 } 476 }
447 477
448 478
449 static void DeleteArgsCountName(char** name_ptr) { 479 static void DeleteArgsCountName(char** name_ptr) {
450 DeleteArray(*name_ptr); 480 DeleteArray(*name_ptr);
451 } 481 }
452 482
(...skipping 10 matching lines...) Expand all
463 (*list_ptr)->Iterate(DeleteCpuProfile); 493 (*list_ptr)->Iterate(DeleteCpuProfile);
464 delete *list_ptr; 494 delete *list_ptr;
465 } 495 }
466 496
467 CpuProfilesCollection::~CpuProfilesCollection() { 497 CpuProfilesCollection::~CpuProfilesCollection() {
468 delete current_profiles_semaphore_; 498 delete current_profiles_semaphore_;
469 current_profiles_.Iterate(DeleteCpuProfile); 499 current_profiles_.Iterate(DeleteCpuProfile);
470 profiles_by_token_.Iterate(DeleteProfilesList); 500 profiles_by_token_.Iterate(DeleteProfilesList);
471 code_entries_.Iterate(DeleteCodeEntry); 501 code_entries_.Iterate(DeleteCodeEntry);
472 args_count_names_.Iterate(DeleteArgsCountName); 502 args_count_names_.Iterate(DeleteArgsCountName);
473 for (HashMap::Entry* p = function_and_resource_names_.Start();
474 p != NULL;
475 p = function_and_resource_names_.Next(p)) {
476 DeleteArray(reinterpret_cast<const char*>(p->value));
477 }
478 } 503 }
479 504
480 505
481 bool CpuProfilesCollection::StartProfiling(const char* title, unsigned uid) { 506 bool CpuProfilesCollection::StartProfiling(const char* title, unsigned uid) {
482 ASSERT(uid > 0); 507 ASSERT(uid > 0);
483 current_profiles_semaphore_->Wait(); 508 current_profiles_semaphore_->Wait();
484 for (int i = 0; i < current_profiles_.length(); ++i) { 509 for (int i = 0; i < current_profiles_.length(); ++i) {
485 if (strcmp(current_profiles_[i]->title(), title) == 0) { 510 if (strcmp(current_profiles_[i]->title(), title) == 0) {
486 // Ignore attempts to start profile with the same title. 511 // Ignore attempts to start profile with the same title.
487 current_profiles_semaphore_->Signal(); 512 current_profiles_semaphore_->Signal();
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 } 684 }
660 685
661 686
662 CodeEntry* CpuProfilesCollection::NewCodeEntry(int security_token_id) { 687 CodeEntry* CpuProfilesCollection::NewCodeEntry(int security_token_id) {
663 CodeEntry* entry = new CodeEntry(security_token_id); 688 CodeEntry* entry = new CodeEntry(security_token_id);
664 code_entries_.Add(entry); 689 code_entries_.Add(entry);
665 return entry; 690 return entry;
666 } 691 }
667 692
668 693
669 const char* CpuProfilesCollection::GetName(String* name) {
670 if (name->IsString()) {
671 char* c_name =
672 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL).Detach();
673 HashMap::Entry* cache_entry =
674 function_and_resource_names_.Lookup(c_name,
675 name->Hash(),
676 true);
677 if (cache_entry->value == NULL) {
678 // New entry added.
679 cache_entry->value = c_name;
680 } else {
681 DeleteArray(c_name);
682 }
683 return reinterpret_cast<const char*>(cache_entry->value);
684 } else {
685 return "";
686 }
687 }
688
689
690 const char* CpuProfilesCollection::GetName(int args_count) { 694 const char* CpuProfilesCollection::GetName(int args_count) {
691 ASSERT(args_count >= 0); 695 ASSERT(args_count >= 0);
692 if (args_count_names_.length() <= args_count) { 696 if (args_count_names_.length() <= args_count) {
693 args_count_names_.AddBlock( 697 args_count_names_.AddBlock(
694 NULL, args_count - args_count_names_.length() + 1); 698 NULL, args_count - args_count_names_.length() + 1);
695 } 699 }
696 if (args_count_names_[args_count] == NULL) { 700 if (args_count_names_[args_count] == NULL) {
697 const int kMaximumNameLength = 32; 701 const int kMaximumNameLength = 32;
698 char* name = NewArray<char>(kMaximumNameLength); 702 char* name = NewArray<char>(kMaximumNameLength);
699 OS::SNPrintF(Vector<char>(name, kMaximumNameLength), "%d", args_count); 703 OS::SNPrintF(Vector<char>(name, kMaximumNameLength), "%d", args_count);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 *entry++ = EntryForVMState(sample.state); 807 *entry++ = EntryForVMState(sample.state);
804 } 808 }
805 } 809 }
806 810
807 profiles_->AddPathToCurrentProfiles(entries); 811 profiles_->AddPathToCurrentProfiles(entries);
808 } 812 }
809 813
810 } } // namespace v8::internal 814 } } // namespace v8::internal
811 815
812 #endif // ENABLE_LOGGING_AND_PROFILING 816 #endif // ENABLE_LOGGING_AND_PROFILING
OLDNEW
« no previous file with comments | « src/profile-generator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698