Showing the changes to interface/src/FrameTimingsScriptingInterface.cpp (1 of 8 files). Show all
Unified · Split
| @@ -0,0 +1,53 @@ | |||
| 1 | // | ||
| 2 | // Created by Bradley Austin Davis on 2016/04/04 | ||
| 3 | // Copyright 2013-2016 High Fidelity, Inc. | ||
| 4 | // | ||
| 5 | // Distributed under the Apache License, Version 2.0. | ||
| 6 | // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html | ||
| 7 | // | ||
| 8 | |||
| 9 | #include "FrameTimingsScriptingInterface.h" | ||
| 10 | |||
| 11 | #include <TextureCache.h> | ||
| 12 | |||
| 13 | void FrameTimingsScriptingInterface::start() { | ||
| 14 | _values.clear(); | ||
| 15 | DependencyManager::get<TextureCache>()->setUnusedResourceCacheSize(0); | ||
| 16 | _values.reserve(8192); | ||
| 17 | _active = true; | ||
| 18 | } | ||
| 19 | |||
| 20 | void FrameTimingsScriptingInterface::addValue(uint64_t value) { | ||
| 21 | if (_active) { | ||
| 22 | _values.push_back(value); | ||
| 23 | } | ||
| 24 | } | ||
| 25 | |||
| 26 | void FrameTimingsScriptingInterface::finish() { | ||
| 27 | _active = false; | ||
| 28 | uint64_t total = 0; | ||
| 29 | _min = std::numeric_limits<uint64_t>::max(); | ||
| 30 | _max = std::numeric_limits<uint64_t>::lowest(); | ||
| 31 | size_t count = _values.size(); | ||
| 32 | for (auto i = 0; i < count; ++i) { | ||
| 33 | const uint64_t& value = _values[i]; | ||
| 34 | _max = std::max(_max, value); | ||
| 35 | _min = std::min(_min, value); | ||
| 36 | total += value; | ||
| 37 | } | ||
| 38 | _mean = (float)total / (float)count; | ||
| 39 | float deviationTotal = 0; | ||
| 40 | for (auto i = 0; i < count; ++i) { | ||
| 41 | float deviation = _values[i] - _mean; | ||
| 42 | deviationTotal += deviation*deviation; | ||
| 43 | } | ||
| 44 | _stdDev = sqrt(deviationTotal / (float)count); | ||
| 45 | } | ||
| 46 | |||
| 47 | QVariantList FrameTimingsScriptingInterface::getValues() const { | ||
| 48 | QVariantList result; | ||
| 49 | for (const auto& v : _values) { | ||
| 50 | result << v; | ||
| 51 | } | ||
| 52 | return result; | ||
| 53 | } | ||