Browse Source

Push some logging utils for naive testing purposes

Guy Carmeli 5 years ago
parent
commit
da8f2d81a7

+ 7
- 0
lib/android/app/src/main/java/com/reactnativenavigation/utils/Functions.java View File

1
+package com.reactnativenavigation.utils;
2
+
3
+public class Functions {
4
+    public interface Unit<T> {
5
+        T get();
6
+    }
7
+}

+ 36
- 0
lib/android/app/src/main/java/com/reactnativenavigation/utils/Time.java View File

1
+package com.reactnativenavigation.utils;
2
+
3
+import android.util.Log;
4
+
5
+import java.util.HashMap;
6
+import java.util.Map;
7
+
8
+@SuppressWarnings("WeakerAccess")
9
+public class Time {
10
+    private static Map<String, Long> tagsToStartTime = new HashMap<>();
11
+    private static Now now = new Now();
12
+
13
+    public static <T> T log(String tag, Functions.Unit<T> unit) {
14
+        log(tag);
15
+        T t = unit.get();
16
+        log(tag);
17
+        return t;
18
+    }
19
+
20
+    public static void log(String tag) {
21
+        if (tagsToStartTime.containsKey(tag)) {
22
+            Log.i(tag, "Elapsed: " + (now() - time(tag)));
23
+        } else {
24
+            Log.i(tag, "logging start");
25
+        }
26
+        tagsToStartTime.put(tag, now());
27
+    }
28
+
29
+    private static long now() {
30
+        return now.now();
31
+    }
32
+
33
+    private static long time(String tag) {
34
+        return tagsToStartTime.get(tag);
35
+    }
36
+}