Commit 8255ff1c authored by Daniel Wolf's avatar Daniel Wolf

Provide mem info

parent c7576a36
......@@ -46,6 +46,8 @@ class ForwardedPacketStore(var logger: Logger?) {
var hasMixedAnswerType:Boolean = true
private set
private var clearing = false
val waitingAnswersSize:Int
get() = forwardedPollablePackets.size + nonPollableForwardedPackets.size + newlyForwardedPackets.size + newlyForwardedNonPollablePackets.size
fun addForwardedQuestion(token: DeviceWriteToken, socket: java.io.Closeable) {
addForwardedQuestion(SocketBasedFutureAnswer(token, socket))
......
......@@ -30,6 +30,7 @@ open class TrafficStats(totalBytesRx: Long = 0,
bytesQueuedToDevice: Long = 0,
openSockets: Long = 0,
totalSockets: Long = 0) {
internal var tunnelHandle:TunnelHandle? = null
var totalBytesRx: Long = totalBytesRx
internal set
var openSockets: Long = openSockets
......@@ -55,6 +56,8 @@ open class TrafficStats(totalBytesRx: Long = 0,
var failedAnswers:Long = 0
internal set
private fun memInfo() = tunnelHandle?.memInfo()
internal fun addLatency(oneLatency:Long) {
floatingAverageLatency = if(floatingAverageLatency == 0L) oneLatency
else {
......
......@@ -50,6 +50,10 @@ class TunnelHandle(proxy: Proxy,
@Volatile
internal var needsLocking:Boolean = true
fun memInfo():MemoryInfo {
return MemoryInfo(meta.size, byteOutput.size, byteOutput.sumOf { it?.size?.toLong() ?: 0 }, forwardedPacketStore?.waitingAnswersSize ?: 0)
}
fun addMeta(token: DeviceWriteToken, data: Any) {
meta[token.index] = data
}
......@@ -133,3 +137,9 @@ class TunnelHandle(proxy: Proxy,
}
class DeviceWriteToken internal constructor(internal val index:Int)
data class MemoryInfo(
val metaSize:Int,
val outputSize:Int,
val outputSizeBytes:Long,
val waitingPacketSize:Int,
)
\ No newline at end of file
......@@ -128,6 +128,7 @@ open class VPNTunnelProxy(val packetProxy: PacketProxy,
logger?.info("Creating tunnel handle")
val localPacketStore = forwardedPacketStore ?: return
tunnelHandle = TunnelHandle(this, localPacketStore, trafficStats)
trafficStats.tunnelHandle = tunnelHandle
packetProxy.injectTunnelHandle(tunnelHandle!!)
logger?.info("Tunnel handle created")
......@@ -265,6 +266,7 @@ open class VPNTunnelProxy(val packetProxy: PacketProxy,
private fun cleanup() {
logger?.info { "cleanup() called" }
trafficStats.tunnelHandle = null
proxyThread?.interrupt()
nonPollableProxyThread?.interrupt()
exceptionCallbacks.clear()
......
Markdown is supported
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