@vpalmisano/webrtcperf 4.4.10 → 4.4.11
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/build/src/scenarios.d.ts +53 -10
- package/build/src/scenarios.js +118 -6
- package/build/src/scenarios.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -1
- package/src/scenarios.ts +127 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vpalmisano/webrtcperf",
|
|
3
|
-
"version": "4.4.
|
|
3
|
+
"version": "4.4.11",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/vpalmisano/webrtcperf.git"
|
|
@@ -67,6 +67,7 @@
|
|
|
67
67
|
"express-basic-auth": "^1.2.1",
|
|
68
68
|
"fast-stats": "^0.0.7",
|
|
69
69
|
"form-data": "^4.0.4",
|
|
70
|
+
"googleapis": "^160.0.0",
|
|
70
71
|
"ipaddr.js": "^2.2.0",
|
|
71
72
|
"json5": "^2.2.3",
|
|
72
73
|
"lorem-ipsum": "^2.0.8",
|
package/src/scenarios.ts
CHANGED
|
@@ -3,8 +3,18 @@ import path from 'path'
|
|
|
3
3
|
import { FastStats } from './stats'
|
|
4
4
|
import { ThrottleConfig, ThrottleRule } from '@vpalmisano/throttler'
|
|
5
5
|
import { Config } from './config'
|
|
6
|
+
import { Auth, google } from 'googleapis'
|
|
7
|
+
import { logger } from './utils'
|
|
6
8
|
|
|
9
|
+
const log = logger('webrtcperf:scenarios')
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* It parses a CSV stats file and returns an array of objects representing each row.
|
|
13
|
+
* @param filePath The path to the CSV stats file.
|
|
14
|
+
* @returns An array of objects where each object represents a row in the CSV file with keys as column headers.
|
|
15
|
+
*/
|
|
7
16
|
export async function parseStatsFile(filePath: string) {
|
|
17
|
+
log.debug(`parseStatsFile: ${filePath}`)
|
|
8
18
|
const fileData = await fs.promises.readFile(filePath, 'utf-8')
|
|
9
19
|
const lines = fileData.split('\n')
|
|
10
20
|
const headers = lines[0].split(',')
|
|
@@ -22,6 +32,23 @@ export async function parseStatsFile(filePath: string) {
|
|
|
22
32
|
return data
|
|
23
33
|
}
|
|
24
34
|
|
|
35
|
+
export type StatsSummary = {
|
|
36
|
+
timestamp: number
|
|
37
|
+
id: string
|
|
38
|
+
scenario: string
|
|
39
|
+
videoRecvBitratePerPixel: FastStats
|
|
40
|
+
videoRecvFps: FastStats
|
|
41
|
+
videoSentFps: FastStats
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* It aggregates the stats summary from multiple test runs in a directory.
|
|
46
|
+
* @param options.dirPath Directory path containing test run subdirectories. Default is 'logs'.
|
|
47
|
+
* @param options.senderParticipantName Participant name of the sender. Default is 'Participant-000001'.
|
|
48
|
+
* @param options.receiverParticipantName Participant name of the receiver. Default is 'Participant-000000'.
|
|
49
|
+
* @param options.nameParser Function to parse test directory names. Default splits by '_' and extracts id and scenario.
|
|
50
|
+
* @returns Array of aggregated stats including timestamp, id, scenario, videoRecvBitratePerPixel, videoRecvFps, and videoSentFps.
|
|
51
|
+
*/
|
|
25
52
|
export async function aggregateStatsSummary({
|
|
26
53
|
dirPath = 'logs',
|
|
27
54
|
senderParticipantName = 'Participant-000001',
|
|
@@ -31,14 +58,8 @@ export async function aggregateStatsSummary({
|
|
|
31
58
|
return { id, scenario }
|
|
32
59
|
},
|
|
33
60
|
}) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
id: string
|
|
37
|
-
scenario: string
|
|
38
|
-
videoRecvBitratePerPixel: FastStats
|
|
39
|
-
videoRecvFps: FastStats
|
|
40
|
-
videoSentFps: FastStats
|
|
41
|
-
}[]
|
|
61
|
+
log.debug(`aggregateStatsSummary: ${dirPath}`)
|
|
62
|
+
const stats: StatsSummary[] = []
|
|
42
63
|
const results = await fs.promises.readdir(dirPath)
|
|
43
64
|
for (const test of results) {
|
|
44
65
|
const filePath = path.join(dirPath, test, 'detailed-stats-summary.csv')
|
|
@@ -76,11 +97,86 @@ export async function aggregateStatsSummary({
|
|
|
76
97
|
return stats.sort((a, b) => a.timestamp - b.timestamp)
|
|
77
98
|
}
|
|
78
99
|
|
|
100
|
+
/**
|
|
101
|
+
* It uploads the aggregated stats to a Google Sheet.
|
|
102
|
+
* A valid Google service account credentials file must be specified
|
|
103
|
+
* in the `GOOGLE_CREDENTIALS_PATH` environment variable.
|
|
104
|
+
* @param stats The aggregated stats to upload.
|
|
105
|
+
* @param spreadsheetId The ID of the Google Spreadsheet.
|
|
106
|
+
* @param table The name of the table (sheet) within the spreadsheet. Default is 'data'.
|
|
107
|
+
*/
|
|
108
|
+
export async function uploadStatsToGoogleSheet(stats: StatsSummary[], spreadsheetId: string, table = 'data') {
|
|
109
|
+
log.debug(`uploadResultsToGoogleSheet spreadsheetId: ${spreadsheetId} table: ${table}`)
|
|
110
|
+
if (!process.env.GOOGLE_CREDENTIALS_PATH) throw new Error('GOOGLE_CREDENTIALS_PATH environment variable is not set')
|
|
111
|
+
if (!fs.existsSync(process.env.GOOGLE_CREDENTIALS_PATH))
|
|
112
|
+
throw new Error(`Google credentials file not found: ${process.env.GOOGLE_CREDENTIALS_PATH}`)
|
|
113
|
+
if (!stats.length) return
|
|
114
|
+
const auth = new Auth.GoogleAuth({
|
|
115
|
+
keyFile: process.env.GOOGLE_CREDENTIALS_PATH,
|
|
116
|
+
scopes: ['https://www.googleapis.com/auth/spreadsheets'],
|
|
117
|
+
})
|
|
118
|
+
const sheets = google.sheets({ version: 'v4', auth })
|
|
119
|
+
// Update headers.
|
|
120
|
+
const headers = ['datetime', 'id', 'scenario', 'videoRecvBitratePerPixel', 'videoRecvFps']
|
|
121
|
+
await sheets.spreadsheets.values.update({
|
|
122
|
+
spreadsheetId,
|
|
123
|
+
range: `${table}!A1:E1`,
|
|
124
|
+
valueInputOption: 'USER_ENTERED',
|
|
125
|
+
requestBody: { majorDimension: 'ROWS', values: [headers] },
|
|
126
|
+
})
|
|
127
|
+
// Append values.
|
|
128
|
+
const values = [] as string[][]
|
|
129
|
+
stats.forEach(s => {
|
|
130
|
+
const { timestamp, id, scenario, videoRecvBitratePerPixel, videoRecvFps } = s
|
|
131
|
+
if (!videoRecvBitratePerPixel.length) return
|
|
132
|
+
const datetime = new Date(timestamp).toLocaleString('en-US', {
|
|
133
|
+
timeZone: 'UTC',
|
|
134
|
+
hourCycle: 'h23',
|
|
135
|
+
})
|
|
136
|
+
values.push([
|
|
137
|
+
datetime,
|
|
138
|
+
id,
|
|
139
|
+
formatThrottleRule(parseThrottleRule(scenario), true),
|
|
140
|
+
videoRecvBitratePerPixel.percentile(95).toFixed(3),
|
|
141
|
+
videoRecvFps.percentile(95).toFixed(3),
|
|
142
|
+
])
|
|
143
|
+
})
|
|
144
|
+
if (values.length) {
|
|
145
|
+
await sheets.spreadsheets.values.append({
|
|
146
|
+
spreadsheetId,
|
|
147
|
+
range: `${table}!A:E`,
|
|
148
|
+
valueInputOption: 'USER_ENTERED',
|
|
149
|
+
insertDataOption: 'INSERT_ROWS',
|
|
150
|
+
requestBody: { majorDimension: 'ROWS', values },
|
|
151
|
+
})
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
79
155
|
export type ThrottleDirection = 'up' | 'down' | 'bidi'
|
|
80
156
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
157
|
+
function formatBitrate(bitrate: number | undefined, prefix = ' ') {
|
|
158
|
+
if (bitrate === undefined) return ''
|
|
159
|
+
let suffix = 'Kbps'
|
|
160
|
+
if (bitrate >= 10000) {
|
|
161
|
+
bitrate /= 1000
|
|
162
|
+
suffix = 'Mbps'
|
|
163
|
+
}
|
|
164
|
+
return `${prefix}${bitrate.toFixed(0)}${suffix}`.padStart(8, ' ')
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function formatLoss(loss: number | undefined, prefix = ' ') {
|
|
168
|
+
return loss !== undefined ? `${prefix}${loss.toFixed(0).padStart(2, ' ')}%` : ''
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function formatDelay(delay: number | undefined, prefix = ' ') {
|
|
172
|
+
return delay !== undefined ? `${prefix}${delay.toFixed(0).padStart(3, ' ')}ms` : ''
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export function formatThrottleRule(throttleRule: ThrottleRule & { direction: ThrottleDirection }, human = false) {
|
|
176
|
+
const { rate, loss, delay, direction } = throttleRule
|
|
177
|
+
return human
|
|
178
|
+
? `${direction.padEnd(4, ' ')}${formatBitrate(rate)}${formatLoss(loss)}${formatDelay(delay)}`
|
|
179
|
+
: `${direction}-r${rate}-l${loss}-d${delay}`
|
|
84
180
|
}
|
|
85
181
|
|
|
86
182
|
export function parseThrottleRule(throttleDesc: string) {
|
|
@@ -93,7 +189,25 @@ export function parseThrottleRule(throttleDesc: string) {
|
|
|
93
189
|
return { direction, rate, loss, delay }
|
|
94
190
|
}
|
|
95
191
|
|
|
96
|
-
|
|
192
|
+
/**
|
|
193
|
+
* It generates a test configuration with a scenario including 2 participants.
|
|
194
|
+
* The first participant sends video and the second receives it.
|
|
195
|
+
* Both participants send and receive audio.
|
|
196
|
+
* The network conditions are applied according to the specified direction to the sender (`up`),
|
|
197
|
+
* the receiver (`down`) or both (`bidi`).
|
|
198
|
+
* The test is repeated the specified number of times.
|
|
199
|
+
* The output is an array of partial configuration objects that can be used to run the tests
|
|
200
|
+
* with the main application, after merging it with a configuration that includes
|
|
201
|
+
* the destination url (mandatory) and other optional parameters.
|
|
202
|
+
* @param id The unique identifier for the test scenario.
|
|
203
|
+
* @param options.rate The target bandwidth in kbps.
|
|
204
|
+
* @param options.loss The packet loss percentage.
|
|
205
|
+
* @param options.delay The network delay in milliseconds.
|
|
206
|
+
* @param options.direction The direction of the network throttling: 'up', 'down', or 'bidi'.
|
|
207
|
+
* @param repeat The number of times to repeat the test scenario. Default is 1.
|
|
208
|
+
* @returns An array of partial configuration objects for each test scenario.
|
|
209
|
+
*/
|
|
210
|
+
export async function twoParticipantsWithRateLossDelay(
|
|
97
211
|
id: string,
|
|
98
212
|
{ rate, loss, delay, direction }: { rate: number; loss: number; delay: number; direction: ThrottleDirection },
|
|
99
213
|
repeat: 1,
|
|
@@ -112,7 +226,7 @@ export async function simpleTestWithRateLossDelay(
|
|
|
112
226
|
{ rate, loss, delay, queue, at: 30 },
|
|
113
227
|
]
|
|
114
228
|
}
|
|
115
|
-
const throttleDesc = formatThrottleRule({ rate, loss, delay
|
|
229
|
+
const throttleDesc = formatThrottleRule({ rate, loss, delay, direction })
|
|
116
230
|
const now = Date.now()
|
|
117
231
|
const ret: Partial<Config>[] = []
|
|
118
232
|
for (let i = 0; i < repeat; i++) {
|