Nanotracer: Simplify templates

Change-Id: Iec6e80ec7622b9fc9162c6852d3736e505c8feff
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Marco Bubke
2025-06-01 21:45:01 +02:00
parent cdc0a2c9b4
commit 87e52c1998
13 changed files with 663 additions and 636 deletions

View File

@@ -50,12 +50,6 @@ constexpr bool isArgumentValid(const ArgumentsString &string)
return string.isValid() && string.size(); return string.isValid() && string.size();
} }
template<typename String>
constexpr bool isArgumentValid(const String &string)
{
return string.size();
}
template<typename TraceEvent> template<typename TraceEvent>
void printEvent(std::ostream &out, const TraceEvent &event, qint64 processId, std::thread::id threadId) void printEvent(std::ostream &out, const TraceEvent &event, qint64 processId, std::thread::id threadId)
{ {

File diff suppressed because it is too large Load Diff

View File

@@ -543,10 +543,10 @@ public:
using TracerCategory = std::decay_t<decltype(sqliteHighLevelCategory())>; using TracerCategory = std::decay_t<decltype(sqliteHighLevelCategory())>;
StatementImplementation &m_statement; StatementImplementation &m_statement;
const source_location &m_sourceLocation; const source_location &m_sourceLocation;
NanotraceHR::Tracer<TracerCategory, typename TracerCategory::IsActive> tracer{ NanotraceHR::Tracer<TracerCategory> tracer{"range",
"range",
sqliteHighLevelCategory(), sqliteHighLevelCategory(),
NanotraceHR::keyValue("sqlite statement", m_statement.handle())}; NanotraceHR::keyValue("sqlite statement",
m_statement.handle())};
}; };
template<typename ResultType> template<typename ResultType>

View File

