mirror of
https://github.com/lubosz/overte.git
synced 2025-04-17 00:57:44 +02:00
Merge pull request #10795 from samcake/brown
Adding trace profiling feature Script
This commit is contained in:
commit
f1db0e9e53
3 changed files with 29 additions and 0 deletions
|
@ -1309,6 +1309,7 @@ QObject* ScriptEngine::setupTimerWithInterval(const QScriptValue& function, int
|
|||
// make sure the timer stops when the script does
|
||||
connect(this, &ScriptEngine::scriptEnding, newTimer, &QTimer::stop);
|
||||
|
||||
|
||||
CallbackData timerData = { function, currentEntityIdentifier, currentSandboxURL };
|
||||
_timerFunctionMap.insert(newTimer, timerData);
|
||||
|
||||
|
@ -1392,6 +1393,15 @@ void ScriptEngine::print(const QString& message) {
|
|||
emit printedMessage(message, getFilename());
|
||||
}
|
||||
|
||||
|
||||
void ScriptEngine::beginProfileRange(const QString& label) const {
|
||||
PROFILE_SYNC_BEGIN(script, label.toStdString().c_str(), label.toStdString().c_str());
|
||||
}
|
||||
|
||||
void ScriptEngine::endProfileRange(const QString& label) const {
|
||||
PROFILE_SYNC_END(script, label.toStdString().c_str(), label.toStdString().c_str());
|
||||
}
|
||||
|
||||
// Script.require.resolve -- like resolvePath, but performs more validation and throws exceptions on invalid module identifiers (for consistency with Node.js)
|
||||
QString ScriptEngine::_requireResolve(const QString& moduleId, const QString& relativeTo) {
|
||||
if (!IS_THREADSAFE_INVOCATION(thread(), __FUNCTION__)) {
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
#include "Vec3.h"
|
||||
#include "ConsoleScriptingInterface.h"
|
||||
#include "SettingHandle.h"
|
||||
#include "Profile.h"
|
||||
|
||||
class QScriptEngineDebugger;
|
||||
|
||||
|
@ -182,6 +183,8 @@ public:
|
|||
Q_INVOKABLE void print(const QString& message);
|
||||
Q_INVOKABLE QUrl resolvePath(const QString& path) const;
|
||||
Q_INVOKABLE QUrl resourcesPath() const;
|
||||
Q_INVOKABLE void beginProfileRange(const QString& label) const;
|
||||
Q_INVOKABLE void endProfileRange(const QString& label) const;
|
||||
|
||||
// Entity Script Related methods
|
||||
Q_INVOKABLE bool isEntityScriptRunning(const EntityItemID& entityID) {
|
||||
|
|
|
@ -46,6 +46,20 @@ private:
|
|||
const QLoggingCategory& _category;
|
||||
};
|
||||
|
||||
|
||||
inline void syncBegin(const QLoggingCategory& category, const QString& name, const QString& id, const QVariantMap& args = QVariantMap(), const QVariantMap& extra = QVariantMap()) {
|
||||
if (category.isDebugEnabled()) {
|
||||
tracing::traceEvent(category, name, tracing::DurationBegin, id, args, extra);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline void syncEnd(const QLoggingCategory& category, const QString& name, const QString& id, const QVariantMap& args = QVariantMap(), const QVariantMap& extra = QVariantMap()) {
|
||||
if (category.isDebugEnabled()) {
|
||||
tracing::traceEvent(category, name, tracing::DurationEnd, id, args, extra);
|
||||
}
|
||||
}
|
||||
|
||||
inline void asyncBegin(const QLoggingCategory& category, const QString& name, const QString& id, const QVariantMap& args = QVariantMap(), const QVariantMap& extra = QVariantMap()) {
|
||||
if (category.isDebugEnabled()) {
|
||||
tracing::traceEvent(category, name, tracing::AsyncNestableStart, id, args, extra);
|
||||
|
@ -80,6 +94,8 @@ inline void metadata(const QString& metadataType, const QVariantMap& args) {
|
|||
#define PROFILE_RANGE_EX(category, name, argbColor, payload, ...) Duration profileRangeThis(trace_##category(), name, argbColor, (uint64_t)payload, ##__VA_ARGS__);
|
||||
#define PROFILE_RANGE_BEGIN(category, rangeId, name, argbColor) rangeId = Duration::beginRange(trace_##category(), name, argbColor)
|
||||
#define PROFILE_RANGE_END(category, rangeId) Duration::endRange(trace_##category(), rangeId)
|
||||
#define PROFILE_SYNC_BEGIN(category, name, id, ...) syncBegin(trace_##category(), name, id, ##__VA_ARGS__);
|
||||
#define PROFILE_SYNC_END(category, name, id, ...) syncEnd(trace_##category(), name, id, ##__VA_ARGS__);
|
||||
#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; } }
|
||||
|
|
Loading…
Reference in a new issue