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 |
11 | 11 |
12 import 'dart:async'; | 12 import 'dart:async'; |
13 | 13 |
14 import 'package:args/args.dart' as args; | 14 import 'package:args/args.dart' as args; |
15 import 'package:common/tracing_helper.dart'; | 15 import 'package:common/tracing_helper.dart'; |
16 import 'package:mojo/application.dart'; | 16 import 'package:mojo/application.dart'; |
17 import 'package:mojo/bindings.dart'; | 17 import 'package:mojo/bindings.dart'; |
18 import 'package:mojo/core.dart'; | 18 import 'package:mojo/core.dart'; |
19 import 'package:mojom/mojo/examples/echo.mojom.dart'; | 19 import 'package:mojom/mojo/examples/echo.mojom.dart'; |
20 | 20 |
21 class EchoTracingApp extends Application { | 21 class EchoTracingApp extends Application { |
22 static const Duration kWarmupDuration = const Duration(seconds: 1); | 22 static const Duration kWarmupDuration = const Duration(seconds: 5); |
23 static const Duration kDelay = const Duration(microseconds: 50); | 23 static const Duration kDelay = const Duration(microseconds: 50); |
24 TracingHelper _tracing; | 24 TracingHelper _tracing; |
25 List<EchoProxy> _echoProxies; | 25 List<EchoProxy> _echoProxies; |
26 bool _doEcho; | 26 bool _doEcho; |
27 bool _warmup; | 27 bool _warmup; |
28 int _numClients; | 28 int _numClients; |
29 int _numActiveClients; | 29 int _numActiveClients; |
30 | 30 |
31 EchoTracingApp.fromHandle(MojoHandle handle) : super.fromHandle(handle) { | 31 EchoTracingApp.fromHandle(MojoHandle handle) : super.fromHandle(handle) { |
32 onError = _errorHandler; | 32 onError = _errorHandler; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 return _echo(idx, "ping").then((_) { | 85 return _echo(idx, "ping").then((_) { |
86 int end = getTimeTicksNow(); | 86 int end = getTimeTicksNow(); |
87 _tracing.traceDuration("ping", "mojo_rtt_benchmark", start, end); | 87 _tracing.traceDuration("ping", "mojo_rtt_benchmark", start, end); |
88 }); | 88 }); |
89 } | 89 } |
90 | 90 |
91 Future _echo(int idx, String s) { | 91 Future _echo(int idx, String s) { |
92 return _echoProxies[idx] | 92 return _echoProxies[idx] |
93 .ptr | 93 .ptr |
94 .echoString(s) | 94 .echoString(s) |
95 .catchError((_) => _errorHandler()); | 95 .catchError((e) => _errorHandler()); |
96 } | 96 } |
97 | 97 |
98 _errorHandler() { | 98 _errorHandler() { |
99 _doEcho = false; | 99 _doEcho = false; |
100 return Future.wait(_echoProxies.map((p) => p.close())).then((_) { | 100 return Future.wait(_echoProxies.map((p) => p.close())).then((_) { |
101 assert(MojoHandle.reportLeakedHandles()); | 101 assert(MojoHandle.reportLeakedHandles()); |
102 }); | 102 }); |
103 } | 103 } |
104 } | 104 } |
105 | 105 |
106 main(List args) { | 106 main(List args) { |
107 MojoHandle appHandle = new MojoHandle(args[0]); | 107 MojoHandle appHandle = new MojoHandle(args[0]); |
108 new EchoTracingApp.fromHandle(appHandle); | 108 new EchoTracingApp.fromHandle(appHandle); |
109 } | 109 } |
OLD | NEW |