aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/ctfvisualizer/ctftracemanager.cpp
diff options
context:
space:
mode:
authorEike Ziller <[email protected]>2023-09-08 10:17:29 +0200
committerEike Ziller <[email protected]>2023-09-12 14:21:27 +0000
commitc83047abb93ead2453ab0168659d4e8c7be903e2 (patch)
tree737fded84058f66402c6909013f1798602c4cce4 /src/plugins/ctfvisualizer/ctftracemanager.cpp
parent67aab388731d1ab34253853d3988be7e71ea7962 (diff)
CtfVisualizer: Allow strings for process and thread id
While the format document only uses numbers for these in its examples, the data type is not really specified there and chrome://tracing itself handles strings for them without complaint. On trace-generating side std::thread::id can't easily be serialized as a number, and strings can easily be supported in the viewer. Change-Id: I36c8497049d4933058b9f72a28f24e1d1cf0d5bb Reviewed-by: Alessandro Portale <[email protected]>
Diffstat (limited to 'src/plugins/ctfvisualizer/ctftracemanager.cpp')
-rw-r--r--src/plugins/ctfvisualizer/ctftracemanager.cpp31
1 files changed, 22 insertions, 9 deletions
diff --git a/src/plugins/ctfvisualizer/ctftracemanager.cpp b/src/plugins/ctfvisualizer/ctftracemanager.cpp
index a2faa108031..82e5b54b762 100644
--- a/src/plugins/ctfvisualizer/ctftracemanager.cpp
+++ b/src/plugins/ctfvisualizer/ctftracemanager.cpp
@@ -105,8 +105,19 @@ void CtfTraceManager::addEvent(const json &event)
m_timeOffset = timestamp;
}
- const int processId = event.value(CtfProcessIdKey, 0);
- const int threadId = event.contains(CtfThreadIdKey) ? int(event[CtfThreadIdKey]) : processId;
+ static const auto getStringValue = [](const json &event, const char *key, const QString &def) {
+ if (!event.contains(key))
+ return def;
+ const json val = event[key];
+ if (val.is_string())
+ return QString::fromStdString(val);
+ if (val.is_number()) {
+ return QString::number(int(val));
+ }
+ return def;
+ };
+ const QString processId = getStringValue(event, CtfProcessIdKey, "0");
+ const QString threadId = getStringValue(event, CtfThreadIdKey, processId);
if (!m_threadModels.contains(threadId)) {
addModelForThread(threadId, processId);
}
@@ -202,14 +213,16 @@ int CtfTraceManager::getSelectionId(const std::string &name)
QList<CtfTimelineModel *> CtfTraceManager::getSortedThreads() const
{
QList<CtfTimelineModel *> models = m_threadModels.values();
- std::sort(models.begin(), models.end(), [](const CtfTimelineModel *a, const CtfTimelineModel *b) -> bool {
- return (a->m_processId != b->m_processId) ? (a->m_processId < b->m_processId)
- : (std::abs(a->m_threadId) < std::abs(b->m_threadId));
- });
+ std::sort(models.begin(),
+ models.end(),
+ [](const CtfTimelineModel *a, const CtfTimelineModel *b) -> bool {
+ return (a->m_processId != b->m_processId) ? (a->m_processId < b->m_processId)
+ : (a->m_threadId < b->m_threadId);
+ });
return models;
}
-void CtfTraceManager::setThreadRestriction(int tid, bool restrictToThisThread)
+void CtfTraceManager::setThreadRestriction(const QString &tid, bool restrictToThisThread)
{
if (m_threadRestrictions.value(tid) == restrictToThisThread)
return;
@@ -218,12 +231,12 @@ void CtfTraceManager::setThreadRestriction(int tid, bool restrictToThisThread)
addModelsToAggregator();
}
-bool CtfTraceManager::isRestrictedTo(int tid) const
+bool CtfTraceManager::isRestrictedTo(const QString &tid) const
{
return m_threadRestrictions.value(tid);
}
-void CtfTraceManager::addModelForThread(int threadId, int processId)
+void CtfTraceManager::addModelForThread(const QString &threadId, const QString &processId)
{
CtfTimelineModel *model = new CtfTimelineModel(m_modelAggregator, this, threadId, processId);
m_threadModels.insert(threadId, model);