Chromium Code Reviews| 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 library tracing; | 5 library tracing; |
| 6 | 6 |
| 7 import 'trace_provider_impl.dart'; | 7 import 'trace_provider_impl.dart'; |
| 8 | 8 |
| 9 import 'dart:async'; | 9 import 'dart:async'; |
| 10 import 'dart:convert'; | 10 import 'dart:convert'; |
| 11 import 'dart:core'; | 11 import 'dart:core'; |
| 12 import 'dart:io'; | 12 import 'dart:io'; |
| 13 import 'dart:isolate'; | 13 import 'dart:isolate'; |
| 14 | 14 |
| 15 import 'package:mojo/application.dart'; | 15 import 'package:mojo/application.dart'; |
| 16 import 'package:mojo/bindings.dart'; | 16 import 'package:mojo/bindings.dart'; |
| 17 import 'package:mojo/core.dart'; | 17 import 'package:mojo/core.dart'; |
| 18 import 'package:mojo_services/tracing/tracing.mojom.dart'; | 18 import 'package:mojo_services/tracing/tracing.mojom.dart'; |
| 19 | 19 |
| 20 // TracingHelper is used by Dart code running in the Mojo shell in order | 20 // TracingHelper is used by Dart code running in the Mojo shell in order |
| 21 // to perform tracing. | 21 // to perform tracing. |
| 22 class TracingHelper { | 22 class TracingHelper { |
| 23 TraceProviderImpl _impl; | 23 TraceProviderImpl _impl; |
| 24 String _tid; | 24 int _tid; |
| 25 | 25 |
| 26 // Construct an instance of TracingHelper from within your application's | 26 // Construct an instance of TracingHelper from within your application's |
| 27 // |initialize()| method. |appName| will be used to form a thread identifier | 27 // |initialize()| method. |appName| will be used to form a thread identifier |
| 28 // for use in trace messages. If |appName| is longer than 20 characters then | 28 // for use in trace messages. If |appName| is longer than 20 characters then |
| 29 // only the last 20 characters of |appName| will be used. | 29 // only the last 20 characters of |appName| will be used. |
| 30 TracingHelper(Application app, String appName) { | 30 TracingHelper(Application app, String appName) { |
| 31 // We use only the last 20 characters of appName to form the tid so that | 31 // We use only the last 20 characters of appName to form the tid so that |
| 32 // the 9-digit Isolate hash code we are appending won't get truncated by the | 32 // the 9-digit Isolate hash code we are appending won't get truncated by the |
| 33 // tracing UI. | 33 // tracing UI. |
| 34 if (appName.length > 20) { | 34 if (appName.length > 20) { |
| 35 appName = appName.substring(appName.length - 20); | 35 appName = appName.substring(appName.length - 20); |
| 36 } | 36 } |
| 37 _tid = "${appName}/${Isolate.current.hashCode.toString()}"; | 37 _tid = Isolate.current.hashCode; |
|
qsr
2015/09/08 12:38:54
Can you mix the hashCode of the appName someway?
ppi
2015/09/08 16:42:50
Done.
| |
| 38 ApplicationConnection connection = app.connectToApplication("mojo:tracing"); | 38 ApplicationConnection connection = app.connectToApplication("mojo:tracing"); |
| 39 connection.provideService(TraceProviderName, (e) { | 39 connection.provideService(TraceProviderName, (e) { |
| 40 assert(_impl == null); | 40 assert(_impl == null); |
| 41 _impl = new TraceProviderImpl.fromEndpoint(e); | 41 _impl = new TraceProviderImpl.fromEndpoint(e); |
| 42 }); | 42 }); |
| 43 } | 43 } |
| 44 | 44 |
| 45 bool isActive() { | 45 bool isActive() { |
| 46 return (_impl != null) && _impl.isActive(); | 46 return (_impl != null) && _impl.isActive(); |
| 47 } | 47 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 | 103 |
| 104 _FunctionTraceImpl(this._tracing, this._functionName, this._categories); | 104 _FunctionTraceImpl(this._tracing, this._functionName, this._categories); |
| 105 | 105 |
| 106 @override | 106 @override |
| 107 void end() { | 107 void end() { |
| 108 if (_functionName != null) { | 108 if (_functionName != null) { |
| 109 _tracing._endFunction(_functionName, _categories); | 109 _tracing._endFunction(_functionName, _categories); |
| 110 } | 110 } |
| 111 } | 111 } |
| 112 } | 112 } |
| OLD | NEW |