mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 19:59:28 +02:00
Merge pull request #5896 from thoys/20672
Worklist job #20672 - Create a script to record a users stats
This commit is contained in:
commit
a6c3a601ae
5 changed files with 178 additions and 13 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));
|
||||||
|
}
|
67
examples/example/misc/statsExample.js
Normal file
67
examples/example/misc/statsExample.js
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
//
|
||||||
|
// statsExample.js
|
||||||
|
// examples/example/misc
|
||||||
|
//
|
||||||
|
// Created by Thijs Wenker on 24 Sept 2015
|
||||||
|
// Copyright 2015 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Prints the stats to the console.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
// The stats to be displayed
|
||||||
|
var stats = [
|
||||||
|
'serverCount',
|
||||||
|
'framerate', // a.k.a. FPS
|
||||||
|
'simrate',
|
||||||
|
'avatarSimrate',
|
||||||
|
'avatarCount',
|
||||||
|
'packetInCount',
|
||||||
|
'packetOutCount',
|
||||||
|
'mbpsIn',
|
||||||
|
'mbpsOut',
|
||||||
|
'audioPing',
|
||||||
|
'avatarPing',
|
||||||
|
'entitiesPing',
|
||||||
|
'assetPing',
|
||||||
|
'velocity',
|
||||||
|
'yaw',
|
||||||
|
'avatarMixerKbps',
|
||||||
|
'avatarMixerPps',
|
||||||
|
'audioMixerKbps',
|
||||||
|
'audioMixerPps',
|
||||||
|
'downloads',
|
||||||
|
'downloadsPending',
|
||||||
|
'triangles',
|
||||||
|
'quads',
|
||||||
|
'materialSwitches',
|
||||||
|
'meshOpaque',
|
||||||
|
'meshTranslucent',
|
||||||
|
'opaqueConsidered',
|
||||||
|
'opaqueOutOfView',
|
||||||
|
'opaqueTooSmall',
|
||||||
|
'translucentConsidered',
|
||||||
|
'translucentOutOfView',
|
||||||
|
'translucentTooSmall',
|
||||||
|
'sendingMode',
|
||||||
|
'packetStats',
|
||||||
|
'lodStatus',
|
||||||
|
'timingStats',
|
||||||
|
'serverElements',
|
||||||
|
'serverInternal',
|
||||||
|
'serverLeaves',
|
||||||
|
'localElements',
|
||||||
|
'localInternal',
|
||||||
|
'localLeaves'
|
||||||
|
];
|
||||||
|
|
||||||
|
// Force update the stats, in case the stats panel is invisible
|
||||||
|
Stats.forceUpdateStats();
|
||||||
|
|
||||||
|
// Loop through the stats and display them
|
||||||
|
for (var i in stats) {
|
||||||
|
var stat = stats[i];
|
||||||
|
print(stat + " = " + Stats[stat]);
|
||||||
|
}
|
|
@ -4075,6 +4075,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri
|
||||||
scriptEngine->registerFunction("WebWindow", WebWindowClass::constructor, 1);
|
scriptEngine->registerFunction("WebWindow", WebWindowClass::constructor, 1);
|
||||||
|
|
||||||
scriptEngine->registerGlobalObject("Menu", MenuScriptingInterface::getInstance());
|
scriptEngine->registerGlobalObject("Menu", MenuScriptingInterface::getInstance());
|
||||||
|
scriptEngine->registerGlobalObject("Stats", Stats::getInstance());
|
||||||
scriptEngine->registerGlobalObject("Settings", SettingsScriptingInterface::getInstance());
|
scriptEngine->registerGlobalObject("Settings", SettingsScriptingInterface::getInstance());
|
||||||
scriptEngine->registerGlobalObject("AudioDevice", AudioDeviceScriptingInterface::getInstance());
|
scriptEngine->registerGlobalObject("AudioDevice", AudioDeviceScriptingInterface::getInstance());
|
||||||
scriptEngine->registerGlobalObject("AnimationCache", DependencyManager::get<AnimationCache>().data());
|
scriptEngine->registerGlobalObject("AnimationCache", DependencyManager::get<AnimationCache>().data());
|
||||||
|
|
|
@ -89,14 +89,14 @@ bool Stats::includeTimingRecord(const QString& name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Stats::updateStats() {
|
void Stats::updateStats(bool force) {
|
||||||
if (!Menu::getInstance()->isOptionChecked(MenuOption::Stats)) {
|
if (!force) {
|
||||||
if (isVisible()) {
|
if (!Menu::getInstance()->isOptionChecked(MenuOption::Stats)) {
|
||||||
setVisible(false);
|
if (isVisible()) {
|
||||||
}
|
setVisible(false);
|
||||||
return;
|
}
|
||||||
} else {
|
return;
|
||||||
if (!isVisible()) {
|
} else if (!isVisible()) {
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,7 +161,7 @@ void Stats::updateStats() {
|
||||||
STAT_UPDATE(position, QVector3D(avatarPos.x, avatarPos.y, avatarPos.z));
|
STAT_UPDATE(position, QVector3D(avatarPos.x, avatarPos.y, avatarPos.z));
|
||||||
STAT_UPDATE_FLOAT(velocity, glm::length(myAvatar->getVelocity()), 0.1f);
|
STAT_UPDATE_FLOAT(velocity, glm::length(myAvatar->getVelocity()), 0.1f);
|
||||||
STAT_UPDATE_FLOAT(yaw, myAvatar->getBodyYaw(), 0.1f);
|
STAT_UPDATE_FLOAT(yaw, myAvatar->getBodyYaw(), 0.1f);
|
||||||
if (_expanded) {
|
if (_expanded || force) {
|
||||||
SharedNodePointer avatarMixer = nodeList->soloNodeOfType(NodeType::AvatarMixer);
|
SharedNodePointer avatarMixer = nodeList->soloNodeOfType(NodeType::AvatarMixer);
|
||||||
if (avatarMixer) {
|
if (avatarMixer) {
|
||||||
STAT_UPDATE(avatarMixerKbps, roundf(
|
STAT_UPDATE(avatarMixerKbps, roundf(
|
||||||
|
@ -175,7 +175,7 @@ void Stats::updateStats() {
|
||||||
STAT_UPDATE(avatarMixerPps, -1);
|
STAT_UPDATE(avatarMixerPps, -1);
|
||||||
}
|
}
|
||||||
SharedNodePointer audioMixerNode = nodeList->soloNodeOfType(NodeType::AudioMixer);
|
SharedNodePointer audioMixerNode = nodeList->soloNodeOfType(NodeType::AudioMixer);
|
||||||
if (audioMixerNode) {
|
if (audioMixerNode || force) {
|
||||||
STAT_UPDATE(audioMixerKbps, roundf(
|
STAT_UPDATE(audioMixerKbps, roundf(
|
||||||
bandwidthRecorder->getAverageInputKilobitsPerSecond(NodeType::AudioMixer) +
|
bandwidthRecorder->getAverageInputKilobitsPerSecond(NodeType::AudioMixer) +
|
||||||
bandwidthRecorder->getAverageOutputKilobitsPerSecond(NodeType::AudioMixer)));
|
bandwidthRecorder->getAverageOutputKilobitsPerSecond(NodeType::AudioMixer)));
|
||||||
|
@ -230,7 +230,7 @@ void Stats::updateStats() {
|
||||||
totalLeaves += stats.getTotalLeaves();
|
totalLeaves += stats.getTotalLeaves();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (_expanded) {
|
if (_expanded || force) {
|
||||||
if (serverCount == 0) {
|
if (serverCount == 0) {
|
||||||
sendingModeStream << "---";
|
sendingModeStream << "---";
|
||||||
}
|
}
|
||||||
|
@ -272,7 +272,7 @@ void Stats::updateStats() {
|
||||||
STAT_UPDATE(serverElements, (int)totalNodes);
|
STAT_UPDATE(serverElements, (int)totalNodes);
|
||||||
STAT_UPDATE(localElements, (int)OctreeElement::getNodeCount());
|
STAT_UPDATE(localElements, (int)OctreeElement::getNodeCount());
|
||||||
|
|
||||||
if (_expanded) {
|
if (_expanded || force) {
|
||||||
STAT_UPDATE(serverInternal, (int)totalInternal);
|
STAT_UPDATE(serverInternal, (int)totalInternal);
|
||||||
STAT_UPDATE(serverLeaves, (int)totalLeaves);
|
STAT_UPDATE(serverLeaves, (int)totalLeaves);
|
||||||
// Local Voxels
|
// Local Voxels
|
||||||
|
|
|
@ -81,7 +81,7 @@ public:
|
||||||
const QString& monospaceFont() {
|
const QString& monospaceFont() {
|
||||||
return _monospaceFont;
|
return _monospaceFont;
|
||||||
}
|
}
|
||||||
void updateStats();
|
void updateStats(bool force = false);
|
||||||
|
|
||||||
bool isExpanded() { return _expanded; }
|
bool isExpanded() { return _expanded; }
|
||||||
bool isTimingExpanded() { return _timingExpanded; }
|
bool isTimingExpanded() { return _timingExpanded; }
|
||||||
|
@ -93,6 +93,9 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void forceUpdateStats() { updateStats(true); }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void expandedChanged();
|
void expandedChanged();
|
||||||
void timingExpandedChanged();
|
void timingExpandedChanged();
|
||||||
|
@ -149,3 +152,4 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_Stats_h
|
#endif // hifi_Stats_h
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue