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

Unified 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, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/runtime/dart_sdk.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..49dd7be62a15c18c657dbde47809140edd57e52c 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);
+
// 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());
+
let originalFunction = $f;
if (!($f instanceof Function)) {
// We're not a function (and hence not a method either)
@@ -157,9 +162,80 @@ 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();
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.
+
+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.
+ String key;
+ num count;
+ 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.
+ num total_pct_div_n;
+
+ ProfileEntry(this.key, this.count, this.total_pct, this.total_pct_div_n);
+}
+
+dumpDynamicStats() {
+ List<ProfileEntry> ret = new List();
+ //StringBuffer sb = new StringBuffer();
+ //sb.write("Stats:");
Jacob 2016/06/01 01:23:17 remove commented out lines.
priscillalee 2016/06/01 20:38:09 Acknowledged.
+ var keys = callMethodStats.keys.toList();
+ 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.
+ for (var val in callMethodStats.values) {
+ total += val;
+ }
+
+ keys.sort((a, b) => callMethodStats[b].compareTo(callMethodStats[a]));
+ num sum = 0;
+ //sb.write('name, count, total%, total%\n');
+ //sb.write('<all>, $total, 100.00%, 100.0%\n');
+ for (var key in keys) {
+ int count = callMethodStats[key];
+ sum += count;
+ ret.add(new ProfileEntry(key, count, count/total*100, sum/total*100));
+ //sb.write(
+ //"$key, $count, ${(count/total*100).toStringAsFixed(2)}%, ${(sum/total*100).toStringAsFixed(2)}%\n");
+ }
+ //print(sb.toString());
+ return ret;
+}
+
+clearDynamicStats() {
+ callMethodStats.clear();
+}
+
+bool _track_profile = false;
Jacob 2016/06/01 01:23:17 this should be named _trackProfile.
priscillalee 2016/06/01 20:38:09 Acknowledged.
+
+set trackProfile(bool b) {
+ _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.
+}
+
+get trackProfile => _track_profile;
+
+_trackCall(obj, name, displayName) {
+ if (!_track_profile) return;
+
+ var actual = getReifiedType(obj);
+ 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.
+ var stack = stackStr.split('\n at ');
+ String 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);
« 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