From 4df9302af9a72258c87bc0cc3152f2698d1dfabc Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 11 Nov 2016 16:23:23 -0800 Subject: [PATCH 1/7] Disable access to deleteLater in ScriptEngine --- libraries/script-engine/src/ScriptEngine.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 776c7cfec6..489787d35b 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -66,6 +66,7 @@ #include "MIDIEvent.h" static const QString SCRIPT_EXCEPTION_FORMAT = "[UncaughtException] %1 in %2:%3"; +static const QScriptEngine::QObjectWrapOptions DEFAULT_QOBJECT_WRAP_OPTIONS = 0; Q_DECLARE_METATYPE(QScriptEngine::FunctionSignature) int functionSignatureMetaID = qRegisterMetaType(); @@ -90,7 +91,7 @@ static QScriptValue debugPrint(QScriptContext* context, QScriptEngine* engine){ } QScriptValue avatarDataToScriptValue(QScriptEngine* engine, AvatarData* const &in) { - return engine->newQObject(in); + return engine->newQObject(in, QScriptEngine::QtOwnership, DEFAULT_QOBJECT_WRAP_OPTIONS); } void avatarDataFromScriptValue(const QScriptValue &object, AvatarData* &out) { @@ -101,7 +102,7 @@ Q_DECLARE_METATYPE(controller::InputController*) //static int inputControllerPointerId = qRegisterMetaType(); QScriptValue inputControllerToScriptValue(QScriptEngine *engine, controller::InputController* const &in) { - return engine->newQObject(in); + return engine->newQObject(in, QScriptEngine::QtOwnership, DEFAULT_QOBJECT_WRAP_OPTIONS); } void inputControllerFromScriptValue(const QScriptValue &object, controller::InputController* &out) { @@ -440,7 +441,8 @@ static QScriptValue scriptableResourceToScriptValue(QScriptEngine* engine, const auto object = engine->newQObject( const_cast(resource), - QScriptEngine::ScriptOwnership); + QScriptEngine::ScriptOwnership, + DEFAULT_QOBJECT_WRAP_OPTIONS); return object; } @@ -459,7 +461,8 @@ static QScriptValue createScriptableResourcePrototype(QScriptEngine* engine) { state->setProperty(metaEnum.key(i), metaEnum.value(i)); } - auto prototypeState = engine->newQObject(state, QScriptEngine::QtOwnership, QScriptEngine::ExcludeSlots | QScriptEngine::ExcludeSuperClassMethods); + auto prototypeState = engine->newQObject(state, QScriptEngine::QtOwnership, + QScriptEngine::ExcludeDeleteLater | QScriptEngine::ExcludeSlots | QScriptEngine::ExcludeSuperClassMethods); prototype.setProperty("State", prototypeState); return prototype; @@ -592,7 +595,7 @@ void ScriptEngine::registerGlobalObject(const QString& name, QObject* object) { if (!globalObject().property(name).isValid()) { if (object) { - QScriptValue value = newQObject(object); + QScriptValue value = newQObject(object, QScriptEngine::QtOwnership, DEFAULT_QOBJECT_WRAP_OPTIONS); globalObject().setProperty(name, value); } else { globalObject().setProperty(name, QScriptValue()); From 51586ae0a33cacc9496c69977f0ac3f859108634 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 11 Nov 2016 16:25:44 -0800 Subject: [PATCH 2/7] Fix log typo in SpatiallyNestable --- libraries/script-engine/src/ScriptEngine.cpp | 3 ++- libraries/shared/src/SpatiallyNestable.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 489787d35b..85c26d15c0 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -66,7 +66,8 @@ #include "MIDIEvent.h" static const QString SCRIPT_EXCEPTION_FORMAT = "[UncaughtException] %1 in %2:%3"; -static const QScriptEngine::QObjectWrapOptions DEFAULT_QOBJECT_WRAP_OPTIONS = 0; +static const QScriptEngine::QObjectWrapOptions DEFAULT_QOBJECT_WRAP_OPTIONS = + QScriptEngine::ExcludeDeleteLater | QScriptEngine::ExcludeChildObjects; Q_DECLARE_METATYPE(QScriptEngine::FunctionSignature) int functionSignatureMetaID = qRegisterMetaType(); diff --git a/libraries/shared/src/SpatiallyNestable.cpp b/libraries/shared/src/SpatiallyNestable.cpp index f75557f73f..2149e72483 100644 --- a/libraries/shared/src/SpatiallyNestable.cpp +++ b/libraries/shared/src/SpatiallyNestable.cpp @@ -488,7 +488,7 @@ glm::vec3 SpatiallyNestable::getVelocity() const { bool success; glm::vec3 result = getVelocity(success); if (!success) { - qDebug() << "Warning -- setVelocity failed" << getID(); + qDebug() << "Warning -- getVelocity failed" << getID(); } return result; } From 8c7ec8b0c58a6ace7112fbf8266910ca145b70fa Mon Sep 17 00:00:00 2001 From: samcake Date: Mon, 9 Jan 2017 18:05:02 -0800 Subject: [PATCH 3/7] Add profiling in COntext batch execution and shortcuts for trace names --- libraries/gpu/src/gpu/Context.cpp | 3 +++ libraries/shared/src/Trace.cpp | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/libraries/gpu/src/gpu/Context.cpp b/libraries/gpu/src/gpu/Context.cpp index b1af4968e0..78b472bdae 100644 --- a/libraries/gpu/src/gpu/Context.cpp +++ b/libraries/gpu/src/gpu/Context.cpp @@ -81,6 +81,7 @@ FramePointer Context::endFrame() { } void Context::executeBatch(Batch& batch) const { + PROFILE_RANGE(render_gpu, __FUNCTION__); batch.flush(); _backend->render(batch); } @@ -94,6 +95,8 @@ void Context::consumeFrameUpdates(const FramePointer& frame) const { } void Context::executeFrame(const FramePointer& frame) const { + PROFILE_RANGE(render_gpu, __FUNCTION__); + // Grab the stats at the around the frame and delta to have a consistent sampling ContextStats beginStats; getStats(beginStats); diff --git a/libraries/shared/src/Trace.cpp b/libraries/shared/src/Trace.cpp index 8422f7f8a9..e4ad70d912 100644 --- a/libraries/shared/src/Trace.cpp +++ b/libraries/shared/src/Trace.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -107,6 +108,12 @@ void Tracer::serialize(const QString& originalPath) { QString path = originalPath; + // Filter for specific tokens potentially present in the path: + auto now = QDateTime::currentDateTime(); + + path = path.replace("{DATE}", now.date().toString("yyyyMMdd")); + path = path.replace("{TIME}", now.time().toString("HHmm")); + // If the filename is relative, turn it into an absolute path relative to the document directory. QFileInfo originalFileInfo(path); if (originalFileInfo.isRelative()) { From 1dd2747ef95c88151f77faf39e226c55a2ba0e97 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Mon, 9 Jan 2017 11:34:47 -0800 Subject: [PATCH 4/7] Push some tracing into 'detail' categories for easy filtering. Add new tracing categories, add counter change tracking. --- interface/src/Application.cpp | 23 +++++++++--------- libraries/animation/src/Rig.cpp | 2 +- .../display-plugins/OpenGLDisplayPlugin.cpp | 8 +++---- .../src/RenderableModelEntityItem.cpp | 2 +- libraries/gpu-gl/src/gpu/gl/GLBackend.cpp | 24 +++++++++++-------- .../gpu-gl/src/gpu/gl/GLBackendQuery.cpp | 4 ++-- libraries/gpu-gl/src/gpu/gl/GLShared.cpp | 1 + libraries/gpu-gl/src/gpu/gl/GLShared.h | 1 + libraries/render-utils/src/Model.cpp | 4 ++-- libraries/shared/src/Profile.cpp | 5 ++++ libraries/shared/src/Profile.h | 7 ++++++ 11 files changed, 50 insertions(+), 31 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 681d160821..ad869ddae3 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -193,8 +193,9 @@ static QTimer pingTimer; static const int MAX_CONCURRENT_RESOURCE_DOWNLOADS = 16; -// For processing on QThreadPool, target 2 less than the ideal number of threads, leaving -// 2 logical cores available for time sensitive tasks. +// For processing on QThreadPool, we target a number of threads after reserving some +// based on how many are being consumed by the application and the display plugin. However, +// we will never drop below the 'min' value static const int MIN_PROCESSING_THREAD_POOL_SIZE = 2; static const QString SNAPSHOT_EXTENSION = ".jpg"; @@ -3313,15 +3314,15 @@ void Application::idle(float nsecsElapsed) { connect(offscreenUi.data(), &OffscreenUi::showDesktop, this, &Application::showDesktop); } - PROFILE_COUNTER(app, "fps", { { "fps", _frameCounter.rate() } }); - PROFILE_COUNTER(app, "downloads", { - { "current", ResourceCache::getLoadingRequests().length() }, - { "pending", ResourceCache::getPendingRequestCount() } - }); - PROFILE_COUNTER(app, "processing", { - { "current", DependencyManager::get()->getStat("Processing") }, - { "pending", DependencyManager::get()->getStat("PendingProcessing") } - }); + auto displayPlugin = getActiveDisplayPlugin(); + if (displayPlugin) { + PROFILE_COUNTER_IF_CHANGED(app, "present", float, displayPlugin->presentRate()); + } + PROFILE_COUNTER_IF_CHANGED(app, "fps", float, _frameCounter.rate()); + PROFILE_COUNTER_IF_CHANGED(app, "currentDownloads", int, ResourceCache::getLoadingRequests().length()); + PROFILE_COUNTER_IF_CHANGED(app, "pendingDownloads", int, ResourceCache::getPendingRequestCount()); + PROFILE_COUNTER_IF_CHANGED(app, "currentProcessing", int, DependencyManager::get()->getStat("Processing").toInt()); + PROFILE_COUNTER_IF_CHANGED(app, "pendingProcessing", int, DependencyManager::get()->getStat("PendingProcessing").toInt()); PROFILE_RANGE(app, __FUNCTION__); diff --git a/libraries/animation/src/Rig.cpp b/libraries/animation/src/Rig.cpp index 8d0c2567fe..fdeeb01739 100644 --- a/libraries/animation/src/Rig.cpp +++ b/libraries/animation/src/Rig.cpp @@ -902,7 +902,7 @@ void Rig::updateAnimationStateHandlers() { // called on avatar update thread (wh void Rig::updateAnimations(float deltaTime, glm::mat4 rootTransform) { - PROFILE_RANGE_EX(simulation_animation, __FUNCTION__, 0xffff00ff, 0); + PROFILE_RANGE_EX(simulation_animation_detail, __FUNCTION__, 0xffff00ff, 0); PerformanceTimer perfTimer("updateAnimations"); setModelOffset(rootTransform); diff --git a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp index a6f7d3caf4..e57c2b1d52 100644 --- a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp @@ -561,22 +561,22 @@ void OpenGLDisplayPlugin::compositeLayers() { updateCompositeFramebuffer(); { - PROFILE_RANGE_EX(render, "compositeScene", 0xff0077ff, (uint64_t)presentCount()) + PROFILE_RANGE_EX(render_detail, "compositeScene", 0xff0077ff, (uint64_t)presentCount()) compositeScene(); } { - PROFILE_RANGE_EX(render, "compositeOverlay", 0xff0077ff, (uint64_t)presentCount()) + PROFILE_RANGE_EX(render_detail, "compositeOverlay", 0xff0077ff, (uint64_t)presentCount()) compositeOverlay(); } auto compositorHelper = DependencyManager::get(); if (compositorHelper->getReticleVisible()) { - PROFILE_RANGE_EX(render, "compositePointer", 0xff0077ff, (uint64_t)presentCount()) + PROFILE_RANGE_EX(render_detail, "compositePointer", 0xff0077ff, (uint64_t)presentCount()) compositePointer(); } { - PROFILE_RANGE_EX(render, "compositeExtra", 0xff0077ff, (uint64_t)presentCount()) + PROFILE_RANGE_EX(render_detail, "compositeExtra", 0xff0077ff, (uint64_t)presentCount()) compositeExtra(); } } diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index f0d39f7507..b901db38e7 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -211,7 +211,7 @@ namespace render { template <> void payloadRender(const RenderableModelEntityItemMeta::Pointer& payload, RenderArgs* args) { if (args) { if (payload && payload->entity) { - PROFILE_RANGE(render, "MetaModelRender"); + PROFILE_RANGE(render_detail, "MetaModelRender"); payload->entity->render(args); } } diff --git a/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp b/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp index 071bfef766..dbfe8fe730 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp @@ -200,7 +200,7 @@ void GLBackend::renderPassTransfer(const Batch& batch) { _inRenderTransferPass = true; { // Sync all the buffers - PROFILE_RANGE(render_gpu_gl, "syncGPUBuffer"); + PROFILE_RANGE(render_gpu_gl_detail, "syncGPUBuffer"); for (auto& cached : batch._buffers._items) { if (cached._data) { @@ -210,7 +210,7 @@ void GLBackend::renderPassTransfer(const Batch& batch) { } { // Sync all the buffers - PROFILE_RANGE(render_gpu_gl, "syncCPUTransform"); + PROFILE_RANGE(render_gpu_gl_detail, "syncCPUTransform"); _transform._cameras.clear(); _transform._cameraOffsets.clear(); @@ -242,7 +242,7 @@ void GLBackend::renderPassTransfer(const Batch& batch) { } { // Sync the transform buffers - PROFILE_RANGE(render_gpu_gl, "syncGPUTransform"); + PROFILE_RANGE(render_gpu_gl_detail, "syncGPUTransform"); transferTransformState(batch); } @@ -304,7 +304,7 @@ void GLBackend::render(const Batch& batch) { } { - PROFILE_RANGE(render_gpu_gl, "Transfer"); + PROFILE_RANGE(render_gpu_gl_detail, "Transfer"); renderPassTransfer(batch); } @@ -314,7 +314,7 @@ void GLBackend::render(const Batch& batch) { } #endif { - PROFILE_RANGE(render_gpu_gl, _stereo._enable ? "Render Stereo" : "Render"); + PROFILE_RANGE(render_gpu_gl_detail, _stereo._enable ? "Render Stereo" : "Render"); renderPassDraw(batch); } #ifdef GPU_STEREO_DRAWCALL_INSTANCED @@ -387,18 +387,22 @@ void GLBackend::resetStages() { void GLBackend::do_pushProfileRange(const Batch& batch, size_t paramOffset) { - auto name = batch._profileRanges.get(batch._params[paramOffset]._uint); - profileRanges.push_back(name); + if (trace_render_gpu_gl_detail().isDebugEnabled()) { + auto name = batch._profileRanges.get(batch._params[paramOffset]._uint); + profileRanges.push_back(name); #if defined(NSIGHT_FOUND) - nvtxRangePush(name.c_str()); + nvtxRangePush(name.c_str()); #endif + } } void GLBackend::do_popProfileRange(const Batch& batch, size_t paramOffset) { - profileRanges.pop_back(); + if (trace_render_gpu_gl_detail().isDebugEnabled()) { + profileRanges.pop_back(); #if defined(NSIGHT_FOUND) - nvtxRangePop(); + nvtxRangePop(); #endif + } } // TODO: As long as we have gl calls explicitely issued from interface diff --git a/libraries/gpu-gl/src/gpu/gl/GLBackendQuery.cpp b/libraries/gpu-gl/src/gpu/gl/GLBackendQuery.cpp index b4afd86abb..bdea67a99a 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLBackendQuery.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLBackendQuery.cpp @@ -28,7 +28,7 @@ void GLBackend::do_beginQuery(const Batch& batch, size_t paramOffset) { auto query = batch._queries.get(batch._params[paramOffset]._uint); GLQuery* glquery = syncGPUObject(*query); if (glquery) { - PROFILE_RANGE_BEGIN(render_gpu_gl, glquery->_profileRangeId, query->getName().c_str(), 0xFFFF7F00); + PROFILE_RANGE_BEGIN(render_gpu_gl_detail, glquery->_profileRangeId, query->getName().c_str(), 0xFFFF7F00); ++_queryStage._rangeQueryDepth; glGetInteger64v(GL_TIMESTAMP, (GLint64*)&glquery->_batchElapsedTime); @@ -62,7 +62,7 @@ void GLBackend::do_endQuery(const Batch& batch, size_t paramOffset) { glGetInteger64v(GL_TIMESTAMP, &now); glquery->_batchElapsedTime = now - glquery->_batchElapsedTime; - PROFILE_RANGE_END(render_gpu_gl, glquery->_profileRangeId); + PROFILE_RANGE_END(render_gpu_gl_detail, glquery->_profileRangeId); (void)CHECK_GL_ERROR(); } diff --git a/libraries/gpu-gl/src/gpu/gl/GLShared.cpp b/libraries/gpu-gl/src/gpu/gl/GLShared.cpp index 59ffc52e85..7acdc0ec79 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLShared.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLShared.cpp @@ -17,6 +17,7 @@ Q_LOGGING_CATEGORY(gpugllogging, "hifi.gpu.gl") Q_LOGGING_CATEGORY(trace_render_gpu_gl, "trace.render.gpu.gl") +Q_LOGGING_CATEGORY(trace_render_gpu_gl_detail, "trace.render.gpu.gl.detail") namespace gpu { namespace gl { diff --git a/libraries/gpu-gl/src/gpu/gl/GLShared.h b/libraries/gpu-gl/src/gpu/gl/GLShared.h index 7c4d8106f9..b0eec23448 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLShared.h +++ b/libraries/gpu-gl/src/gpu/gl/GLShared.h @@ -16,6 +16,7 @@ Q_DECLARE_LOGGING_CATEGORY(gpugllogging) Q_DECLARE_LOGGING_CATEGORY(trace_render_gpu_gl) +Q_DECLARE_LOGGING_CATEGORY(trace_render_gpu_gl_detail) namespace gpu { namespace gl { diff --git a/libraries/render-utils/src/Model.cpp b/libraries/render-utils/src/Model.cpp index ffbe1fb34c..32c42ca7c0 100644 --- a/libraries/render-utils/src/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -283,7 +283,7 @@ void Model::reset() { } bool Model::updateGeometry() { - PROFILE_RANGE(render, __FUNCTION__); + PROFILE_RANGE(render_detail, __FUNCTION__); PerformanceTimer perfTimer("Model::updateGeometry"); bool needFullUpdate = false; @@ -1114,7 +1114,7 @@ void Model::snapToRegistrationPoint() { } void Model::simulate(float deltaTime, bool fullUpdate) { - PROFILE_RANGE(simulation, __FUNCTION__); + PROFILE_RANGE(simulation_detail, __FUNCTION__); PerformanceTimer perfTimer("Model::simulate"); fullUpdate = updateGeometry() || fullUpdate || (_scaleToFit && !_scaledToFit) || (_snapModelToRegistrationPoint && !_snappedToRegistrationPoint); diff --git a/libraries/shared/src/Profile.cpp b/libraries/shared/src/Profile.cpp index 27ca303ccc..f23c17c6be 100644 --- a/libraries/shared/src/Profile.cpp +++ b/libraries/shared/src/Profile.cpp @@ -9,16 +9,21 @@ #include "Profile.h" Q_LOGGING_CATEGORY(trace_app, "trace.app") +Q_LOGGING_CATEGORY(trace_app_detail, "trace.app.detail") Q_LOGGING_CATEGORY(trace_network, "trace.network") Q_LOGGING_CATEGORY(trace_parse, "trace.parse") Q_LOGGING_CATEGORY(trace_render, "trace.render") +Q_LOGGING_CATEGORY(trace_render_detail, "trace.render.detail") Q_LOGGING_CATEGORY(trace_render_gpu, "trace.render.gpu") Q_LOGGING_CATEGORY(trace_resource, "trace.resource") Q_LOGGING_CATEGORY(trace_resource_network, "trace.resource.network") Q_LOGGING_CATEGORY(trace_resource_parse, "trace.resource.parse") Q_LOGGING_CATEGORY(trace_simulation, "trace.simulation") +Q_LOGGING_CATEGORY(trace_simulation_detail, "trace.simulation.detail") Q_LOGGING_CATEGORY(trace_simulation_animation, "trace.simulation.animation") +Q_LOGGING_CATEGORY(trace_simulation_animation_detail, "trace.simulation.animation.detail") Q_LOGGING_CATEGORY(trace_simulation_physics, "trace.simulation.physics") +Q_LOGGING_CATEGORY(trace_simulation_physics_detail, "trace.simulation.physics.detail") #if defined(NSIGHT_FOUND) #include "nvToolsExt.h" diff --git a/libraries/shared/src/Profile.h b/libraries/shared/src/Profile.h index 7472768ce1..da786526a7 100644 --- a/libraries/shared/src/Profile.h +++ b/libraries/shared/src/Profile.h @@ -13,16 +13,22 @@ #include "Trace.h" #include "SharedUtil.h" +// When profiling something that may happen many times per frame, use a xxx_detail category so that they may easily be filtered out of trace results Q_DECLARE_LOGGING_CATEGORY(trace_app) +Q_DECLARE_LOGGING_CATEGORY(trace_app_detail) Q_DECLARE_LOGGING_CATEGORY(trace_network) Q_DECLARE_LOGGING_CATEGORY(trace_render) +Q_DECLARE_LOGGING_CATEGORY(trace_render_detail) Q_DECLARE_LOGGING_CATEGORY(trace_render_gpu) Q_DECLARE_LOGGING_CATEGORY(trace_resource) Q_DECLARE_LOGGING_CATEGORY(trace_resource_parse) Q_DECLARE_LOGGING_CATEGORY(trace_resource_network) Q_DECLARE_LOGGING_CATEGORY(trace_simulation) +Q_DECLARE_LOGGING_CATEGORY(trace_simulation_detail) Q_DECLARE_LOGGING_CATEGORY(trace_simulation_animation) +Q_DECLARE_LOGGING_CATEGORY(trace_simulation_animation_detail) Q_DECLARE_LOGGING_CATEGORY(trace_simulation_physics) +Q_DECLARE_LOGGING_CATEGORY(trace_simulation_physics_detail) class Duration { public: @@ -69,6 +75,7 @@ inline void counter(const QLoggingCategory& category, const QString& name, const #define PROFILE_RANGE_END(category, rangeId) Duration::endRange(trace_##category(), rangeId) #define PROFILE_ASYNC_BEGIN(category, name, id, ...) asyncBegin(trace_##category(), name, id, ##__VA_ARGS__); #define PROFILE_ASYNC_END(category, name, id, ...) asyncEnd(trace_##category(), name, id, ##__VA_ARGS__); +#define PROFILE_COUNTER_IF_CHANGED(category, name, type, value) { static type lastValue = 0; type newValue = value; if (newValue != lastValue) { counter(trace_##category(), name, { { name, newValue }}); lastValue = newValue; } } #define PROFILE_COUNTER(category, name, ...) counter(trace_##category(), name, ##__VA_ARGS__); #define PROFILE_INSTANT(category, name, ...) instant(trace_##category(), name, ##__VA_ARGS__); From 42b2b2154eef3700e86f72a061d25f4b9972a00e Mon Sep 17 00:00:00 2001 From: howard-stearns Date: Tue, 10 Jan 2017 13:08:07 -0800 Subject: [PATCH 5/7] store audio level in overlay data object (so that they gc properly and we have the data to color with). --- scripts/system/pal.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/scripts/system/pal.js b/scripts/system/pal.js index c0450a0b94..1f37af63e2 100644 --- a/scripts/system/pal.js +++ b/scripts/system/pal.js @@ -422,7 +422,7 @@ var LOUDNESS_FLOOR = 11.0; var LOUDNESS_SCALE = 2.8 / 5.0; var LOG2 = Math.log(2.0); var AUDIO_LEVEL_UPDATE_INTERVAL_MS = 100; // 10hz for now (change this and change the AVERAGING_RATIO too) -var accumulatedLevels = {}; +var myData = {}; // we're not includied in ExtendedOverlay.get. function getAudioLevel(id) { // the VU meter should work similarly to the one in AvatarInputs: log scale, exponentially averaged @@ -430,13 +430,18 @@ function getAudioLevel(id) { // of updating (the latter for efficiency too). var avatar = AvatarList.getAvatar(id); var audioLevel = 0.0; + var data = id ? ExtendedOverlay.get(id) : myData; + if (!data) { + print('no data for', id); + return audioLevel; + } // we will do exponential moving average by taking some the last loudness and averaging - accumulatedLevels[id] = AVERAGING_RATIO * (accumulatedLevels[id] || 0) + (1 - AVERAGING_RATIO) * (avatar.audioLoudness); + data.accumulatedLevel = AVERAGING_RATIO * (data.accumulatedLevel || 0) + (1 - AVERAGING_RATIO) * (avatar.audioLoudness); // add 1 to insure we don't go log() and hit -infinity. Math.log is // natural log, so to get log base 2, just divide by ln(2). - var logLevel = Math.log(accumulatedLevels[id] + 1) / LOG2; + var logLevel = Math.log(data.accumulatedLevel + 1) / LOG2; if (logLevel <= LOUDNESS_FLOOR) { audioLevel = logLevel / LOUDNESS_FLOOR * LOUDNESS_SCALE; @@ -455,7 +460,7 @@ function getAudioLevel(id) { Script.setInterval(function () { if (pal.visible) { var param = {}; - AvatarList.getAvatarIdentifiers().sort().forEach(function (id) { + AvatarList.getAvatarIdentifiers().forEach(function (id) { var level = getAudioLevel(id); // qml didn't like an object with null/empty string for a key, so... var userId = id || 0; From e67675ac36f7e9dadebe6a8c1f20dbe78041ea9e Mon Sep 17 00:00:00 2001 From: howard-stearns Date: Tue, 10 Jan 2017 13:24:38 -0800 Subject: [PATCH 6/7] color nodes by audio level --- scripts/system/pal.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/system/pal.js b/scripts/system/pal.js index 1f37af63e2..f83b2b6796 100644 --- a/scripts/system/pal.js +++ b/scripts/system/pal.js @@ -58,8 +58,13 @@ ExtendedOverlay.prototype.editOverlay = function (properties) { // change displa Overlays.editOverlay(this.activeOverlay, properties); }; -function color(selected) { - return selected ? SELECTED_COLOR : UNSELECTED_COLOR; +function color(selected, level) { + var base = selected ? SELECTED_COLOR : UNSELECTED_COLOR; + function scale(component) { + var delta = 0xFF - component; + return component + (delta * level); + } + return {red: scale(base.red), green: scale(base.green), blue: scale(base.blue)}; } function textures(selected) { @@ -71,7 +76,7 @@ ExtendedOverlay.prototype.select = function (selected) { return; } - this.editOverlay({color: color(selected)}); + this.editOverlay({color: color(selected, this.audioLevel)}); if (this.model) { this.model.editOverlay({textures: textures(selected)}); } @@ -204,7 +209,7 @@ function addAvatarNode(id) { drawInFront: true, solid: true, alpha: 0.8, - color: color(selected), + color: color(selected, 0.0), ignoreRayIntersection: false}, selected, true); } function populateUserList() { @@ -288,6 +293,7 @@ function updateOverlays() { overlay.ping = pingPong; overlay.editOverlay({ + color: color(ExtendedOverlay.isSelected(id), overlay.audioLevel), position: target, dimensions: 0.032 * distance }); @@ -451,6 +457,7 @@ function getAudioLevel(id) { if (audioLevel > 1.0) { audioLevel = 1; } + data.audioLevel = audioLevel; return audioLevel; } From 31f39d7eefe2f2f3046f1226cd86910835d39f28 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Tue, 10 Jan 2017 11:33:14 -0800 Subject: [PATCH 7/7] Allow scripts to inject tracing events --- interface/src/scripting/TestScriptingInterface.cpp | 9 +++++++++ interface/src/scripting/TestScriptingInterface.h | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/interface/src/scripting/TestScriptingInterface.cpp b/interface/src/scripting/TestScriptingInterface.cpp index 3d9e84ce63..22a33ae858 100644 --- a/interface/src/scripting/TestScriptingInterface.cpp +++ b/interface/src/scripting/TestScriptingInterface.cpp @@ -18,6 +18,8 @@ #include "Application.h" +Q_LOGGING_CATEGORY(trace_test, "trace.test") + TestScriptingInterface* TestScriptingInterface::getInstance() { static TestScriptingInterface sharedInstance; return &sharedInstance; @@ -125,3 +127,10 @@ bool TestScriptingInterface::waitForCondition(qint64 maxWaitMs, std::function condition); };