Merge branch 'master' of https://github.com/highfidelity/hifi into improveInterval

Conflicts:
	tests/networking/src/ResourceTests.cpp
This commit is contained in:
Brad Hefta-Gaub 2016-12-29 16:42:52 -08:00
commit 84eca0159e
13 changed files with 86 additions and 75 deletions

View file

@ -38,13 +38,13 @@ set(${EXTERNAL_NAME_UPPER}_DLL_PATH ${INSTALL_DIR}/lib CACHE FILEPATH "Location
if (APPLE) if (APPLE)
set(${EXTERNAL_NAME_UPPER}_LIBRARY_RELEASE ${INSTALL_DIR}/lib/libquazip5.1.0.0.dylib CACHE FILEPATH "Location of QuaZip release library") set(${EXTERNAL_NAME_UPPER}_LIBRARY_RELEASE ${INSTALL_DIR}/lib/libquazip5.1.0.0.dylib CACHE FILEPATH "Location of QuaZip release library")
set(${EXTERNAL_NAME_UPPER}_LIBRARY_DEBUG ${INSTALL_DIR}/lib/libquazip5d.1.0.0.dylib CACHE FILEPATH "Location of QuaZip release library") set(${EXTERNAL_NAME_UPPER}_LIBRARY_DEBUG ${INSTALL_DIR}/lib/libquazip5.1.0.0.dylib CACHE FILEPATH "Location of QuaZip release library")
elseif (WIN32) elseif (WIN32)
set(${EXTERNAL_NAME_UPPER}_LIBRARY_RELEASE ${INSTALL_DIR}/lib/quazip5.lib CACHE FILEPATH "Location of QuaZip release library") set(${EXTERNAL_NAME_UPPER}_LIBRARY_RELEASE ${INSTALL_DIR}/lib/quazip5.lib CACHE FILEPATH "Location of QuaZip release library")
set(${EXTERNAL_NAME_UPPER}_LIBRARY_DEBUG ${INSTALL_DIR}/lib/quazip5d.lib CACHE FILEPATH "Location of QuaZip release library") set(${EXTERNAL_NAME_UPPER}_LIBRARY_DEBUG ${INSTALL_DIR}/lib/quazip5.lib CACHE FILEPATH "Location of QuaZip release library")
else () else ()
set(${EXTERNAL_NAME_UPPER}_LIBRARY_RELEASE ${INSTALL_DIR}/lib/libquazip5.so CACHE FILEPATH "Location of QuaZip release library") set(${EXTERNAL_NAME_UPPER}_LIBRARY_RELEASE ${INSTALL_DIR}/lib/libquazip5.so CACHE FILEPATH "Location of QuaZip release library")
set(${EXTERNAL_NAME_UPPER}_LIBRARY_DEBUG ${INSTALL_DIR}/lib/libquazip5d.so CACHE FILEPATH "Location of QuaZip release library") set(${EXTERNAL_NAME_UPPER}_LIBRARY_DEBUG ${INSTALL_DIR}/lib/libquazip5.so CACHE FILEPATH "Location of QuaZip release library")
endif () endif ()
include(SelectLibraryConfigurations) include(SelectLibraryConfigurations)
@ -52,4 +52,4 @@ select_library_configurations(${EXTERNAL_NAME_UPPER})
# Force selected libraries into the cache # Force selected libraries into the cache
set(${EXTERNAL_NAME_UPPER}_LIBRARY ${${EXTERNAL_NAME_UPPER}_LIBRARY} CACHE FILEPATH "Location of QuaZip libraries") set(${EXTERNAL_NAME_UPPER}_LIBRARY ${${EXTERNAL_NAME_UPPER}_LIBRARY} CACHE FILEPATH "Location of QuaZip libraries")
set(${EXTERNAL_NAME_UPPER}_LIBRARIES ${${EXTERNAL_NAME_UPPER}_LIBRARIES} CACHE FILEPATH "Location of QuaZip libraries") set(${EXTERNAL_NAME_UPPER}_LIBRARIES ${${EXTERNAL_NAME_UPPER}_LIBRARIES} CACHE FILEPATH "Location of QuaZip libraries")

View file

@ -1271,6 +1271,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
properties["sim_rate"] = getAverageSimsPerSecond(); properties["sim_rate"] = getAverageSimsPerSecond();
properties["avatar_sim_rate"] = getAvatarSimrate(); properties["avatar_sim_rate"] = getAvatarSimrate();
properties["has_async_reprojection"] = displayPlugin->hasAsyncReprojection(); properties["has_async_reprojection"] = displayPlugin->hasAsyncReprojection();
properties["hardware_stats"] = displayPlugin->getHardwareStats();
auto bandwidthRecorder = DependencyManager::get<BandwidthRecorder>(); auto bandwidthRecorder = DependencyManager::get<BandwidthRecorder>();
properties["packet_rate_in"] = bandwidthRecorder->getCachedTotalAverageInputPacketsPerSecond(); properties["packet_rate_in"] = bandwidthRecorder->getCachedTotalAverageInputPacketsPerSecond();

View file

@ -16,6 +16,7 @@
#include <QtCore/QSize> #include <QtCore/QSize>
#include <QtCore/QPoint> #include <QtCore/QPoint>
#include <QtCore/QElapsedTimer> #include <QtCore/QElapsedTimer>
#include <QtCore/QJsonObject>
#include <GLMHelpers.h> #include <GLMHelpers.h>
#include <RegisteredMetaTypes.h> #include <RegisteredMetaTypes.h>
@ -194,6 +195,9 @@ public:
virtual float newFramePresentRate() const { return -1.0f; } virtual float newFramePresentRate() const { return -1.0f; }
// Rate at which rendered frames are being skipped // Rate at which rendered frames are being skipped
virtual float droppedFrameRate() const { return -1.0f; } virtual float droppedFrameRate() const { return -1.0f; }
// Hardware specific stats
virtual QJsonObject getHardwareStats() const { return QJsonObject(); }
uint32_t presentCount() const { return _presentedFrameIndex; } uint32_t presentCount() const { return _presentedFrameIndex; }
// Time since last call to incrementPresentCount (only valid if DEBUG_PAINT_DELAY is defined) // Time since last call to incrementPresentCount (only valid if DEBUG_PAINT_DELAY is defined)

View file

@ -370,7 +370,7 @@ glm::quat glmExtractRotation(const glm::mat4& matrix) {
glm::vec3 extractScale(const glm::mat4& matrix) { glm::vec3 extractScale(const glm::mat4& matrix) {
glm::mat3 m(matrix); glm::mat3 m(matrix);
float det = glm::determinant(m); float det = glm::determinant(m);
if (det < 0) { if (det < 0.0f) {
// left handed matrix, flip sign to compensate. // left handed matrix, flip sign to compensate.
return glm::vec3(-glm::length(m[0]), glm::length(m[1]), glm::length(m[2])); return glm::vec3(-glm::length(m[0]), glm::length(m[1]), glm::length(m[2]));
} else { } else {

View file

@ -22,6 +22,13 @@
const char* OculusDisplayPlugin::NAME { "Oculus Rift" }; const char* OculusDisplayPlugin::NAME { "Oculus Rift" };
static ovrPerfHudMode currentDebugMode = ovrPerfHud_Off; static ovrPerfHudMode currentDebugMode = ovrPerfHud_Off;
OculusDisplayPlugin::OculusDisplayPlugin() {
_appDroppedFrames.store(0);
_compositorDroppedFrames.store(0);
}
bool OculusDisplayPlugin::internalActivate() { bool OculusDisplayPlugin::internalActivate() {
bool result = Parent::internalActivate(); bool result = Parent::internalActivate();
currentDebugMode = ovrPerfHud_Off; currentDebugMode = ovrPerfHud_Off;
@ -147,19 +154,31 @@ void OculusDisplayPlugin::hmdPresent() {
logWarning("Failed to present"); logWarning("Failed to present");
} }
static int droppedFrames = 0; static int compositorDroppedFrames = 0;
static int appDroppedFrames = 0;
ovrPerfStats perfStats; ovrPerfStats perfStats;
ovr_GetPerfStats(_session, &perfStats); ovr_GetPerfStats(_session, &perfStats);
for (int i = 0; i < perfStats.FrameStatsCount; ++i) { for (int i = 0; i < perfStats.FrameStatsCount; ++i) {
const auto& frameStats = perfStats.FrameStats[i]; const auto& frameStats = perfStats.FrameStats[i];
int delta = frameStats.CompositorDroppedFrameCount - droppedFrames; int delta = frameStats.CompositorDroppedFrameCount - compositorDroppedFrames;
_stutterRate.increment(delta); _stutterRate.increment(delta);
droppedFrames = frameStats.CompositorDroppedFrameCount; compositorDroppedFrames = frameStats.CompositorDroppedFrameCount;
appDroppedFrames = frameStats.AppDroppedFrameCount;
} }
_appDroppedFrames.store(appDroppedFrames);
_compositorDroppedFrames.store(compositorDroppedFrames);
} }
_presentRate.increment(); _presentRate.increment();
} }
QJsonObject OculusDisplayPlugin::getHardwareStats() const {
QJsonObject hardwareStats;
hardwareStats["app_dropped_frame_count"] = _appDroppedFrames.load();
hardwareStats["compositor_dropped_frame_count"] = _compositorDroppedFrames.load();
return hardwareStats;
}
bool OculusDisplayPlugin::isHmdMounted() const { bool OculusDisplayPlugin::isHmdMounted() const {
ovrSessionStatus status; ovrSessionStatus status;
return (OVR_SUCCESS(ovr_GetSessionStatus(_session, &status)) && return (OVR_SUCCESS(ovr_GetSessionStatus(_session, &status)) &&

View file

@ -12,6 +12,7 @@
class OculusDisplayPlugin : public OculusBaseDisplayPlugin { class OculusDisplayPlugin : public OculusBaseDisplayPlugin {
using Parent = OculusBaseDisplayPlugin; using Parent = OculusBaseDisplayPlugin;
public: public:
OculusDisplayPlugin();
~OculusDisplayPlugin(); ~OculusDisplayPlugin();
const QString getName() const override { return NAME; } const QString getName() const override { return NAME; }
@ -19,6 +20,8 @@ public:
QString getPreferredAudioInDevice() const override; QString getPreferredAudioInDevice() const override;
QString getPreferredAudioOutDevice() const override; QString getPreferredAudioOutDevice() const override;
virtual QJsonObject getHardwareStats() const;
protected: protected:
bool internalActivate() override; bool internalActivate() override;
@ -33,5 +36,8 @@ private:
ovrTextureSwapChain _textureSwapChain; ovrTextureSwapChain _textureSwapChain;
gpu::FramebufferPointer _outputFramebuffer; gpu::FramebufferPointer _outputFramebuffer;
bool _customized { false }; bool _customized { false };
std::atomic_int _compositorDroppedFrames;
std::atomic_int _appDroppedFrames;
}; };

View file

@ -36,7 +36,7 @@ void AudioRingBufferTests::runAllTests() {
int readIndexAt; int readIndexAt;
AudioRingBuffer ringBuffer(10, false, 10); // makes buffer of 100 int16_t samples AudioRingBuffer ringBuffer(10, 10); // makes buffer of 100 int16_t samples
for (int T = 0; T < 300; T++) { for (int T = 0; T < 300; T++) {
writeIndexAt = 0; writeIndexAt = 0;

View file

@ -12,29 +12,29 @@
#include "PacketTests.h" #include "PacketTests.h"
#include "../QTestExtensions.h" #include "../QTestExtensions.h"
#include <udt/Packet.h> #include <NLPacket.h>
QTEST_MAIN(PacketTests) QTEST_MAIN(PacketTests)
std::unique_ptr<Packet> copyToReadPacket(std::unique_ptr<Packet>& packet) { std::unique_ptr<NLPacket> copyToReadPacket(std::unique_ptr<NLPacket>& packet) {
auto size = packet->getDataSize(); auto size = packet->getDataSize();
auto data = std::unique_ptr<char[]>(new char[size]); auto data = std::unique_ptr<char[]>(new char[size]);
memcpy(data.get(), packet->getData(), size); memcpy(data.get(), packet->getData(), size);
return Packet::fromReceivedPacket(std::move(data), size, HifiSockAddr()); return NLPacket::fromReceivedPacket(std::move(data), size, HifiSockAddr());
} }
void PacketTests::emptyPacketTest() { void PacketTests::emptyPacketTest() {
auto packet = Packet::create(PacketType::Unknown); auto packet = NLPacket::create(PacketType::Unknown);
QCOMPARE(packet->getType(), PacketType::Unknown); QCOMPARE(packet->getType(), PacketType::Unknown);
QCOMPARE(packet->getPayloadSize(), 0); QCOMPARE(packet->getPayloadSize(), 0);
QCOMPARE(packet->getDataSize(), packet->totalHeadersSize()); QCOMPARE(packet->getDataSize(), NLPacket::totalHeaderSize(packet->getType()));
QCOMPARE(packet->bytesLeftToRead(), 0); QCOMPARE(packet->bytesLeftToRead(), 0);
QCOMPARE(packet->bytesAvailableForWrite(), packet->getPayloadCapacity()); QCOMPARE(packet->bytesAvailableForWrite(), packet->getPayloadCapacity());
} }
void PacketTests::packetTypeTest() { void PacketTests::packetTypeTest() {
auto packet = Packet::create(PacketType::EntityAdd); auto packet = NLPacket::create(PacketType::EntityAdd);
QCOMPARE(packet->getType(), PacketType::EntityAdd); QCOMPARE(packet->getType(), PacketType::EntityAdd);
@ -46,7 +46,7 @@ void PacketTests::packetTypeTest() {
} }
void PacketTests::writeTest() { void PacketTests::writeTest() {
auto packet = Packet::create(PacketType::Unknown); auto packet = NLPacket::create(PacketType::Unknown);
QCOMPARE(packet->getPayloadSize(), 0); QCOMPARE(packet->getPayloadSize(), 0);
@ -62,7 +62,7 @@ void PacketTests::writeTest() {
void PacketTests::readTest() { void PacketTests::readTest() {
// Test reads for several different size packets // Test reads for several different size packets
for (int i = 1; i < 4; i++) { for (int i = 1; i < 4; i++) {
auto packet = Packet::create(PacketType::Unknown); auto packet = NLPacket::create(PacketType::Unknown);
auto size = packet->getPayloadCapacity(); auto size = packet->getPayloadCapacity();
size /= i; size /= i;
@ -91,7 +91,7 @@ void PacketTests::readTest() {
} }
void PacketTests::writePastCapacityTest() { void PacketTests::writePastCapacityTest() {
auto packet = Packet::create(PacketType::Unknown); auto packet = NLPacket::create(PacketType::Unknown);
auto size = packet->getPayloadCapacity(); auto size = packet->getPayloadCapacity();
char* data = new char[size]; char* data = new char[size];
@ -111,20 +111,20 @@ void PacketTests::writePastCapacityTest() {
QCOMPARE(packet->bytesAvailableForWrite(), 0); QCOMPARE(packet->bytesAvailableForWrite(), 0);
QCOMPARE(packet->getPayloadSize(), size); QCOMPARE(packet->getPayloadSize(), size);
QCOMPARE(Packet::PACKET_WRITE_ERROR, packet->write("data")); QCOMPARE(NLPacket::PACKET_WRITE_ERROR, packet->write("data")); // asserts in DEBUG
// Packet::write() shouldn't allow the caller to write if no space is left // NLPacket::write() shouldn't allow the caller to write if no space is left
QCOMPARE(packet->getPayloadSize(), size); QCOMPARE(packet->getPayloadSize(), size);
} }
void PacketTests::primitiveTest() { void PacketTests::primitiveTest() {
auto packet = Packet::create(PacketType::Unknown); auto packet = NLPacket::create(PacketType::Unknown);
int value1 = 5; int value1 = 5;
char value2 = 10; char value2 = 10;
bool value3 = true; bool value3 = true;
qint64 value4 = -93404; qint64 value4 = -93404;
packet->writePrimitive(value1); packet->writePrimitive(value1);
packet->writePrimitive(value2); packet->writePrimitive(value2);
packet->writePrimitive(value3); packet->writePrimitive(value3);
@ -133,7 +133,7 @@ void PacketTests::primitiveTest() {
auto recvPacket = copyToReadPacket(packet); auto recvPacket = copyToReadPacket(packet);
// Peek & read first value // Peek & read first value
{ {
int peekValue = 0; int peekValue = 0;
QCOMPARE(recvPacket->peekPrimitive(&peekValue), (int)sizeof(peekValue)); QCOMPARE(recvPacket->peekPrimitive(&peekValue), (int)sizeof(peekValue));
QCOMPARE(peekValue, value1); QCOMPARE(peekValue, value1);

View file

@ -37,31 +37,10 @@ void ResourceTests::initTestCase() {
static QSharedPointer<Resource> resource; static QSharedPointer<Resource> resource;
static bool waitForSignal(QObject *sender, const char *signal, int timeout = 1000) {
QEventLoop loop;
QTimer timer;
// The default timer type is not very accurate below about 200ms http://doc.qt.io/qt-5/qt.html#TimerType-enum
static const int MIN_TIMEOUT_FOR_COARSE_TIMER = 200;
if (timeout < MIN_TIMEOUT_FOR_COARSE_TIMER) {
timer.setTimerType(Qt::PreciseTimer);
}
timer.setInterval(timeout);
timer.setSingleShot(true);
loop.connect(sender, signal, SLOT(quit()));
loop.connect(&timer, SIGNAL(timeout()), SLOT(quit()));
timer.start();
loop.exec();
return timer.isActive();
}
void ResourceTests::downloadFirst() { void ResourceTests::downloadFirst() {
// download the Mery fst file // download the Mery fst file
QUrl meryUrl = QUrl("http://hifi-public.s3.amazonaws.com/marketplace/contents/e21c0b95-e502-4d15-8c41-ea2fc40f1125/3585ddf674869a67d31d5964f7b52de1.fst"); QUrl meryUrl = QUrl("http://hifi-public.s3.amazonaws.com/marketplace/contents/e21c0b95-e502-4d15-8c41-ea2fc40f1125/3585ddf674869a67d31d5964f7b52de1.fst");
resource = QSharedPointer<Resource>::create(meryUrl, false); resource = QSharedPointer<Resource>::create(meryUrl);
resource->setSelf(resource); resource->setSelf(resource);
const int timeout = 1000; const int timeout = 1000;
@ -70,9 +49,9 @@ void ResourceTests::downloadFirst() {
timer.setInterval(timeout); // 1s, Qt::CoarseTimer acceptable timer.setInterval(timeout); // 1s, Qt::CoarseTimer acceptable
timer.setSingleShot(true); timer.setSingleShot(true);
loop.connect(resource, SIGNAL(loaded(QNetworkReply&)), SLOT(quit())); connect(resource.data(), &Resource::loaded, &loop, &QEventLoop::quit);
loop.connect(resource, SIGNAL(failed(QNetworkReply::NetworkError)), SLOT(quit())); connect(resource.data(), &Resource::failed, &loop, &QEventLoop::quit);
loop.connect(&timer, SIGNAL(timeout()), SLOT(quit())); connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
timer.start(); timer.start();
resource->ensureLoading(); resource->ensureLoading();
@ -82,10 +61,9 @@ void ResourceTests::downloadFirst() {
} }
void ResourceTests::downloadAgain() { void ResourceTests::downloadAgain() {
// download the Mery fst file // download the Mery fst file
QUrl meryUrl = QUrl("http://hifi-public.s3.amazonaws.com/marketplace/contents/e21c0b95-e502-4d15-8c41-ea2fc40f1125/3585ddf674869a67d31d5964f7b52de1.fst"); QUrl meryUrl = QUrl("http://hifi-public.s3.amazonaws.com/marketplace/contents/e21c0b95-e502-4d15-8c41-ea2fc40f1125/3585ddf674869a67d31d5964f7b52de1.fst");
resource = QSharedPointer<Resource>::create(meryUrl, false); resource = QSharedPointer<Resource>::create(meryUrl);
resource->setSelf(resource); resource->setSelf(resource);
const int timeout = 1000; const int timeout = 1000;
@ -94,14 +72,13 @@ void ResourceTests::downloadAgain() {
timer.setInterval(timeout); // 1s, Qt::CoarseTimer acceptable timer.setInterval(timeout); // 1s, Qt::CoarseTimer acceptable
timer.setSingleShot(true); timer.setSingleShot(true);
loop.connect(resource, SIGNAL(loaded(QNetworkReply&)), SLOT(quit())); connect(resource.data(), &Resource::loaded, &loop, &QEventLoop::quit);
loop.connect(resource, SIGNAL(failed(QNetworkReply::NetworkError)), SLOT(quit())); connect(resource.data(), &Resource::failed, &loop, &QEventLoop::quit);
loop.connect(&timer, SIGNAL(timeout()), SLOT(quit())); connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
timer.start(); timer.start();
resource->ensureLoading(); resource->ensureLoading();
loop.exec(); loop.exec();
QVERIFY(resource->isLoaded()); QVERIFY(resource->isLoaded());
} }

View file

@ -255,11 +255,11 @@ void GeometryUtilTests::testTwistSwingDecomposition() {
glm::quat measuredTwistRotation; glm::quat measuredTwistRotation;
glm::quat measuredSwingRotation; glm::quat measuredSwingRotation;
swingTwistDecomposition(totalRotation, twistAxis, measuredSwingRotation, measuredTwistRotation); swingTwistDecomposition(totalRotation, twistAxis, measuredSwingRotation, measuredTwistRotation);
// dot decomposed with components // dot decomposed with components
float twistDot = fabsf(glm::dot(twistRotation, measuredTwistRotation)); float twistDot = fabsf(glm::dot(twistRotation, measuredTwistRotation));
float swingDot = fabsf(glm::dot(swingRotation, measuredSwingRotation)); float swingDot = fabsf(glm::dot(swingRotation, measuredSwingRotation));
// the dot products should be very close to 1.0 // the dot products should be very close to 1.0
const float MIN_ERROR = 1.0e-6f; const float MIN_ERROR = 1.0e-6f;
QCOMPARE_WITH_ABS_ERROR(1.0f, twistDot, MIN_ERROR); QCOMPARE_WITH_ABS_ERROR(1.0f, twistDot, MIN_ERROR);
@ -277,7 +277,7 @@ void GeometryUtilTests::testSphereCapsulePenetration() {
glm::vec3 capsuleEnd(0.0f, 10.0f, 0.0f); glm::vec3 capsuleEnd(0.0f, 10.0f, 0.0f);
float capsuleRadius = 1.0f; float capsuleRadius = 1.0f;
glm::vec3 penetration(glm::vec3::_null); glm::vec3 penetration(0.0f);
bool hit = findSphereCapsulePenetration(sphereCenter, sphereRadius, capsuleStart, capsuleEnd, capsuleRadius, penetration); bool hit = findSphereCapsulePenetration(sphereCenter, sphereRadius, capsuleStart, capsuleEnd, capsuleRadius, penetration);
QCOMPARE(hit, true); QCOMPARE(hit, true);
QCOMPARE_WITH_ABS_ERROR(penetration, glm::vec3(-0.5f, 0.0f, 0.0f), EPSILON); QCOMPARE_WITH_ABS_ERROR(penetration, glm::vec3(-0.5f, 0.0f, 0.0f), EPSILON);

View file

@ -39,19 +39,21 @@ void MovingPercentileTests::testRunningMedian() {
} }
float MovingPercentileTests::random() { int64_t MovingPercentileTests::random() {
return rand() / (float)RAND_MAX; return ((int64_t) rand() << 48) ^
((int64_t) rand() << 32) ^
((int64_t) rand() << 16) ^
((int64_t) rand());
} }
void MovingPercentileTests::testRunningMinForN (int n) { void MovingPercentileTests::testRunningMinForN (int n) {
// Stores the last n samples // Stores the last n samples
QQueue<float> samples; QQueue<int64_t> samples;
MovingPercentile movingMin (n, 0.0f); MovingPercentile movingMin (n, 0.0f);
for (int s = 0; s < 3 * n; ++s) { for (int s = 0; s < 3 * n; ++s) {
float sample = random(); int64_t sample = random();
samples.push_back(sample); samples.push_back(sample);
if (samples.size() > n) if (samples.size() > n)
@ -64,30 +66,32 @@ void MovingPercentileTests::testRunningMinForN (int n) {
movingMin.updatePercentile(sample); movingMin.updatePercentile(sample);
// Calculate the minimum of the moving samples // Calculate the minimum of the moving samples
float expectedMin = std::numeric_limits<float>::max(); int64_t expectedMin = std::numeric_limits<int64_t>::max();
int prevSize = samples.size(); int prevSize = samples.size();
for (auto val : samples) for (auto val : samples) {
expectedMin = std::min(val, expectedMin); expectedMin = std::min(val, expectedMin);
}
QCOMPARE(samples.size(), prevSize); QCOMPARE(samples.size(), prevSize);
QCOMPARE(movingMin.getValueAtPercentile(), expectedMin); QVERIFY(movingMin.getValueAtPercentile() - expectedMin == 0L);
} }
} }
void MovingPercentileTests::testRunningMaxForN (int n) { void MovingPercentileTests::testRunningMaxForN (int n) {
// Stores the last n samples // Stores the last n samples
QQueue<float> samples; QQueue<int64_t> samples;
MovingPercentile movingMax (n, 1.0f); MovingPercentile movingMax (n, 1.0f);
for (int s = 0; s < 10000; ++s) { for (int s = 0; s < 10000; ++s) {
float sample = random(); int64_t sample = random();
samples.push_back(sample); samples.push_back(sample);
if (samples.size() > n) if (samples.size() > n) {
samples.pop_front(); samples.pop_front();
}
if (samples.size() == 0) { if (samples.size() == 0) {
QFAIL_WITH_MESSAGE("\n\n\n\tWTF\n\tsamples.size() = " << samples.size() << ", n = " << n); QFAIL_WITH_MESSAGE("\n\n\n\tWTF\n\tsamples.size() = " << samples.size() << ", n = " << n);
@ -96,22 +100,22 @@ void MovingPercentileTests::testRunningMaxForN (int n) {
movingMax.updatePercentile(sample); movingMax.updatePercentile(sample);
// Calculate the maximum of the moving samples // Calculate the maximum of the moving samples
float expectedMax = std::numeric_limits<float>::min(); int64_t expectedMax = std::numeric_limits<int64_t>::min();
for (auto val : samples) for (auto val : samples)
expectedMax = std::max(val, expectedMax); expectedMax = std::max(val, expectedMax);
QCOMPARE(movingMax.getValueAtPercentile(), expectedMax); QVERIFY(movingMax.getValueAtPercentile() - expectedMax == 0L);
} }
} }
void MovingPercentileTests::testRunningMedianForN (int n) { void MovingPercentileTests::testRunningMedianForN (int n) {
// Stores the last n samples // Stores the last n samples
QQueue<float> samples; QQueue<int64_t> samples;
MovingPercentile movingMedian (n, 0.5f); MovingPercentile movingMedian (n, 0.5f);
for (int s = 0; s < 10000; ++s) { for (int s = 0; s < 10000; ++s) {
float sample = random(); int64_t sample = random();
samples.push_back(sample); samples.push_back(sample);
if (samples.size() > n) if (samples.size() > n)

View file

@ -25,7 +25,7 @@ private slots:
private: private:
// Utilities and helper functions // Utilities and helper functions
float random(); int64_t random();
void testRunningMinForN (int n); void testRunningMinForN (int n);
void testRunningMaxForN (int n); void testRunningMaxForN (int n);
void testRunningMedianForN (int n); void testRunningMedianForN (int n);

View file

@ -28,7 +28,7 @@ void TraceTests::testTraceSerialization() {
auto start = usecTimestampNow(); auto start = usecTimestampNow();
PROFILE_RANGE(test, "TestEvent") PROFILE_RANGE(test, "TestEvent")
for (size_t i = 0; i < 10000; ++i) { for (size_t i = 0; i < 10000; ++i) {
SAMPLE_PROFILE_COUNTER(0.1f, test, "TestCounter", { { "i", i } }) SAMPLE_PROFILE_COUNTER(0.1f, test, "TestCounter", { { "i", (int)i } })
} }
auto duration = usecTimestampNow() - start; auto duration = usecTimestampNow() - start;
duration /= USECS_PER_MSEC; duration /= USECS_PER_MSEC;