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

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 topLevelMethod() => "TOP";
46 topLevelCall() {
47 topLevelMethod();
48 return null;
49 }
50
34 script() { 51 script() {
35 for (int i = 0; i < 10; i++) monomorphic(new A()); 52 for (int i = 0; i < 10; i++) monomorphic(new A());
36 53
37 for (int i = 0; i < 10; i++) polymorphic(new A()); 54 for (int i = 0; i < 10; i++) polymorphic(new A());
38 for (int i = 0; i < 20; i++) polymorphic(new B()); 55 for (int i = 0; i < 20; i++) polymorphic(new B());
39 for (int i = 0; i < 30; i++) polymorphic(new C()); 56 for (int i = 0; i < 30; i++) polymorphic(new C());
40 57
41 for (int i = 0; i < 10; i++) megamorphic(new A()); 58 for (int i = 0; i < 10; i++) megamorphic(new A());
42 for (int i = 0; i < 20; i++) megamorphic(new B()); 59 for (int i = 0; i < 20; i++) megamorphic(new B());
43 for (int i = 0; i < 30; i++) megamorphic(new C()); 60 for (int i = 0; i < 30; i++) megamorphic(new C());
44 for (int i = 0; i < 40; i++) megamorphic(new D()); 61 for (int i = 0; i < 40; i++) megamorphic(new D());
45 for (int i = 0; i < 50; i++) megamorphic(new E()); 62 for (int i = 0; i < 50; i++) megamorphic(new E());
46 for (int i = 0; i < 60; i++) megamorphic(new F()); 63 for (int i = 0; i < 60; i++) megamorphic(new F());
47 for (int i = 0; i < 70; i++) megamorphic(new G()); 64 for (int i = 0; i < 70; i++) megamorphic(new G());
48 for (int i = 0; i < 80; i++) megamorphic(new H()); 65 for (int i = 0; i < 80; i++) megamorphic(new H());
66
67 for (int i = 0; i < 10; i++) staticCall();
68
69 for (int i = 0; i < 10; i++) constructorCall();
70
71 for (int i = 0; i < 10; i++) topLevelCall();
49 } 72 }
50 73
51 74
52 Set<String> stringifyCacheEntries(Map callSite) { 75 Set<String> stringifyCacheEntries(Map callSite) {
53 return callSite['cacheEntries'].map((entry) { 76 return callSite['cacheEntries'].map((entry) {
54 return "${entry['receiverClass']['name']}:${entry['count']}"; 77 return "${entry['receiverContainer']['name']}:${entry['count']}";
55 }).toSet(); 78 }).toSet();
56 } 79 }
57 80
58 var tests = [ 81 var tests = [
59 (Isolate isolate) { 82 (Isolate isolate) {
60 return isolate.rootLib.load().then((Library lib) { 83 return isolate.rootLib.load().then((Library lib) {
61 var monomorphic = lib.functions.singleWhere((f) => f.name == 'monomorphic'); 84 var monomorphic = lib.functions.singleWhere((f) => f.name == 'monomorphic');
62 var polymorphic = lib.functions.singleWhere((f) => f.name == 'polymorphic'); 85 var polymorphic = lib.functions.singleWhere((f) => f.name == 'polymorphic');
63 var megamorphic = lib.functions.singleWhere((f) => f.name == 'megamorphic'); 86 var megamorphic = lib.functions.singleWhere((f) => f.name == 'megamorphic');
87 var staticCall = lib.functions.singleWhere((f) => f.name == 'staticCall');
88 var constructorCall = lib.functions.singleWhere((f) => f.name == 'constructo rCall');
89 var topLevelCall = lib.functions.singleWhere((f) => f.name == 'topLevelCall' );
64 90
65 List tests = []; 91 List tests = [];
66 tests.add(isolate.invokeRpcNoUpgrade('getCallSiteData', 92 tests.add(isolate.invokeRpcNoUpgrade('getCallSiteData',
67 { 'targetId': monomorphic.id }) 93 { 'targetId': monomorphic.id })
68 .then((Map response) { 94 .then((Map response) {
69 print("Monomorphic: $response"); 95 print("Monomorphic: $response");
70 expect(response['type'], equals('_CallSiteData')); 96 expect(response['type'], equals('_CallSiteData'));
71 expect(response['function']['id'], equals(monomorphic.id)); 97 expect(response['function']['id'], equals(monomorphic.id));
72 expect(response['callSites'], isList); 98 expect(response['callSites'], isList);
73 expect(response['callSites'], hasLength(1)); 99 expect(response['callSites'], hasLength(1));
(...skipping 28 matching lines...) Expand all
102 expect(response['callSites'], isList); 128 expect(response['callSites'], isList);
103 expect(response['callSites'], hasLength(1)); 129 expect(response['callSites'], hasLength(1));
104 Map callSite = response['callSites'].single; 130 Map callSite = response['callSites'].single;
105 expect(callSite['name'], equals('foo')); 131 expect(callSite['name'], equals('foo'));
106 // expect(callSite['deoptReasons'], equals('')); 132 // expect(callSite['deoptReasons'], equals(''));
107 expect(stringifyCacheEntries(callSite), 133 expect(stringifyCacheEntries(callSite),
108 equals(['A:10', 'B:20', 'C:30', 'D:40', 134 equals(['A:10', 'B:20', 'C:30', 'D:40',
109 'E:50', 'F:60', 'G:70', 'H:80'].toSet())); 135 'E:50', 'F:60', 'G:70', 'H:80'].toSet()));
110 })); 136 }));
111 137
138 tests.add(isolate.invokeRpcNoUpgrade('getCallSiteData',
139 { 'targetId': staticCall.id })
140 .then((Map response) {
141 expect(response['type'], equals('_CallSiteData'));
142 expect(response['function']['id'], equals(staticCall.id));
143 expect(response['callSites'], isList);
144 expect(response['callSites'], hasLength(1));
145 Map callSite = response['callSites'].single;
146 expect(callSite['name'], equals('staticMethod'));
147 // expect(callSite['deoptReasons'], equals(''));
148 expect(stringifyCacheEntries(callSite),
149 equals(['Static:10'].toSet()));
150 }));
151
152 tests.add(isolate.invokeRpcNoUpgrade('getCallSiteData',
153 { 'targetId': constructorCall.id })
154 .then((Map response) {
155 expect(response['type'], equals('_CallSiteData'));
156 expect(response['function']['id'], equals(constructorCall.id ));
157 expect(response['callSites'], isList);
158 expect(response['callSites'], hasLength(1));
159 Map callSite = response['callSites'].single;
160 expect(callSite['name'], equals('Static.'));
161 // expect(callSite['deoptReasons'], equals(''));
162 expect(stringifyCacheEntries(callSite),
163 equals(['Static:10'].toSet()));
164 }));
165
166 tests.add(isolate.invokeRpcNoUpgrade('getCallSiteData',
167 { 'targetId': topLevelCall.id })
168 .then((Map response) {
169 expect(response['type'], equals('_CallSiteData'));
170 expect(response['function']['id'], equals(topLevelCall.id));
171 expect(response['callSites'], isList);
172 expect(response['callSites'], hasLength(1));
173 Map callSite = response['callSites'].single;
174 expect(callSite['name'], equals('topLevelMethod'));
175 // expect(callSite['deoptReasons'], equals(''));
176 expect(stringifyCacheEntries(callSite),
177 equals(['call_site_data_test:10'].toSet()));
178 }));
179
112 return Future.wait(tests); 180 return Future.wait(tests);
113 }); 181 });
114 }, 182 },
115 183
116 ]; 184 ];
117 185
118 main(args) => runIsolateTests(args, tests, testeeBefore: script); 186 main(args) => runIsolateTests(args, tests, testeeBefore: script);
OLDNEW
« no previous file with comments | « runtime/observatory/lib/src/service/object.dart ('k') | runtime/observatory/test/debugging_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698