Skip to content

Commit 1eb6f34

Browse files
committed
Port RuntimeInfo to Kotlin
1 parent 7a3a66e commit 1eb6f34

File tree

4 files changed

+55
-82
lines changed

4 files changed

+55
-82
lines changed

aat-gtk/src/main/java/ch/bailu/aat_gtk/lib/GResource.java

Lines changed: 0 additions & 28 deletions
This file was deleted.

aat-gtk/src/main/java/ch/bailu/aat_gtk/lib/RuntimeInfo.java

Lines changed: 0 additions & 53 deletions
This file was deleted.

aat-gtk/src/main/kotlin/ch/bailu/aat_gtk/app/App.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package ch.bailu.aat_gtk.app
22

33
import ch.bailu.aat_gtk.config.Environment
44
import ch.bailu.aat_gtk.config.Strings
5-
import ch.bailu.aat_gtk.lib.GResource
65
import ch.bailu.aat_gtk.lib.RuntimeInfo
76
import ch.bailu.aat_gtk.preferences.GtkStorage
87
import ch.bailu.aat_gtk.preferences.PreferenceLoadDefaults
@@ -17,6 +16,7 @@ import ch.bailu.aat_lib.logger.BroadcastLoggerFactory
1716
import ch.bailu.aat_lib.logger.PrintLnLoggerFactory
1817
import ch.bailu.gtk.adw.Application
1918
import ch.bailu.gtk.gio.ApplicationFlags
19+
import ch.bailu.gtk.lib.bridge.GResource
2020
import ch.bailu.gtk.type.Strs
2121
import org.mapsforge.map.gtk.graphics.GtkGraphicFactory
2222
import kotlin.system.exitProcess
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package ch.bailu.aat_gtk.lib
2+
3+
import ch.bailu.aat_lib.util.MemSize
4+
import ch.bailu.gtk.lib.util.SizeLog
5+
6+
class RuntimeInfo : Runnable {
7+
override fun run() {
8+
val max = SizeLog(getIdentifier("Max"))
9+
val total = SizeLog(getIdentifier("Total"))
10+
val free = SizeLog(getIdentifier("Free"))
11+
val used = SizeLog(getIdentifier("Used"))
12+
val processors = SizeLog(getIdentifier("Processors"))
13+
14+
val runtime = Runtime.getRuntime()
15+
16+
try {
17+
Thread.sleep(TIMEOUT)
18+
processors.log(runtime.availableProcessors().toLong())
19+
free.log(runtime.freeMemory() / MemSize.MB)
20+
21+
while (on) {
22+
max.log(runtime.maxMemory() / MemSize.MB)
23+
total.log(runtime.totalMemory() / MemSize.MB)
24+
used.log((runtime.totalMemory() - runtime.freeMemory()) / MemSize.MB)
25+
Thread.sleep(TIMEOUT)
26+
}
27+
} catch (e: InterruptedException) {
28+
on = false
29+
System.err.println(e.message)
30+
}
31+
}
32+
33+
companion object {
34+
private const val TIMEOUT: Long = 5000
35+
private var on = false
36+
37+
private fun getIdentifier(name: String): String {
38+
return Runtime::class.java.simpleName + ":" + name
39+
}
40+
41+
@Synchronized
42+
fun startLogging() {
43+
if (!on) {
44+
on = true
45+
Thread(RuntimeInfo()).start()
46+
}
47+
}
48+
49+
@Synchronized
50+
fun stopLogging() {
51+
on = false
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)