refine speed stat
This commit is contained in:
@@ -44,7 +44,7 @@
|
||||
<!-- notification category -->
|
||||
<string name="forward_success">Shadowsocks started.</string>
|
||||
<string name="service_running">Running in the background.</string>
|
||||
<string name="service_status" formatted="false">Upload: %d KB/s, Download: %d KB/s</string>
|
||||
<string name="service_status" formatted="false">Upload: %d KB/s\t|\tDownload: %d KB/s</string>
|
||||
<string name="forward_fail">Shadowsocks failed to start.</string>
|
||||
<string name="service_stopped">Shadowsocks stopped.</string>
|
||||
<string name="forward_stop">Shadowsocks stopped.</string>
|
||||
|
||||
@@ -120,8 +120,10 @@ class ShadowsocksService extends Service {
|
||||
private var state = State.INIT
|
||||
private var last = new TrafficStat(TrafficStats.getTotalTxBytes,
|
||||
TrafficStats.getTotalRxBytes, java.lang.System.currentTimeMillis())
|
||||
private var lastTxRate = 0
|
||||
private var lastRxRate = 0
|
||||
private val timer = new Timer(true)
|
||||
private val TIMER_INTERVAL = 5
|
||||
private val TIMER_INTERVAL = 1
|
||||
|
||||
private def changeState(s: Int) {
|
||||
if (state != s) {
|
||||
@@ -412,13 +414,19 @@ class ShadowsocksService extends Service {
|
||||
def run() {
|
||||
val now = new TrafficStat(TrafficStats.getTotalTxBytes,
|
||||
TrafficStats.getTotalRxBytes, java.lang.System.currentTimeMillis())
|
||||
val txRate = (now.tx - last.tx) / 1024 / TIMER_INTERVAL
|
||||
val rxRate = (now.rx - last.rx) / 1024 / TIMER_INTERVAL
|
||||
val txRate = ((now.tx - last.tx) / 1024 / TIMER_INTERVAL).toInt
|
||||
val rxRate = ((now.rx - last.rx) / 1024 / TIMER_INTERVAL).toInt
|
||||
last = now
|
||||
if (lastTxRate == txRate && lastRxRate == rxRate) {
|
||||
return
|
||||
} else {
|
||||
lastTxRate = txRate
|
||||
lastRxRate = rxRate
|
||||
}
|
||||
if (state == State.CONNECTED) {
|
||||
Log.d(TAG, getString(R.string.service_status).format(txRate, rxRate))
|
||||
notifyForegroundAlert(getString(R.string.forward_success),
|
||||
getString(R.string.service_status).format(txRate, rxRate), txRate.toInt + rxRate.toInt)
|
||||
getString(R.string.service_status).format(txRate, rxRate), txRate + rxRate)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user