Add RandomAccessMemory class for in-memory binary operations
This commit is contained in:
84
dart/lib/dev_tools/watch_tickets.dart
Normal file
84
dart/lib/dev_tools/watch_tickets.dart
Normal file
@@ -0,0 +1,84 @@
|
||||
import 'dart:io';
|
||||
import 'dart:async';
|
||||
import 'package:sweepstore/header.dart';
|
||||
|
||||
|
||||
void main() async {
|
||||
int refreshCount = 0;
|
||||
int? previousMasterHeartbeat;
|
||||
Map<int, int> previousWorkerHeartbeats = {};
|
||||
|
||||
while (true) {
|
||||
// Clear console
|
||||
if (Platform.isWindows) {
|
||||
print(Process.runSync("cls", [], runInShell: true).stdout);
|
||||
} else {
|
||||
print(Process.runSync("clear", [], runInShell: true).stdout);
|
||||
}
|
||||
|
||||
refreshCount++;
|
||||
|
||||
// Read example.bin
|
||||
final file = File('example.bin');
|
||||
|
||||
if (await file.exists()) {
|
||||
final raf = await file.open(mode: FileMode.read);
|
||||
|
||||
|
||||
try {
|
||||
final header = SweepstoreHeader(raf);
|
||||
final concurrency = header.concurrency;
|
||||
|
||||
int now32 = (DateTime.now().millisecondsSinceEpoch ~/ 1000) & 0xFFFFFFFF;
|
||||
|
||||
print('Sweepstore Tickets - Refresh #$refreshCount');
|
||||
print('Current Time (now32): $now32');
|
||||
print('Master ID: ${concurrency.masterIdentifier}');
|
||||
|
||||
int masterAge = now32 - concurrency.masterHeartbeat;
|
||||
String masterStatus = masterAge > 5 ? "(stale)" : "(active)";
|
||||
String masterPrevious = previousMasterHeartbeat != null ? "(previously $previousMasterHeartbeat)" : "";
|
||||
print('Master Heartbeat: ${concurrency.masterHeartbeat} $masterStatus $masterPrevious');
|
||||
|
||||
print('Workers: ${concurrency.numberOfWorkers}');
|
||||
print('Read Allowed: ${concurrency.isReadAllowed}');
|
||||
print('');
|
||||
|
||||
// display each ticket
|
||||
for (int i = 0; i < concurrency.numberOfWorkers; i++) {
|
||||
final ticket = concurrency[i];
|
||||
|
||||
print('--- Ticket #$i ---');
|
||||
print(' Identifier: ${ticket.identifier}');
|
||||
|
||||
int workerAge = now32 - ticket.workerHeartbeat;
|
||||
String workerStatus = workerAge > 5 ? "(stale)" : "(active)";
|
||||
String workerPrevious = previousWorkerHeartbeats.containsKey(i) ? "(previously ${previousWorkerHeartbeats[i]})" : "";
|
||||
print(' Heartbeat: ${ticket.workerHeartbeat} $workerStatus $workerPrevious');
|
||||
|
||||
print(' State: ${ticket.ticketState.name}');
|
||||
print(' Operation: ${ticket.ticketOperation.name}');
|
||||
print(' Key Hash: ${ticket.keyHash}');
|
||||
print(' Write Ptr: ${ticket.writePointer}');
|
||||
print(' Write Size: ${ticket.writeSize} bytes');
|
||||
print('');
|
||||
|
||||
// update previous heartbeat
|
||||
previousWorkerHeartbeats[i] = ticket.workerHeartbeat;
|
||||
|
||||
}
|
||||
|
||||
// updat previous master heartbeat
|
||||
previousMasterHeartbeat = concurrency.masterHeartbeat;
|
||||
|
||||
print('--- Refreshing in 1 seconds ---');
|
||||
} finally {
|
||||
await raf.close();
|
||||
}
|
||||
} else {
|
||||
print('Error: example.bin not found - Refresh #$refreshCount');
|
||||
}
|
||||
|
||||
await Future.delayed(Duration(seconds: 1));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user