croupier: Add diff log
To evaluate syncbase performance better we are trying to grab
sync deltas in a log file.
Note: This isn't perfect since the clock time on each device can easily
be "off" by a few seconds. They don't correctly synchronize their time
without user assistance.
Change-Id: I793cea5fd3bef02167a4b5f1961a56d6c91cdb23
diff --git a/lib/src/syncbase/log_writer.dart b/lib/src/syncbase/log_writer.dart
index a8ea950..f9cd9fb 100644
--- a/lib/src/syncbase/log_writer.dart
+++ b/lib/src/syncbase/log_writer.dart
@@ -22,6 +22,8 @@
import 'dart:async';
import 'dart:convert' show UTF8, JSON;
+import 'dart:io' show File, FileMode;
+import 'dart:math' as math;
import 'package:syncbase/syncbase_client.dart'
show SyncbaseDatabase, SyncbaseTable, WatchChange, WatchChangeTypes;
@@ -65,11 +67,24 @@
SyncbaseTable tb;
static final String tbName = util.tableNameGames;
+ // A file reference to track how Syncbase sync is going.
+ final File _diffFile =
+ new File('/data/data/org.chromium.mojo.shell/diffFile.txt');
+
// The LogWriter takes a callback for watch updates, the list of users, and
// the logPrefix to write at on table.
LogWriter(this.updateCallback, this.users)
: _cc = new CroupierClient.singleton() {
_prepareLog();
+ _diffFileLog("=========Starting Log Writer=========");
+ }
+
+ Future _diffFileLog(String s, [DateTime other]) async {
+ DateTime now = new DateTime.now();
+ int diff = other != null ? now.difference(other).inMilliseconds : null;
+ String logStr = "${now.millisecondsSinceEpoch}\t${diff}\t${s}\n";
+ print(logStr);
+ await _diffFile.writeAsString(logStr, mode: FileMode.APPEND, flush: true);
}
Future _prepareLog() async {
@@ -90,6 +105,12 @@
Future _onChange(String rowKey, String value, bool duringScan) async {
String key = rowKey.replaceFirst("${this.logPrefix}/", "");
+ String timeStr = key.split("-")[0];
+ String front = timeStr.substring(0, 8);
+ String back = timeStr.substring(8);
+ int time = int.parse(front) * math.pow(10, back.length) + int.parse(back);
+ await _diffFileLog("Key: ${key} Value: ${value}",
+ new DateTime.fromMillisecondsSinceEpoch(time));
if (_isProposalKey(key)) {
if (value != null && !_acceptedProposals.contains(key) && !duringScan) {