Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: tool/input_sdk/private/ddc_runtime/operations.dart

Issue 2024353002: Profile dynamic calls. (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/runtime/dart_sdk.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 /// This library defines runtime operations on objects used by the code 5 /// This library defines runtime operations on objects used by the code
6 /// generator. 6 /// generator.
7 part of dart._runtime; 7 part of dart._runtime;
8 8
9 _canonicalFieldName(obj, name, args, displayName) => JS('', '''(() => { 9 _canonicalFieldName(obj, name, args, displayName) => JS('', '''(() => {
10 $name = $canonicalMember($obj, $name); 10 $name = $canonicalMember($obj, $name);
11 if ($name) return $name; 11 if ($name) return $name;
12 // TODO(jmesserly): in the future we might have types that "overlay" Dart 12 // TODO(jmesserly): in the future we might have types that "overlay" Dart
13 // methods while also exposing the full native API, e.g. dart:html vs 13 // methods while also exposing the full native API, e.g. dart:html vs
14 // dart:dom. To support that we'd need to fall back to the normal name 14 // dart:dom. To support that we'd need to fall back to the normal name
15 // if an extension method wasn't found. 15 // if an extension method wasn't found.
16 $throwNoSuchMethodFunc($obj, $displayName, $args); 16 $throwNoSuchMethodFunc($obj, $displayName, $args);
17 })()'''); 17 })()''');
18 18
19 dload(obj, field) => JS('', '''(() => { 19 dload(obj, field) => JS('', '''(() => {
20 $_trackCall(obj, $field, null);
20 $field = $_canonicalFieldName($obj, $field, [], $field); 21 $field = $_canonicalFieldName($obj, $field, [], $field);
21 if ($hasMethod($obj, $field)) { 22 if ($hasMethod($obj, $field)) {
22 return $bind($obj, $field); 23 return $bind($obj, $field);
23 } 24 }
24 // TODO(vsm): Implement NSM robustly. An 'in' check breaks on certain 25 // TODO(vsm): Implement NSM robustly. An 'in' check breaks on certain
25 // types. hasOwnProperty doesn't chase the proto chain. 26 // types. hasOwnProperty doesn't chase the proto chain.
26 // Also, do we want an NSM on regular JS objects? 27 // Also, do we want an NSM on regular JS objects?
27 // See: https://github.com/dart-lang/dev_compiler/issues/169 28 // See: https://github.com/dart-lang/dev_compiler/issues/169
28 let result = $obj[$field]; 29 let result = $obj[$field];
29 return result; 30 return result;
30 })()'''); 31 })()''');
31 32
32 dput(obj, field, value) => JS('', '''(() => { 33 dput(obj, field, value) => JS('', '''(() => {
33 $field = $_canonicalFieldName($obj, $field, [$value], $field); 34 $field = $_canonicalFieldName($obj, $field, [$value], $field);
35 $_trackCall(obj, $field, null);
36
34 // TODO(vsm): Implement NSM and type checks. 37 // TODO(vsm): Implement NSM and type checks.
35 // See: https://github.com/dart-lang/dev_compiler/issues/170 38 // See: https://github.com/dart-lang/dev_compiler/issues/170
36 $obj[$field] = $value; 39 $obj[$field] = $value;
37 return $value; 40 return $value;
38 })()'''); 41 })()''');
39 42
40 /// Check that a function of a given type can be applied to 43 /// Check that a function of a given type can be applied to
41 /// actuals. 44 /// actuals.
42 _checkApply(type, actuals) => JS('', '''(() => { 45 _checkApply(type, actuals) => JS('', '''(() => {
43 if ($actuals.length < $type.args.length) return false; 46 if ($actuals.length < $type.args.length) return false;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 throwNoSuchMethod(obj, name, pArgs, nArgs, extras) => JS('', '''(() => { 84 throwNoSuchMethod(obj, name, pArgs, nArgs, extras) => JS('', '''(() => {
82 $throw_(new $NoSuchMethodError($obj, $_dartSymbol($name), $pArgs, $nArgs, $ext ras)); 85 $throw_(new $NoSuchMethodError($obj, $_dartSymbol($name), $pArgs, $nArgs, $ext ras));
83 })()'''); 86 })()''');
84 87
85 throwNoSuchMethodFunc(obj, name, pArgs, opt_func) => JS('', '''(() => { 88 throwNoSuchMethodFunc(obj, name, pArgs, opt_func) => JS('', '''(() => {
86 if ($obj === void 0) $obj = $opt_func; 89 if ($obj === void 0) $obj = $opt_func;
87 $throwNoSuchMethod($obj, $name, $pArgs); 90 $throwNoSuchMethod($obj, $name, $pArgs);
88 })()'''); 91 })()''');
89 92
90 _checkAndCall(f, ftype, obj, typeArgs, args, name) => JS('', '''(() => { 93 _checkAndCall(f, ftype, obj, typeArgs, args, name) => JS('', '''(() => {
94 $_trackCall(obj, name, f.toString());
95
91 let originalFunction = $f; 96 let originalFunction = $f;
92 if (!($f instanceof Function)) { 97 if (!($f instanceof Function)) {
93 // We're not a function (and hence not a method either) 98 // We're not a function (and hence not a method either)
94 // Grab the `call` method if it's not a function. 99 // Grab the `call` method if it's not a function.
95 if ($f != null) { 100 if ($f != null) {
96 $ftype = $getMethodType($f, 'call'); 101 $ftype = $getMethodType($f, 'call');
97 $f = $f.call; 102 $f = $f.call;
98 } 103 }
99 if (!($f instanceof Function)) { 104 if (!($f instanceof Function)) {
100 $throwNoSuchMethodFunc($obj, $name, $args, originalFunction); 105 $throwNoSuchMethodFunc($obj, $name, $args, originalFunction);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 $throwNoSuchMethodFunc($obj, $name, $args, originalFunction); 155 $throwNoSuchMethodFunc($obj, $name, $args, originalFunction);
151 })()'''); 156 })()''');
152 157
153 dcall(f, @rest args) => _checkAndCall( 158 dcall(f, @rest args) => _checkAndCall(
154 f, _getRuntimeType(f), JS('', 'void 0'), null, args, 'call'); 159 f, _getRuntimeType(f), JS('', 'void 0'), null, args, 'call');
155 160
156 161
157 dgcall(f, typeArgs, @rest args) => _checkAndCall( 162 dgcall(f, typeArgs, @rest args) => _checkAndCall(
158 f, _getRuntimeType(f), JS('', 'void 0'), typeArgs, args, 'call'); 163 f, _getRuntimeType(f), JS('', 'void 0'), typeArgs, args, 'call');
159 164
165 Map<String, int> callMethodStats = new Map();
Jacob 2016/06/01 01:23:17 this one is my fault but fix it anyway :) change t
priscillalee 2016/06/01 20:38:09 Acknowledged.
166
167 class ProfileEntry {
Jacob 2016/06/01 01:23:17 you can make all fields in this class final. E.g.
priscillalee 2016/06/01 20:38:09 Acknowledged.
168 String key;
169 num count;
170 num total_pct;
Jacob 2016/06/01 01:23:17 See the dart style guide for naming members. https
priscillalee 2016/06/01 20:38:09 Acknowledged.
171 num total_pct_div_n;
172
173 ProfileEntry(this.key, this.count, this.total_pct, this.total_pct_div_n);
174 }
175
176 dumpDynamicStats() {
177 List<ProfileEntry> ret = new List();
178 //StringBuffer sb = new StringBuffer();
179 //sb.write("Stats:");
Jacob 2016/06/01 01:23:17 remove commented out lines.
priscillalee 2016/06/01 20:38:09 Acknowledged.
180 var keys = callMethodStats.keys.toList();
181 num total = 0;
Jacob 2016/06/01 01:23:17 you can remove total now that we are calculating i
priscillalee 2016/06/01 20:38:09 thanks, I also removed sum.
182 for (var val in callMethodStats.values) {
183 total += val;
184 }
185
186 keys.sort((a, b) => callMethodStats[b].compareTo(callMethodStats[a]));
187 num sum = 0;
188 //sb.write('name, count, total%, total%\n');
189 //sb.write('<all>, $total, 100.00%, 100.0%\n');
190 for (var key in keys) {
191 int count = callMethodStats[key];
192 sum += count;
193 ret.add(new ProfileEntry(key, count, count/total*100, sum/total*100));
194 //sb.write(
195 //"$key, $count, ${(count/total*100).toStringAsFixed(2)}%, ${(sum/total* 100).toStringAsFixed(2)}%\n");
196 }
197 //print(sb.toString());
198 return ret;
199 }
200
201 clearDynamicStats() {
202 callMethodStats.clear();
203 }
204
205 bool _track_profile = false;
Jacob 2016/06/01 01:23:17 this should be named _trackProfile.
priscillalee 2016/06/01 20:38:09 Acknowledged.
206
207 set trackProfile(bool b) {
208 _track_profile = b;
Jacob 2016/06/01 01:23:17 nit: change this from bool v to bool value
priscillalee 2016/06/01 20:38:09 Acknowledged.
209 }
210
211 get trackProfile => _track_profile;
212
213 _trackCall(obj, name, displayName) {
214 if (!_track_profile) return;
215
216 var actual = getReifiedType(obj);
217 String stackStr = JS('String', "new Error().stack");
Jacob 2016/06/01 01:23:17 add // TODO(jacobr): pass caller information in in
priscillalee 2016/06/01 20:38:09 Acknowledged.
218 var stack = stackStr.split('\n at ');
219 String src = '';
220 for (int i = 2; i < stack.length; ++i) {
221 var frame = stack[i];
222 if (!frame.contains('dev_compiler/lib/runtime/dart_sdk.js')) {
223 src = frame;
224 break;
225 }
226 }
227
228 name = "${typeName(actual)}.$name <$src>";
229 if (callMethodStats.containsKey(name)) {
230 callMethodStats[name] = callMethodStats[name] + 1;
231 } else {
232 callMethodStats[name] = 1;
233 }
234 }
160 235
161 /// Shared code for dsend, dindex, and dsetindex. 236 /// Shared code for dsend, dindex, and dsetindex.
162 _callMethod(obj, name, typeArgs, args, displayName) { 237 _callMethod(obj, name, typeArgs, args, displayName) {
238 _trackCall(obj, name, displayName);
163 var symbol = _canonicalFieldName(obj, name, args, displayName); 239 var symbol = _canonicalFieldName(obj, name, args, displayName);
164 var f = obj != null ? JS('', '#[#]', obj, symbol) : null; 240 var f = obj != null ? JS('', '#[#]', obj, symbol) : null;
165 var ftype = getMethodType(obj, symbol); 241 var ftype = getMethodType(obj, symbol);
166 return _checkAndCall(f, ftype, obj, typeArgs, args, displayName); 242 return _checkAndCall(f, ftype, obj, typeArgs, args, displayName);
167 } 243 }
168 244
169 dsend(obj, method, @rest args) => _callMethod(obj, method, null, args, method); 245 dsend(obj, method, @rest args) => _callMethod(obj, method, null, args, method);
170 246
171 dgsend(obj, typeArgs, method, @rest args) => 247 dgsend(obj, typeArgs, method, @rest args) =>
172 _callMethod(obj, method, typeArgs, args, method); 248 _callMethod(obj, method, typeArgs, args, method);
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 constructor(dartIterator) { 663 constructor(dartIterator) {
588 this.dartIterator = dartIterator; 664 this.dartIterator = dartIterator;
589 } 665 }
590 next() { 666 next() {
591 let i = this.dartIterator; 667 let i = this.dartIterator;
592 let done = !i.moveNext(); 668 let done = !i.moveNext();
593 return { done: done, value: done ? void 0 : i.current }; 669 return { done: done, value: done ? void 0 : i.current };
594 } 670 }
595 } 671 }
596 '''); 672 ''');
OLDNEW
« no previous file with comments | « lib/runtime/dart_sdk.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698