Skip to content

Commit

Permalink
fix track stats indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
vpalmisano committed Apr 17, 2024
1 parent d9fa1d8 commit 2c8e2d6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 17 deletions.
8 changes: 8 additions & 0 deletions scripts/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ window.getParticipantNameForSave = () => {
return window.getParticipantName().split('_')[0]
}

/**
* Returns the name of the sender participant for a given track.
* @param {MediaStreamTrack} track
*/
window.getReceiverParticipantName = track => {
return track.id
}

/**
* getElement
* @param {string} selector
Expand Down
5 changes: 3 additions & 2 deletions scripts/peer-connection-stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ async function getPeerConnectionStats(
.getParameters()
.encodings.filter(encoding => encoding.active)
if (track) {
const trackId = `${id}-${track.kind[0]}s-${track.id}`
const trackId = track.id
const stats = await pc.getStats(track)
const values = {
enabled:
Expand Down Expand Up @@ -316,7 +316,7 @@ async function getPeerConnectionStats(
if (t.receiver && t.receiver.track) {
const track = t.receiver.track
if (track) {
const trackId = `${id}-${track.kind[0]}r-${track.id}`
const trackId = window.getReceiverParticipantName(track)
const stats = await pc.getStats(track)
const values = {
enabled: window.isRecvTrackEnabled(track),
Expand Down Expand Up @@ -598,5 +598,6 @@ window.collectPeerConnectionStats = async (raw = false, verbose = false) => {
stats,
activePeerConnections,
signalingHost,
participantName: window.getParticipantName(),
}
}
3 changes: 2 additions & 1 deletion src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ declare global {
stats: RtcStats[]
activePeerConnections: number
signalingHost?: string
participantName?: string
}>
let collectVideoEndToEndDelayStats: () => {
videoEndToEndDelay: number
Expand Down Expand Up @@ -1519,7 +1520,7 @@ window.SERVER_USE_HTTPS = ${this.serverUseHttps};
videoEndToEndStats: collectVideoEndToEndDelayStats(),
httpResourcesStats: collectHttpResourcesStats(),
}))
const participantName = await page.evaluate(() => getParticipantName())
const { participantName } = peerConnectionStats

// Get host from the first collected remote address.
if (
Expand Down
22 changes: 9 additions & 13 deletions src/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ export class Stats extends events.EventEmitter {
log.info(`Logging stats into ${this.statsPath}`)
this.detailedStatsWriter = new StatsWriter(this.detailedStatsPath, [
'participantName',
'trackId',
...this.statsNames,
])
}
Expand Down Expand Up @@ -955,29 +956,24 @@ export class Stats extends events.EventEmitter {
await this.statsWriter.push(values)
}
if (this.detailedStatsWriter) {
const participants = new Map<string, Record<string, FastStats>>()
const participants = new Map<string, Record<string, string>>()
Object.entries(this.collectedStats).forEach(([name, stats]) => {
Object.entries(stats.byParticipantAndTrack).forEach(
([label, value]) => {
const [participantName] = label.split(':', 2)
let participant = participants.get(participantName)
let participant = participants.get(label)
if (!participant) {
participant = {}
participants.set(participantName, participant)
participants.set(label, participant)
}
if (!participant[name]) {
participant[name] = new FastStats({ store_data: false })
}
participant[name].push(value)
participant[name] = toPrecision(value, 6)
},
)
})
for (const [participantName, participant] of participants.entries()) {
const values = [participantName]
for (const [label, participant] of participants.entries()) {
const [participantName, trackId] = label.split(':', 2)
const values = [participantName, trackId]
for (const name of this.statsNames) {
values.push(
participant[name] ? toPrecision(participant[name].amean()) : '',
)
values.push(participant[name] !== undefined ? participant[name] : '')
}
await this.detailedStatsWriter.push(values)
}
Expand Down
2 changes: 1 addition & 1 deletion src/throttle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ async function start(): Promise<void> {
`\
set -e;
sudo -n modprobe ifb;
sudo -n modprobe ifb || true;
sudo -n ip link add ifb0 type ifb || true;
sudo -n ip link set dev ifb0 up;
Expand Down

0 comments on commit 2c8e2d6

Please sign in to comment.