| 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/code_observers.h" | 9 #include "vm/code_observers.h" |
| 10 #include "vm/globals.h" | 10 #include "vm/globals.h" |
| 11 #include "vm/thread.h" | 11 #include "vm/thread.h" |
| 12 #include "vm/thread_interrupter.h" | 12 #include "vm/thread_interrupter.h" |
| 13 | 13 |
| 14 namespace dart { | 14 namespace dart { |
| 15 | 15 |
| 16 // Forward declarations. | 16 // Forward declarations. |
| 17 class JSONArray; | 17 class JSONArray; |
| 18 class JSONStream; | 18 class JSONStream; |
| 19 class ProfilerCodeRegionTable; |
| 19 struct Sample; | 20 struct Sample; |
| 20 | 21 |
| 21 // Profiler | 22 // Profiler |
| 22 class Profiler : public AllStatic { | 23 class Profiler : public AllStatic { |
| 23 public: | 24 public: |
| 24 static void InitOnce(); | 25 static void InitOnce(); |
| 25 static void Shutdown(); | 26 static void Shutdown(); |
| 26 | 27 |
| 27 static void InitProfilingForIsolate(Isolate* isolate, | 28 static void InitProfilingForIsolate(Isolate* isolate, |
| 28 bool shared_buffer = false); | 29 bool shared_buffer = false); |
| 29 static void ShutdownProfilingForIsolate(Isolate* isolate); | 30 static void ShutdownProfilingForIsolate(Isolate* isolate); |
| 30 | 31 |
| 31 static void BeginExecution(Isolate* isolate); | 32 static void BeginExecution(Isolate* isolate); |
| 32 static void EndExecution(Isolate* isolate); | 33 static void EndExecution(Isolate* isolate); |
| 33 | 34 |
| 34 static void PrintToJSONStream(Isolate* isolate, JSONStream* stream); | 35 static void PrintToJSONStream(Isolate* isolate, JSONStream* stream, |
| 35 | 36 bool full); |
| 36 static void WriteTracing(Isolate* isolate); | 37 static void WriteProfile(Isolate* isolate); |
| 37 | 38 |
| 38 static SampleBuffer* sample_buffer() { | 39 static SampleBuffer* sample_buffer() { |
| 39 return sample_buffer_; | 40 return sample_buffer_; |
| 40 } | 41 } |
| 41 | 42 |
| 42 private: | 43 private: |
| 43 static bool initialized_; | 44 static bool initialized_; |
| 44 static Monitor* monitor_; | 45 static Monitor* monitor_; |
| 45 | 46 |
| 46 static void WriteTracingSample(Isolate* isolate, intptr_t pid, | 47 static intptr_t ProcessSamples(Isolate* isolate, |
| 47 Sample* sample, JSONArray& events); | 48 ProfilerCodeRegionTable* code_region_table, |
| 49 SampleBuffer* sample_buffer); |
| 50 |
| 51 static intptr_t ProcessSample(Isolate* isolate, |
| 52 ProfilerCodeRegionTable* code_region_table, |
| 53 Sample* sample); |
| 48 | 54 |
| 49 static void RecordTickInterruptCallback(const InterruptedThreadState& state, | 55 static void RecordTickInterruptCallback(const InterruptedThreadState& state, |
| 50 void* data); | 56 void* data); |
| 51 | 57 |
| 52 static void RecordSampleInterruptCallback(const InterruptedThreadState& state, | 58 static void RecordSampleInterruptCallback(const InterruptedThreadState& state, |
| 53 void* data); | 59 void* data); |
| 54 | 60 |
| 55 static SampleBuffer* sample_buffer_; | 61 static SampleBuffer* sample_buffer_; |
| 56 }; | 62 }; |
| 57 | 63 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 69 | 75 |
| 70 private: | 76 private: |
| 71 SampleBuffer* sample_buffer_; | 77 SampleBuffer* sample_buffer_; |
| 72 bool own_sample_buffer_; | 78 bool own_sample_buffer_; |
| 73 DISALLOW_COPY_AND_ASSIGN(IsolateProfilerData); | 79 DISALLOW_COPY_AND_ASSIGN(IsolateProfilerData); |
| 74 }; | 80 }; |
| 75 | 81 |
| 76 | 82 |
| 77 // Profile sample. | 83 // Profile sample. |
| 78 struct Sample { | 84 struct Sample { |
| 79 static const char* kLookupSymbol; | |
| 80 static const char* kNoSymbol; | |
| 81 static const char* kNoFrame; | |
| 82 static const intptr_t kNumStackFrames = 6; | 85 static const intptr_t kNumStackFrames = 6; |
| 83 enum SampleType { | 86 enum SampleType { |
| 84 kIsolateStart, | 87 kIsolateStart, |
| 85 kIsolateStop, | 88 kIsolateStop, |
| 86 kIsolateSample, | 89 kIsolateSample, |
| 87 }; | 90 }; |
| 88 int64_t timestamp; | 91 int64_t timestamp; |
| 89 ThreadId tid; | 92 ThreadId tid; |
| 90 Isolate* isolate; | 93 Isolate* isolate; |
| 91 uintptr_t pcs[kNumStackFrames]; | 94 uintptr_t pcs[kNumStackFrames]; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 102 public: | 105 public: |
| 103 static const intptr_t kDefaultBufferCapacity = 120000; // 2 minutes @ 1000hz. | 106 static const intptr_t kDefaultBufferCapacity = 120000; // 2 minutes @ 1000hz. |
| 104 | 107 |
| 105 explicit SampleBuffer(intptr_t capacity = kDefaultBufferCapacity); | 108 explicit SampleBuffer(intptr_t capacity = kDefaultBufferCapacity); |
| 106 ~SampleBuffer(); | 109 ~SampleBuffer(); |
| 107 | 110 |
| 108 intptr_t capacity() const { return capacity_; } | 111 intptr_t capacity() const { return capacity_; } |
| 109 | 112 |
| 110 Sample* ReserveSample(); | 113 Sample* ReserveSample(); |
| 111 | 114 |
| 112 Sample* GetSample(intptr_t i) const { | 115 Sample GetSample(intptr_t i) const { |
| 113 ASSERT(i >= 0); | 116 ASSERT(i >= 0); |
| 114 ASSERT(i < capacity_); | 117 ASSERT(i < capacity_); |
| 115 return &samples_[i]; | 118 return samples_[i]; |
| 116 } | 119 } |
| 117 | 120 |
| 118 private: | 121 private: |
| 119 Sample* samples_; | 122 Sample* samples_; |
| 120 intptr_t capacity_; | 123 intptr_t capacity_; |
| 121 uintptr_t cursor_; | 124 uintptr_t cursor_; |
| 122 | 125 |
| 123 DISALLOW_COPY_AND_ASSIGN(SampleBuffer); | 126 DISALLOW_COPY_AND_ASSIGN(SampleBuffer); |
| 124 }; | 127 }; |
| 125 | 128 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 149 const uintptr_t original_pc_; | 152 const uintptr_t original_pc_; |
| 150 const uintptr_t original_fp_; | 153 const uintptr_t original_fp_; |
| 151 const uintptr_t original_sp_; | 154 const uintptr_t original_sp_; |
| 152 uintptr_t lower_bound_; | 155 uintptr_t lower_bound_; |
| 153 }; | 156 }; |
| 154 | 157 |
| 155 | 158 |
| 156 } // namespace dart | 159 } // namespace dart |
| 157 | 160 |
| 158 #endif // VM_PROFILER_H_ | 161 #endif // VM_PROFILER_H_ |
| OLD | NEW |