OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 #ifndef VM_PROFILER_H_ | |
6 #define VM_PROFILER_H_ | |
7 | |
8 #include "platform/hashmap.h" | |
9 #include "platform/thread.h" | |
10 #include "vm/allocation.h" | |
11 #include "vm/code_observers.h" | |
12 #include "vm/globals.h" | |
13 | |
14 namespace dart { | |
15 | |
16 | |
siva
2013/10/28 05:19:21
extra blank line?
Cutch
2013/11/04 20:36:05
Done.
| |
17 // Profiler manager. | |
18 class ProfilerManager : public AllStatic { | |
19 public: | |
20 static void InitOnce(); | |
21 static void Shutdown(); | |
22 | |
23 static void SetupIsolateForProfiling(Isolate* isolate); | |
24 static void ShutdownIsolate(Isolate* isolate); | |
siva
2013/10/28 05:19:21
should be ShutdownIsolateProfiling
ShutdownIsolat
Cutch
2013/11/04 20:36:05
Done.
| |
25 static void ScheduleIsolate(Isolate* isolate); | |
26 static void DescheduleIsolate(Isolate* isolate); | |
27 | |
28 static void PrintToJSONStream(Isolate* isolate, JSONStream* stream); | |
29 | |
30 static void WriteTracing(Isolate* isolate, const char* name, Dart_Port port); | |
31 | |
32 private: | |
33 static bool initialized_; | |
34 static bool shutdown_; | |
35 static Monitor* monitor_; | |
36 | |
37 static Isolate** isolates_; | |
38 static intptr_t isolates_capacity_; | |
39 static intptr_t isolates_size_; | |
40 | |
41 static void ResizeIsolates(intptr_t new_capacity); | |
42 static void AddIsolate(Isolate* isolate); | |
43 static intptr_t FindIsolate(Isolate* isolate); | |
44 static void RemoveIsolate(intptr_t i); | |
45 | |
46 // Returns the microseconds until the next live timer fires. | |
47 static int64_t SampleAndRescheduleIsolates(int64_t current_time); | |
48 static void FreeIsolateProfilingData(Isolate* isolate); | |
49 static void ThreadMain(uword parameters); | |
siva
2013/10/28 05:19:21
DISALLOW_COPY stuff?
Cutch
2013/11/04 20:36:05
Done.
| |
50 }; | |
51 | |
52 | |
53 class IsolateProfilerData { | |
54 public: | |
55 static const int64_t kDescheduledCpuUsage = -1; | |
56 static const int64_t kNoExpirationTime = -2; | |
57 | |
58 IsolateProfilerData(Isolate* isolate, SampleBuffer* sample_buffer); | |
59 ~IsolateProfilerData(); | |
60 | |
61 int64_t sample_interval() const { return sample_interval_micros_; } | |
62 | |
63 void set_sample_interval(int64_t sample_interval) { | |
64 sample_interval_micros_ = sample_interval; | |
65 } | |
66 | |
67 bool CanExpire() { | |
68 return timer_expiration_micros_ != kNoExpirationTime; | |
69 } | |
70 | |
71 bool ShouldSample(int64_t current_time) { | |
72 return CanExpire() && TimeUntilExpiration(current_time) <= 0; | |
73 } | |
74 | |
75 int64_t TimeUntilExpiration(int64_t current_time) { | |
siva
2013/10/28 05:19:21
maybe call it current_time_in_micros?
Cutch
2013/11/04 20:36:05
Done.
| |
76 ASSERT(CanExpire()); | |
77 return timer_expiration_micros_ - current_time; | |
78 } | |
79 | |
80 void set_cpu_usage(int64_t cpu_usage) { | |
81 cpu_usage_ = cpu_usage; | |
82 } | |
83 | |
84 void SampledAt(int64_t current_time); | |
85 | |
86 void Scheduled(int64_t current_time, ThreadId thread); | |
87 | |
88 void Descheduled(); | |
89 | |
90 int64_t cpu_usage() const { return cpu_usage_; } | |
91 | |
92 int64_t set_and_delta_cpu_usage(int64_t cpu_usage) { | |
93 int64_t delta = 0; | |
94 if (cpu_usage_ != kDescheduledCpuUsage) { | |
95 // Only compute the real delta if we are being sampled regularly. | |
96 delta = cpu_usage - cpu_usage_; | |
97 } | |
98 set_cpu_usage(cpu_usage); | |
99 return delta; | |
100 } | |
101 | |
102 ThreadId thread_id() const { return thread_id_; } | |
103 | |
104 Isolate* isolate() const { return isolate_; } | |
105 | |
106 SampleBuffer* sample_buffer() const { return sample_buffer_; } | |
107 | |
108 private: | |
109 int64_t last_sampled_micros_; | |
110 int64_t timer_expiration_micros_; | |
111 int64_t sample_interval_micros_; | |
112 int64_t cpu_usage_; | |
113 ThreadId thread_id_; | |
114 Isolate* isolate_; | |
115 SampleBuffer* sample_buffer_; | |
siva
2013/10/28 05:19:21
DISALLOW stuff.
Cutch
2013/11/04 20:36:05
Done.
| |
116 }; | |
117 | |
118 | |
119 // Profile sample. | |
120 struct Sample { | |
121 static const char* kLookupSymbol; | |
122 static const char* kNoSymbol; | |
123 static const intptr_t kNumStackFrames = 4; | |
124 enum SampleState { | |
125 kIdle = 0, | |
126 kExecuting = 1, | |
127 kNumSampleStates | |
128 }; | |
129 int64_t timestamp; | |
130 int64_t cpu_usage; | |
131 uintptr_t pcs[kNumStackFrames]; | |
132 uint16_t vm_tags; | |
133 uint16_t runtime_tags; | |
134 Sample(); | |
135 }; | |
136 | |
137 | |
138 // Ring buffer of samples. One per isolate. | |
139 class SampleBuffer { | |
140 public: | |
141 static const intptr_t kDefaultBufferCapacity = 1000000; | |
142 | |
143 explicit SampleBuffer(intptr_t capacity = kDefaultBufferCapacity); | |
144 ~SampleBuffer(); | |
145 | |
146 intptr_t capacity() const { return capacity_; } | |
147 | |
148 Sample* ReserveSample(); | |
149 | |
150 Sample* FirstSample() const; | |
151 Sample* NextSample(Sample* sample) const; | |
152 Sample* LastSample() const; | |
153 private: | |
154 Sample* samples_; | |
155 intptr_t capacity_; | |
156 intptr_t start_; | |
157 intptr_t end_; | |
158 | |
159 intptr_t WrapIncrement(intptr_t i) const; | |
siva
2013/10/28 05:19:21
DISALLOW_ stuff.
Cutch
2013/11/04 20:36:05
Done.
| |
160 }; | |
161 | |
162 | |
siva
2013/10/28 05:19:21
extra blank line?
Cutch
2013/11/04 20:36:05
Done.
| |
163 } // namespace dart | |
164 | |
165 #endif // VM_PROFILER_H_ | |
OLD | NEW |