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

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

Issue 2047243002: Make use of std::map for profiler code map. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 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
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/profiler/profile-generator.h" 5 #include "src/profiler/profile-generator.h"
6 6
7 #include "src/ast/scopeinfo.h" 7 #include "src/ast/scopeinfo.h"
8 #include "src/base/adapters.h" 8 #include "src/base/adapters.h"
9 #include "src/debug/debug.h" 9 #include "src/debug/debug.h"
10 #include "src/deoptimizer.h" 10 #include "src/deoptimizer.h"
11 #include "src/global-handles.h" 11 #include "src/global-handles.h"
12 #include "src/profiler/profile-generator-inl.h" 12 #include "src/profiler/profile-generator-inl.h"
13 #include "src/profiler/tick-sample.h" 13 #include "src/profiler/tick-sample.h"
14 #include "src/splay-tree-inl.h"
15 #include "src/unicode.h" 14 #include "src/unicode.h"
16 15
17 namespace v8 { 16 namespace v8 {
18 namespace internal { 17 namespace internal {
19 18
20 19
21 JITLineInfoTable::JITLineInfoTable() {} 20 JITLineInfoTable::JITLineInfoTable() {}
22 21
23 22
24 JITLineInfoTable::~JITLineInfoTable() {} 23 JITLineInfoTable::~JITLineInfoTable() {}
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 const std::vector<CodeEntry*>& path, int src_line, 376 const std::vector<CodeEntry*>& path, int src_line,
378 bool update_stats) { 377 bool update_stats) {
379 ProfileNode* top_frame_node = 378 ProfileNode* top_frame_node =
380 top_down_.AddPathFromEnd(path, src_line, update_stats); 379 top_down_.AddPathFromEnd(path, src_line, update_stats);
381 if (record_samples_ && !timestamp.IsNull()) { 380 if (record_samples_ && !timestamp.IsNull()) {
382 timestamps_.Add(timestamp); 381 timestamps_.Add(timestamp);
383 samples_.Add(top_frame_node); 382 samples_.Add(top_frame_node);
384 } 383 }
385 } 384 }
386 385
387
388 void CpuProfile::CalculateTotalTicksAndSamplingRate() { 386 void CpuProfile::CalculateTotalTicksAndSamplingRate() {
389 end_time_ = base::TimeTicks::HighResolutionNow(); 387 end_time_ = base::TimeTicks::HighResolutionNow();
390 } 388 }
391 389
392
393 void CpuProfile::Print() { 390 void CpuProfile::Print() {
394 base::OS::Print("[Top down]:\n"); 391 base::OS::Print("[Top down]:\n");
395 top_down_.Print(); 392 top_down_.Print();
396 } 393 }
397 394
398
399 CodeMap::~CodeMap() {}
400
401
402 const CodeMap::CodeTreeConfig::Key CodeMap::CodeTreeConfig::kNoKey = NULL;
403
404
405 void CodeMap::AddCode(Address addr, CodeEntry* entry, unsigned size) { 395 void CodeMap::AddCode(Address addr, CodeEntry* entry, unsigned size) {
406 DeleteAllCoveredCode(addr, addr + size); 396 DeleteAllCoveredCode(addr, addr + size);
407 CodeTree::Locator locator; 397 code_map_.insert({addr, CodeEntryInfo(entry, size)});
408 tree_.Insert(addr, &locator);
409 locator.set_value(CodeEntryInfo(entry, size));
410 } 398 }
411 399
412
413 void CodeMap::DeleteAllCoveredCode(Address start, Address end) { 400 void CodeMap::DeleteAllCoveredCode(Address start, Address end) {
414 List<Address> to_delete; 401 auto left = code_map_.upper_bound(start);
415 Address addr = end - 1; 402 if (left != code_map_.begin()) {
416 while (addr >= start) { 403 --left;
417 CodeTree::Locator locator; 404 if (left->first + left->second.size <= start) ++left;
418 if (!tree_.FindGreatestLessThan(addr, &locator)) break;
419 Address start2 = locator.key(), end2 = start2 + locator.value().size;
420 if (start2 < end && start < end2) to_delete.Add(start2);
421 addr = start2 - 1;
422 } 405 }
423 for (int i = 0; i < to_delete.length(); ++i) tree_.Remove(to_delete[i]); 406 auto right = left;
407 while (right != code_map_.end() && right->first < end) ++right;
408 code_map_.erase(left, right);
424 } 409 }
425 410
426
427 CodeEntry* CodeMap::FindEntry(Address addr) { 411 CodeEntry* CodeMap::FindEntry(Address addr) {
428 CodeTree::Locator locator; 412 auto it = code_map_.upper_bound(addr);
429 if (tree_.FindGreatestLessThan(addr, &locator)) { 413 if (it == code_map_.begin()) return nullptr;
430 // locator.key() <= addr. Need to check that addr is within entry. 414 --it;
431 const CodeEntryInfo& entry = locator.value(); 415 Address end_address = it->first + it->second.size;
432 if (addr < (locator.key() + entry.size)) { 416 return addr < end_address ? it->second.entry : nullptr;
433 return entry.entry;
434 }
435 }
436 return NULL;
437 } 417 }
438 418
439
440 void CodeMap::MoveCode(Address from, Address to) { 419 void CodeMap::MoveCode(Address from, Address to) {
441 if (from == to) return; 420 if (from == to) return;
442 CodeTree::Locator locator; 421 auto it = code_map_.find(from);
443 if (!tree_.Find(from, &locator)) return; 422 if (it == code_map_.end()) return;
444 CodeEntryInfo entry = locator.value(); 423 CodeEntryInfo info = it->second;
445 tree_.Remove(from); 424 code_map_.erase(it);
446 AddCode(to, entry.entry, entry.size); 425 AddCode(to, info.entry, info.size);
447 } 426 }
448 427
449 428 void CodeMap::Print() {
450 void CodeMap::CodeTreePrinter::Call( 429 for (auto it = code_map_.begin(); it != code_map_.end(); ++it) {
451 const Address& key, const CodeMap::CodeEntryInfo& value) { 430 base::OS::Print("%p %5d %s\n", static_cast<void*>(it->first),
452 base::OS::Print("%p %5d %s\n", static_cast<void*>(key), value.size, 431 it->second.size, it->second.entry->name());
453 value.entry->name()); 432 }
454 } 433 }
455 434
456
457 void CodeMap::Print() {
458 CodeTreePrinter printer;
459 tree_.ForEach(&printer);
460 }
461
462
463 CpuProfilesCollection::CpuProfilesCollection(Heap* heap) 435 CpuProfilesCollection::CpuProfilesCollection(Heap* heap)
464 : function_and_resource_names_(heap), 436 : function_and_resource_names_(heap),
465 isolate_(heap->isolate()), 437 isolate_(heap->isolate()),
466 current_profiles_semaphore_(1) {} 438 current_profiles_semaphore_(1) {}
467 439
468 440
469 static void DeleteCodeEntry(CodeEntry** entry_ptr) { 441 static void DeleteCodeEntry(CodeEntry** entry_ptr) {
470 delete *entry_ptr; 442 delete *entry_ptr;
471 } 443 }
472 444
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 case EXTERNAL: 684 case EXTERNAL:
713 return program_entry_; 685 return program_entry_;
714 case IDLE: 686 case IDLE:
715 return idle_entry_; 687 return idle_entry_;
716 default: return NULL; 688 default: return NULL;
717 } 689 }
718 } 690 }
719 691
720 } // namespace internal 692 } // namespace internal
721 } // namespace v8 693 } // namespace v8
OLDNEW
« src/profiler/profile-generator.h ('K') | « src/profiler/profile-generator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698