Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
com.ccwangluo.accelerator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sheteng
com.ccwangluo.accelerator
Commits
6749afd2
Commit
6749afd2
authored
Nov 12, 2015
by
Max Lv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add TrafficMonitor
parent
4e4e0514
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
98 additions
and
1 deletion
+98
-1
src/main/scala/com/github/shadowsocks/database/DBHelper.scala
...main/scala/com/github/shadowsocks/database/DBHelper.scala
+6
-1
src/main/scala/com/github/shadowsocks/database/Profile.scala
src/main/scala/com/github/shadowsocks/database/Profile.scala
+9
-0
src/main/scala/com/github/shadowsocks/utils/TrafficMonitor.scala
...n/scala/com/github/shadowsocks/utils/TrafficMonitor.scala
+83
-0
No files found.
src/main/scala/com/github/shadowsocks/database/DBHelper.scala
View file @
6749afd2
...
...
@@ -51,7 +51,7 @@ object DBHelper {
}
class
DBHelper
(
val
context
:
Context
)
extends
OrmLiteSqliteOpenHelper
(
context
,
DBHelper
.
PROFILE
,
null
,
1
2
)
{
extends
OrmLiteSqliteOpenHelper
(
context
,
DBHelper
.
PROFILE
,
null
,
1
3
)
{
lazy
val
profileDao
:
Dao
[
Profile
,
Int
]
=
getDao
(
classOf
[
Profile
])
...
...
@@ -89,6 +89,11 @@ class DBHelper(val context: Context)
" ipv6, individual FROM `tmp`;"
)
profileDao
.
executeRawNoArgs
(
"DROP TABLE `tmp`;"
)
}
if
(
oldVersion
<
13
)
{
profileDao
.
executeRawNoArgs
(
"ALTER TABLE `profile` ADD COLUMN tx LONG;"
)
profileDao
.
executeRawNoArgs
(
"ALTER TABLE `profile` ADD COLUMN rx LONG;"
)
profileDao
.
executeRawNoArgs
(
"ALTER TABLE `profile` ADD COLUMN date DATE;"
)
}
}
}
}
...
...
src/main/scala/com/github/shadowsocks/database/Profile.scala
View file @
6749afd2
...
...
@@ -83,4 +83,13 @@ class Profile {
@DatabaseField
(
dataType
=
DataType
.
LONG_STRING
)
var
individual
:
String
=
""
@DatabaseField
var
tx
:
Long
=
0
@DatabaseField
var
rx
:
Long
=
0
@DatabaseField
val
date
:
java.util.Date
=
new
java
.
util
.
Date
()
}
src/main/scala/com/github/shadowsocks/utils/TrafficMonitor.scala
0 → 100644
View file @
6749afd2
package
com.github.shadowsocks.utils
import
android.net.TrafficStats
import
android.os.Process
import
java.lang.
{
String
,
System
}
import
java.util.Locale
case
class
Traffic
(
tx
:
Long
,
rx
:
Long
,
timestamp
:
Long
)
object
TrafficMonitor
{
val
uid
=
Process
.
myUid
var
last
:
Traffic
=
getTraffic
// Kilo bytes per second
var
txRate
:
Long
=
0
var
rxRate
:
Long
=
0
// Kilo bytes for the current session
var
txTotal
:
Long
=
0
var
rxTotal
:
Long
=
0
def
getTraffic
()
:
Traffic
=
{
new
Traffic
(
TrafficStats
.
getUidTxBytes
(
uid
),
TrafficStats
.
getUidRxBytes
(
uid
),
System
.
currentTimeMillis
())
}
def
formatTraffic
(
n
:
Long
)
:
String
{
if
(
n
<=
1024
)
{
"
%d
KB
"
.formatLocal
(
Locale.ENGLISH
,
n
)
}
else
if
(
n
>
1024
)
{
"
%d
MB
"
.formatLocal
(
Locale.ENGLISH
,
n
/
1024
)
}
else
if
(
n
>
1024
*
1024
)
{
"%d GB"
.
formatLocal
(
Locale
.
ENGLISH
,
n
/
1024
/
1024
)
}
else
if
(
n
>
1024
*
1024
*
1024
)
{
"%d TB"
.
formatLocal
(
Locale
.
ENGLISH
,
n
/
1024
/
1024
/
1024
)
}
else
{
">1024 TB"
}
}
def
updateTraffic
()
{
val
now
=
getTraffic
txRate
=
((
now
.
tx
-
last
.
tx
)
/
1024
/
(
now
.
timestamp
-
last
.
timestamp
))
rxRate
=
((
now
.
rx
-
last
.
rx
)
/
1024
/
(
now
.
timestamp
-
last
.
timestamp
))
txTotal
+=
(
now
.
tx
-
last
.
tx
)
/
1024
rxTotal
+=
(
now
.
rx
-
last
.
rx
)
/
1024
last
=
now
}
def
resetTraffic
()
{
txRate
=
0
rxRate
=
0
txTotal
=
0
rxTotal
=
0
last
=
getTraffic
}
def
getTxTotal
()
:
String
=
{
formatTraffic
(
txTotal
)
}
def
getRxTotal
()
:
String
=
{
formatTraffic
(
rxTotal
)
}
def
getTotal
()
:
String
=
{
formatTraffic
(
txTotal
+
rxTotal
)
}
def
getTxRate
()
:
String
=
{
formatTraffic
(
txRate
)
+
"/s"
}
def
getTxRate
()
:
String
=
{
formatTraffic
(
rxRate
)
+
"/s"
}
def
getRate
()
:
String
=
{
formatTraffic
(
txRate
+
rxRate
)
+
"/s"
}
}
class
TrafficMonitor
()
Write
Preview
Markdown
is supported
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