| OLD | NEW |
| 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 #ifndef RUNTIME_VM_PROFILER_H_ | 5 #ifndef RUNTIME_VM_PROFILER_H_ |
| 6 #define RUNTIME_VM_PROFILER_H_ | 6 #define RUNTIME_VM_PROFILER_H_ |
| 7 | 7 |
| 8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
| 9 #include "vm/bitfield.h" | 9 #include "vm/bitfield.h" |
| 10 #include "vm/code_observers.h" | 10 #include "vm/code_observers.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 | 53 |
| 54 static void SetSampleDepth(intptr_t depth); | 54 static void SetSampleDepth(intptr_t depth); |
| 55 static void SetSamplePeriod(intptr_t period); | 55 static void SetSamplePeriod(intptr_t period); |
| 56 | 56 |
| 57 static SampleBuffer* sample_buffer() { return sample_buffer_; } | 57 static SampleBuffer* sample_buffer() { return sample_buffer_; } |
| 58 | 58 |
| 59 static void DumpStackTrace(void* context); | 59 static void DumpStackTrace(void* context); |
| 60 static void DumpStackTrace(); | 60 static void DumpStackTrace(); |
| 61 | 61 |
| 62 static void SampleAllocation(Thread* thread, intptr_t cid); | 62 static void SampleAllocation(Thread* thread, intptr_t cid); |
| 63 static Sample* SampleNativeAllocation(intptr_t skip_count); | 63 static Sample* SampleNativeAllocation(intptr_t skip_count, |
| 64 uword address, |
| 65 uintptr_t allocation_size); |
| 64 | 66 |
| 65 // SampleThread is called from inside the signal handler and hence it is very | 67 // SampleThread is called from inside the signal handler and hence it is very |
| 66 // critical that the implementation of SampleThread does not do any of the | 68 // critical that the implementation of SampleThread does not do any of the |
| 67 // following: | 69 // following: |
| 68 // * Accessing TLS -- Because on Windows the callback will be running in a | 70 // * Accessing TLS -- Because on Windows the callback will be running in a |
| 69 // different thread. | 71 // different thread. |
| 70 // * Allocating memory -- Because this takes locks which may already be | 72 // * Allocating memory -- Because this takes locks which may already be |
| 71 // held, resulting in a dead lock. | 73 // held, resulting in a dead lock. |
| 72 // * Taking a lock -- See above. | 74 // * Taking a lock -- See above. |
| 73 static void SampleThread(Thread* thread, const InterruptedThreadState& state); | 75 static void SampleThread(Thread* thread, const InterruptedThreadState& state); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 virtual bool FilterSample(Sample* sample) { return true; } | 136 virtual bool FilterSample(Sample* sample) { return true; } |
| 135 | 137 |
| 136 Dart_Port port() const { return port_; } | 138 Dart_Port port() const { return port_; } |
| 137 | 139 |
| 138 // Returns |true| if |sample| passes the time filter. | 140 // Returns |true| if |sample| passes the time filter. |
| 139 bool TimeFilterSample(Sample* sample); | 141 bool TimeFilterSample(Sample* sample); |
| 140 | 142 |
| 141 // Returns |true| if |sample| passes the thread task filter. | 143 // Returns |true| if |sample| passes the thread task filter. |
| 142 bool TaskFilterSample(Sample* sample); | 144 bool TaskFilterSample(Sample* sample); |
| 143 | 145 |
| 146 static const intptr_t kNoTaskFilter = -1; |
| 147 |
| 144 private: | 148 private: |
| 145 Dart_Port port_; | 149 Dart_Port port_; |
| 146 intptr_t thread_task_mask_; | 150 intptr_t thread_task_mask_; |
| 147 int64_t time_origin_micros_; | 151 int64_t time_origin_micros_; |
| 148 int64_t time_extent_micros_; | 152 int64_t time_extent_micros_; |
| 149 }; | 153 }; |
| 150 | 154 |
| 151 | 155 |
| 152 class ClearProfileVisitor : public SampleVisitor { | 156 class ClearProfileVisitor : public SampleVisitor { |
| 153 public: | 157 public: |
| (...skipping 22 matching lines...) Expand all Loading... |
| 176 port_ = ILLEGAL_PORT; | 180 port_ = ILLEGAL_PORT; |
| 177 pc_marker_ = 0; | 181 pc_marker_ = 0; |
| 178 for (intptr_t i = 0; i < kStackBufferSizeInWords; i++) { | 182 for (intptr_t i = 0; i < kStackBufferSizeInWords; i++) { |
| 179 stack_buffer_[i] = 0; | 183 stack_buffer_[i] = 0; |
| 180 } | 184 } |
| 181 vm_tag_ = VMTag::kInvalidTagId; | 185 vm_tag_ = VMTag::kInvalidTagId; |
| 182 user_tag_ = UserTags::kDefaultUserTag; | 186 user_tag_ = UserTags::kDefaultUserTag; |
| 183 lr_ = 0; | 187 lr_ = 0; |
| 184 metadata_ = 0; | 188 metadata_ = 0; |
| 185 state_ = 0; | 189 state_ = 0; |
| 190 native_allocation_address_ = 0; |
| 191 native_allocation_size_bytes_ = 0; |
| 186 continuation_index_ = -1; | 192 continuation_index_ = -1; |
| 187 uword* pcs = GetPCArray(); | 193 uword* pcs = GetPCArray(); |
| 188 for (intptr_t i = 0; i < pcs_length_; i++) { | 194 for (intptr_t i = 0; i < pcs_length_; i++) { |
| 189 pcs[i] = 0; | 195 pcs[i] = 0; |
| 190 } | 196 } |
| 191 set_head_sample(true); | 197 set_head_sample(true); |
| 192 } | 198 } |
| 193 | 199 |
| 194 // Timestamp sample was taken at. | 200 // Timestamp sample was taken at. |
| 195 int64_t timestamp() const { return timestamp_; } | 201 int64_t timestamp() const { return timestamp_; } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 | 278 |
| 273 bool is_native_allocation_sample() const { | 279 bool is_native_allocation_sample() const { |
| 274 return NativeAllocationSampleBit::decode(state_); | 280 return NativeAllocationSampleBit::decode(state_); |
| 275 } | 281 } |
| 276 | 282 |
| 277 void set_is_native_allocation_sample(bool native_allocation_sample) { | 283 void set_is_native_allocation_sample(bool native_allocation_sample) { |
| 278 state_ = | 284 state_ = |
| 279 NativeAllocationSampleBit::update(native_allocation_sample, state_); | 285 NativeAllocationSampleBit::update(native_allocation_sample, state_); |
| 280 } | 286 } |
| 281 | 287 |
| 288 void set_native_allocation_address(uword address) { |
| 289 native_allocation_address_ = address; |
| 290 } |
| 291 |
| 292 uword native_allocation_address() const { return native_allocation_address_; } |
| 293 |
| 294 bool NativeAllocationFreed() const { |
| 295 return (native_allocation_address_ == 0); |
| 296 } |
| 297 |
| 298 uintptr_t native_allocation_size_bytes() const { |
| 299 return native_allocation_size_bytes_; |
| 300 } |
| 301 |
| 302 void set_native_allocation_size_bytes(uintptr_t size) { |
| 303 native_allocation_size_bytes_ = size; |
| 304 } |
| 305 |
| 282 Thread::TaskKind thread_task() const { return ThreadTaskBit::decode(state_); } | 306 Thread::TaskKind thread_task() const { return ThreadTaskBit::decode(state_); } |
| 283 | 307 |
| 284 void set_thread_task(Thread::TaskKind task) { | 308 void set_thread_task(Thread::TaskKind task) { |
| 285 state_ = ThreadTaskBit::update(task, state_); | 309 state_ = ThreadTaskBit::update(task, state_); |
| 286 } | 310 } |
| 287 | 311 |
| 288 bool is_continuation_sample() const { | 312 bool is_continuation_sample() const { |
| 289 return ContinuationSampleBit::decode(state_); | 313 return ContinuationSampleBit::decode(state_); |
| 290 } | 314 } |
| 291 | 315 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 int64_t timestamp_; | 390 int64_t timestamp_; |
| 367 ThreadId tid_; | 391 ThreadId tid_; |
| 368 Dart_Port port_; | 392 Dart_Port port_; |
| 369 uword pc_marker_; | 393 uword pc_marker_; |
| 370 uword stack_buffer_[kStackBufferSizeInWords]; | 394 uword stack_buffer_[kStackBufferSizeInWords]; |
| 371 uword vm_tag_; | 395 uword vm_tag_; |
| 372 uword user_tag_; | 396 uword user_tag_; |
| 373 uword metadata_; | 397 uword metadata_; |
| 374 uword lr_; | 398 uword lr_; |
| 375 uword state_; | 399 uword state_; |
| 400 uword native_allocation_address_; |
| 401 uintptr_t native_allocation_size_bytes_; |
| 376 intptr_t continuation_index_; | 402 intptr_t continuation_index_; |
| 377 | 403 |
| 378 /* There are a variable number of words that follow, the words hold the | 404 /* There are a variable number of words that follow, the words hold the |
| 379 * sampled pc values. Access via GetPCArray() */ | 405 * sampled pc values. Access via GetPCArray() */ |
| 380 | 406 |
| 381 DISALLOW_COPY_AND_ASSIGN(Sample); | 407 DISALLOW_COPY_AND_ASSIGN(Sample); |
| 382 }; | 408 }; |
| 383 | 409 |
| 384 | 410 |
| 385 // A Code object descriptor. | 411 // A Code object descriptor. |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 // The user tag. | 583 // The user tag. |
| 558 uword user_tag() const { return user_tag_; } | 584 uword user_tag() const { return user_tag_; } |
| 559 void set_user_tag(uword tag) { user_tag_ = tag; } | 585 void set_user_tag(uword tag) { user_tag_ = tag; } |
| 560 | 586 |
| 561 // The class id if this is an allocation profile sample. -1 otherwise. | 587 // The class id if this is an allocation profile sample. -1 otherwise. |
| 562 intptr_t allocation_cid() const { return allocation_cid_; } | 588 intptr_t allocation_cid() const { return allocation_cid_; } |
| 563 void set_allocation_cid(intptr_t cid) { allocation_cid_ = cid; } | 589 void set_allocation_cid(intptr_t cid) { allocation_cid_ = cid; } |
| 564 | 590 |
| 565 bool IsAllocationSample() const { return allocation_cid_ > 0; } | 591 bool IsAllocationSample() const { return allocation_cid_ > 0; } |
| 566 | 592 |
| 593 bool is_native_allocation_sample() const { return native_allocation_sample_; } |
| 594 void set_is_native_allocation_sample(bool native_allocation_sample) { |
| 595 native_allocation_sample_ = native_allocation_sample; |
| 596 } |
| 597 |
| 598 uintptr_t native_allocation_size_bytes() const { |
| 599 return native_allocation_size_bytes_; |
| 600 } |
| 601 void set_native_allocation_size_bytes(uintptr_t allocation_size) { |
| 602 native_allocation_size_bytes_ = allocation_size; |
| 603 } |
| 604 |
| 567 // Was the stack trace truncated? | 605 // Was the stack trace truncated? |
| 568 bool truncated() const { return truncated_; } | 606 bool truncated() const { return truncated_; } |
| 569 void set_truncated(bool truncated) { truncated_ = truncated; } | 607 void set_truncated(bool truncated) { truncated_ = truncated; } |
| 570 | 608 |
| 571 // Was the first frame in the stack trace executing? | 609 // Was the first frame in the stack trace executing? |
| 572 bool first_frame_executing() const { return first_frame_executing_; } | 610 bool first_frame_executing() const { return first_frame_executing_; } |
| 573 void set_first_frame_executing(bool first_frame_executing) { | 611 void set_first_frame_executing(bool first_frame_executing) { |
| 574 first_frame_executing_ = first_frame_executing; | 612 first_frame_executing_ = first_frame_executing; |
| 575 } | 613 } |
| 576 | 614 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 591 uword* stack_buffer); | 629 uword* stack_buffer); |
| 592 | 630 |
| 593 ZoneGrowableArray<uword> pcs_; | 631 ZoneGrowableArray<uword> pcs_; |
| 594 int64_t timestamp_; | 632 int64_t timestamp_; |
| 595 ThreadId tid_; | 633 ThreadId tid_; |
| 596 uword vm_tag_; | 634 uword vm_tag_; |
| 597 uword user_tag_; | 635 uword user_tag_; |
| 598 intptr_t allocation_cid_; | 636 intptr_t allocation_cid_; |
| 599 bool truncated_; | 637 bool truncated_; |
| 600 bool first_frame_executing_; | 638 bool first_frame_executing_; |
| 639 bool native_allocation_sample_; |
| 640 uword native_allocation_address_; |
| 641 uintptr_t native_allocation_size_bytes_; |
| 601 ProfileTrieNode* timeline_trie_; | 642 ProfileTrieNode* timeline_trie_; |
| 602 | 643 |
| 603 friend class SampleBuffer; | 644 friend class SampleBuffer; |
| 604 DISALLOW_COPY_AND_ASSIGN(ProcessedSample); | 645 DISALLOW_COPY_AND_ASSIGN(ProcessedSample); |
| 605 }; | 646 }; |
| 606 | 647 |
| 607 | 648 |
| 608 // A collection of |ProcessedSample|s. | 649 // A collection of |ProcessedSample|s. |
| 609 class ProcessedSampleBuffer : public ZoneAllocated { | 650 class ProcessedSampleBuffer : public ZoneAllocated { |
| 610 public: | 651 public: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 623 private: | 664 private: |
| 624 ZoneGrowableArray<ProcessedSample*> samples_; | 665 ZoneGrowableArray<ProcessedSample*> samples_; |
| 625 CodeLookupTable* code_lookup_table_; | 666 CodeLookupTable* code_lookup_table_; |
| 626 | 667 |
| 627 DISALLOW_COPY_AND_ASSIGN(ProcessedSampleBuffer); | 668 DISALLOW_COPY_AND_ASSIGN(ProcessedSampleBuffer); |
| 628 }; | 669 }; |
| 629 | 670 |
| 630 } // namespace dart | 671 } // namespace dart |
| 631 | 672 |
| 632 #endif // RUNTIME_VM_PROFILER_H_ | 673 #endif // RUNTIME_VM_PROFILER_H_ |
| OLD | NEW |