OLD | NEW |
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 Loading... |
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 } |
OLD | NEW |