Commit 0940e250 authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Regularly print memory info

parent 9778c56a
package com.frostnerd.smokescreen.service package com.frostnerd.smokescreen.service
import android.os.Debug
import android.text.format.Formatter
import com.frostnerd.smokescreen.Logger import com.frostnerd.smokescreen.Logger
import com.frostnerd.vpntunnelproxy.TrafficStats import com.frostnerd.vpntunnelproxy.TrafficStats
import kotlinx.coroutines.* import kotlinx.coroutines.*
...@@ -60,6 +62,7 @@ class ConnectionWatchdog(private val trafficStats: TrafficStats, ...@@ -60,6 +62,7 @@ class ConnectionWatchdog(private val trafficStats: TrafficStats,
private suspend fun checkConnection() { private suspend fun checkConnection() {
delay(checkIntervalMs) delay(checkIntervalMs)
log("Beginning connection check") log("Beginning connection check")
printMemInfo()
if(trafficStats.packetsReceivedFromDevice >= 15 if(trafficStats.packetsReceivedFromDevice >= 15
&& trafficStats.bytesSentToDevice > 0 && trafficStats.bytesSentToDevice > 0
&& packetCountAtLastCheck?.let { trafficStats.packetsReceivedFromDevice - it > 10 } != false && packetCountAtLastCheck?.let { trafficStats.packetsReceivedFromDevice - it > 10 } != false
...@@ -117,6 +120,30 @@ class ConnectionWatchdog(private val trafficStats: TrafficStats, ...@@ -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() { private fun callCallback() {
if(!running) return if(!running) return
logFine("Calling callback.") logFine("Calling callback.")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment