summaryrefslogtreecommitdiff
path: root/impls
diff options
context:
space:
mode:
authorcyan <cyjan@mrcyjanek.net>2024-09-08 17:52:09 +0200
committerGitHub <noreply@github.com>2024-09-08 17:52:09 +0200
commit4f844740bced43b5653d3152717f8b1e10b13293 (patch)
treed123816ee4d8cb50e2a2fb7f9caff543df5872d2 /impls
parent1e22390f512f97c89b6b4c75da4958c16316da22 (diff)
use less memory for debugCallLength Map (#48)
* use less memory for debugCallLength Map * ignore errors in default debug functions
Diffstat (limited to 'impls')
-rw-r--r--impls/monero.dart/lib/monero.dart34
-rw-r--r--impls/monero.dart/lib/wownero.dart34
2 files changed, 56 insertions, 12 deletions
diff --git a/impls/monero.dart/lib/monero.dart b/impls/monero.dart/lib/monero.dart
index 997f1b6..4fcc970 100644
--- a/impls/monero.dart/lib/monero.dart
+++ b/impls/monero.dart/lib/monero.dart
@@ -101,14 +101,36 @@ final Stopwatch sw = Stopwatch()..start();
bool printStarts = false;
void Function(String call)? debugStart = (call) {
- if (printStarts) print("MONERO: $call");
- debugCallLength[call] ??= <int>[];
- debugCallLength[call]!.add(sw.elapsedMicroseconds);
+ try {
+ if (printStarts) print("MONERO: $call");
+ debugCallLength[call] ??= <int>[];
+ debugCallLength[call]!.add(sw.elapsedMicroseconds);
+ } catch (e) {}
};
+void debugChores() {
+ for (var key in debugCallLength.keys) {
+ if (debugCallLength[key]!.length > 1000000) {
+ final elm =
+ debugCallLength[key]!.reduce((value, element) => value + element);
+ debugCallLength[key]!.clear();
+ debugCallLength["${key}_1M"] ??= <int>[];
+ debugCallLength["${key}_1M"]!.add(elm);
+ }
+ }
+}
+
+int debugCount = 0;
+
void Function(String call)? debugEnd = (call) {
- final id = debugCallLength[call]!.length - 1;
- debugCallLength[call]![id] =
- sw.elapsedMicroseconds - debugCallLength[call]![id];
+ try {
+ final id = debugCallLength[call]!.length - 1;
+ if (++debugCount > 1000000) {
+ debugCount = 0;
+ debugChores();
+ }
+ debugCallLength[call]![id] =
+ sw.elapsedMicroseconds - debugCallLength[call]![id];
+ } catch (e) {}
};
void Function(String call, dynamic error)? errorHandler = (call, error) {
print("$call: $error");
diff --git a/impls/monero.dart/lib/wownero.dart b/impls/monero.dart/lib/wownero.dart
index e87488c..d355005 100644
--- a/impls/monero.dart/lib/wownero.dart
+++ b/impls/monero.dart/lib/wownero.dart
@@ -101,14 +101,36 @@ final Stopwatch sw = Stopwatch()..start();
bool printStarts = false;
void Function(String call)? debugStart = (call) {
- if (printStarts) print("MONERO: $call");
- debugCallLength[call] ??= <int>[];
- debugCallLength[call]!.add(sw.elapsedMicroseconds);
+ try {
+ if (printStarts) print("MONERO: $call");
+ debugCallLength[call] ??= <int>[];
+ debugCallLength[call]!.add(sw.elapsedMicroseconds);
+ } catch (e) {}
};
+void debugChores() {
+ for (var key in debugCallLength.keys) {
+ if (debugCallLength[key]!.length > 1000000) {
+ final elm =
+ debugCallLength[key]!.reduce((value, element) => value + element);
+ debugCallLength[key]!.clear();
+ debugCallLength["${key}_1M"] ??= <int>[];
+ debugCallLength["${key}_1M"]!.add(elm);
+ }
+ }
+}
+
+int debugCount = 0;
+
void Function(String call)? debugEnd = (call) {
- final id = debugCallLength[call]!.length - 1;
- debugCallLength[call]![id] =
- sw.elapsedMicroseconds - debugCallLength[call]![id];
+ try {
+ final id = debugCallLength[call]!.length - 1;
+ if (++debugCount > 1000000) {
+ debugCount = 0;
+ debugChores();
+ }
+ debugCallLength[call]![id] =
+ sw.elapsedMicroseconds - debugCallLength[call]![id];
+ } catch (e) {}
};
void Function(String call, dynamic error)? errorHandler = (call, error) {
print("$call: $error");