feat(ui-flow): voice trace bytes/sec window and reset on leave-voice
Track rolling bytesPerSec in voice-capture trace logs and reset capture counters when the user leaves voice. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -9,6 +9,16 @@ const flowLog = createLogger('ui-flow')
|
|||||||
let voiceCaptureChunkCount = 0
|
let voiceCaptureChunkCount = 0
|
||||||
let voiceCaptureBytes = 0
|
let voiceCaptureBytes = 0
|
||||||
let displayCaptureFrameCount = 0
|
let displayCaptureFrameCount = 0
|
||||||
|
let voiceCaptureTraceWindowStart = 0
|
||||||
|
let voiceCaptureTraceWindowBytes = 0
|
||||||
|
|
||||||
|
function resetVoiceCaptureTrace () {
|
||||||
|
voiceCaptureChunkCount = 0
|
||||||
|
voiceCaptureBytes = 0
|
||||||
|
displayCaptureFrameCount = 0
|
||||||
|
voiceCaptureTraceWindowStart = Date.now()
|
||||||
|
voiceCaptureTraceWindowBytes = 0
|
||||||
|
}
|
||||||
|
|
||||||
function fromBase64 (str) {
|
function fromBase64 (str) {
|
||||||
if (typeof Buffer !== 'undefined') return Buffer.from(str || '', 'base64')
|
if (typeof Buffer !== 'undefined') return Buffer.from(str || '', 'base64')
|
||||||
@@ -426,19 +436,29 @@ async function dispatchUiMessage (platform, msg, hooks = {}) {
|
|||||||
if (t === 'voice-capture-chunk') {
|
if (t === 'voice-capture-chunk') {
|
||||||
voiceCaptureChunkCount++
|
voiceCaptureChunkCount++
|
||||||
const chunk = msg.data
|
const chunk = msg.data
|
||||||
|
let nbytes = 0
|
||||||
if (chunk) {
|
if (chunk) {
|
||||||
if (typeof chunk === 'string') voiceCaptureBytes += chunk.length
|
if (typeof chunk === 'string') nbytes = chunk.length
|
||||||
else if (chunk.byteLength != null) voiceCaptureBytes += chunk.byteLength
|
else if (chunk.byteLength != null) nbytes = chunk.byteLength
|
||||||
else if (chunk.length != null) voiceCaptureBytes += chunk.length
|
else if (chunk.length != null) nbytes = chunk.length
|
||||||
|
voiceCaptureBytes += nbytes
|
||||||
}
|
}
|
||||||
if (
|
if (process.env.PEARCORD_LOG_VOICE_CAPTURE_TRACE === '1') {
|
||||||
process.env.PEARCORD_LOG_VOICE_CAPTURE_TRACE === '1' &&
|
if (!voiceCaptureTraceWindowStart) voiceCaptureTraceWindowStart = Date.now()
|
||||||
voiceCaptureChunkCount % 200 === 0
|
voiceCaptureTraceWindowBytes += nbytes
|
||||||
) {
|
if (voiceCaptureChunkCount % 200 === 0) {
|
||||||
log.trace('voice-capture chunks', {
|
const elapsedSec = Math.max(
|
||||||
count: voiceCaptureChunkCount,
|
0.001,
|
||||||
bytes: voiceCaptureBytes
|
(Date.now() - voiceCaptureTraceWindowStart) / 1000
|
||||||
})
|
)
|
||||||
|
log.trace('voice-capture chunks', {
|
||||||
|
count: voiceCaptureChunkCount,
|
||||||
|
bytes: voiceCaptureBytes,
|
||||||
|
bytesPerSec: Math.round(voiceCaptureTraceWindowBytes / elapsedSec)
|
||||||
|
})
|
||||||
|
voiceCaptureTraceWindowStart = Date.now()
|
||||||
|
voiceCaptureTraceWindowBytes = 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
platform.ingestVoiceCapture(msg.data)
|
platform.ingestVoiceCapture(msg.data)
|
||||||
return true
|
return true
|
||||||
@@ -553,6 +573,7 @@ async function dispatchUiMessage (platform, msg, hooks = {}) {
|
|||||||
}
|
}
|
||||||
if (t === 'leave-voice') {
|
if (t === 'leave-voice') {
|
||||||
await platform.leaveVoiceChannel()
|
await platform.leaveVoiceChannel()
|
||||||
|
resetVoiceCaptureTrace()
|
||||||
pushState()
|
pushState()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user