| OLD | NEW |
| 1 #!mojo mojo:dart_content_handler | 1 #!mojo mojo:dart_content_handler |
| 2 // Copyright 2015 The Chromium Authors. All rights reserved. | 2 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 3 // Use of this source code is governed by a BSD-style license that can be | 3 // Use of this source code is governed by a BSD-style license that can be |
| 4 // found in the LICENSE file. | 4 // found in the LICENSE file. |
| 5 | 5 |
| 6 // This example application illustrates how to use Mojo Tracing from Dart code. | 6 // This example application illustrates how to use Mojo Tracing from Dart code. |
| 7 // | 7 // |
| 8 // To run this app: | 8 // To run this app: |
| 9 // mojo/devtools/common/mojo_run --trace-startup \ | 9 // mojo/devtools/common/mojo_run --trace-startup \ |
| 10 // https://core.mojoapps.io/examples/dart/traced_application/lib/main.dart | 10 // https://core.mojoapps.io/examples/dart/traced_application/lib/main.dart |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 void initialize(List<String> args, String url) { | 28 void initialize(List<String> args, String url) { |
| 29 // This sets up a connection between this application and the Mojo | 29 // This sets up a connection between this application and the Mojo |
| 30 // tracing service. | 30 // tracing service. |
| 31 _tracing = new TracingHelper(this, "example_traced_application"); | 31 _tracing = new TracingHelper(this, "example_traced_application"); |
| 32 _tracing.traceInstant("initialized", "traced_application"); | 32 _tracing.traceInstant("initialized", "traced_application"); |
| 33 | 33 |
| 34 // Now we schedule some random work just so we have something to trace. | 34 // Now we schedule some random work just so we have something to trace. |
| 35 new Timer.periodic(new Duration(seconds: 1), (t) => function1()); | 35 new Timer.periodic(new Duration(seconds: 1), (t) => function1()); |
| 36 } | 36 } |
| 37 | 37 |
| 38 @override |
| 39 void acceptConnection(String requestorUrl, String resolvedUrl, |
| 40 ApplicationConnection connection) { |
| 41 _tracing.traceInstant("connected", "traced_application"); |
| 42 } |
| 43 |
| 44 |
| 38 void function1() { | 45 void function1() { |
| 39 var trace = _tracing.beginFunction("function1", "traced_application"); | 46 var trace = _tracing.beginFunction("function1", "traced_application"); |
| 40 waitForMilliseconds(100); | 47 waitForMilliseconds(100); |
| 41 function2(42); | 48 function2(42); |
| 42 waitForMilliseconds(100); | 49 waitForMilliseconds(100); |
| 43 trace.end(); | 50 trace.end(); |
| 44 } | 51 } |
| 45 | 52 |
| 46 void function2(int x) { | 53 void function2(int x) { |
| 47 var trace = _tracing.beginFunction("function2", "traced_application", | 54 var trace = _tracing.beginFunction("function2", "traced_application", |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 void waitForMilliseconds(int milliseconds) { | 93 void waitForMilliseconds(int milliseconds) { |
| 87 (new MojoMessagePipe()).endpoints[0] | 94 (new MojoMessagePipe()).endpoints[0] |
| 88 .handle | 95 .handle |
| 89 .wait(MojoHandleSignals.kReadable, milliseconds * 1000); | 96 .wait(MojoHandleSignals.kReadable, milliseconds * 1000); |
| 90 } | 97 } |
| 91 | 98 |
| 92 main(List args) { | 99 main(List args) { |
| 93 MojoHandle appHandle = new MojoHandle(args[0]); | 100 MojoHandle appHandle = new MojoHandle(args[0]); |
| 94 new TestUsingTracingApp.fromHandle(appHandle); | 101 new TestUsingTracingApp.fromHandle(appHandle); |
| 95 } | 102 } |
| OLD | NEW |