X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=gui%2Fprofiledialog.cpp;h=f33020386796def64e5d8f3c71e4eacd347c9568;hb=b70a86af10057c5b7fcf79b674cfe5abbeaadebb;hp=5568b54120a905518f97dc50af6e8658722adf47;hpb=4c4896f8490aca7f32956e402ffdf413d04c36dd;p=apitrace diff --git a/gui/profiledialog.cpp b/gui/profiledialog.cpp index 5568b54..f330203 100644 --- a/gui/profiledialog.cpp +++ b/gui/profiledialog.cpp @@ -9,7 +9,8 @@ ProfileDialog::ProfileDialog(QWidget *parent) setupUi(this); connect(m_timeline, SIGNAL(jumpToCall(int)), SIGNAL(jumpToCall(int))); - connect(m_timeline, SIGNAL(selectionChanged(int64_t,int64_t)), SLOT(selectionChanged(int64_t,int64_t))); + connect(m_gpuGraph, SIGNAL(jumpToCall(int)), SIGNAL(jumpToCall(int))); + connect(m_cpuGraph, SIGNAL(jumpToCall(int)), SIGNAL(jumpToCall(int))); } @@ -26,34 +27,113 @@ void ProfileDialog::tableDoubleClicked(const QModelIndex& index) if (call) { emit jumpToCall(call->no); + } else { + unsigned program = model->getProgram(index); + m_timeline->selectProgram(program); + m_cpuGraph->selectProgram(program); + m_gpuGraph->selectProgram(program); } } void ProfileDialog::setProfile(trace::Profile* profile) { - if (m_profile) { - delete m_profile; + delete m_profile; + + if (profile->frames.size() == 0) { + m_profile = NULL; + } else { + m_profile = profile; + m_timeline->setProfile(m_profile); + m_gpuGraph->setProfile(m_profile, GraphGpu); + m_cpuGraph->setProfile(m_profile, GraphCpu); + + ProfileTableModel* model = new ProfileTableModel(m_table); + model->setProfile(m_profile); + + delete m_table->model(); + m_table->setModel(model); + m_table->update(QModelIndex()); + m_table->sortByColumn(1, Qt::DescendingOrder); + m_table->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents); + m_table->resizeColumnsToContents(); } +} + - m_profile = profile; - m_timeline->setProfile(m_profile); +void ProfileDialog::selectNone() +{ + QObject* src = QObject::sender(); + + /* Update table model */ + ProfileTableModel* model = (ProfileTableModel*)m_table->model(); + model->selectNone(); + m_table->reset(); + + /* Update graphs */ + if (src != m_gpuGraph) { + m_gpuGraph->selectNone(); + } - ProfileTableModel* model = new ProfileTableModel(m_table); - model->setProfile(m_profile); + if (src != m_cpuGraph) { + m_cpuGraph->selectNone(); + } - delete m_table->model(); - m_table->setModel(model); - m_table->resizeColumnsToContents(); - m_table->sortByColumn(2, Qt::DescendingOrder); + /* Update timeline */ + if (src != m_timeline) { + m_timeline->selectNone(); + } } -void ProfileDialog::selectionChanged(int64_t start, int64_t end) +void ProfileDialog::selectProgram(unsigned program) { + QObject* src = QObject::sender(); + + /* Update table model */ ProfileTableModel* model = (ProfileTableModel*)m_table->model(); - model->setTimeSelection(start, end); + model->selectNone(); m_table->reset(); + m_table->selectRow(model->getRowIndex(program)); + + /* Update graphs */ + if (src != m_gpuGraph) { + m_gpuGraph->selectProgram(program); + } + + if (src != m_cpuGraph) { + m_cpuGraph->selectProgram(program); + } + + /* Update timeline */ + if (src != m_timeline) { + m_timeline->selectProgram(program); + } +} + + +void ProfileDialog::selectTime(int64_t start, int64_t end) +{ + QObject* src = QObject::sender(); + + /* Update table model */ + ProfileTableModel* model = (ProfileTableModel*)m_table->model(); + model->selectTime(start, end); + m_table->reset(); + + /* Update graphs */ + if (src != m_gpuGraph) { + m_gpuGraph->selectTime(start, end); + } + + if (src != m_cpuGraph) { + m_cpuGraph->selectTime(start, end); + } + + /* Update timeline */ + if (src != m_timeline) { + m_timeline->selectTime(start, end); + } } @@ -80,4 +160,52 @@ void ProfileDialog::setHorizontalScrollMax(int max) } } + +/** + * Convert a CPU / GPU time to a textual representation. + * This includes automatic unit selection. + */ +QString getTimeString(int64_t time, int64_t unitTime) +{ + QString text; + QString unit = " ns"; + double unitScale = 1; + + if (unitTime == 0) { + unitTime = time; + } + + if (unitTime >= 60e9) { + int64_t mins = time / 60e9; + text += QString("%1 m ").arg(mins); + + time -= mins * 60e9; + unit = " s"; + unitScale = 1e9; + } else if (unitTime >= 1e9) { + unit = " s"; + unitScale = 1e9; + } else if (unitTime >= 1e6) { + unit = " ms"; + unitScale = 1e6; + } else if (unitTime >= 1e3) { + unit = QString::fromUtf8(" µs"); + unitScale = 1e3; + } + + /* 3 decimal places */ + text += QString("%1").arg(time / unitScale, 0, 'f', 3); + + /* Remove trailing 0 */ + while(text.endsWith('0')) + text.truncate(text.length() - 1); + + /* Remove trailing decimal point */ + if (text.endsWith(QLocale::system().decimalPoint())) + text.truncate(text.length() - 1); + + return text + unit; +} + + #include "profiledialog.moc"