@@ -25,8 +25,8 @@ public:
~TaskQueue() { destroy(); } ~TaskQueue() { destroy(); }
template<typename TraceEvent, NanotraceHR::Tracing isEnabled, typename... Arguments> template<typename Category, typename... Arguments>
void addTask(NanotraceHR::Token<TraceEvent, isEnabled> traceToken, Arguments &&...arguments) void addTask(NanotraceHR::Token<Category> traceToken, Arguments &&...arguments)
{ {
{ {
std::unique_lock lock{m_mutex}; std::unique_lock lock{m_mutex};

View File

@@ -20,17 +20,17 @@ namespace ImageCache {
#ifdef ENABLE_IMAGE_CACHE_TRACING #ifdef ENABLE_IMAGE_CACHE_TRACING
using Category = NanotraceHR::EnabledCategory; using Category = NanotraceHR::EnabledCategory;
using TraceToken = Category::FlowTokenType; using TraceToken = NanotraceHR::EnabledFlowToken;
using FlowToken = Category::FlowTokenType; using FlowToken = NanotraceHR::EnabledFlowToken;
using Token = Category::TokenType; using Token = NanotraceHR::EnabledToken;
[[gnu::pure]] QMLDESIGNERCORE_EXPORT Category &category(); [[gnu::pure]] QMLDESIGNERCORE_EXPORT Category &category();
#else #else
using Category = NanotraceHR::DisabledCategory; using Category = NanotraceHR::DisabledCategory;
using TraceToken = Category::FlowTokenType; using TraceToken = NanotraceHR::DisabledFlowToken;
using FlowToken = Category::FlowTokenType; using FlowToken = NanotraceHR::DisabledFlowToken;
using Token = Category::TokenType; using Token = NanotraceHR::DisabledToken;
inline Category category() inline Category category()
{ {

View File

@@ -59,7 +59,7 @@ public:
int majorVersion, int majorVersion,
int minorVersion, int minorVersion,
qint32 internalId, qint32 internalId,
ModelTracing::Category::FlowTokenType flowTraceToken) ModelTracing::FlowToken flowTraceToken)
: typeName(typeName.toByteArray()) : typeName(typeName.toByteArray())
, majorVersion(majorVersion) , majorVersion(majorVersion)
, minorVersion(minorVersion) , minorVersion(minorVersion)

View File

@@ -30,7 +30,7 @@
namespace QmlDesigner { namespace QmlDesigner {
constexpr auto category = ProjectStorageTracing::projectStorageUpdaterCategory; constexpr auto category = ProjectStorageTracing::projectStorageUpdaterCategory;
using NanotraceHR::keyValue; using NanotraceHR::keyValue;
using Tracer = ProjectStorageTracing::Category::TracerType; using Tracer = NanotraceHR::Tracer<ProjectStorageTracing::Category>;
template<typename String> template<typename String>
void convertToString(String &string, const ProjectStorageUpdater::FileState &state) void convertToString(String &string, const ProjectStorageUpdater::FileState &state)

View File

@@ -168,7 +168,7 @@ private:
NotUpdatedSourceIds &notUpdatedSourceIds, NotUpdatedSourceIds &notUpdatedSourceIds,
WatchedSourceIds &WatchedSourceIds, WatchedSourceIds &WatchedSourceIds,
IsInsideProject isInsideProject, IsInsideProject isInsideProject,
ProjectStorageTracing::Category::TracerType &tracer); NanotraceHR::Tracer<ProjectStorageTracing::Category> &tracer);
void annotationDirectoryChanged(Utils::SmallStringView directoryPath, void annotationDirectoryChanged(Utils::SmallStringView directoryPath,
DirectoryPathId directoryId, DirectoryPathId directoryId,
DirectoryPathId annotationDirectoryId, DirectoryPathId annotationDirectoryId,

View File

@@ -26,7 +26,7 @@ namespace QmlDesigner {
constexpr auto category = ProjectStorageTracing::projectStorageUpdaterCategory; constexpr auto category = ProjectStorageTracing::projectStorageUpdaterCategory;
using NanotraceHR::keyValue; using NanotraceHR::keyValue;
using Storage::IsInsideProject; using Storage::IsInsideProject;
using Tracer = ProjectStorageTracing::Category::TracerType; using Tracer = NanotraceHR::Tracer<ProjectStorageTracing::Category>;
namespace QmlDom = QQmlJS::Dom; namespace QmlDom = QQmlJS::Dom;
namespace Synchronization = Storage::Synchronization; namespace Synchronization = Storage::Synchronization;

View File

@@ -28,7 +28,7 @@ namespace QmlDesigner {
constexpr auto category = ProjectStorageTracing::projectStorageUpdaterCategory; constexpr auto category = ProjectStorageTracing::projectStorageUpdaterCategory;
using NanotraceHR::keyValue; using NanotraceHR::keyValue;
using Storage::IsInsideProject; using Storage::IsInsideProject;
using Tracer = ProjectStorageTracing::Category::TracerType; using Tracer = NanotraceHR::Tracer<ProjectStorageTracing::Category>;
using Storage::ModuleKind; using Storage::ModuleKind;
namespace QmlDom = QQmlJS::Dom; namespace QmlDom = QQmlJS::Dom;

View File

@@ -9,10 +9,10 @@ namespace QmlDesigner {
using namespace NanotraceHR::Literals; using namespace NanotraceHR::Literals;
#ifdef ENABLE_QMLDESIGNER_TRACING
namespace Tracing { namespace Tracing {
#ifdef ENABLE_QMLDESIGNER_TRACING
namespace { namespace {
using TraceFile = NanotraceHR::EnabledTraceFile; using TraceFile = NanotraceHR::EnabledTraceFile;
@@ -42,6 +42,8 @@ EventQueueWithoutArguments &eventQueueWithoutArguments()
return eventQueue; return eventQueue;
} }
#endif
} // namespace Tracing } // namespace Tracing
namespace ModelTracing { namespace ModelTracing {
@@ -112,6 +114,4 @@ Category &category()
} // namespace SourcePathStorageTracing } // namespace SourcePathStorageTracing
#endif
} // namespace QmlDesigner } // namespace QmlDesigner

View File

@@ -28,14 +28,16 @@ namespace ModelTracing {
using Category = NanotraceHR::EnabledCategory; using Category = NanotraceHR::EnabledCategory;
using SourceLocation = Category::SourceLocation; using SourceLocation = Category::SourceLocation;
using AsynchronousToken = Category::AsynchronousTokenType; using AsynchronousToken = NanotraceHR::EnabledAsynchronousToken;
using FlowToken = NanotraceHR::EnabledFlowToken;
[[gnu::pure]] QMLDESIGNERCORE_EXPORT Category &category(); [[gnu::pure]] QMLDESIGNERCORE_EXPORT Category &category();
#else #else
using Category = NanotraceHR::DisabledCategory; using Category = NanotraceHR::DisabledCategory;
using SourceLocation = Category::SourceLocation; using SourceLocation = Category::SourceLocation;
using AsynchronousToken = Category::AsynchronousTokenType; using AsynchronousToken = NanotraceHR::DisabledAsynchronousToken;
using FlowToken = NanotraceHR::DisabledFlowToken;
inline Category category() inline Category category()
{ {

View File

@@ -26,8 +26,6 @@ auto IsTask(Matcher matcher)
class TaskQueue : public testing::Test class TaskQueue : public testing::Test
{ {
using Category = NanotraceHR::DisabledCategory;
protected: protected:
Notification notification; Notification notification;
Notification waitInThread; Notification waitInThread;
@@ -36,7 +34,7 @@ protected:
using Queue = QmlDesigner::TaskQueue<Task, using Queue = QmlDesigner::TaskQueue<Task,
decltype(mockDispatchCallback.AsStdFunction()), decltype(mockDispatchCallback.AsStdFunction()),
decltype(mockCleanCallback.AsStdFunction())>; decltype(mockCleanCallback.AsStdFunction())>;
NanotraceHR::Token<Category, NanotraceHR::Tracing::IsDisabled> dummyToken; NanotraceHR::DisabledToken dummyToken;
}; };
TEST_F(TaskQueue, add_task_dispatches_task) TEST_F(TaskQueue, add_task_dispatches_task)