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

Unified Diff: mojo/common/dart/lib/src/trace_provider_impl.dart

Issue 1401853005: Dart: Makes timing of sending trace events configurable. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/common/dart/BUILD.gn ('k') | mojo/common/dart/lib/trace_provider_impl.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/common/dart/lib/src/trace_provider_impl.dart
diff --git a/mojo/common/dart/lib/trace_provider_impl.dart b/mojo/common/dart/lib/src/trace_provider_impl.dart
similarity index 59%
rename from mojo/common/dart/lib/trace_provider_impl.dart
rename to mojo/common/dart/lib/src/trace_provider_impl.dart
index 07effcadbdce095ac5f24ae1f85ac186817a03d1..43066a029d3cf2ecafcae6c1788beef45f154359 100644
--- a/mojo/common/dart/lib/trace_provider_impl.dart
+++ b/mojo/common/dart/lib/src/trace_provider_impl.dart
@@ -7,6 +7,12 @@ import 'dart:async';
import 'package:mojo/core.dart';
import 'package:mojo_services/tracing/tracing.mojom.dart';
+enum TraceSendTiming {
+ IMMEDIATE,
+ // TODO: Add BATCHED?
+ AT_END,
+}
+
class TraceProviderImpl implements TraceProvider {
// Any messages sent before the tracing service connects to us will be
// recorded and kept until one second after construction of the trace
@@ -23,16 +29,17 @@ class TraceProviderImpl implements TraceProvider {
// TODO(rudominer) We currently ignore _categories.
String _categories;
- TraceProviderImpl() {
+ TraceSendTiming _timing;
+
+ TraceProviderImpl([TraceSendTiming timing = TraceSendTiming.IMMEDIATE]) {
_message_queue = [];
_enqueuing = true;
- new Future(() {
- new Future.delayed(const Duration(seconds: 1), () {
- if (_enqueuing) {
- _enqueuing = false;
- _message_queue.clear();
- }
- });
+ _timing = timing;
+ new Future.delayed(const Duration(seconds: 1), () {
+ if (_enqueuing) {
+ _enqueuing = false;
+ _message_queue.clear();
+ }
});
}
@@ -47,17 +54,25 @@ class TraceProviderImpl implements TraceProvider {
_recorder = recorder;
_categories = categories;
_enqueuing = false;
+ if (_timing == TraceSendTiming.IMMEDIATE) {
+ for (String message in _message_queue) {
+ _recorder.ptr.record(message);
+ }
+ _message_queue.clear();
+ }
}
@override
void stopTracing() {
assert(_recorder != null);
- for (String message in _message_queue) {
- _recorder.ptr.record(message);
+ if (_timing == TraceSendTiming.AT_END) {
+ for (String message in _message_queue) {
+ _recorder.ptr.record(message);
+ }
+ _message_queue.clear();
}
_recorder.close();
_recorder = null;
- _message_queue.clear();
}
bool isActive() {
@@ -65,8 +80,19 @@ class TraceProviderImpl implements TraceProvider {
}
void sendTraceMessage(String message) {
- if (isActive()) {
- _message_queue.add(message);
+ switch (_timing) {
+ case TraceSendTiming.IMMEDIATE:
+ if (_recorder != null) {
+ _recorder.ptr.record(message);
+ } else if (_enqueuing) {
+ _message_queue.add(message);
+ }
+ break;
+ case TraceSendTiming.AT_END:
+ if (isActive()) {
+ _message_queue.add(message);
+ }
+ break;
}
}
}
« no previous file with comments | « mojo/common/dart/BUILD.gn ('k') | mojo/common/dart/lib/trace_provider_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698