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

Side by Side Diff: runtime/vm/profiler.cc

Issue 345713006: Make size of sample variable based on the profile depth flag (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/profiler.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 (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/utils.h" 5 #include "platform/utils.h"
6 6
7 #include "vm/allocation.h" 7 #include "vm/allocation.h"
8 #include "vm/atomic.h" 8 #include "vm/atomic.h"
9 #include "vm/code_patcher.h" 9 #include "vm/code_patcher.h"
10 #include "vm/isolate.h" 10 #include "vm/isolate.h"
(...skipping 28 matching lines...) Expand all
39 DEFINE_FLAG(bool, profile_native_stack, true, 39 DEFINE_FLAG(bool, profile_native_stack, true,
40 "Use native stack in profiler."); 40 "Use native stack in profiler.");
41 41
42 bool Profiler::initialized_ = false; 42 bool Profiler::initialized_ = false;
43 SampleBuffer* Profiler::sample_buffer_ = NULL; 43 SampleBuffer* Profiler::sample_buffer_ = NULL;
44 44
45 void Profiler::InitOnce() { 45 void Profiler::InitOnce() {
46 // Place some sane restrictions on user controlled flags. 46 // Place some sane restrictions on user controlled flags.
47 SetSamplePeriod(FLAG_profile_period); 47 SetSamplePeriod(FLAG_profile_period);
48 SetSampleDepth(FLAG_profile_depth); 48 SetSampleDepth(FLAG_profile_depth);
49 Sample::InitOnce();
49 if (!FLAG_profile) { 50 if (!FLAG_profile) {
50 return; 51 return;
51 } 52 }
52 ASSERT(!initialized_); 53 ASSERT(!initialized_);
53 sample_buffer_ = new SampleBuffer(); 54 sample_buffer_ = new SampleBuffer();
54 NativeSymbolResolver::InitOnce(); 55 NativeSymbolResolver::InitOnce();
55 ThreadInterrupter::SetInterruptPeriod(FLAG_profile_period); 56 ThreadInterrupter::SetInterruptPeriod(FLAG_profile_period);
56 ThreadInterrupter::Startup(); 57 ThreadInterrupter::Startup();
57 initialized_ = true; 58 initialized_ = true;
58 } 59 }
59 60
60 61
61 void Profiler::Shutdown() { 62 void Profiler::Shutdown() {
62 if (!FLAG_profile) { 63 if (!FLAG_profile) {
63 return; 64 return;
64 } 65 }
65 ASSERT(initialized_); 66 ASSERT(initialized_);
66 ThreadInterrupter::Shutdown(); 67 ThreadInterrupter::Shutdown();
67 NativeSymbolResolver::ShutdownOnce(); 68 NativeSymbolResolver::ShutdownOnce();
68 } 69 }
69 70
70 71
71 void Profiler::SetSampleDepth(intptr_t depth) { 72 void Profiler::SetSampleDepth(intptr_t depth) {
72 const int kMinimumDepth = 1; 73 const int kMinimumDepth = 1;
73 const int kMaximumDepth = kSampleFramesSize - 1; 74 const int kMaximumDepth = 255;
74 if (depth < kMinimumDepth) { 75 if (depth < kMinimumDepth) {
75 FLAG_profile_depth = kMinimumDepth; 76 FLAG_profile_depth = kMinimumDepth;
76 } else if (depth > kMaximumDepth) { 77 } else if (depth > kMaximumDepth) {
77 FLAG_profile_depth = kMaximumDepth; 78 FLAG_profile_depth = kMaximumDepth;
78 } else { 79 } else {
79 FLAG_profile_depth = depth; 80 FLAG_profile_depth = depth;
80 } 81 }
81 } 82 }
82 83
83 84
(...skipping 1526 matching lines...) Expand 10 before | Expand all | Expand 10 after
1610 if (block_count_ < 0) { 1611 if (block_count_ < 0) {
1611 FATAL("Too many calls to Dart_IsolateUnblocked."); 1612 FATAL("Too many calls to Dart_IsolateUnblocked.");
1612 } 1613 }
1613 if (!blocked()) { 1614 if (!blocked()) {
1614 // We just unblocked this isolate, wake up the thread interrupter. 1615 // We just unblocked this isolate, wake up the thread interrupter.
1615 ThreadInterrupter::WakeUp(); 1616 ThreadInterrupter::WakeUp();
1616 } 1617 }
1617 } 1618 }
1618 1619
1619 1620
1621 intptr_t Sample::pcs_length_ = 0;
1622 intptr_t Sample::instance_size_ = 0;
1623
1624
1625 void Sample::InitOnce() {
1626 ASSERT(FLAG_profile_depth >= 1);
1627 pcs_length_ = FLAG_profile_depth;
1628 instance_size_ =
1629 sizeof(Sample) + (sizeof(uword) * pcs_length_); // NOLINT.
1630 }
1631
1632
1633 uword* Sample::GetPCArray() const {
1634 return reinterpret_cast<uword*>(
1635 reinterpret_cast<uintptr_t>(this) + sizeof(*this));
1636 }
1637
1638
1639 SampleBuffer::SampleBuffer(intptr_t capacity) {
1640 ASSERT(Sample::instance_size() > 0);
1641 samples_ = reinterpret_cast<Sample*>(
1642 calloc(capacity, Sample::instance_size()));
1643 capacity_ = capacity;
1644 cursor_ = 0;
1645 }
1646
1647
1648 Sample* SampleBuffer::At(intptr_t idx) const {
1649 ASSERT(idx >= 0);
1650 ASSERT(idx < capacity_);
1651 intptr_t offset = idx * Sample::instance_size();
1652 uint8_t* samples = reinterpret_cast<uint8_t*>(samples_);
1653 return reinterpret_cast<Sample*>(samples + offset);
1654 }
1655
1656
1620 Sample* SampleBuffer::ReserveSample() { 1657 Sample* SampleBuffer::ReserveSample() {
1621 ASSERT(samples_ != NULL); 1658 ASSERT(samples_ != NULL);
1622 uintptr_t cursor = AtomicOperations::FetchAndIncrement(&cursor_); 1659 uintptr_t cursor = AtomicOperations::FetchAndIncrement(&cursor_);
1623 // Map back into sample buffer range. 1660 // Map back into sample buffer range.
1624 cursor = cursor % capacity_; 1661 cursor = cursor % capacity_;
1625 return At(cursor); 1662 return At(cursor);
1626 } 1663 }
1627 1664
1628 1665
1629 class ProfilerDartStackWalker : public ValueObject { 1666 class ProfilerDartStackWalker : public ValueObject {
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1862 ProfilerDartStackWalker stackWalker(sample); 1899 ProfilerDartStackWalker stackWalker(sample);
1863 stackWalker.walk(); 1900 stackWalker.walk();
1864 } else { 1901 } else {
1865 // TODO(johnmccutchan): Support collecting only Dart frames with 1902 // TODO(johnmccutchan): Support collecting only Dart frames with
1866 // ProfilerNativeStackWalker. 1903 // ProfilerNativeStackWalker.
1867 } 1904 }
1868 } 1905 }
1869 } 1906 }
1870 1907
1871 } // namespace dart 1908 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/profiler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698