@vpalmisano/webrtcperf 4.4.12 → 4.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/scenarios.ts CHANGED
@@ -6,9 +6,12 @@ import { Config } from './config'
6
6
  import { Auth, google } from 'googleapis'
7
7
  import { logger } from './utils'
8
8
  import { sprintf } from 'sprintf-js'
9
+ import { PlotData, plotHtml } from './plot'
9
10
 
10
11
  const log = logger('webrtcperf:scenarios')
11
12
 
13
+ export type StatsRow = Record<string, string | number>
14
+
12
15
  /**
13
16
  * It parses a CSV stats file and returns an array of objects representing each row.
14
17
  * @param filePath The path to the CSV stats file.
@@ -20,15 +23,12 @@ export async function parseStatsFile(filePath: string) {
20
23
  const lines = fileData.split('\n')
21
24
  const headers = lines[0].split(',')
22
25
  const data = lines.slice(1).map(line =>
23
- line.split(',').reduce(
24
- (acc, value, index) => {
25
- if (value !== '') {
26
- acc[headers[index]] = isNaN(Number(value)) ? value : Number(value)
27
- }
28
- return acc
29
- },
30
- {} as Record<string, string | number>,
31
- ),
26
+ line.split(',').reduce((acc, value, index) => {
27
+ if (value !== '') {
28
+ acc[headers[index]] = isNaN(Number(value)) ? value : Number(value)
29
+ }
30
+ return acc
31
+ }, {} as StatsRow),
32
32
  )
33
33
  return data
34
34
  }
@@ -155,28 +155,32 @@ export async function uploadStatsToGoogleSheet(stats: StatsSummary[], spreadshee
155
155
 
156
156
  export type ThrottleDirection = 'up' | 'down' | 'bidi'
157
157
 
158
- export function formatBitrate(bitrate: number | undefined, prefix = ' ') {
158
+ export function formatBitrate(bitrate: number | undefined, prefix = ' ', pad = true) {
159
159
  if (bitrate === undefined) return ''
160
160
  let suffix = 'Kbps'
161
161
  if (bitrate >= 1000) {
162
162
  bitrate /= 1000
163
163
  suffix = 'Mbps'
164
164
  }
165
- return `${prefix}${sprintf('%5.4g', bitrate)}${suffix}`
165
+ return `${prefix}${sprintf(`%${pad ? '5' : ''}.4g`, bitrate)}${suffix}`
166
166
  }
167
167
 
168
- export function formatLoss(loss: number | undefined, prefix = ' ') {
169
- return loss !== undefined ? `${prefix}${loss.toFixed(0).padStart(2, ' ')}%` : ''
168
+ export function formatLoss(loss: number | undefined, prefix = ' ', pad = true) {
169
+ return loss !== undefined ? `${prefix}${loss.toFixed(0).padStart(pad ? 2 : 0, ' ')}%` : ''
170
170
  }
171
171
 
172
- export function formatDelay(delay: number | undefined, prefix = ' ') {
173
- return delay !== undefined ? `${prefix}${delay.toFixed(0).padStart(3, ' ')}ms` : ''
172
+ export function formatDelay(delay: number | undefined, prefix = ' ', pad = true) {
173
+ return delay !== undefined ? `${prefix}${delay.toFixed(0).padStart(pad ? 3 : 0, ' ')}ms` : ''
174
174
  }
175
175
 
176
- export function formatThrottleRule(throttleRule: ThrottleRule & { direction: ThrottleDirection }, human = false) {
176
+ export function formatThrottleRule(
177
+ throttleRule: ThrottleRule & { direction: ThrottleDirection },
178
+ human = false,
179
+ pad = true,
180
+ ) {
177
181
  const { rate, loss, delay, direction } = throttleRule
178
182
  return human
179
- ? `${direction.padEnd(4, ' ')}${formatBitrate(rate)}${formatLoss(loss)}${formatDelay(delay)}`
183
+ ? `${direction.padEnd(pad ? 4 : 0, ' ')}${formatBitrate(rate, ' ', pad)}${formatLoss(loss, ' ', pad)}${formatDelay(delay, ' ', pad)}`
180
184
  : `${direction}-r${rate}-l${loss}-d${delay}`
181
185
  }
182
186
 
@@ -190,6 +194,50 @@ export function parseThrottleRule(throttleDesc: string) {
190
194
  return { direction, rate, loss, delay }
191
195
  }
192
196
 
197
+ export async function plotStatsSummary(stats: StatsSummary[]) {
198
+ const labels = new Set<string>()
199
+ const data = {} as Record<string, Record<string, FastStats>>
200
+ stats.forEach(s => {
201
+ const { id, scenario, videoRecvBitratePerPixel } = s
202
+ if (!videoRecvBitratePerPixel.length) return null
203
+ if (!data[id]) {
204
+ data[id] = {}
205
+ }
206
+ const scenarioFormatted = formatThrottleRule(parseThrottleRule(scenario), true, true)
207
+ if (!data[id][scenarioFormatted]) {
208
+ data[id][scenarioFormatted] = new FastStats()
209
+ }
210
+ labels.add(scenarioFormatted)
211
+ data[id][scenarioFormatted].push(videoRecvBitratePerPixel.percentile(95))
212
+ })
213
+ const series: PlotData[] = []
214
+ Object.entries(data)
215
+ .sort((a, b) => a[0].localeCompare(b[0]))
216
+ .forEach(([id, data]) => {
217
+ const plotData: PlotData = { label: id, data: [] }
218
+ Object.entries(data)
219
+ .sort((a, b) => a[0].localeCompare(b[0]))
220
+ .forEach(([scenario, stats]) => {
221
+ plotData.data.push({
222
+ x: scenario,
223
+ y: stats.percentile(50),
224
+ yMin: stats.percentile(5),
225
+ yMax: stats.percentile(95),
226
+ })
227
+ })
228
+ series.push(plotData)
229
+ })
230
+ await plotHtml(
231
+ {
232
+ type: 'barWithErrorBars',
233
+ xLabel: 'Scenario',
234
+ yLabel: 'Video Receive Bitrate per Pixel',
235
+ labels: Array.from(labels).sort((a, b) => a.localeCompare(b)),
236
+ },
237
+ series,
238
+ )
239
+ }
240
+
193
241
  /**
194
242
  * It generates a test configuration with a scenario including 2 participants.
195
243
  * The first participant sends video and the second receives it.