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

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

Issue 920113002: Add getCallSiteData to the VM service. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: sync'd Created 5 years, 10 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
« no previous file with comments | « no previous file | runtime/vm/object.h » ('j') | runtime/vm/service.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library call_site_data_test;
6
7 import 'package:observatory/service_io.dart';
8 import 'package:unittest/unittest.dart';
9 import 'test_helper.dart';
10 import 'dart:async';
11
12 class A { foo() => 'A'; }
13 class B { foo() => 'B'; }
14 class C { foo() => 'C'; }
15 class D { foo() => 'D'; }
16 class E { foo() => 'E'; }
17 class F { foo() => 'F'; }
18 class G { foo() => 'G'; }
19 class H { foo() => 'H'; }
20
21 monomorphic(fooable) {
22 fooable.foo();
23 return null;
24 }
25 polymorphic(fooable) {
26 fooable.foo();
27 return null;
28 }
29 megamorphic(fooable) {
30 fooable.foo();
31 return null;
32 }
33
34 script() {
35 for (int i = 0; i < 10; i++) monomorphic(new A());
36
37 for (int i = 0; i < 10; i++) polymorphic(new A());
38 for (int i = 0; i < 20; i++) polymorphic(new B());
39 for (int i = 0; i < 30; i++) polymorphic(new C());
40
41 for (int i = 0; i < 10; i++) megamorphic(new A());
42 for (int i = 0; i < 20; i++) megamorphic(new B());
43 for (int i = 0; i < 30; i++) megamorphic(new C());
44 for (int i = 0; i < 40; i++) megamorphic(new D());
45 for (int i = 0; i < 50; i++) megamorphic(new E());
46 for (int i = 0; i < 60; i++) megamorphic(new F());
47 for (int i = 0; i < 70; i++) megamorphic(new G());
48 for (int i = 0; i < 80; i++) megamorphic(new H());
49 }
50
51
52 Set<String> stringifyCacheEntries(Map callSite) {
53 return callSite['cacheEntries'].map((entry) {
54 return "${entry['receiverClass']['name']}:${entry['count']}";
55 }).toSet();
56 }
57
58 var tests = [
59 (Isolate isolate) {
60 return isolate.rootLib.load().then((Library lib) {
61 var monomorphic = lib.functions.singleWhere((f) => f.name == 'monomorphic');
62 var polymorphic = lib.functions.singleWhere((f) => f.name == 'polymorphic');
63 var megamorphic = lib.functions.singleWhere((f) => f.name == 'megamorphic');
64
65 List tests = [];
66 tests.add(isolate.invokeRpcNoUpgrade('getCallSiteData',
67 { 'targetId': monomorphic.id })
68 .then((Map response) {
69 print("Monomorphic: $response");
70 expect(response['type'], equals('CallSiteData'));
71 expect(response['function']['id'], equals(monomorphic.id));
72 expect(response['callSites'], isList);
73 expect(response['callSites'], hasLength(1));
74 Map callSite = response['callSites'].single;
75 expect(callSite['name'], equals('foo'));
76 // expect(callSite['deoptReasons'], equals(''));
77 expect(stringifyCacheEntries(callSite),
78 equals(['A:10'].toSet()));
79 }));
80
81 tests.add(isolate.invokeRpcNoUpgrade('getCallSiteData',
82 { 'targetId': polymorphic.id })
83 .then((Map response) {
84 print("Polymorphic: $response");
85 expect(response['type'], equals('CallSiteData'));
86 expect(response['function']['id'], equals(polymorphic.id));
87 expect(response['callSites'], isList);
88 expect(response['callSites'], hasLength(1));
89 Map callSite = response['callSites'].single;
90 expect(callSite['name'], equals('foo'));
91 // expect(callSite['deoptReasons'], equals(''));
92 expect(stringifyCacheEntries(callSite),
93 equals(['A:10', 'B:20', 'C:30'].toSet()));
94 }));
95
96 tests.add(isolate.invokeRpcNoUpgrade('getCallSiteData',
97 { 'targetId': megamorphic.id })
98 .then((Map response) {
99 print("Megamorphic: $response");
100 expect(response['type'], equals('CallSiteData'));
101 expect(response['function']['id'], equals(megamorphic.id));
102 expect(response['callSites'], isList);
103 expect(response['callSites'], hasLength(1));
104 Map callSite = response['callSites'].single;
105 expect(callSite['name'], equals('foo'));
106 // expect(callSite['deoptReasons'], equals(''));
107 expect(stringifyCacheEntries(callSite),
108 equals(['A:10', 'B:20', 'C:30', 'D:40',
109 'E:50', 'F:60', 'G:70', 'H:80'].toSet()));
110 }));
111
112 return Future.wait(tests);
113 });
114 },
115
116 ];
117
118 main(args) => runIsolateTests(args, tests, testeeBefore: script);
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/object.h » ('j') | runtime/vm/service.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698