diff --git a/examples/utilities/render/rates.qml b/examples/utilities/render/rates.qml new file mode 100644 index 0000000000..f4a4ee2c6c --- /dev/null +++ b/examples/utilities/render/rates.qml @@ -0,0 +1,49 @@ +// +// stats.qml +// examples/utilities/cache +// +// Created by Zach Pomerantz on 4/1/2016 +// Copyright 2016 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html +// +import QtQuick 2.5 +import QtQuick.Controls 1.4 +import "../lib/plotperf" + +Item { + id: root + anchors.fill: parent + + property var caches: [ ["Present", "present"], ["Present", "present"], ["New", "newFrame"], ["Dropped", "dropped"], ["Simulation", "simulation"], ["Avatar", "avatar"] ] + property var colors: [ "#1AC567", "#00B4EF" ] + + Grid { + id: grid + rows: (root.caches.length / 2); columns: 2; spacing: 8 + anchors.fill: parent + + Repeater { + id: repeater + + model: root.caches + + Row { + PlotPerf { + title: modelData[0] + " Rate" + height: (grid.height - (grid.spacing * ((root.caches.length / 2) + 1))) / (root.caches.length / 2) + width: grid.width / 2 - grid.spacing * 1.5 + object: Rates + valueScale: 1 + valueUnit: "fps" + valueNumDigits: "2" + plots: [{ + prop: modelData[1], + color: root.colors[index % 2] + }] + } + } + } + } +} diff --git a/examples/utilities/render/renderRates.js b/examples/utilities/render/renderRates.js new file mode 100644 index 0000000000..1d15f4041c --- /dev/null +++ b/examples/utilities/render/renderRates.js @@ -0,0 +1,21 @@ +// +// cacheStats.js +// examples/utilities/cache +// +// Zach Pomerantz, created on 4/1/2016. +// Copyright 2016 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +// Set up the qml ui +var qml = Script.resolvePath('rates.qml'); +var window = new OverlayWindow({ + title: 'Render Rates', + source: qml, + width: 300, + height: 200 +}); +window.setPosition(500, 50); +window.closed.connect(function() { Script.stop(); }); diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 4e01fe85c3..4071043c87 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -131,6 +131,7 @@ #include "scripting/WebWindowClass.h" #include "scripting/WindowScriptingInterface.h" #include "scripting/ControllerScriptingInterface.h" +#include "scripting/RatesScriptingInterface.h" #if defined(Q_OS_MAC) || defined(Q_OS_WIN) #include "SpeechRecognizer.h" #endif @@ -1384,6 +1385,7 @@ void Application::initializeUi() { rootContext->setContextProperty("Preferences", DependencyManager::get().data()); rootContext->setContextProperty("AddressManager", DependencyManager::get().data()); rootContext->setContextProperty("FrameTimings", &_frameTimingsScriptingInterface); + rootContext->setContextProperty("Rates", new RatesScriptingInterface(this)); rootContext->setContextProperty("TREE_SCALE", TREE_SCALE); rootContext->setContextProperty("Quat", new Quat()); @@ -4439,6 +4441,8 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri // AvatarManager has some custom types AvatarManager::registerMetaTypes(scriptEngine); + scriptEngine->registerGlobalObject("Rates", new RatesScriptingInterface(this)); + // hook our avatar and avatar hash map object into this script engine scriptEngine->registerGlobalObject("MyAvatar", getMyAvatar()); qScriptRegisterMetaType(scriptEngine, audioListenModeToScriptValue, audioListenModeFromScriptValue); diff --git a/interface/src/scripting/RatesScriptingInterface.h b/interface/src/scripting/RatesScriptingInterface.h new file mode 100644 index 0000000000..7bcab0ea70 --- /dev/null +++ b/interface/src/scripting/RatesScriptingInterface.h @@ -0,0 +1,37 @@ +// +// RatesScriptingInterface.h +// interface/src/scripting +// +// Created by Zach Pomerantz on 4/20/16. +// Copyright 2016 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef HIFI_RATES_SCRIPTING_INTERFACE_H +#define HIFI_RATES_SCRIPTING_INTERFACE_H + +#include + +class RatesScriptingInterface : public QObject { + Q_OBJECT + + Q_PROPERTY(float render READ getRenderRate) + Q_PROPERTY(float present READ getPresentRate) + Q_PROPERTY(float newFrame READ getNewFrameRate) + Q_PROPERTY(float dropped READ getDropRate) + Q_PROPERTY(float simulation READ getSimulationRate) + Q_PROPERTY(float avatar READ getAvatarRate) + +public: + RatesScriptingInterface(QObject* parent) : QObject(parent) {} + float getRenderRate() { return qApp->getFps(); } + float getPresentRate() { return qApp->getActiveDisplayPlugin()->presentRate(); } + float getNewFrameRate() { return qApp->getActiveDisplayPlugin()->newFramePresentRate(); } + float getDropRate() { return qApp->getActiveDisplayPlugin()->droppedFrameRate(); } + float getSimulationRate() { return qApp->getAverageSimsPerSecond(); } + float getAvatarRate() { return qApp->getAvatarSimrate(); } +}; + +#endif // HIFI_INTERFACE_RATES_SCRIPTING_INTERFACE_H diff --git a/libraries/shared/src/shared/RateCounter.h b/libraries/shared/src/shared/RateCounter.h index e24b1e6eca..d04d87493a 100644 --- a/libraries/shared/src/shared/RateCounter.h +++ b/libraries/shared/src/shared/RateCounter.h @@ -11,6 +11,7 @@ #define hifi_Shared_RateCounter_h #include +#include #include #include @@ -20,6 +21,8 @@ template class RateCounter { public: + RateCounter() { _rate = 0; } // avoid use of std::atomic copy ctor + void increment(size_t count = 1) { auto now = usecTimestampNow(); float currentIntervalMs = (now - _start) / (float) USECS_PER_MSEC; @@ -42,8 +45,8 @@ public: private: uint64_t _start { usecTimestampNow() }; size_t _count { 0 }; - float _rate { 0 }; const float _scale { powf(10, PRECISION) }; + std::atomic _rate; }; #endif