5
5
import org .jackhuang .hmcl .util .platform .Architecture ;
6
6
import org .jackhuang .hmcl .util .platform .OperatingSystem ;
7
7
8
- import java .io .File ;
9
8
import java .time .LocalDateTime ;
10
9
import java .time .format .DateTimeFormatter ;
11
- import java .util .Map ;
12
-
13
- import static org .jackhuang .hmcl .util .Lang .mapOf ;
14
- import static org .jackhuang .hmcl .util .Pair .pair ;
15
- import static org .jackhuang .hmcl .util .logging .Logger .LOG ;
16
10
17
11
public class CrashReport {
18
12
19
13
private final Thread thread ;
20
14
private final Throwable throwable ;
21
15
private final String stackTrace ;
22
16
23
- private boolean nonFatal ;
24
-
25
17
public CrashReport (Thread thread , Throwable throwable ) {
26
18
this .thread = thread ;
27
19
this .throwable = throwable ;
28
20
stackTrace = StringUtils .getStackTrace (throwable );
29
- nonFatal = false ;
30
21
}
31
22
32
23
public Throwable getThrowable () {
33
24
return this .throwable ;
34
25
}
35
26
36
- public CrashReport setNonFatal () {
37
- nonFatal = true ;
38
- return this ;
39
- }
40
-
41
27
public boolean shouldBeReport () {
42
28
if (!stackTrace .contains ("org.jackhuang" ))
43
29
return false ;
@@ -48,23 +34,6 @@ public boolean shouldBeReport() {
48
34
return true ;
49
35
}
50
36
51
- public Map <String , Object > getMetrics (long runningTime ) {
52
- return mapOf (
53
- pair ("_run" , runningTime ),
54
- pair ("_app_version" , Metadata .VERSION ),
55
- pair ("_os" , OperatingSystem .SYSTEM_NAME ),
56
- pair ("_os_version" , OperatingSystem .SYSTEM_VERSION ),
57
- pair ("_disk_current" , getDiskAvailable ()),
58
- pair ("_disk_total" , getDiskTotal ()),
59
- pair ("_ram_current" , getMemoryAvailable ()),
60
- pair ("_ram_total" , Runtime .getRuntime ().maxMemory () / BYTES_IN_MB ),
61
- pair ("_error" , stackTrace ),
62
- pair ("_logs" , LOG .getLogs ()),
63
- pair ("_name" , throwable .getLocalizedMessage ()),
64
- pair ("_nonfatal" , nonFatal )
65
- );
66
- }
67
-
68
37
public String getDisplayText () {
69
38
return "---- Hello Minecraft! Crash Report ----\n " +
70
39
" Version: " + Metadata .VERSION + "\n " +
@@ -82,29 +51,4 @@ public String getDisplayText() {
82
51
" JVM Total Memory: " + Runtime .getRuntime ().totalMemory () + "\n " +
83
52
" JVM Free Memory: " + Runtime .getRuntime ().freeMemory () + "\n " ;
84
53
}
85
-
86
- private static final Long BYTES_IN_MB = 1024L * 1024 ;
87
-
88
- private static long getMemoryAvailable () {
89
- Long total = Runtime .getRuntime ().totalMemory ();
90
- Long availMem = Runtime .getRuntime ().freeMemory ();
91
- return (total - availMem ) / BYTES_IN_MB ;
92
- }
93
-
94
- private static long getDiskAvailable () {
95
- long total = 0 , free = 0 ;
96
- for (File f : File .listRoots ()) {
97
- total += f .getTotalSpace ();
98
- free += f .getUsableSpace ();
99
- }
100
- return (total - free ) / BYTES_IN_MB ;
101
- }
102
-
103
- private static long getDiskTotal () {
104
- long total = 0 ;
105
- for (File f : File .listRoots ()) {
106
- total += f .getTotalSpace ();
107
- }
108
- return total / BYTES_IN_MB ;
109
- }
110
54
}
0 commit comments