mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 11:45:36 +02:00
Merge pull request #1 from imgntn/thoys-20672
Update stat collection to occur in batches
This commit is contained in:
commit
5fc053cf97
1 changed files with 93 additions and 0 deletions
93
examples/example/misc/collectHifiStats.js
Normal file
93
examples/example/misc/collectHifiStats.js
Normal file
|
@ -0,0 +1,93 @@
|
|||
//
|
||||
// collectHifiStats.js
|
||||
//
|
||||
// Created by Thijs Wenker on 24 Sept 2015
|
||||
// Additions by James B. Pollack @imgntn on 25 Sept 2015
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// Collects stats for analysis to a REST endpoint. Defaults to batching stats, but can be customized.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
// The url where the data will be posted.
|
||||
var ENDPOINT_URL = "";
|
||||
|
||||
var BATCH_STATS = true;
|
||||
var BATCH_SIZE = 5;
|
||||
|
||||
var batch = [];
|
||||
|
||||
if (BATCH_STATS) {
|
||||
|
||||
var RECORD_EVERY = 1000; // 1 seconds
|
||||
var batchCount = 0;
|
||||
|
||||
Script.setInterval(function() {
|
||||
|
||||
if (batchCount === BATCH_SIZE) {
|
||||
sendBatchToEndpoint(batch);
|
||||
batchCount = 0;
|
||||
}
|
||||
Stats.forceUpdateStats();
|
||||
batch.push(getBatchStats());
|
||||
batchCount++;
|
||||
}, RECORD_EVERY);
|
||||
|
||||
|
||||
} else {
|
||||
// Send the data every:
|
||||
var SEND_EVERY = 30000; // 30 seconds
|
||||
|
||||
Script.setInterval(function() {
|
||||
Stats.forceUpdateStats();
|
||||
var req = new XMLHttpRequest();
|
||||
req.open("POST", ENDPOINT_URL, false);
|
||||
req.send(getStats());
|
||||
}, SEND_EVERY);
|
||||
}
|
||||
|
||||
function getStats() {
|
||||
return JSON.stringify({
|
||||
username: GlobalServices.username,
|
||||
location: Window.location.hostname,
|
||||
framerate: Stats.framerate,
|
||||
simrate: Stats.simrate,
|
||||
ping: {
|
||||
audio: Stats.audioPing,
|
||||
avatar: Stats.avatarPing,
|
||||
entities: Stats.entitiesPing,
|
||||
asset: Stats.assetPing
|
||||
},
|
||||
position: Camera.position,
|
||||
yaw: Stats.yaw,
|
||||
rotation: Camera.orientation.x + ',' + Camera.orientation.y + ',' + Camera.orientation.z + ',' + Camera.orientation.w
|
||||
})
|
||||
}
|
||||
|
||||
function getBatchStats() {
|
||||
// print('GET BATCH STATS');
|
||||
return {
|
||||
username: GlobalServices.username,
|
||||
location: Window.location.hostname,
|
||||
framerate: Stats.framerate,
|
||||
simrate: Stats.simrate,
|
||||
ping: {
|
||||
audio: Stats.audioPing,
|
||||
avatar: Stats.avatarPing,
|
||||
entities: Stats.entitiesPing,
|
||||
asset: Stats.assetPing
|
||||
},
|
||||
position: Camera.position,
|
||||
yaw: Stats.yaw,
|
||||
rotation: Camera.orientation.x + ',' + Camera.orientation.y + ',' + Camera.orientation.z + ',' + Camera.orientation.w
|
||||
}
|
||||
}
|
||||
|
||||
function sendBatchToEndpoint(batch) {
|
||||
// print('SEND BATCH TO ENDPOINT');
|
||||
var req = new XMLHttpRequest();
|
||||
req.open("POST", ENDPOINT_URL, false);
|
||||
req.send(JSON.stringify(batch));
|
||||
}
|
Loading…
Reference in a new issue