Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Frank Tobin
Nebulo
Commits
0940e250
Commit
0940e250
authored
Dec 31, 2020
by
Daniel Wolf
Browse files
Regularly print memory info
parent
9778c56a
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/com/frostnerd/smokescreen/service/ConnectionWatchdog.kt
View file @
0940e250
package
com.frostnerd.smokescreen.service
import
android.os.Debug
import
android.text.format.Formatter
import
com.frostnerd.smokescreen.Logger
import
com.frostnerd.vpntunnelproxy.TrafficStats
import
kotlinx.coroutines.*
...
...
@@ -60,6 +62,7 @@ class ConnectionWatchdog(private val trafficStats: TrafficStats,
private
suspend
fun
checkConnection
()
{
delay
(
checkIntervalMs
)
log
(
"Beginning connection check"
)
printMemInfo
()
if
(
trafficStats
.
packetsReceivedFromDevice
>=
15
&&
trafficStats
.
bytesSentToDevice
>
0
&&
packetCountAtLastCheck
?.
let
{
trafficStats
.
packetsReceivedFromDevice
-
it
>
10
}
!=
false
...
...
@@ -117,6 +120,30 @@ class ConnectionWatchdog(private val trafficStats: TrafficStats,
}
}
private
fun
printMemInfo
()
{
val
nativeHeapSize
=
Debug
.
getNativeHeapSize
()
val
nativeHeapFreeSize
=
Debug
.
getNativeHeapFreeSize
()
log
(
buildString
{
append
(
"MemInfo: ["
)
append
(
"OpenSockets: "
)
append
(
trafficStats
.
openSockets
)
append
(
", TotalSockets: "
)
append
(
trafficStats
.
totalSockets
)
append
(
", BytesFromDevice: "
)
append
(
trafficStats
.
bytesFromDevice
)
append
(
", BytesToDevice: "
)
append
(
trafficStats
.
bytesSentToDevice
)
append
(
", BytesQueued: "
)
append
(
trafficStats
.
bytesQueuedToDevice
)
append
(
", HeapSize: "
)
append
(
nativeHeapSize
/
1000
/
1000
)
append
(
"mb"
)
append
(
", FreeHeap: "
)
append
(
nativeHeapFreeSize
/
1000
/
1000
)
append
(
"mb"
)
})
}
private
fun
callCallback
()
{
if
(!
running
)
return
logFine
(
"Calling callback."
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment