Tracing: CtfVisualizer: Apply thread restrictions to statistics, too

The statistics are now also filtered by the selected threads. If no
thread is selected, the statistics are presented for all threads combined.
This fixes a bug with double counted events, too.

Change-Id: I9afa0bf5bc85ccf363e00600e75001c0ab3f2e8a
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
Tim Henning
2019-10-17 16:20:13 +02:00
parent b90200cb19
commit 1673e692c5
6 changed files with 37 additions and 8 deletions

View File

@@ -47,11 +47,9 @@ void CtfStatisticsModel::beginLoading()
m_data.clear(); m_data.clear();
} }
void CtfStatisticsModel::addEvent(const json &event, qint64 durationInNs) void CtfStatisticsModel::addEvent(const QString &title, qint64 durationInNs)
{ {
const std::string name = event.value(CtfEventNameKey, ""); EventData &data = m_data[title];
EventData &data = m_data[QString::fromStdString(name)];
++data.count; ++data.count;
if (durationInNs >= 0) { if (durationInNs >= 0) {
data.totalDuration += durationInNs; data.totalDuration += durationInNs;

View File

@@ -66,7 +66,7 @@ public:
~CtfStatisticsModel() override = default; ~CtfStatisticsModel() override = default;
void beginLoading(); void beginLoading();
void addEvent(const nlohmann::json &event, qint64 duration); void addEvent(const QString &title, qint64 durationInNs);
void endLoading(); void endLoading();
private: private:

View File

@@ -222,6 +222,15 @@ int CtfTimelineModel::tid() const
return m_threadId; return m_threadId;
} }
QString CtfTimelineModel::eventTitle(int index) const
{
const int counterIdx = m_itemToCounterIdx.value(index, 0);
if (counterIdx > 0) {
return QString::fromStdString(m_counterNames.at(counterIdx - 1));
}
return m_details.value(index).value(0).second;
}
void CtfTimelineModel::updateName() void CtfTimelineModel::updateName()
{ {
if (m_threadName.isEmpty()) { if (m_threadName.isEmpty()) {

View File

@@ -68,6 +68,7 @@ public:
void finalize(double traceBegin, double traceEnd, const QString &processName, const QString &threadName); void finalize(double traceBegin, double traceEnd, const QString &processName, const QString &threadName);
int tid() const; int tid() const;
QString eventTitle(int index) const;
signals: signals:
void detailsRequested(const QString &eventName) const; void detailsRequested(const QString &eventName) const;

View File

@@ -146,7 +146,6 @@ void CtfTraceManager::addEvent(const json &event)
if (visibleOnTimeline) { if (visibleOnTimeline) {
m_traceBegin = std::min(m_traceBegin, timestamp); m_traceBegin = std::min(m_traceBegin, timestamp);
m_traceEnd = std::max(m_traceEnd, timestamp); m_traceEnd = std::max(m_traceEnd, timestamp);
m_statisticsModel->addEvent(event, result.second);
} else if (m_timeOffset == timestamp) { } else if (m_timeOffset == timestamp) {
// this timestamp was used as the time offset but it is not a visible element // this timestamp was used as the time offset but it is not a visible element
// -> reset the time offset again: // -> reset the time offset again:
@@ -169,10 +168,9 @@ void CtfVisualizer::Internal::CtfTraceManager::load(const QString &filename)
json::parser_callback_t callback = [&ctfParser](int depth, json::parse_event_t event, json &parsed) { json::parser_callback_t callback = [&ctfParser](int depth, json::parse_event_t event, json &parsed) {
return ctfParser.callback(depth, event, parsed); return ctfParser.callback(depth, event, parsed);
}; };
m_statisticsModel->beginLoading();
json unusedValues = json::parse(file, callback, /*allow_exceptions*/ false); json unusedValues = json::parse(file, callback, /*allow_exceptions*/ false);
m_statisticsModel->endLoading();
file.close(); file.close();
updateStatistics();
} }
void CtfTraceManager::finalize() void CtfTraceManager::finalize()
@@ -264,6 +262,27 @@ void CtfTraceManager::addModelsToAggregator()
modelsToAdd.append(QVariant::fromValue(model)); modelsToAdd.append(QVariant::fromValue(model));
} }
m_modelAggregator->setModels(modelsToAdd); m_modelAggregator->setModels(modelsToAdd);
updateStatistics();
}
void CtfTraceManager::updateStatistics()
{
const bool showAll = std::none_of(m_threadRestrictions.begin(), m_threadRestrictions.end(), [](bool value) {
return value;
});
m_statisticsModel->beginLoading();
for (auto thread : m_threadModels) {
if (showAll || m_threadRestrictions[thread->tid()])
{
const int eventCount = thread->count();
for (int i = 0; i < eventCount; ++i) {
QString title = thread->eventTitle(i);
m_statisticsModel->addEvent(title, thread->duration(i));
}
}
}
m_statisticsModel->endLoading();
} }
void CtfTraceManager::clearAll() void CtfTraceManager::clearAll()

View File

@@ -77,6 +77,8 @@ protected:
void addModelForThread(int threadId, int processId); void addModelForThread(int threadId, int processId);
void addModelsToAggregator(); void addModelsToAggregator();
void updateStatistics();
void clearAll(); void clearAll();
Timeline::TimelineModelAggregator *const m_modelAggregator; Timeline::TimelineModelAggregator *const m_modelAggregator;