1 #include "profiletablemodel.h"
2 #include "profiledialog.h"
6 typedef trace::Profile::Call Call;
7 typedef trace::Profile::Frame Frame;
8 typedef trace::Profile::Program Program;
18 COLUMN_PIXELS_AVERAGE,
22 static QString columnNames[] = {
25 QString("Total GPU Time"),
26 QString("Total CPU Time"),
27 QString("Total Pixels Drawn"),
28 QString("Avg GPU Time"),
29 QString("Avg CPU Time"),
30 QString("Avg Pixels Drawn")
33 ProfileTableModel::ProfileTableModel(QObject *parent)
34 : QAbstractTableModel(parent),
36 m_sortColumn(COLUMN_GPU_TIME),
37 m_sortOrder(Qt::DescendingOrder)
42 void ProfileTableModel::setProfile(trace::Profile* profile)
45 m_timeMin = m_profile->frames.front().cpuStart;
46 m_timeMax = m_profile->frames.back().cpuStart + m_profile->frames.back().cpuDuration;
51 void ProfileTableModel::setTimeSelection(int64_t start, int64_t end)
56 sort(m_sortColumn, m_sortOrder);
61 * Creates the row data from trace profile
63 void ProfileTableModel::updateModel()
65 if (m_timeMin == m_timeMax) {
66 m_timeMin = m_profile->frames.front().cpuStart;
67 m_timeMax = m_profile->frames.back().cpuStart + m_profile->frames.back().cpuDuration;
70 for (QList<ProfileTableRow>::iterator itr = m_rowData.begin(); itr != m_rowData.end(); ++itr) {
71 ProfileTableRow& row = *itr;
77 row.longestCpu = NULL;
78 row.longestGpu = NULL;
79 row.longestPixel = NULL;
82 for (std::vector<Program>::const_iterator itr = m_profile->programs.begin(); itr != m_profile->programs.end(); ++itr) {
83 ProfileTableRow* row = NULL;
84 const Program& program = *itr;
86 for (std::vector<unsigned>::const_iterator jtr = program.calls.begin(); jtr != program.calls.end(); ++jtr) {
87 const Call& call = m_profile->calls[*jtr];
89 if (call.cpuStart > m_timeMax) {
93 if (call.cpuStart + call.cpuDuration < m_timeMin) {
98 row = getRow(itr - m_profile->programs.begin());
102 row->pixels += call.pixels;
103 row->gpuTime += call.gpuDuration;
104 row->cpuTime += call.cpuDuration;
106 if (!row->longestGpu || row->longestGpu->gpuDuration < call.gpuDuration) {
107 row->longestGpu = &call;
110 if (!row->longestCpu || row->longestCpu->cpuDuration < call.cpuDuration) {
111 row->longestCpu = &call;
114 if (!row->longestPixel || row->longestPixel->pixels < call.pixels) {
115 row->longestPixel = &call;
123 * Get the appropriate call associated with an item in the table
125 const trace::Profile::Call *ProfileTableModel::getJumpCall(const QModelIndex & index) const {
126 const ProfileTableRow& row = m_rowData[index.row()];
128 switch(index.column()) {
129 case COLUMN_GPU_TIME:
130 case COLUMN_GPU_AVERAGE:
131 return row.longestGpu;
132 case COLUMN_CPU_TIME:
133 case COLUMN_CPU_AVERAGE:
134 return row.longestCpu;
135 case COLUMN_PIXELS_DRAWN:
136 case COLUMN_PIXELS_AVERAGE:
137 return row.longestPixel;
144 ProfileTableRow* ProfileTableModel::getRow(unsigned program) {
145 for (QList<ProfileTableRow>::iterator itr = m_rowData.begin(); itr != m_rowData.end(); ++itr) {
146 if (itr->program == program)
150 m_rowData.append(ProfileTableRow(program));
151 return &m_rowData.back();
155 int ProfileTableModel::rowCount(const QModelIndex & parent) const
157 if (!parent.isValid()) {
158 return m_rowData.size();
165 int ProfileTableModel::columnCount(const QModelIndex & /*parent*/) const
171 QVariant ProfileTableModel::data(const QModelIndex &index, int role) const
173 if (!index.isValid()) {
177 if (role == Qt::DisplayRole) {
178 const ProfileTableRow& row = m_rowData[index.row()];
180 switch(index.column()) {
184 return QLocale::system().toString(row.uses);
185 case COLUMN_GPU_TIME:
186 return getTimeString(row.gpuTime);
187 case COLUMN_CPU_TIME:
188 return getTimeString(row.cpuTime);
189 case COLUMN_PIXELS_DRAWN:
190 return QLocale::system().toString((qlonglong)row.pixels);
191 case COLUMN_GPU_AVERAGE:
192 return getTimeString((row.uses <= 0) ? 0 : (row.gpuTime / row.uses));
193 case COLUMN_CPU_AVERAGE:
194 return getTimeString((row.uses <= 0) ? 0 : (row.cpuTime / row.uses));
195 case COLUMN_PIXELS_AVERAGE:
196 return QLocale::system().toString((row.uses <= 0) ? 0 : (row.pixels / row.uses));
198 } else if (role == Qt::TextAlignmentRole) {
199 return Qt::AlignRight;
206 QVariant ProfileTableModel::headerData(int section, Qt::Orientation orientation, int role) const
208 if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
209 if (section >= 0 && section < MAX_COLUMN) {
210 return columnNames[section];
218 class ProgramSorter {
220 ProgramSorter(int column, Qt::SortOrder order)
221 : mSortColumn(column),
226 bool operator()(const ProfileTableRow &p1, const ProfileTableRow &p2) const
230 switch(mSortColumn) {
232 result = p1.program < p2.program;
235 result = p1.uses < p2.uses;
237 case COLUMN_GPU_TIME:
238 result = p1.gpuTime < p2.gpuTime;
240 case COLUMN_CPU_TIME:
241 result = p1.cpuTime < p2.cpuTime;
243 case COLUMN_PIXELS_DRAWN:
244 result = p1.pixels < p2.pixels;
246 case COLUMN_GPU_AVERAGE:
247 result = ((p1.uses <= 0) ? 0 : (p1.gpuTime / p1.uses)) < ((p2.uses <= 0) ? 0 : (p2.gpuTime / p2.uses));
249 case COLUMN_CPU_AVERAGE:
250 result = ((p1.uses <= 0) ? 0 : (p1.cpuTime / p1.uses)) < ((p2.uses <= 0) ? 0 : (p2.cpuTime / p2.uses));
252 case COLUMN_PIXELS_AVERAGE:
253 result = ((p1.uses <= 0) ? 0 : (p1.pixels / p1.uses)) < ((p2.uses <= 0) ? 0 : (p2.pixels / p2.uses));
257 if (mSortOrder == Qt::DescendingOrder) {
266 Qt::SortOrder mSortOrder;
270 void ProfileTableModel::sort(int column, Qt::SortOrder order) {
271 m_sortColumn = column;
273 qSort(m_rowData.begin(), m_rowData.end(), ProgramSorter(column, order));
274 emit dataChanged(createIndex(0, 0), createIndex(m_rowData.size(), MAX_COLUMN));
278 #include "profiletablemodel.moc"