| 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 VM_PROFILER_H_ | 5 #ifndef VM_PROFILER_H_ |
| 6 #define VM_PROFILER_H_ | 6 #define 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" |
| 11 #include "vm/globals.h" | 11 #include "vm/globals.h" |
| 12 #include "vm/growable_array.h" | 12 #include "vm/growable_array.h" |
| 13 #include "vm/object.h" | 13 #include "vm/object.h" |
| 14 #include "vm/tags.h" | 14 #include "vm/tags.h" |
| 15 #include "vm/thread_interrupter.h" | 15 #include "vm/thread_interrupter.h" |
| 16 | 16 |
| 17 // Profiler sampling and stack walking support. | 17 // Profiler sampling and stack walking support. |
| 18 // NOTE: For service related code, see profile_service.h. | 18 // NOTE: For service related code, see profile_service.h. |
| 19 | 19 |
| 20 namespace dart { | 20 namespace dart { |
| 21 | 21 |
| 22 // Forward declarations. | 22 // Forward declarations. |
| 23 class ProcessedSample; | 23 class ProcessedSample; |
| 24 class ProcessedSampleBuffer; | 24 class ProcessedSampleBuffer; |
| 25 | 25 |
| 26 class Sample; | 26 class Sample; |
| 27 class SampleBuffer; | 27 class SampleBuffer; |
| 28 class ProfileTrieNode; | 28 class ProfileTrieNode; |
| 29 | 29 |
| 30 struct ProfilerCounters { |
| 31 // Count of bail out reasons: |
| 32 int64_t bail_out_unknown_task; |
| 33 int64_t bail_out_jump_to_exception_handler; |
| 34 int64_t bail_out_check_isolate; |
| 35 // Count of single frame sampling reasons: |
| 36 int64_t single_frame_sample_deoptimizing; |
| 37 int64_t single_frame_sample_register_check; |
| 38 int64_t single_frame_sample_get_and_validate_stack_bounds; |
| 39 // Count of stack walkers used: |
| 40 int64_t stack_walker_native; |
| 41 int64_t stack_walker_dart_exit; |
| 42 int64_t stack_walker_dart; |
| 43 int64_t stack_walker_none; |
| 44 }; |
| 45 |
| 46 |
| 30 class Profiler : public AllStatic { | 47 class Profiler : public AllStatic { |
| 31 public: | 48 public: |
| 32 static void InitOnce(); | 49 static void InitOnce(); |
| 33 static void Shutdown(); | 50 static void Shutdown(); |
| 34 | 51 |
| 35 static void SetSampleDepth(intptr_t depth); | 52 static void SetSampleDepth(intptr_t depth); |
| 36 static void SetSamplePeriod(intptr_t period); | 53 static void SetSamplePeriod(intptr_t period); |
| 37 | 54 |
| 38 static SampleBuffer* sample_buffer() { | 55 static SampleBuffer* sample_buffer() { |
| 39 return sample_buffer_; | 56 return sample_buffer_; |
| 40 } | 57 } |
| 41 | 58 |
| 42 static void DumpStackTrace(bool native_stack_trace = true); | 59 static void DumpStackTrace(bool native_stack_trace = true); |
| 43 | 60 |
| 44 static void SampleAllocation(Thread* thread, intptr_t cid); | 61 static void SampleAllocation(Thread* thread, intptr_t cid); |
| 45 | 62 |
| 46 // SampleThread is called from inside the signal handler and hence it is very | 63 // SampleThread is called from inside the signal handler and hence it is very |
| 47 // critical that the implementation of SampleThread does not do any of the | 64 // critical that the implementation of SampleThread does not do any of the |
| 48 // following: | 65 // following: |
| 49 // * Accessing TLS -- Because on Windows the callback will be running in a | 66 // * Accessing TLS -- Because on Windows the callback will be running in a |
| 50 // different thread. | 67 // different thread. |
| 51 // * Allocating memory -- Because this takes locks which may already be | 68 // * Allocating memory -- Because this takes locks which may already be |
| 52 // held, resulting in a dead lock. | 69 // held, resulting in a dead lock. |
| 53 // * Taking a lock -- See above. | 70 // * Taking a lock -- See above. |
| 54 static void SampleThread(Thread* thread, | 71 static void SampleThread(Thread* thread, |
| 55 const InterruptedThreadState& state); | 72 const InterruptedThreadState& state); |
| 56 | 73 |
| 74 static ProfilerCounters counters() { |
| 75 // Copies the counter values. |
| 76 return counters_; |
| 77 } |
| 78 |
| 57 private: | 79 private: |
| 58 // Does not walk the thread's stack. | 80 // Does not walk the thread's stack. |
| 59 static void SampleThreadSingleFrame(Thread* thread, uintptr_t pc); | 81 static void SampleThreadSingleFrame(Thread* thread, uintptr_t pc); |
| 60 static bool initialized_; | 82 static bool initialized_; |
| 61 | 83 |
| 62 static SampleBuffer* sample_buffer_; | 84 static SampleBuffer* sample_buffer_; |
| 63 | 85 |
| 86 static ProfilerCounters counters_; |
| 87 |
| 64 friend class Thread; | 88 friend class Thread; |
| 65 }; | 89 }; |
| 66 | 90 |
| 67 | 91 |
| 68 class SampleVisitor : public ValueObject { | 92 class SampleVisitor : public ValueObject { |
| 69 public: | 93 public: |
| 70 explicit SampleVisitor(Isolate* isolate) : isolate_(isolate), visited_(0) { } | 94 explicit SampleVisitor(Isolate* isolate) : isolate_(isolate), visited_(0) { } |
| 71 virtual ~SampleVisitor() {} | 95 virtual ~SampleVisitor() {} |
| 72 | 96 |
| 73 virtual void VisitSample(Sample* sample) = 0; | 97 virtual void VisitSample(Sample* sample) = 0; |
| (...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 private: | 679 private: |
| 656 ZoneGrowableArray<ProcessedSample*> samples_; | 680 ZoneGrowableArray<ProcessedSample*> samples_; |
| 657 CodeLookupTable* code_lookup_table_; | 681 CodeLookupTable* code_lookup_table_; |
| 658 | 682 |
| 659 DISALLOW_COPY_AND_ASSIGN(ProcessedSampleBuffer); | 683 DISALLOW_COPY_AND_ASSIGN(ProcessedSampleBuffer); |
| 660 }; | 684 }; |
| 661 | 685 |
| 662 } // namespace dart | 686 } // namespace dart |
| 663 | 687 |
| 664 #endif // VM_PROFILER_H_ | 688 #endif // VM_PROFILER_H_ |
| OLD | NEW |