1 #include "profiledialog.h"
2 #include "profiletablemodel.h"
3 #include <QSortFilterProxyModel>
5 ProfileDialog::ProfileDialog(QWidget *parent)
11 connect(m_timeline, SIGNAL(jumpToCall(int)), SIGNAL(jumpToCall(int)));
12 connect(m_gpuGraph, SIGNAL(jumpToCall(int)), SIGNAL(jumpToCall(int)));
13 connect(m_cpuGraph, SIGNAL(jumpToCall(int)), SIGNAL(jumpToCall(int)));
17 ProfileDialog::~ProfileDialog()
23 void ProfileDialog::tableDoubleClicked(const QModelIndex& index)
25 ProfileTableModel* model = (ProfileTableModel*)m_table->model();
26 const trace::Profile::Call* call = model->getJumpCall(index);
29 emit jumpToCall(call->no);
31 unsigned program = model->getProgram(index);
32 m_timeline->selectProgram(program);
33 m_cpuGraph->selectProgram(program);
34 m_gpuGraph->selectProgram(program);
39 void ProfileDialog::setProfile(trace::Profile* profile)
43 if (profile->frames.size() == 0) {
47 m_timeline->setProfile(m_profile);
48 m_gpuGraph->setProfile(m_profile, GraphGpu);
49 m_cpuGraph->setProfile(m_profile, GraphCpu);
51 ProfileTableModel* model = new ProfileTableModel(m_table);
52 model->setProfile(m_profile);
54 delete m_table->model();
55 m_table->setModel(model);
56 m_table->update(QModelIndex());
57 m_table->sortByColumn(1, Qt::DescendingOrder);
58 m_table->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
59 m_table->resizeColumnsToContents();
64 void ProfileDialog::selectNone()
66 QObject* src = QObject::sender();
68 /* Update table model */
69 ProfileTableModel* model = (ProfileTableModel*)m_table->model();
74 if (src != m_gpuGraph) {
75 m_gpuGraph->selectNone();
78 if (src != m_cpuGraph) {
79 m_cpuGraph->selectNone();
83 if (src != m_timeline) {
84 m_timeline->selectNone();
89 void ProfileDialog::selectProgram(unsigned program)
91 QObject* src = QObject::sender();
93 /* Update table model */
94 ProfileTableModel* model = (ProfileTableModel*)m_table->model();
97 m_table->selectRow(model->getRowIndex(program));
100 if (src != m_gpuGraph) {
101 m_gpuGraph->selectProgram(program);
104 if (src != m_cpuGraph) {
105 m_cpuGraph->selectProgram(program);
108 /* Update timeline */
109 if (src != m_timeline) {
110 m_timeline->selectProgram(program);
115 void ProfileDialog::selectTime(int64_t start, int64_t end)
117 QObject* src = QObject::sender();
119 /* Update table model */
120 ProfileTableModel* model = (ProfileTableModel*)m_table->model();
121 model->selectTime(start, end);
125 if (src != m_gpuGraph) {
126 m_gpuGraph->selectTime(start, end);
129 if (src != m_cpuGraph) {
130 m_cpuGraph->selectTime(start, end);
133 /* Update timeline */
134 if (src != m_timeline) {
135 m_timeline->selectTime(start, end);
140 void ProfileDialog::setVerticalScrollMax(int max)
143 m_verticalScrollBar->hide();
145 m_verticalScrollBar->show();
146 m_verticalScrollBar->setMinimum(0);
147 m_verticalScrollBar->setMaximum(max);
152 void ProfileDialog::setHorizontalScrollMax(int max)
155 m_horizontalScrollBar->hide();
157 m_horizontalScrollBar->show();
158 m_horizontalScrollBar->setMinimum(0);
159 m_horizontalScrollBar->setMaximum(max);
165 * Convert a CPU / GPU time to a textual representation.
166 * This includes automatic unit selection.
168 QString getTimeString(int64_t time, int64_t unitTime)
171 QString unit = " ns";
172 double unitScale = 1;
178 if (unitTime >= 60e9) {
179 int64_t mins = time / 60e9;
180 text += QString("%1 m ").arg(mins);
185 } else if (unitTime >= 1e9) {
188 } else if (unitTime >= 1e6) {
191 } else if (unitTime >= 1e3) {
192 unit = QString::fromUtf8(" µs");
196 /* 3 decimal places */
197 text += QString("%1").arg(time / unitScale, 0, 'f', 3);
199 /* Remove trailing 0 */
200 while(text.endsWith('0'))
201 text.truncate(text.length() - 1);
203 /* Remove trailing decimal point */
204 if (text.endsWith(QLocale::system().decimalPoint()))
205 text.truncate(text.length() - 1);
211 #include "profiledialog.moc"