Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coviu/cpu usage monitor #24

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,29 @@ module.exports = function(qc, opts) {

function log(peerId, pc, data) {
if (!provider) return;
return provider.getStats(pc).then((reports) => {
const tc = connections[data.id];

// Only reschedule while we are monitoring
if (tc) {
timers[data.id] = setTimeout(log.bind(this, peerId, pc, data), emitter.pollInterval);
}
return provider.getStats(pc)
.then(reports => provider.pushCustomCoviuStats(reports))
.then(reports => {
const tc = connections[data.id];

var reporter = new Reporter({
source: qc.id,
about: data,
pc: pc,
reports: reports
});
// Only reschedule while we are monitoring
if (tc) {
timers[data.id] = setTimeout(log.bind(this, peerId, pc, data), emitter.pollInterval);
}

emitter.emit('health:report', reporter, pc);
}).catch((err) => {
// No operation
});
var reporter = new Reporter({
source: qc.id,
about: data,
pc: pc,
reports: reports
});

emitter.emit('health:report', reporter, pc);
})
.catch(err => {
// No operation
});
}

/**
Expand Down
54 changes: 54 additions & 0 deletions lib/custom-stats/render-rate-volatility.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const StatsReport = require('../statsreport');

// stores the last 8 FPS per incoming video
const rollingFpsSamples = {};

const pushFpsSamples = (inboundRtpStats) => {
inboundRtpStats.forEach(stat => {
const { trackIdentifier, framesPerSecond } = stat.data || {};
if (!trackIdentifier || isNaN(framesPerSecond)) return;

const sample = rollingFpsSamples[trackIdentifier] = rollingFpsSamples[trackIdentifier] || [];

if (sample.length >= 8) sample.shift();

sample.push(framesPerSecond);
});
};

const getRenderRateVolatilityStat = (fpsSample, trackIdentifier) => {
const meanFps = fpsSample.reduce((sum, currentFps) => {
return sum + currentFps;
}, 0) / fpsSample.length;

const latestFps = fpsSample[fpsSample.length - 1];

const renderRateVolatility = (Math.abs(latestFps - meanFps) * 100) / meanFps;

const stat = new StatsReport({
id: `renderratevolatility:${trackIdentifier}`,
type: 'coviuRenderRateVolatility',
category: 'coviuStat',
version: '1.0'
});

stat.set('trackIdentifier', trackIdentifier);
stat.set('renderRateVolatility', renderRateVolatility);

return stat;
};

module.exports = (stats) => {
const inboundRtpStats = stats.filter(stat => stat.type === 'inboundRtp'
&& stat.data?.kind === 'video'
&& !!stat.data?.trackIdentifier
);
pushFpsSamples(inboundRtpStats);

const renderRateVolatilities = Object.keys(rollingFpsSamples).map(trackId => {
const sample = rollingFpsSamples[trackId];
return getRenderRateVolatilityStat(sample, trackId);
});

return renderRateVolatilities;
};
5 changes: 4 additions & 1 deletion lib/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ exports.AS_INT = [
'frameWidthSent', 'nacksReceived', 'plisReceived',

'decodingCNG', 'decodingCTN', 'decodingCTSG', 'decodingNormal',
'decodingPLC', 'decodingPLCCNG'
'decodingPLC', 'decodingPLCCNG',

// custom coviu stats
'renderRateVolatility'
];

exports.AS_COMPARABLE = [
Expand Down
Loading