mirror of
https://github.com/lubosz/overte.git
synced 2025-04-23 20:34:07 +02:00
Add support for adding thread names to a trace
This commit is contained in:
parent
87e2936a05
commit
a5e61184bf
4 changed files with 49 additions and 18 deletions
|
@ -10,6 +10,7 @@
|
|||
|
||||
Q_LOGGING_CATEGORY(trace_app, "trace.app")
|
||||
Q_LOGGING_CATEGORY(trace_app_detail, "trace.app.detail")
|
||||
Q_LOGGING_CATEGORY(trace_metadata, "trace.metadata")
|
||||
Q_LOGGING_CATEGORY(trace_network, "trace.network")
|
||||
Q_LOGGING_CATEGORY(trace_parse, "trace.parse")
|
||||
Q_LOGGING_CATEGORY(trace_render, "trace.render")
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
// 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_metadata)
|
||||
Q_DECLARE_LOGGING_CATEGORY(trace_network)
|
||||
Q_DECLARE_LOGGING_CATEGORY(trace_render)
|
||||
Q_DECLARE_LOGGING_CATEGORY(trace_render_detail)
|
||||
|
@ -69,6 +70,10 @@ inline void counter(const QLoggingCategory& category, const QString& name, const
|
|||
}
|
||||
}
|
||||
|
||||
inline void metadata(const QString& metadataType, const QVariantMap& args) {
|
||||
tracing::traceEvent(trace_metadata(), metadataType, tracing::Metadata, "", args);
|
||||
}
|
||||
|
||||
#define PROFILE_RANGE(category, name) Duration profileRangeThis(trace_##category(), name);
|
||||
#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)
|
||||
|
@ -78,6 +83,7 @@ inline void counter(const QLoggingCategory& category, const QString& name, const
|
|||
#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__);
|
||||
#define PROFILE_SET_THREAD_NAME(threadName) metadata("thread_name", { { "name", threadName } });
|
||||
|
||||
#define SAMPLE_PROFILE_RANGE(chance, category, name, ...) if (randFloat() <= chance) { PROFILE_RANGE(category, name); }
|
||||
#define SAMPLE_PROFILE_RANGE_EX(chance, category, name, ...) if (randFloat() <= chance) { PROFILE_RANGE_EX(category, name, argbColor, payload, ##__VA_ARGS__); }
|
||||
|
|
|
@ -132,6 +132,9 @@ void Tracer::serialize(const QString& originalPath) {
|
|||
{
|
||||
std::lock_guard<std::mutex> guard(_eventsMutex);
|
||||
currentEvents.swap(_events);
|
||||
for (auto& event : _metadataEvents) {
|
||||
currentEvents.push_back(event);
|
||||
}
|
||||
}
|
||||
|
||||
// If the file exists and we can't remove it, fail early
|
||||
|
@ -194,33 +197,53 @@ void Tracer::serialize(const QString& originalPath) {
|
|||
#endif
|
||||
}
|
||||
|
||||
void Tracer::traceEvent(const QLoggingCategory& category,
|
||||
const QString& name, EventType type,
|
||||
qint64 timestamp, qint64 processID, qint64 threadID,
|
||||
const QString& id,
|
||||
const QVariantMap& args, const QVariantMap& extra) {
|
||||
void Tracer::traceEvent(const QLoggingCategory& category,
|
||||
const QString& name, EventType type,
|
||||
qint64 timestamp, qint64 processID, qint64 threadID,
|
||||
const QString& id,
|
||||
const QVariantMap& args, const QVariantMap& extra) {
|
||||
std::lock_guard<std::mutex> guard(_eventsMutex);
|
||||
if (!_enabled) {
|
||||
|
||||
// We always want to store metadata events even if tracing is not enabled so that when
|
||||
// tracing is enabled we will be able to associate that metadata with that trace.
|
||||
// Metadata events should be used sparingly - as of 12/30/16 the Chrome Tracing
|
||||
// spec only supports thread+process metadata, so we should only expect to see metadata
|
||||
// events created when a new thread or process is created.
|
||||
if (!_enabled && type != Metadata) {
|
||||
return;
|
||||
}
|
||||
|
||||
_events.push_back({
|
||||
id,
|
||||
name,
|
||||
type,
|
||||
timestamp,
|
||||
processID,
|
||||
threadID,
|
||||
category,
|
||||
args,
|
||||
extra
|
||||
});
|
||||
if (type == Metadata) {
|
||||
_metadataEvents.push_back({
|
||||
id,
|
||||
name,
|
||||
type,
|
||||
timestamp,
|
||||
processID,
|
||||
threadID,
|
||||
category,
|
||||
args,
|
||||
extra
|
||||
});
|
||||
} else {
|
||||
_events.push_back({
|
||||
id,
|
||||
name,
|
||||
type,
|
||||
timestamp,
|
||||
processID,
|
||||
threadID,
|
||||
category,
|
||||
args,
|
||||
extra
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void Tracer::traceEvent(const QLoggingCategory& category,
|
||||
const QString& name, EventType type, const QString& id,
|
||||
const QVariantMap& args, const QVariantMap& extra) {
|
||||
if (!_enabled) {
|
||||
if (!_enabled && type != Metadata) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -97,6 +97,7 @@ private:
|
|||
|
||||
bool _enabled { false };
|
||||
std::list<TraceEvent> _events;
|
||||
std::list<TraceEvent> _metadataEvents;
|
||||
std::mutex _eventsMutex;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue