]> git.cworth.org Git - apitrace/blob - gui/profiledialog.cpp
Change the default graphic system to raster.
[apitrace] / gui / profiledialog.cpp
1 #include "profiledialog.h"
2 #include "profiletablemodel.h"
3 #include <QSortFilterProxyModel>
4
5 ProfileDialog::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)));
12     connect(m_gpuGraph, SIGNAL(jumpToCall(int)), SIGNAL(jumpToCall(int)));
13     connect(m_cpuGraph, SIGNAL(jumpToCall(int)), SIGNAL(jumpToCall(int)));
14 }
15
16
17 ProfileDialog::~ProfileDialog()
18 {
19     delete m_profile;
20 }
21
22
23 void ProfileDialog::tableDoubleClicked(const QModelIndex& index)
24 {
25     ProfileTableModel* model = (ProfileTableModel*)m_table->model();
26     const trace::Profile::Call* call = model->getJumpCall(index);
27
28     if (call) {
29         emit jumpToCall(call->no);
30     } else {
31         unsigned program = model->getProgram(index);
32         m_timeline->selectProgram(program);
33         m_cpuGraph->selectProgram(program);
34         m_gpuGraph->selectProgram(program);
35     }
36 }
37
38
39 void ProfileDialog::setProfile(trace::Profile* profile)
40 {
41     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();
60     }
61 }
62
63
64 void ProfileDialog::selectNone()
65 {
66     QObject* src = QObject::sender();
67
68     /* Update table model */
69     ProfileTableModel* model = (ProfileTableModel*)m_table->model();
70     model->selectNone();
71     m_table->reset();
72
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
89 void 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
115 void 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     }
137 }
138
139
140 void 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
152 void 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
163
164 /**
165  * Convert a CPU / GPU time to a textual representation.
166  * This includes automatic unit selection.
167  */
168 QString 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) {
192         unit = QString::fromUtf8(" µs");
193         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
211 #include "profiledialog.moc"