OLD | NEW |
---|---|
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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_SERVICE_H_ | 5 #ifndef RUNTIME_VM_PROFILER_SERVICE_H_ |
6 #define RUNTIME_VM_PROFILER_SERVICE_H_ | 6 #define RUNTIME_VM_PROFILER_SERVICE_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/growable_array.h" | 11 #include "vm/growable_array.h" |
12 #include "vm/hash_map.h" | |
12 #include "vm/object.h" | 13 #include "vm/object.h" |
13 #include "vm/tags.h" | 14 #include "vm/tags.h" |
14 #include "vm/thread_interrupter.h" | 15 #include "vm/thread_interrupter.h" |
15 #include "vm/token_position.h" | 16 #include "vm/token_position.h" |
16 | 17 |
17 // CPU Profile model and service protocol bits. | 18 // CPU Profile model and service protocol bits. |
18 // NOTE: For sampling and stack walking related code, see profiler.h. | 19 // NOTE: For sampling and stack walking related code, see profiler.h. |
19 | 20 |
20 namespace dart { | 21 namespace dart { |
21 | 22 |
22 // Forward declarations. | 23 // Forward declarations. |
23 class Code; | 24 class Code; |
24 class Function; | 25 class Function; |
25 class JSONArray; | 26 class JSONArray; |
26 class JSONStream; | 27 class JSONStream; |
27 class ProfileFunctionTable; | 28 class ProfileFunctionTable; |
28 class ProfileCodeTable; | 29 class ProfileCodeTable; |
29 class RawCode; | 30 class RawCode; |
30 class RawFunction; | 31 class RawFunction; |
31 class SampleFilter; | 32 class SampleFilter; |
33 class ProcessedSample; | |
32 class ProcessedSampleBuffer; | 34 class ProcessedSampleBuffer; |
33 | 35 |
34 class ProfileFunctionSourcePosition { | 36 class ProfileFunctionSourcePosition { |
35 public: | 37 public: |
36 explicit ProfileFunctionSourcePosition(TokenPosition token_pos); | 38 explicit ProfileFunctionSourcePosition(TokenPosition token_pos); |
37 | 39 |
38 void Tick(bool exclusive); | 40 void Tick(bool exclusive); |
39 | 41 |
40 TokenPosition token_pos() const { return token_pos_; } | 42 TokenPosition token_pos() const { return token_pos_; } |
41 intptr_t exclusive_ticks() const { return exclusive_ticks_; } | 43 intptr_t exclusive_ticks() const { return exclusive_ticks_; } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 const Function* function() const { return &function_; } | 78 const Function* function() const { return &function_; } |
77 | 79 |
78 bool is_visible() const; | 80 bool is_visible() const; |
79 | 81 |
80 intptr_t table_index() const { return table_index_; } | 82 intptr_t table_index() const { return table_index_; } |
81 | 83 |
82 Kind kind() const { return kind_; } | 84 Kind kind() const { return kind_; } |
83 | 85 |
84 intptr_t exclusive_ticks() const { return exclusive_ticks_; } | 86 intptr_t exclusive_ticks() const { return exclusive_ticks_; } |
85 intptr_t inclusive_ticks() const { return inclusive_ticks_; } | 87 intptr_t inclusive_ticks() const { return inclusive_ticks_; } |
86 | |
87 void IncInclusiveTicks() { inclusive_ticks_++; } | 88 void IncInclusiveTicks() { inclusive_ticks_++; } |
88 | |
89 void Tick(bool exclusive, | 89 void Tick(bool exclusive, |
90 intptr_t inclusive_serial, | 90 intptr_t inclusive_serial, |
91 TokenPosition token_position); | 91 TokenPosition token_position); |
92 | 92 |
93 bool contains_native_allocation() const { | |
94 return contains_native_allocation_; | |
Cutch
2017/03/21 20:27:11
is this used anywhere? why is it needed?
bkonyi
2017/03/22 21:25:21
Apparently not. Removed.
| |
95 } | |
96 | |
93 static const char* KindToCString(Kind kind); | 97 static const char* KindToCString(Kind kind); |
94 | 98 |
95 void PrintToJSONArray(JSONArray* functions); | 99 void PrintToJSONArray(JSONArray* functions); |
96 | 100 |
97 // Returns true if the call was successful and |pfsp| is set. | 101 // Returns true if the call was successful and |pfsp| is set. |
98 bool GetSinglePosition(ProfileFunctionSourcePosition* pfsp); | 102 bool GetSinglePosition(ProfileFunctionSourcePosition* pfsp); |
99 | 103 |
100 void TickSourcePosition(TokenPosition token_position, bool exclusive); | 104 void TickSourcePosition(TokenPosition token_position, bool exclusive); |
101 | 105 |
102 intptr_t NumSourcePositions() const { | 106 intptr_t NumSourcePositions() const { |
103 return source_position_ticks_.length(); | 107 return source_position_ticks_.length(); |
104 } | 108 } |
105 | 109 |
106 const ProfileFunctionSourcePosition& GetSourcePosition(intptr_t i) const { | 110 const ProfileFunctionSourcePosition& GetSourcePosition(intptr_t i) const { |
107 return source_position_ticks_.At(i); | 111 return source_position_ticks_.At(i); |
108 } | 112 } |
109 | 113 |
110 private: | 114 private: |
111 const Kind kind_; | 115 const Kind kind_; |
112 const char* name_; | 116 const char* name_; |
113 const Function& function_; | 117 const Function& function_; |
114 const intptr_t table_index_; | 118 const intptr_t table_index_; |
115 ZoneGrowableArray<intptr_t> profile_codes_; | 119 ZoneGrowableArray<intptr_t> profile_codes_; |
116 ZoneGrowableArray<ProfileFunctionSourcePosition> source_position_ticks_; | 120 ZoneGrowableArray<ProfileFunctionSourcePosition> source_position_ticks_; |
117 | 121 |
118 intptr_t exclusive_ticks_; | 122 intptr_t exclusive_ticks_; |
119 intptr_t inclusive_ticks_; | 123 intptr_t inclusive_ticks_; |
120 intptr_t inclusive_serial_; | 124 intptr_t inclusive_serial_; |
121 | 125 |
126 bool contains_native_allocation_; | |
127 | |
122 void PrintToJSONObject(JSONObject* func); | 128 void PrintToJSONObject(JSONObject* func); |
123 // A |ProfileCode| that contains this function. | 129 // A |ProfileCode| that contains this function. |
124 void AddProfileCode(intptr_t code_table_index); | 130 void AddProfileCode(intptr_t code_table_index); |
125 | 131 |
126 friend class ProfileCode; | 132 friend class ProfileCode; |
127 friend class ProfileBuilder; | 133 friend class ProfileBuilder; |
128 }; | 134 }; |
129 | 135 |
130 | 136 |
131 class ProfileCodeAddress { | 137 class ProfileCodeAddress { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 exclusive_ticks_ = exclusive_ticks; | 192 exclusive_ticks_ = exclusive_ticks; |
187 } | 193 } |
188 void IncExclusiveTicks() { exclusive_ticks_++; } | 194 void IncExclusiveTicks() { exclusive_ticks_++; } |
189 | 195 |
190 intptr_t inclusive_ticks() const { return inclusive_ticks_; } | 196 intptr_t inclusive_ticks() const { return inclusive_ticks_; } |
191 void set_inclusive_ticks(intptr_t inclusive_ticks) { | 197 void set_inclusive_ticks(intptr_t inclusive_ticks) { |
192 inclusive_ticks_ = inclusive_ticks; | 198 inclusive_ticks_ = inclusive_ticks; |
193 } | 199 } |
194 void IncInclusiveTicks() { inclusive_ticks_++; } | 200 void IncInclusiveTicks() { inclusive_ticks_++; } |
195 | 201 |
202 bool contains_native_allocation() const { | |
203 return contains_native_allocation_; | |
204 } | |
205 | |
196 bool IsOptimizedDart() const; | 206 bool IsOptimizedDart() const; |
197 RawCode* code() const { return code_.raw(); } | 207 RawCode* code() const { return code_.raw(); } |
198 | 208 |
199 const char* name() const { return name_; } | 209 const char* name() const { return name_; } |
200 void SetName(const char* name); | 210 void SetName(const char* name); |
201 void GenerateAndSetSymbolName(const char* prefix); | 211 void GenerateAndSetSymbolName(const char* prefix); |
202 | 212 |
203 static const char* KindToCString(Kind kind); | 213 static const char* KindToCString(Kind kind); |
204 | 214 |
205 void PrintToJSONArray(JSONArray* codes); | 215 void PrintToJSONArray(JSONArray* codes); |
(...skipping 14 matching lines...) Expand all Loading... | |
220 void set_code_table_index(intptr_t index) { code_table_index_ = index; } | 230 void set_code_table_index(intptr_t index) { code_table_index_ = index; } |
221 intptr_t code_table_index() const { return code_table_index_; } | 231 intptr_t code_table_index() const { return code_table_index_; } |
222 | 232 |
223 const Kind kind_; | 233 const Kind kind_; |
224 uword start_; | 234 uword start_; |
225 uword end_; | 235 uword end_; |
226 intptr_t exclusive_ticks_; | 236 intptr_t exclusive_ticks_; |
227 intptr_t inclusive_ticks_; | 237 intptr_t inclusive_ticks_; |
228 intptr_t inclusive_serial_; | 238 intptr_t inclusive_serial_; |
229 | 239 |
240 bool contains_native_allocation_; | |
241 | |
230 const Code& code_; | 242 const Code& code_; |
231 char* name_; | 243 char* name_; |
232 int64_t compile_timestamp_; | 244 int64_t compile_timestamp_; |
233 ProfileFunction* function_; | 245 ProfileFunction* function_; |
234 intptr_t code_table_index_; | 246 intptr_t code_table_index_; |
235 ZoneGrowableArray<ProfileCodeAddress> address_ticks_; | 247 ZoneGrowableArray<ProfileCodeAddress> address_ticks_; |
236 | 248 |
237 friend class ProfileBuilder; | 249 friend class ProfileBuilder; |
238 }; | 250 }; |
239 | 251 |
(...skipping 10 matching lines...) Expand all Loading... | |
250 explicit ProfileTrieNode(intptr_t index); | 262 explicit ProfileTrieNode(intptr_t index); |
251 virtual ~ProfileTrieNode(); | 263 virtual ~ProfileTrieNode(); |
252 | 264 |
253 virtual void PrintToJSONArray(JSONArray* array) const = 0; | 265 virtual void PrintToJSONArray(JSONArray* array) const = 0; |
254 | 266 |
255 // Index into function or code tables. | 267 // Index into function or code tables. |
256 intptr_t table_index() const { return table_index_; } | 268 intptr_t table_index() const { return table_index_; } |
257 | 269 |
258 intptr_t count() const { return count_; } | 270 intptr_t count() const { return count_; } |
259 | 271 |
260 void Tick() { count_++; } | 272 void Tick(ProcessedSample* sample, bool exclusive = false); |
273 | |
274 void IncrementAllocation(intptr_t allocation, bool exclusive) { | |
275 ASSERT(allocation >= 0); | |
276 if (exclusive) { | |
277 exclusive_allocations_ += allocation; | |
278 } | |
279 inclusive_allocations_ += allocation; | |
280 } | |
261 | 281 |
262 intptr_t NumChildren() const { return children_.length(); } | 282 intptr_t NumChildren() const { return children_.length(); } |
263 | 283 |
264 ProfileTrieNode* At(intptr_t i) { return children_.At(i); } | 284 ProfileTrieNode* At(intptr_t i) { return children_.At(i); } |
265 | 285 |
266 intptr_t IndexOf(ProfileTrieNode* node); | 286 intptr_t IndexOf(ProfileTrieNode* node); |
267 | 287 |
268 intptr_t frame_id() const { return frame_id_; } | 288 intptr_t frame_id() const { return frame_id_; } |
269 void set_frame_id(intptr_t id) { | 289 void set_frame_id(intptr_t id) { |
270 ASSERT(frame_id_ == -1); | 290 ASSERT(frame_id_ == -1); |
271 frame_id_ = id; | 291 frame_id_ = id; |
272 } | 292 } |
273 | 293 |
274 protected: | 294 protected: |
275 void SortChildren(); | 295 void SortChildren(); |
276 | 296 |
277 static int ProfileTrieNodeCompare(ProfileTrieNode* const* a, | 297 static int ProfileTrieNodeCompare(ProfileTrieNode* const* a, |
278 ProfileTrieNode* const* b) { | 298 ProfileTrieNode* const* b) { |
279 ASSERT(a != NULL); | 299 ASSERT(a != NULL); |
280 ASSERT(b != NULL); | 300 ASSERT(b != NULL); |
281 return (*b)->count() - (*a)->count(); | 301 return (*b)->count() - (*a)->count(); |
282 } | 302 } |
283 | 303 |
284 | 304 |
285 intptr_t table_index_; | 305 intptr_t table_index_; |
286 intptr_t count_; | 306 intptr_t count_; |
307 intptr_t exclusive_allocations_; | |
308 intptr_t inclusive_allocations_; | |
287 ZoneGrowableArray<ProfileTrieNode*> children_; | 309 ZoneGrowableArray<ProfileTrieNode*> children_; |
288 intptr_t frame_id_; | 310 intptr_t frame_id_; |
289 | 311 |
290 friend class ProfileBuilder; | 312 friend class ProfileBuilder; |
291 }; | 313 }; |
292 | 314 |
293 | 315 |
294 // The model for a profile. Most of the model is zone allocated, therefore | 316 // The model for a profile. Most of the model is zone allocated, therefore |
295 // a zone must be created that lives longer than this object. | 317 // a zone must be created that lives longer than this object. |
296 class Profile : public ValueObject { | 318 class Profile : public ValueObject { |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
436 JSONStream* stream, | 458 JSONStream* stream, |
437 Profile::TagOrder tag_order, | 459 Profile::TagOrder tag_order, |
438 intptr_t extra_tags, | 460 intptr_t extra_tags, |
439 SampleFilter* filter, | 461 SampleFilter* filter, |
440 bool as_timline); | 462 bool as_timline); |
441 }; | 463 }; |
442 | 464 |
443 } // namespace dart | 465 } // namespace dart |
444 | 466 |
445 #endif // RUNTIME_VM_PROFILER_SERVICE_H_ | 467 #endif // RUNTIME_VM_PROFILER_SERVICE_H_ |
OLD | NEW |