Chromium Code Reviews| Index: tool/input_sdk/private/ddc_runtime/operations.dart |
| diff --git a/tool/input_sdk/private/ddc_runtime/operations.dart b/tool/input_sdk/private/ddc_runtime/operations.dart |
| index 92f62e2ba2a968c8ec46fb76989d01db13f42f22..967e1ea61fa83e73b980b2516b37128d816d0cff 100644 |
| --- a/tool/input_sdk/private/ddc_runtime/operations.dart |
| +++ b/tool/input_sdk/private/ddc_runtime/operations.dart |
| @@ -17,6 +17,7 @@ _canonicalFieldName(obj, name, args, displayName) => JS('', '''(() => { |
| })()'''); |
| dload(obj, field) => JS('', '''(() => { |
| + $_trackCall(obj, $field, null); |
| $field = $_canonicalFieldName($obj, $field, [], $field); |
| if ($hasMethod($obj, $field)) { |
| return $bind($obj, $field); |
| @@ -31,6 +32,8 @@ dload(obj, field) => JS('', '''(() => { |
| dput(obj, field, value) => JS('', '''(() => { |
| $field = $_canonicalFieldName($obj, $field, [$value], $field); |
| + $_trackCall(obj, $field, null); |
|
Leaf
2016/06/01 21:47:11
Why is tracking for this done on the canonical nam
priscillalee
2016/06/01 23:32:15
Thanks for catching that. Fixed tracking to be on
|
| + |
| // TODO(vsm): Implement NSM and type checks. |
| // See: https://github.com/dart-lang/dev_compiler/issues/170 |
| $obj[$field] = $value; |
| @@ -88,6 +91,8 @@ throwNoSuchMethodFunc(obj, name, pArgs, opt_func) => JS('', '''(() => { |
| })()'''); |
| _checkAndCall(f, ftype, obj, typeArgs, args, name) => JS('', '''(() => { |
| + $_trackCall(obj, name, f.toString()); |
|
Leaf
2016/06/01 21:47:11
I think this double counts, since callMethod uses
priscillalee
2016/06/01 23:32:15
Removed _trackCall from _callMethod, so there's no
Leaf
2016/06/01 23:59:43
I missed this the first time, but the f.toString()
priscillalee
2016/06/02 16:19:48
Removed f.toString().
|
| + |
| let originalFunction = $f; |
| if (!($f instanceof Function)) { |
| // We're not a function (and hence not a method either) |
| @@ -157,9 +162,67 @@ dcall(f, @rest args) => _checkAndCall( |
| dgcall(f, typeArgs, @rest args) => _checkAndCall( |
| f, _getRuntimeType(f), JS('', 'void 0'), typeArgs, args, 'call'); |
| +Map<String, int> _callMethodStats = new Map(); |
| + |
| +class ProfileEntry { |
| + final String key; |
| + final num count; |
| + |
| + ProfileEntry(this.key, this.count); |
| +} |
| + |
| +List<ProfileEntry> getDynamicStats() { |
| + List<ProfileEntry> ret = new List(); |
| + |
| + var keys = _callMethodStats.keys.toList(); |
| + |
| + keys.sort((a, b) => _callMethodStats[b].compareTo(_callMethodStats[a])); |
| + for (var key in keys) { |
| + int count = _callMethodStats[key]; |
| + ret.add(new ProfileEntry(key, count)); |
| + } |
| + |
| + return ret; |
| +} |
| + |
| +clearDynamicStats() { |
| + _callMethodStats.clear(); |
| +} |
| + |
| +bool _trackProfile = false; |
| + |
| +set trackProfile(bool value) { |
| + _trackProfile = value; |
| +} |
| + |
| +get trackProfile => _trackProfile; |
| + |
| +_trackCall(obj, name, displayName) { |
|
Leaf
2016/06/01 23:59:43
Is displayName unused?
Jacob
2016/06/02 00:10:28
It is unused.
priscillalee
2016/06/02 16:19:48
Removed displayName.
|
| + if (!_trackProfile) return; |
|
Leaf
2016/06/01 21:47:11
Can we make this inline JS to avoid the pointless
priscillalee
2016/06/01 23:32:15
Done.
|
| + |
| + var actual = getReifiedType(obj); |
| + String stackStr = JS('String', "new Error().stack"); |
| + var stack = stackStr.split('\n at '); |
| + var src = ''; |
| + for (int i = 2; i < stack.length; ++i) { |
| + var frame = stack[i]; |
| + if (!frame.contains('dev_compiler/lib/runtime/dart_sdk.js')) { |
| + src = frame; |
| + break; |
| + } |
| + } |
| + |
| + name = "${typeName(actual)}.$name <$src>"; |
| + if (_callMethodStats.containsKey(name)) { |
| + _callMethodStats[name] = _callMethodStats[name] + 1; |
| + } else { |
| + _callMethodStats[name] = 1; |
| + } |
| +} |
| /// Shared code for dsend, dindex, and dsetindex. |
| _callMethod(obj, name, typeArgs, args, displayName) { |
| + _trackCall(obj, name, displayName); |
| var symbol = _canonicalFieldName(obj, name, args, displayName); |
| var f = obj != null ? JS('', '#[#]', obj, symbol) : null; |
| var ftype = getMethodType(obj, symbol); |