Collecting stats every fixed time in webrtc_video_streaming.js test
and prepare the format these collected stats to be plotted using one of external dev-tools. R=andresp@webrtc.org Review URL: https://webrtc-codereview.appspot.com/29589004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@7340 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
db75a66b0f
commit
d0bb5862f5
@ -17,10 +17,9 @@ var vm = require('vm');
|
||||
var BotManager = require('./botmanager.js');
|
||||
|
||||
function Test(botType) {
|
||||
// TODO(houssainy) set the time out.
|
||||
this.timeout_ = setTimeout(
|
||||
this.fail.bind(this, "Test timeout!"),
|
||||
10000);
|
||||
100000);
|
||||
this.botType_ = botType;
|
||||
}
|
||||
|
||||
@ -74,12 +73,64 @@ Test.prototype = {
|
||||
this.botManager_ = new BotManager();
|
||||
this.botManager_.spawnNewBot(name, this.botType_, doneCallback);
|
||||
},
|
||||
|
||||
createStatisticsReport: function (outputFileName) {
|
||||
return new StatisticsReport(outputFileName);
|
||||
},
|
||||
}
|
||||
|
||||
StatisticsReport = function (outputFileName) {
|
||||
this.output_ = [];
|
||||
this.output_.push("Version: 1");
|
||||
this.outputFileName_ = outputFileName;
|
||||
}
|
||||
|
||||
StatisticsReport.prototype = {
|
||||
collectStatsFromPeerConnection: function (prefix, pc) {
|
||||
setInterval(this.addPeerConnectionStats.bind(this, prefix, pc), 100);
|
||||
},
|
||||
|
||||
addPeerConnectionStats: function (prefix, pc) {
|
||||
pc.getStats(onStatsReady.bind(this));
|
||||
|
||||
function onStatsReady(reports) {
|
||||
for (index in reports) {
|
||||
var stats = {};
|
||||
stats[reports[index].id] = collectStats(reports[index].stats);
|
||||
|
||||
var data = {};
|
||||
data[prefix] = stats;
|
||||
|
||||
this.output_.push({
|
||||
type: "UpdateCounters",
|
||||
startTime: (new Date()).getTime(),
|
||||
data: data,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
function collectStats(stats) {
|
||||
var outputStats = {};
|
||||
for (index in stats) {
|
||||
var statValue = parseFloat(stats[index].stat);
|
||||
outputStats[stats[index].name] = isNaN(statValue)?
|
||||
stats[index].stat : statValue;
|
||||
}
|
||||
return outputStats;
|
||||
};
|
||||
},
|
||||
|
||||
finish: function (doneCallback) {
|
||||
fs.writeFile("test/reports/" + this.outputFileName_ + "_" +
|
||||
(new Date()).getTime() +".json", JSON.stringify(this.output_),
|
||||
doneCallback);
|
||||
},
|
||||
}
|
||||
|
||||
function runTest(botType, testfile) {
|
||||
console.log("Running test: " + testfile);
|
||||
var script = vm.createScript(fs.readFileSync(testfile), testfile);
|
||||
script.runInNewContext({ test: new Test(botType), setInterval: setInterval
|
||||
script.runInNewContext({ test: new Test(botType), setInterval: setInterval,
|
||||
setTimeout: setTimeout });
|
||||
}
|
||||
|
||||
|
||||
@ -7,15 +7,17 @@
|
||||
// be found in the AUTHORS file in the root of the source tree.
|
||||
//
|
||||
// A unidirectional video and audio flowing test from bot 1 to bot 2.
|
||||
// The test succeeds after collecting stats for 10 seconds from both bots
|
||||
// and then write these stats to a file.
|
||||
//
|
||||
// Note: the source of the video and audio stream is getUserMedia().
|
||||
//
|
||||
// TODO(houssainy): get a condition to terminate the test.
|
||||
//
|
||||
function testVideoStreaming(bot1, bot2) {
|
||||
var pc1 = null;
|
||||
var pc2 = null;
|
||||
|
||||
var report = test.createStatisticsReport("webrtc_video_streaming");
|
||||
|
||||
test.wait([
|
||||
createPeerConnection.bind(bot1),
|
||||
createPeerConnection.bind(bot2) ],
|
||||
@ -81,11 +83,21 @@ function testVideoStreaming(bot1, bot2) {
|
||||
test.fail);
|
||||
pc1.setRemoteDescription(answer, onSetSessionDescriptionSuccess,
|
||||
test.fail);
|
||||
collectStats();
|
||||
}
|
||||
|
||||
function onSetSessionDescriptionSuccess() {
|
||||
test.log("Set session description success.");
|
||||
}
|
||||
|
||||
function collectStats() {
|
||||
report.collectStatsFromPeerConnection("bot1", pc1);
|
||||
report.collectStatsFromPeerConnection("bot2", pc2);
|
||||
|
||||
setTimeout(function() {
|
||||
report.finish(test.done);
|
||||
}, 10000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user