forked from qt-creator/qt-creator
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:
@@ -47,11 +47,9 @@ void CtfStatisticsModel::beginLoading()
|
||||
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[QString::fromStdString(name)];
|
||||
EventData &data = m_data[title];
|
||||
++data.count;
|
||||
if (durationInNs >= 0) {
|
||||
data.totalDuration += durationInNs;
|
||||
|
||||
@@ -66,7 +66,7 @@ public:
|
||||
~CtfStatisticsModel() override = default;
|
||||
|
||||
void beginLoading();
|
||||
void addEvent(const nlohmann::json &event, qint64 duration);
|
||||
void addEvent(const QString &title, qint64 durationInNs);
|
||||
void endLoading();
|
||||
|
||||
private:
|
||||
|
||||
@@ -222,6 +222,15 @@ int CtfTimelineModel::tid() const
|
||||
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()
|
||||
{
|
||||
if (m_threadName.isEmpty()) {
|
||||
|
||||
@@ -68,6 +68,7 @@ public:
|
||||
void finalize(double traceBegin, double traceEnd, const QString &processName, const QString &threadName);
|
||||
|
||||
int tid() const;
|
||||
QString eventTitle(int index) const;
|
||||
|
||||
signals:
|
||||
void detailsRequested(const QString &eventName) const;
|
||||
|
||||
@@ -146,7 +146,6 @@ void CtfTraceManager::addEvent(const json &event)
|
||||
if (visibleOnTimeline) {
|
||||
m_traceBegin = std::min(m_traceBegin, timestamp);
|
||||
m_traceEnd = std::max(m_traceEnd, timestamp);
|
||||
m_statisticsModel->addEvent(event, result.second);
|
||||
} else if (m_timeOffset == timestamp) {
|
||||
// this timestamp was used as the time offset but it is not a visible element
|
||||
// -> 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) {
|
||||
return ctfParser.callback(depth, event, parsed);
|
||||
};
|
||||
m_statisticsModel->beginLoading();
|
||||
json unusedValues = json::parse(file, callback, /*allow_exceptions*/ false);
|
||||
m_statisticsModel->endLoading();
|
||||
file.close();
|
||||
updateStatistics();
|
||||
}
|
||||
|
||||
void CtfTraceManager::finalize()
|
||||
@@ -264,6 +262,27 @@ void CtfTraceManager::addModelsToAggregator()
|
||||
modelsToAdd.append(QVariant::fromValue(model));
|
||||
}
|
||||
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()
|
||||
|
||||
@@ -77,6 +77,8 @@ protected:
|
||||
void addModelForThread(int threadId, int processId);
|
||||
void addModelsToAggregator();
|
||||
|
||||
void updateStatistics();
|
||||
|
||||
void clearAll();
|
||||
|
||||
Timeline::TimelineModelAggregator *const m_modelAggregator;
|
||||
|
||||
Reference in New Issue
Block a user