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

Side by Side Diff: benchmarks/mojo_rtt_benchmark/lib/main.dart

Issue 2006093002: Dart: Futures -> Callbacks. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Merge Created 4 years, 6 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This Mojo app is a benchmark of Mojo/Dart IPC Round Trip Times. 5 // This Mojo app is a benchmark of Mojo/Dart IPC Round Trip Times.
6 // It creates many proxies from a single isolate, and makes requests using those 6 // It creates many proxies from a single isolate, and makes requests using those
7 // proxies round-robin. 7 // proxies round-robin.
8 // To run it, and the other RTT benchmarks: 8 // To run it, and the other RTT benchmarks:
9 // 9 //
10 // $ ./mojo/devtools/common/mojo_benchmark [--release] mojo/tools/data/rtt_bench marks 10 // $ ./mojo/devtools/common/mojo_benchmark [--release] mojo/tools/data/rtt_bench marks
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 _warmup = true; 62 _warmup = true;
63 new Timer(kWarmupDuration, () => _warmup = false); 63 new Timer(kWarmupDuration, () => _warmup = false);
64 } 64 }
65 65
66 _run(int idx) { 66 _run(int idx) {
67 if (idx == _numActiveClients) { 67 if (idx == _numActiveClients) {
68 idx = 0; 68 idx = 0;
69 } 69 }
70 if (_doEcho) { 70 if (_doEcho) {
71 if (_warmup) { 71 if (_warmup) {
72 _echo(idx, "ping").then((r) { 72 _echo(idx, "ping", (String r) {
73 new Timer(kDelay, () => _run(idx + 1)); 73 new Timer(kDelay, () => _run(idx + 1));
74 }); 74 });
75 } else { 75 } else {
76 _tracedEcho(idx, "ping").then((r) { 76 _tracedEcho(idx, "ping", (String r) {
77 new Timer(kDelay, () => _run(idx + 1)); 77 new Timer(kDelay, () => _run(idx + 1));
78 }); 78 });
79 } 79 }
80 } 80 }
81 } 81 }
82 82
83 Future _tracedEcho(int idx, String s) { 83 void _tracedEcho(int idx, String s, void callback(String r)) {
84 // This is not the correct way to use the Timeline API. In particular, 84 // This is not the correct way to use the Timeline API. In particular,
85 // the start and end events below could occur on different threads. 85 // the start and end events below could occur on different threads.
86 // This could mess up the interpretation of the trace by about:tracing. 86 // This could mess up the interpretation of the trace by about:tracing.
87 // We do this here as a hack to reduce overhead. The correct way to do 87 // We do this here as a hack to reduce overhead. The correct way to do
88 // this would be to emit an async begin and end pair using TimelineTask. 88 // this would be to emit an async begin and end pair using TimelineTask.
89 // Using the sync API means that we only record one event after the finish 89 // Using the sync API means that we only record one event after the finish
90 // time has been recorded. 90 // time has been recorded.
91 Timeline.startSync("ping"); 91 Timeline.startSync("ping");
92 return _echo(idx, s).then((r) { 92 _echo(idx, s, (String r) {
93 Timeline.finishSync(); 93 Timeline.finishSync();
94 return r; 94 callback(r);
95 }); 95 });
96 } 96 }
97 97
98 Future _echo(int idx, String s) { 98 void _echo(int idx, String s, void callback(String r)) {
99 return _echoProxies[idx].echoString(s); 99 _echoProxies[idx].echoString(s, callback);
100 } 100 }
101 101
102 _errorHandler(Object e) { 102 _errorHandler(Object e) {
103 _doEcho = false; 103 _doEcho = false;
104 return Future.wait(_echoProxies.map((p) => p.close())).then((_) { 104 return Future.wait(_echoProxies.map((p) => p.close())).then((_) {
105 MojoHandle.reportLeakedHandles(); 105 MojoHandle.reportLeakedHandles();
106 }); 106 });
107 } 107 }
108 } 108 }
109 109
110 main(List args, Object handleToken) { 110 main(List args, Object handleToken) {
111 MojoHandle appHandle = new MojoHandle(handleToken); 111 MojoHandle appHandle = new MojoHandle(handleToken);
112 new EchoTracingApp.fromHandle(appHandle); 112 new EchoTracingApp.fromHandle(appHandle);
113 } 113 }
OLDNEW
« no previous file with comments | « benchmarks/mojo_rtt_benchmark/lib/echo_server.dart ('k') | examples/dart/device_info/lib/main.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698