Tracing: CtfVisualizer: Add menu to restrict view to certain threads

Add a new dropdown menu to select which threads should be displayed.
If no threads are selected, all are shown (this is why the word
'restriction' was chosen). At the moment this only affects the
timeline view, see the follow up for the statistics view.

Change-Id: Ib3b08ea895e852189156e23feb8dea5f843cceb3
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
Tim Henning
2019-10-17 13:36:37 +02:00
parent ee7aad5719
commit b90200cb19
6 changed files with 92 additions and 12 deletions

View File

@@ -217,12 +217,17 @@ void CtfTimelineModel::finalize(double traceBegin, double traceEnd, const QStrin
emit contentChanged(); emit contentChanged();
} }
int CtfTimelineModel::tid() const
{
return m_threadId;
}
void CtfTimelineModel::updateName() void CtfTimelineModel::updateName()
{ {
if (m_threadName.isEmpty()) { if (m_threadName.isEmpty()) {
setDisplayName(tr("> Thread %1").arg(m_threadId)); setDisplayName(tr("Thread %1").arg(m_threadId));
} else { } else {
setDisplayName(QString("> %1 (%2)").arg(m_threadName).arg(m_threadId)); setDisplayName(QString("%1 (%2)").arg(m_threadName).arg(m_threadId));
} }
QString process = m_processName.isEmpty() ? QString::number(m_processId) : QString process = m_processName.isEmpty() ? QString::number(m_processId) :
QString("%1 (%2)").arg(m_processName).arg(m_processId); QString("%1 (%2)").arg(m_processName).arg(m_processId);

View File

@@ -67,6 +67,8 @@ 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;
signals: signals:
void detailsRequested(const QString &eventName) const; void detailsRequested(const QString &eventName) const;

View File

@@ -192,6 +192,7 @@ void CtfTraceManager::finalize()
} }
} }
m_threadModels.remove(tid); m_threadModels.remove(tid);
m_threadRestrictions.remove(tid);
} }
} }
for (CtfTimelineModel *model: m_threadModels) { for (CtfTimelineModel *model: m_threadModels) {
@@ -216,24 +217,50 @@ int CtfTraceManager::getSelectionId(const std::string &name)
return *it; return *it;
} }
void CtfTraceManager::addModelForThread(int threadId, int processId) QList<CtfTimelineModel *> CtfTraceManager::getSortedThreads() const
{
CtfTimelineModel *model = new CtfTimelineModel(m_modelAggregator, this, threadId, processId);
m_threadModels.insert(threadId, model);
connect(model, &CtfTimelineModel::detailsRequested, this,
&CtfTraceManager::detailsRequested);
}
void CtfTraceManager::addModelsToAggregator()
{ {
QList<CtfTimelineModel *> models = m_threadModels.values(); QList<CtfTimelineModel *> models = m_threadModels.values();
std::sort(models.begin(), models.end(), [](const CtfTimelineModel *a, const CtfTimelineModel *b) -> bool { 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) return (a->m_processId != b->m_processId) ? (a->m_processId < b->m_processId)
: (std::abs(a->m_threadId) < std::abs(b->m_threadId)); : (std::abs(a->m_threadId) < std::abs(b->m_threadId));
}); });
return models;
}
void CtfTraceManager::setThreadRestriction(int tid, bool restrictToThisThread)
{
if (m_threadRestrictions.value(tid) == restrictToThisThread)
return;
m_threadRestrictions[tid] = restrictToThisThread;
addModelsToAggregator();
}
bool CtfTraceManager::isRestrictedTo(int tid) const
{
return m_threadRestrictions.value(tid);
}
void CtfTraceManager::addModelForThread(int threadId, int processId)
{
CtfTimelineModel *model = new CtfTimelineModel(m_modelAggregator, this, threadId, processId);
m_threadModels.insert(threadId, model);
m_threadRestrictions.insert(threadId, false);
connect(model, &CtfTimelineModel::detailsRequested, this,
&CtfTraceManager::detailsRequested);
}
void CtfTraceManager::addModelsToAggregator()
{
const QList<CtfTimelineModel *> models = getSortedThreads();
const bool showAll = std::none_of(m_threadRestrictions.begin(), m_threadRestrictions.end(), [](bool value) {
return value;
});
QVariantList modelsToAdd; QVariantList modelsToAdd;
for (CtfTimelineModel *model: models) { for (CtfTimelineModel *model: models) {
if (showAll || isRestrictedTo(model->tid()))
modelsToAdd.append(QVariant::fromValue(model)); modelsToAdd.append(QVariant::fromValue(model));
} }
m_modelAggregator->setModels(modelsToAdd); m_modelAggregator->setModels(modelsToAdd);

View File

@@ -64,6 +64,11 @@ public:
int getSelectionId(const std::string &name); int getSelectionId(const std::string &name);
QList<CtfTimelineModel *> getSortedThreads() const;
void setThreadRestriction(int tid, bool restrictToThisThread);
bool isRestrictedTo(int tid) const;
signals: signals:
void detailsRequested(const QString &title); void detailsRequested(const QString &title);
@@ -81,6 +86,7 @@ protected:
QHash<qint64, QString> m_processNames; QHash<qint64, QString> m_processNames;
QHash<qint64, QString> m_threadNames; QHash<qint64, QString> m_threadNames;
QMap<std::string, int> m_name2selectionId; QMap<std::string, int> m_name2selectionId;
QHash<qint64, bool> m_threadRestrictions;
double m_traceBegin = std::numeric_limits<double>::max(); double m_traceBegin = std::numeric_limits<double>::max();
double m_traceEnd = std::numeric_limits<double>::min(); double m_traceEnd = std::numeric_limits<double>::min();

View File

@@ -29,6 +29,7 @@
#include "ctfstatisticsmodel.h" #include "ctfstatisticsmodel.h"
#include "ctfstatisticsview.h" #include "ctfstatisticsview.h"
#include "ctftimelinemodel.h"
#include "ctfvisualizertraceview.h" #include "ctfvisualizertraceview.h"
#include <coreplugin/actionmanager/actioncontainer.h> #include <coreplugin/actionmanager/actioncontainer.h>
@@ -36,6 +37,7 @@
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/progressmanager/progressmanager.h> #include <coreplugin/progressmanager/progressmanager.h>
#include <debugger/analyzer/analyzerconstants.h> #include <debugger/analyzer/analyzerconstants.h>
#include <utils/utilsicons.h>
#include <QAction> #include <QAction>
#include <QApplication> #include <QApplication>
@@ -62,6 +64,8 @@ CtfVisualizerTool::CtfVisualizerTool()
, m_statisticsModel(new CtfStatisticsModel(this)) , m_statisticsModel(new CtfStatisticsModel(this))
, m_statisticsView(nullptr) , m_statisticsView(nullptr)
, m_traceManager(new CtfTraceManager(this, m_modelAggregator.get(), m_statisticsModel.get())) , m_traceManager(new CtfTraceManager(this, m_modelAggregator.get(), m_statisticsModel.get()))
, m_restrictToThreadsButton(new QToolButton)
, m_restrictToThreadsMenu(new QMenu(m_restrictToThreadsButton))
{ {
ActionContainer *menu = ActionManager::actionContainer(Debugger::Constants::M_DEBUG_ANALYZER); ActionContainer *menu = ActionManager::actionContainer(Debugger::Constants::M_DEBUG_ANALYZER);
ActionContainer *options = ActionManager::createMenu(Constants::CtfVisualizerMenuId); ActionContainer *options = ActionManager::createMenu(Constants::CtfVisualizerMenuId);
@@ -78,6 +82,16 @@ CtfVisualizerTool::CtfVisualizerTool()
options->addAction(command); options->addAction(command);
m_perspective.setAboutToActivateCallback([this]() { createViews(); }); m_perspective.setAboutToActivateCallback([this]() { createViews(); });
m_restrictToThreadsButton->setIcon(Utils::Icons::FILTER.icon());
m_restrictToThreadsButton->setToolTip(tr("Restrict to threads"));
m_restrictToThreadsButton->setPopupMode(QToolButton::InstantPopup);
m_restrictToThreadsButton->setProperty("noArrow", true);
m_restrictToThreadsButton->setMenu(m_restrictToThreadsMenu);
connect(m_restrictToThreadsMenu, &QMenu::triggered,
this, &CtfVisualizerTool::toggleThreadRestriction);
m_perspective.addToolBarWidget(m_restrictToThreadsButton);
} }
CtfVisualizerTool::~CtfVisualizerTool() = default; CtfVisualizerTool::~CtfVisualizerTool() = default;
@@ -116,6 +130,24 @@ void CtfVisualizerTool::createViews()
m_perspective.setAboutToActivateCallback(Utils::Perspective::Callback()); m_perspective.setAboutToActivateCallback(Utils::Perspective::Callback());
} }
void CtfVisualizerTool::setAvailableThreads(const QList<CtfTimelineModel *> &threads)
{
m_restrictToThreadsMenu->clear();
for (auto timelineModel : threads) {
QAction *action = m_restrictToThreadsMenu->addAction(timelineModel->displayName());
action->setCheckable(true);
action->setData(timelineModel->tid());
action->setChecked(m_traceManager->isRestrictedTo(timelineModel->tid()));
}
}
void CtfVisualizerTool::toggleThreadRestriction(QAction *action)
{
const int tid = action->data().toInt();
m_traceManager->setThreadRestriction(tid, action->isChecked());
}
Timeline::TimelineModelAggregator *CtfVisualizerTool::modelAggregator() const Timeline::TimelineModelAggregator *CtfVisualizerTool::modelAggregator() const
{ {
return m_modelAggregator.get(); return m_modelAggregator.get();
@@ -169,6 +201,7 @@ void CtfVisualizerTool::loadJson()
zoomControl()->setTrace(m_traceManager->traceBegin(), m_traceManager->traceEnd() + m_traceManager->traceDuration() / 20); zoomControl()->setTrace(m_traceManager->traceBegin(), m_traceManager->traceEnd() + m_traceManager->traceDuration() / 20);
zoomControl()->setRange(m_traceManager->traceBegin(), m_traceManager->traceEnd() + m_traceManager->traceDuration() / 20); zoomControl()->setRange(m_traceManager->traceBegin(), m_traceManager->traceEnd() + m_traceManager->traceDuration() / 20);
} }
setAvailableThreads(m_traceManager->getSortedThreads());
thread->deleteLater(); thread->deleteLater();
delete task; delete task;
delete futureInterface; delete futureInterface;

View File

@@ -40,6 +40,7 @@ namespace Internal {
class CtfTraceManager; class CtfTraceManager;
class CtfStatisticsModel; class CtfStatisticsModel;
class CtfStatisticsView; class CtfStatisticsView;
class CtfTimelineModel;
class CtfVisualizerTraceView; class CtfVisualizerTraceView;
@@ -63,6 +64,9 @@ private:
void initialize(); void initialize();
void finalize(); void finalize();
void setAvailableThreads(const QList<CtfTimelineModel *> &threads);
void toggleThreadRestriction(QAction *action);
Utils::Perspective m_perspective{Constants::CtfVisualizerPerspectiveId, Utils::Perspective m_perspective{Constants::CtfVisualizerPerspectiveId,
tr("Chrome Trace Format Visualizer")}; tr("Chrome Trace Format Visualizer")};
@@ -77,6 +81,9 @@ private:
CtfStatisticsView *m_statisticsView; CtfStatisticsView *m_statisticsView;
const QScopedPointer<CtfTraceManager> m_traceManager; const QScopedPointer<CtfTraceManager> m_traceManager;
QToolButton *const m_restrictToThreadsButton;
QMenu *const m_restrictToThreadsMenu;
}; };
} // namespace Internal } // namespace Internal