Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
galene
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
nexedi
galene
Commits
0064aa6f
Commit
0064aa6f
authored
Sep 13, 2020
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Split out statistics functions into stats.go.
parent
1fe64e15
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
130 additions
and
123 deletions
+130
-123
group.go
group.go
+0
-123
stats.go
stats.go
+130
-0
No files found.
group.go
View file @
0064aa6f
...
...
@@ -17,8 +17,6 @@ import (
"time"
"github.com/pion/webrtc/v3"
"sfu/rtptime"
)
type
chatHistoryEntry
struct
{
...
...
@@ -489,124 +487,3 @@ func readPublicGroups() {
}
}
}
type
groupStats
struct
{
name
string
clients
[]
clientStats
}
type
clientStats
struct
{
id
string
up
,
down
[]
connStats
}
type
connStats
struct
{
id
string
maxBitrate
uint64
tracks
[]
trackStats
}
type
trackStats
struct
{
bitrate
uint64
maxBitrate
uint64
loss
uint8
rtt
time
.
Duration
jitter
time
.
Duration
}
func
getGroupStats
()
[]
groupStats
{
names
:=
getGroupNames
()
gs
:=
make
([]
groupStats
,
0
,
len
(
names
))
for
_
,
name
:=
range
names
{
g
:=
getGroup
(
name
)
if
g
==
nil
{
continue
}
clients
:=
g
.
getClients
(
nil
)
stats
:=
groupStats
{
name
:
name
,
clients
:
make
([]
clientStats
,
0
,
len
(
clients
)),
}
for
_
,
c
:=
range
clients
{
c
,
ok
:=
c
.
(
*
webClient
)
if
ok
{
cs
:=
getClientStats
(
c
)
stats
.
clients
=
append
(
stats
.
clients
,
cs
)
}
}
sort
.
Slice
(
stats
.
clients
,
func
(
i
,
j
int
)
bool
{
return
stats
.
clients
[
i
]
.
id
<
stats
.
clients
[
j
]
.
id
})
gs
=
append
(
gs
,
stats
)
}
sort
.
Slice
(
gs
,
func
(
i
,
j
int
)
bool
{
return
gs
[
i
]
.
name
<
gs
[
j
]
.
name
})
return
gs
}
func
getClientStats
(
c
*
webClient
)
clientStats
{
c
.
mu
.
Lock
()
defer
c
.
mu
.
Unlock
()
cs
:=
clientStats
{
id
:
c
.
id
,
}
for
_
,
up
:=
range
c
.
up
{
conns
:=
connStats
{
id
:
up
.
id
,
}
tracks
:=
up
.
getTracks
()
for
_
,
t
:=
range
tracks
{
expected
,
lost
,
_
,
_
:=
t
.
cache
.
GetStats
(
false
)
if
expected
==
0
{
expected
=
1
}
loss
:=
uint8
(
lost
*
100
/
expected
)
jitter
:=
time
.
Duration
(
t
.
jitter
.
Jitter
())
*
(
time
.
Second
/
time
.
Duration
(
t
.
jitter
.
HZ
()))
rate
,
_
:=
t
.
rate
.
Estimate
()
conns
.
tracks
=
append
(
conns
.
tracks
,
trackStats
{
bitrate
:
uint64
(
rate
)
*
8
,
loss
:
loss
,
jitter
:
jitter
,
})
}
cs
.
up
=
append
(
cs
.
up
,
conns
)
}
sort
.
Slice
(
cs
.
up
,
func
(
i
,
j
int
)
bool
{
return
cs
.
up
[
i
]
.
id
<
cs
.
up
[
j
]
.
id
})
jiffies
:=
rtptime
.
Jiffies
()
for
_
,
down
:=
range
c
.
down
{
conns
:=
connStats
{
id
:
down
.
id
,
maxBitrate
:
down
.
GetMaxBitrate
(
jiffies
),
}
for
_
,
t
:=
range
down
.
tracks
{
rate
,
_
:=
t
.
rate
.
Estimate
()
rtt
:=
rtptime
.
ToDuration
(
atomic
.
LoadUint64
(
&
t
.
rtt
),
rtptime
.
JiffiesPerSec
)
loss
,
jitter
:=
t
.
stats
.
Get
(
jiffies
)
j
:=
time
.
Duration
(
jitter
)
*
time
.
Second
/
time
.
Duration
(
t
.
track
.
Codec
()
.
ClockRate
)
conns
.
tracks
=
append
(
conns
.
tracks
,
trackStats
{
bitrate
:
uint64
(
rate
)
*
8
,
maxBitrate
:
t
.
maxBitrate
.
Get
(
jiffies
),
loss
:
uint8
(
uint32
(
loss
)
*
100
/
256
),
rtt
:
rtt
,
jitter
:
j
,
})
}
cs
.
down
=
append
(
cs
.
down
,
conns
)
}
sort
.
Slice
(
cs
.
down
,
func
(
i
,
j
int
)
bool
{
return
cs
.
down
[
i
]
.
id
<
cs
.
down
[
j
]
.
id
})
return
cs
}
stats.go
0 → 100644
View file @
0064aa6f
package
main
import
(
"sort"
"sync/atomic"
"time"
"sfu/rtptime"
)
type
groupStats
struct
{
name
string
clients
[]
clientStats
}
type
clientStats
struct
{
id
string
up
,
down
[]
connStats
}
type
connStats
struct
{
id
string
maxBitrate
uint64
tracks
[]
trackStats
}
type
trackStats
struct
{
bitrate
uint64
maxBitrate
uint64
loss
uint8
rtt
time
.
Duration
jitter
time
.
Duration
}
func
getGroupStats
()
[]
groupStats
{
names
:=
getGroupNames
()
gs
:=
make
([]
groupStats
,
0
,
len
(
names
))
for
_
,
name
:=
range
names
{
g
:=
getGroup
(
name
)
if
g
==
nil
{
continue
}
clients
:=
g
.
getClients
(
nil
)
stats
:=
groupStats
{
name
:
name
,
clients
:
make
([]
clientStats
,
0
,
len
(
clients
)),
}
for
_
,
c
:=
range
clients
{
c
,
ok
:=
c
.
(
*
webClient
)
if
ok
{
cs
:=
getClientStats
(
c
)
stats
.
clients
=
append
(
stats
.
clients
,
cs
)
}
}
sort
.
Slice
(
stats
.
clients
,
func
(
i
,
j
int
)
bool
{
return
stats
.
clients
[
i
]
.
id
<
stats
.
clients
[
j
]
.
id
})
gs
=
append
(
gs
,
stats
)
}
sort
.
Slice
(
gs
,
func
(
i
,
j
int
)
bool
{
return
gs
[
i
]
.
name
<
gs
[
j
]
.
name
})
return
gs
}
func
getClientStats
(
c
*
webClient
)
clientStats
{
c
.
mu
.
Lock
()
defer
c
.
mu
.
Unlock
()
cs
:=
clientStats
{
id
:
c
.
id
,
}
for
_
,
up
:=
range
c
.
up
{
conns
:=
connStats
{
id
:
up
.
id
,
}
tracks
:=
up
.
getTracks
()
for
_
,
t
:=
range
tracks
{
expected
,
lost
,
_
,
_
:=
t
.
cache
.
GetStats
(
false
)
if
expected
==
0
{
expected
=
1
}
loss
:=
uint8
(
lost
*
100
/
expected
)
jitter
:=
time
.
Duration
(
t
.
jitter
.
Jitter
())
*
(
time
.
Second
/
time
.
Duration
(
t
.
jitter
.
HZ
()))
rate
,
_
:=
t
.
rate
.
Estimate
()
conns
.
tracks
=
append
(
conns
.
tracks
,
trackStats
{
bitrate
:
uint64
(
rate
)
*
8
,
loss
:
loss
,
jitter
:
jitter
,
})
}
cs
.
up
=
append
(
cs
.
up
,
conns
)
}
sort
.
Slice
(
cs
.
up
,
func
(
i
,
j
int
)
bool
{
return
cs
.
up
[
i
]
.
id
<
cs
.
up
[
j
]
.
id
})
jiffies
:=
rtptime
.
Jiffies
()
for
_
,
down
:=
range
c
.
down
{
conns
:=
connStats
{
id
:
down
.
id
,
maxBitrate
:
down
.
GetMaxBitrate
(
jiffies
),
}
for
_
,
t
:=
range
down
.
tracks
{
rate
,
_
:=
t
.
rate
.
Estimate
()
rtt
:=
rtptime
.
ToDuration
(
atomic
.
LoadUint64
(
&
t
.
rtt
),
rtptime
.
JiffiesPerSec
)
loss
,
jitter
:=
t
.
stats
.
Get
(
jiffies
)
j
:=
time
.
Duration
(
jitter
)
*
time
.
Second
/
time
.
Duration
(
t
.
track
.
Codec
()
.
ClockRate
)
conns
.
tracks
=
append
(
conns
.
tracks
,
trackStats
{
bitrate
:
uint64
(
rate
)
*
8
,
maxBitrate
:
t
.
maxBitrate
.
Get
(
jiffies
),
loss
:
uint8
(
uint32
(
loss
)
*
100
/
256
),
rtt
:
rtt
,
jitter
:
j
,
})
}
cs
.
down
=
append
(
cs
.
down
,
conns
)
}
sort
.
Slice
(
cs
.
down
,
func
(
i
,
j
int
)
bool
{
return
cs
.
down
[
i
]
.
id
<
cs
.
down
[
j
]
.
id
})
return
cs
}
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