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

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

Issue 85333006: Profiler fixes (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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') | runtime/vm/profiler_android.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 (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 <cstdio> 5 #include <cstdio>
6 6
7 #include "platform/utils.h" 7 #include "platform/utils.h"
8 8
9 #include "vm/isolate.h" 9 #include "vm/isolate.h"
10 #include "vm/json_stream.h" 10 #include "vm/json_stream.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 61
62 // Notes on stack frame walking: 62 // Notes on stack frame walking:
63 // 63 //
64 // The sampling profiler will collect up to Sample::kNumStackFrames stack frames 64 // The sampling profiler will collect up to Sample::kNumStackFrames stack frames
65 // The stack frame walking code uses the frame pointer to traverse the stack. 65 // The stack frame walking code uses the frame pointer to traverse the stack.
66 // If the VM is compiled without frame pointers (which is the default on 66 // If the VM is compiled without frame pointers (which is the default on
67 // recent GCC versions with optimizing enabled) the stack walking code will 67 // recent GCC versions with optimizing enabled) the stack walking code will
68 // fail (sometimes leading to a crash). 68 // fail (sometimes leading to a crash).
69 // 69 //
70 70
71
72 DEFINE_FLAG(bool, profile, true, "Enable Sampling Profiler"); 71 DEFINE_FLAG(bool, profile, true, "Enable Sampling Profiler");
73 DEFINE_FLAG(bool, trace_profiled_isolates, false, "Trace profiled isolates."); 72 DEFINE_FLAG(bool, trace_profiled_isolates, false, "Trace profiled isolates.");
74 73
75 bool ProfilerManager::initialized_ = false; 74 bool ProfilerManager::initialized_ = false;
76 bool ProfilerManager::shutdown_ = false; 75 bool ProfilerManager::shutdown_ = false;
77 Monitor* ProfilerManager::monitor_ = NULL; 76 Monitor* ProfilerManager::monitor_ = NULL;
78 Isolate** ProfilerManager::isolates_ = NULL; 77 Isolate** ProfilerManager::isolates_ = NULL;
79 intptr_t ProfilerManager::isolates_capacity_ = 0; 78 intptr_t ProfilerManager::isolates_capacity_ = 0;
80 intptr_t ProfilerManager::isolates_size_ = 0; 79 intptr_t ProfilerManager::isolates_size_ = 0;
81 80
82 81
83 void ProfilerManager::InitOnce() { 82 void ProfilerManager::InitOnce() {
83 #if defined(USING_SIMULATOR)
84 // Force disable of profiling on simulator.
85 FLAG_profile = false;
86 #endif
84 if (!FLAG_profile) { 87 if (!FLAG_profile) {
85 return; 88 return;
86 } 89 }
87 NativeSymbolResolver::InitOnce(); 90 NativeSymbolResolver::InitOnce();
88 ASSERT(!initialized_); 91 ASSERT(!initialized_);
89 monitor_ = new Monitor(); 92 monitor_ = new Monitor();
90 initialized_ = true; 93 initialized_ = true;
91 ResizeIsolates(16); 94 ResizeIsolates(16);
92 Thread::Start(ThreadMain, 0); 95 Thread::Start(ThreadMain, 0);
93 } 96 }
(...skipping 22 matching lines...) Expand all
116 void ProfilerManager::SetupIsolateForProfiling(Isolate* isolate) { 119 void ProfilerManager::SetupIsolateForProfiling(Isolate* isolate) {
117 if (!FLAG_profile) { 120 if (!FLAG_profile) {
118 return; 121 return;
119 } 122 }
120 ASSERT(isolate != NULL); 123 ASSERT(isolate != NULL);
121 { 124 {
122 ScopedSignalBlocker ssb; 125 ScopedSignalBlocker ssb;
123 { 126 {
124 ScopedMutex profiler_data_lock(isolate->profiler_data_mutex()); 127 ScopedMutex profiler_data_lock(isolate->profiler_data_mutex());
125 SampleBuffer* sample_buffer = new SampleBuffer(); 128 SampleBuffer* sample_buffer = new SampleBuffer();
129 ASSERT(sample_buffer != NULL);
126 IsolateProfilerData* profiler_data = 130 IsolateProfilerData* profiler_data =
127 new IsolateProfilerData(isolate, sample_buffer); 131 new IsolateProfilerData(isolate, sample_buffer);
132 ASSERT(profiler_data != NULL);
128 profiler_data->set_sample_interval_micros(1000); 133 profiler_data->set_sample_interval_micros(1000);
129 isolate->set_profiler_data(profiler_data); 134 isolate->set_profiler_data(profiler_data);
130 if (FLAG_trace_profiled_isolates) { 135 if (FLAG_trace_profiled_isolates) {
131 OS::Print("PROF SETUP %p %s %p\n", 136 OS::Print("PROF SETUP %p %s %p\n",
132 isolate, 137 isolate,
133 isolate->name(), 138 isolate->name(),
134 reinterpret_cast<void*>(Thread::GetCurrentThreadId())); 139 reinterpret_cast<void*>(Thread::GetCurrentThreadId()));
135 } 140 }
136 } 141 }
137 } 142 }
138 } 143 }
139 144
140 145
141 void ProfilerManager::FreeIsolateProfilingData(Isolate* isolate) { 146 void ProfilerManager::FreeIsolateProfilingData(Isolate* isolate) {
142 ScopedMutex profiler_data_lock(isolate->profiler_data_mutex()); 147 ScopedMutex profiler_data_lock(isolate->profiler_data_mutex());
143 IsolateProfilerData* profiler_data = isolate->profiler_data(); 148 IsolateProfilerData* profiler_data = isolate->profiler_data();
144 if (profiler_data == NULL) { 149 if (profiler_data == NULL) {
145 // Already freed. 150 // Already freed.
146 return; 151 return;
147 } 152 }
148 isolate->set_profiler_data(NULL); 153 isolate->set_profiler_data(NULL);
149 SampleBuffer* sample_buffer = profiler_data->sample_buffer(); 154 SampleBuffer* sample_buffer = profiler_data->sample_buffer();
150 ASSERT(sample_buffer != NULL); 155 ASSERT(sample_buffer != NULL);
156 profiler_data->set_sample_buffer(NULL);
151 delete sample_buffer; 157 delete sample_buffer;
152 delete profiler_data; 158 delete profiler_data;
153 if (FLAG_trace_profiled_isolates) { 159 if (FLAG_trace_profiled_isolates) {
154 OS::Print("PROF SHUTDOWN %p %s %p\n", isolate, 160 OS::Print("PROF SHUTDOWN %p %s %p\n", isolate,
155 isolate->name(), reinterpret_cast<void*>(Thread::GetCurrentThreadId())); 161 isolate->name(), reinterpret_cast<void*>(Thread::GetCurrentThreadId()));
156 } 162 }
157 } 163 }
158 164
159 165
160 void ProfilerManager::ShutdownIsolateForProfiling(Isolate* isolate) { 166 void ProfilerManager::ShutdownIsolateForProfiling(Isolate* isolate) {
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 } 527 }
522 vm_tags = kIdle; 528 vm_tags = kIdle;
523 runtime_tags = 0; 529 runtime_tags = 0;
524 } 530 }
525 531
526 532
527 SampleBuffer::SampleBuffer(intptr_t capacity) { 533 SampleBuffer::SampleBuffer(intptr_t capacity) {
528 start_ = 0; 534 start_ = 0;
529 end_ = 0; 535 end_ = 0;
530 capacity_ = capacity; 536 capacity_ = capacity;
531 samples_ = reinterpret_cast<Sample*>(calloc(capacity, sizeof(Sample))); 537 samples_ = new Sample[capacity];
532 } 538 }
533 539
534 540
535 SampleBuffer::~SampleBuffer() { 541 SampleBuffer::~SampleBuffer() {
536 if (samples_ != NULL) { 542 if (samples_ != NULL) {
537 free(samples_); 543 delete[] samples_;
538 samples_ = NULL; 544 samples_ = NULL;
539 } 545 }
540 } 546 }
541 547
542 548
543 Sample* SampleBuffer::ReserveSample() { 549 Sample* SampleBuffer::ReserveSample() {
550 ASSERT(samples_ != NULL);
544 intptr_t index = end_; 551 intptr_t index = end_;
545 end_ = WrapIncrement(end_); 552 end_ = WrapIncrement(end_);
546 if (end_ == start_) { 553 if (end_ == start_) {
547 start_ = WrapIncrement(start_); 554 start_ = WrapIncrement(start_);
548 } 555 }
556 ASSERT(index >= 0);
557 ASSERT(index < capacity_);
549 // Reset. 558 // Reset.
550 samples_[index] = Sample(); 559 samples_[index] = Sample();
551 return &samples_[index]; 560 return &samples_[index];
552 } 561 }
553 562
554 563
555 Sample* SampleBuffer::FirstSample() const { 564 Sample* SampleBuffer::FirstSample() const {
556 return &samples_[start_]; 565 return &samples_[start_];
557 } 566 }
558 567
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 return false; 653 return false;
645 } 654 }
646 uintptr_t cursor = reinterpret_cast<uintptr_t>(fp); 655 uintptr_t cursor = reinterpret_cast<uintptr_t>(fp);
647 cursor += sizeof(fp); 656 cursor += sizeof(fp);
648 bool r = cursor >= lower_bound_ && cursor < stack_upper_; 657 bool r = cursor >= lower_bound_ && cursor < stack_upper_;
649 return r; 658 return r;
650 } 659 }
651 660
652 661
653 } // namespace dart 662 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/profiler.h ('k') | runtime/vm/profiler_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698