|
@@ -0,0 +1,36 @@
|
|
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
|
+}
|