blob: f33020386796def64e5d8f3c71e4eacd347c9568 [file] [log] [blame]
James Bentonfc4f55a2012-08-08 17:09:07 +01001#include "profiledialog.h"
2#include "profiletablemodel.h"
3#include <QSortFilterProxyModel>
4
5ProfileDialog::ProfileDialog(QWidget *parent)
6 : QDialog(parent),
7 m_profile(0)
8{
9 setupUi(this);
10
11 connect(m_timeline, SIGNAL(jumpToCall(int)), SIGNAL(jumpToCall(int)));
James Bentondd2a1c02012-08-22 14:17:01 +010012 connect(m_gpuGraph, SIGNAL(jumpToCall(int)), SIGNAL(jumpToCall(int)));
13 connect(m_cpuGraph, SIGNAL(jumpToCall(int)), SIGNAL(jumpToCall(int)));
James Bentonfc4f55a2012-08-08 17:09:07 +010014}
15
16
17ProfileDialog::~ProfileDialog()
18{
19 delete m_profile;
20}
21
22
23void ProfileDialog::tableDoubleClicked(const QModelIndex& index)
24{
25 ProfileTableModel* model = (ProfileTableModel*)m_table->model();
James Benton4c4896f2012-08-22 12:11:37 +010026 const trace::Profile::Call* call = model->getJumpCall(index);
James Bentonfc4f55a2012-08-08 17:09:07 +010027
28 if (call) {
29 emit jumpToCall(call->no);
James Bentonb70a86a2012-08-28 18:41:43 +010030 } else {
31 unsigned program = model->getProgram(index);
32 m_timeline->selectProgram(program);
33 m_cpuGraph->selectProgram(program);
34 m_gpuGraph->selectProgram(program);
James Bentonfc4f55a2012-08-08 17:09:07 +010035 }
36}
37
38
39void ProfileDialog::setProfile(trace::Profile* profile)
40{
James Bentonb70a86a2012-08-28 18:41:43 +010041 delete m_profile;
42
43 if (profile->frames.size() == 0) {
44 m_profile = NULL;
45 } else {
46 m_profile = profile;
47 m_timeline->setProfile(m_profile);
48 m_gpuGraph->setProfile(m_profile, GraphGpu);
49 m_cpuGraph->setProfile(m_profile, GraphCpu);
50
51 ProfileTableModel* model = new ProfileTableModel(m_table);
52 model->setProfile(m_profile);
53
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();
James Bentonfc4f55a2012-08-08 17:09:07 +010060 }
James Bentonfc4f55a2012-08-08 17:09:07 +010061}
62
63
James Bentonb70a86a2012-08-28 18:41:43 +010064void ProfileDialog::selectNone()
James Bentonfc4f55a2012-08-08 17:09:07 +010065{
James Bentonb70a86a2012-08-28 18:41:43 +010066 QObject* src = QObject::sender();
67
68 /* Update table model */
James Bentonfc4f55a2012-08-08 17:09:07 +010069 ProfileTableModel* model = (ProfileTableModel*)m_table->model();
James Bentonb70a86a2012-08-28 18:41:43 +010070 model->selectNone();
James Bentonfc4f55a2012-08-08 17:09:07 +010071 m_table->reset();
James Bentonb70a86a2012-08-28 18:41:43 +010072
73 /* Update graphs */
74 if (src != m_gpuGraph) {
75 m_gpuGraph->selectNone();
76 }
77
78 if (src != m_cpuGraph) {
79 m_cpuGraph->selectNone();
80 }
81
82 /* Update timeline */
83 if (src != m_timeline) {
84 m_timeline->selectNone();
85 }
86}
87
88
89void ProfileDialog::selectProgram(unsigned program)
90{
91 QObject* src = QObject::sender();
92
93 /* Update table model */
94 ProfileTableModel* model = (ProfileTableModel*)m_table->model();
95 model->selectNone();
96 m_table->reset();
97 m_table->selectRow(model->getRowIndex(program));
98
99 /* Update graphs */
100 if (src != m_gpuGraph) {
101 m_gpuGraph->selectProgram(program);
102 }
103
104 if (src != m_cpuGraph) {
105 m_cpuGraph->selectProgram(program);
106 }
107
108 /* Update timeline */
109 if (src != m_timeline) {
110 m_timeline->selectProgram(program);
111 }
112}
113
114
115void ProfileDialog::selectTime(int64_t start, int64_t end)
116{
117 QObject* src = QObject::sender();
118
119 /* Update table model */
120 ProfileTableModel* model = (ProfileTableModel*)m_table->model();
121 model->selectTime(start, end);
122 m_table->reset();
123
124 /* Update graphs */
125 if (src != m_gpuGraph) {
126 m_gpuGraph->selectTime(start, end);
127 }
128
129 if (src != m_cpuGraph) {
130 m_cpuGraph->selectTime(start, end);
131 }
132
133 /* Update timeline */
134 if (src != m_timeline) {
135 m_timeline->selectTime(start, end);
136 }
James Bentonfc4f55a2012-08-08 17:09:07 +0100137}
138
139
140void ProfileDialog::setVerticalScrollMax(int max)
141{
142 if (max <= 0) {
143 m_verticalScrollBar->hide();
144 } else {
145 m_verticalScrollBar->show();
146 m_verticalScrollBar->setMinimum(0);
147 m_verticalScrollBar->setMaximum(max);
148 }
149}
150
151
152void ProfileDialog::setHorizontalScrollMax(int max)
153{
154 if (max <= 0) {
155 m_horizontalScrollBar->hide();
156 } else {
157 m_horizontalScrollBar->show();
158 m_horizontalScrollBar->setMinimum(0);
159 m_horizontalScrollBar->setMaximum(max);
160 }
161}
162
James Benton902626c2012-08-22 12:18:09 +0100163
164/**
165 * Convert a CPU / GPU time to a textual representation.
166 * This includes automatic unit selection.
167 */
168QString getTimeString(int64_t time, int64_t unitTime)
169{
170 QString text;
171 QString unit = " ns";
172 double unitScale = 1;
173
174 if (unitTime == 0) {
175 unitTime = time;
176 }
177
178 if (unitTime >= 60e9) {
179 int64_t mins = time / 60e9;
180 text += QString("%1 m ").arg(mins);
181
182 time -= mins * 60e9;
183 unit = " s";
184 unitScale = 1e9;
185 } else if (unitTime >= 1e9) {
186 unit = " s";
187 unitScale = 1e9;
188 } else if (unitTime >= 1e6) {
189 unit = " ms";
190 unitScale = 1e6;
191 } else if (unitTime >= 1e3) {
James Benton418a32e2012-08-22 15:26:03 +0100192 unit = QString::fromUtf8(" µs");
James Benton902626c2012-08-22 12:18:09 +0100193 unitScale = 1e3;
194 }
195
196 /* 3 decimal places */
197 text += QString("%1").arg(time / unitScale, 0, 'f', 3);
198
199 /* Remove trailing 0 */
200 while(text.endsWith('0'))
201 text.truncate(text.length() - 1);
202
203 /* Remove trailing decimal point */
204 if (text.endsWith(QLocale::system().decimalPoint()))
205 text.truncate(text.length() - 1);
206
207 return text + unit;
208}
209
210
James Bentonfc4f55a2012-08-08 17:09:07 +0100211#include "profiledialog.moc"