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

Side by Side Diff: runtime/observatory/test/call_site_data_test.dart

Issue 977283002: Display call site data for functions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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 | Annotate | Revision Log
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 library call_site_data_test; 5 library call_site_data_test;
6 6
7 import 'package:observatory/service_io.dart'; 7 import 'package:observatory/service_io.dart';
8 import 'package:unittest/unittest.dart'; 8 import 'package:unittest/unittest.dart';
9 import 'test_helper.dart'; 9 import 'test_helper.dart';
10 import 'dart:async'; 10 import 'dart:async';
(...skipping 13 matching lines...) Expand all
24 } 24 }
25 polymorphic(fooable) { 25 polymorphic(fooable) {
26 fooable.foo(); 26 fooable.foo();
27 return null; 27 return null;
28 } 28 }
29 megamorphic(fooable) { 29 megamorphic(fooable) {
30 fooable.foo(); 30 fooable.foo();
31 return null; 31 return null;
32 } 32 }
33 33
34 class Static {
35 static staticMethod() => 2;
36 }
37 staticCall() {
38 Static.staticMethod();
39 return null;
40 }
41 constructorCall() {
42 new Static();
43 return null;
44 }
45
34 script() { 46 script() {
35 for (int i = 0; i < 10; i++) monomorphic(new A()); 47 for (int i = 0; i < 10; i++) monomorphic(new A());
36 48
37 for (int i = 0; i < 10; i++) polymorphic(new A()); 49 for (int i = 0; i < 10; i++) polymorphic(new A());
38 for (int i = 0; i < 20; i++) polymorphic(new B()); 50 for (int i = 0; i < 20; i++) polymorphic(new B());
39 for (int i = 0; i < 30; i++) polymorphic(new C()); 51 for (int i = 0; i < 30; i++) polymorphic(new C());
40 52
41 for (int i = 0; i < 10; i++) megamorphic(new A()); 53 for (int i = 0; i < 10; i++) megamorphic(new A());
42 for (int i = 0; i < 20; i++) megamorphic(new B()); 54 for (int i = 0; i < 20; i++) megamorphic(new B());
43 for (int i = 0; i < 30; i++) megamorphic(new C()); 55 for (int i = 0; i < 30; i++) megamorphic(new C());
44 for (int i = 0; i < 40; i++) megamorphic(new D()); 56 for (int i = 0; i < 40; i++) megamorphic(new D());
45 for (int i = 0; i < 50; i++) megamorphic(new E()); 57 for (int i = 0; i < 50; i++) megamorphic(new E());
46 for (int i = 0; i < 60; i++) megamorphic(new F()); 58 for (int i = 0; i < 60; i++) megamorphic(new F());
47 for (int i = 0; i < 70; i++) megamorphic(new G()); 59 for (int i = 0; i < 70; i++) megamorphic(new G());
48 for (int i = 0; i < 80; i++) megamorphic(new H()); 60 for (int i = 0; i < 80; i++) megamorphic(new H());
61
62 for (int i = 0; i < 10; i++) staticCall();
63
64 for (int i = 0; i < 10; i++) constructorCall();
49 } 65 }
50 66
51 67
52 Set<String> stringifyCacheEntries(Map callSite) { 68 Set<String> stringifyCacheEntries(Map callSite) {
53 return callSite['cacheEntries'].map((entry) { 69 return callSite['cacheEntries'].map((entry) {
54 return "${entry['receiverClass']['name']}:${entry['count']}"; 70 return "${entry['receiverClass']['name']}:${entry['count']}";
55 }).toSet(); 71 }).toSet();
56 } 72 }
57 73
58 var tests = [ 74 var tests = [
59 (Isolate isolate) { 75 (Isolate isolate) {
60 return isolate.rootLib.load().then((Library lib) { 76 return isolate.rootLib.load().then((Library lib) {
61 var monomorphic = lib.functions.singleWhere((f) => f.name == 'monomorphic'); 77 var monomorphic = lib.functions.singleWhere((f) => f.name == 'monomorphic');
62 var polymorphic = lib.functions.singleWhere((f) => f.name == 'polymorphic'); 78 var polymorphic = lib.functions.singleWhere((f) => f.name == 'polymorphic');
63 var megamorphic = lib.functions.singleWhere((f) => f.name == 'megamorphic'); 79 var megamorphic = lib.functions.singleWhere((f) => f.name == 'megamorphic');
80 var staticCall = lib.functions.singleWhere((f) => f.name == 'staticCall');
81 var constructorCall = lib.functions.singleWhere((f) => f.name == 'constructo rCall');
64 82
65 List tests = []; 83 List tests = [];
66 tests.add(isolate.invokeRpcNoUpgrade('getCallSiteData', 84 tests.add(isolate.invokeRpcNoUpgrade('getCallSiteData',
67 { 'targetId': monomorphic.id }) 85 { 'targetId': monomorphic.id })
68 .then((Map response) { 86 .then((Map response) {
69 print("Monomorphic: $response"); 87 print("Monomorphic: $response");
70 expect(response['type'], equals('_CallSiteData')); 88 expect(response['type'], equals('_CallSiteData'));
71 expect(response['function']['id'], equals(monomorphic.id)); 89 expect(response['function']['id'], equals(monomorphic.id));
72 expect(response['callSites'], isList); 90 expect(response['callSites'], isList);
73 expect(response['callSites'], hasLength(1)); 91 expect(response['callSites'], hasLength(1));
(...skipping 28 matching lines...) Expand all
102 expect(response['callSites'], isList); 120 expect(response['callSites'], isList);
103 expect(response['callSites'], hasLength(1)); 121 expect(response['callSites'], hasLength(1));
104 Map callSite = response['callSites'].single; 122 Map callSite = response['callSites'].single;
105 expect(callSite['name'], equals('foo')); 123 expect(callSite['name'], equals('foo'));
106 // expect(callSite['deoptReasons'], equals('')); 124 // expect(callSite['deoptReasons'], equals(''));
107 expect(stringifyCacheEntries(callSite), 125 expect(stringifyCacheEntries(callSite),
108 equals(['A:10', 'B:20', 'C:30', 'D:40', 126 equals(['A:10', 'B:20', 'C:30', 'D:40',
109 'E:50', 'F:60', 'G:70', 'H:80'].toSet())); 127 'E:50', 'F:60', 'G:70', 'H:80'].toSet()));
110 })); 128 }));
111 129
130 tests.add(isolate.invokeRpcNoUpgrade('getCallSiteData',
131 { 'targetId': staticCall.id })
132 .then((Map response) {
133 expect(response['type'], equals('_CallSiteData'));
134 expect(response['function']['id'], equals(staticCall.id));
135 expect(response['callSites'], isList);
136 expect(response['callSites'], hasLength(1));
137 Map callSite = response['callSites'].single;
138 expect(callSite['name'], equals('staticMethod'));
139 // expect(callSite['deoptReasons'], equals(''));
140 expect(stringifyCacheEntries(callSite),
141 equals(['Static:10'].toSet()));
142 }));
143
144 tests.add(isolate.invokeRpcNoUpgrade('getCallSiteData',
145 { 'targetId': constructorCall.id })
146 .then((Map response) {
147 expect(response['type'], equals('_CallSiteData'));
148 expect(response['function']['id'], equals(constructorCall.id ));
149 expect(response['callSites'], isList);
150 expect(response['callSites'], hasLength(1));
151 Map callSite = response['callSites'].single;
152 expect(callSite['name'], equals('Static.'));
153 // expect(callSite['deoptReasons'], equals(''));
154 expect(stringifyCacheEntries(callSite),
155 equals(['Static:10'].toSet()));
156 }));
157
112 return Future.wait(tests); 158 return Future.wait(tests);
113 }); 159 });
114 }, 160 },
115 161
116 ]; 162 ];
117 163
118 main(args) => runIsolateTests(args, tests, testeeBefore: script); 164 main(args) => runIsolateTests(args, tests, testeeBefore: script);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698