1 #include "profiletablemodel.h"
3 typedef trace::Profile::Frame Frame;
4 typedef trace::Profile::Program Program;
5 typedef trace::Profile::CpuCall CpuCall;
6 typedef trace::Profile::DrawCall DrawCall;
16 COLUMN_PIXELS_AVERAGE,
20 static QString columnNames[] = {
23 QString("Total GPU Time"),
24 QString("Total CPU Time"),
25 QString("Total Pixels Drawn"),
26 QString("Avg GPU Time"),
27 QString("Avg CPU Time"),
28 QString("Avg Pixels Drawn")
31 ProfileTableModel::ProfileTableModel(QObject *parent)
32 : QAbstractTableModel(parent),
34 m_sortColumn(COLUMN_GPU_TIME),
35 m_sortOrder(Qt::DescendingOrder)
40 void ProfileTableModel::setProfile(trace::Profile* profile)
43 m_timeMin = m_profile->frames.front().cpuStart;
44 m_timeMax = m_profile->frames.back().cpuStart + m_profile->frames.back().cpuDuration;
49 void ProfileTableModel::setTimeSelection(int64_t start, int64_t end)
54 sort(m_sortColumn, m_sortOrder);
59 * Creates the row data from trace profile
61 void ProfileTableModel::updateModel()
63 if (m_timeMin == m_timeMax) {
64 m_timeMin = m_profile->frames.front().cpuStart;
65 m_timeMax = m_profile->frames.back().cpuStart + m_profile->frames.back().cpuDuration;
68 for (QList<ProfileTableRow>::iterator itr = m_rowData.begin(); itr != m_rowData.end(); ++itr) {
69 ProfileTableRow& row = *itr;
75 row.longestCpu = NULL;
76 row.longestGpu = NULL;
77 row.longestPixel = NULL;
80 for (std::vector<Program>::const_iterator itr = m_profile->programs.begin(); itr != m_profile->programs.end(); ++itr) {
81 ProfileTableRow* row = getRow(itr - m_profile->programs.begin());
82 const Program& program = *itr;
84 for (std::vector<DrawCall>::const_iterator jtr = program.drawCalls.begin(); jtr != program.drawCalls.end(); ++jtr) {
85 const DrawCall& call = *jtr;
87 if (call.cpuStart > m_timeMax) {
91 if (call.cpuStart + call.cpuDuration < m_timeMin) {
96 row->pixels += call.pixels;
97 row->gpuTime += call.gpuDuration;
98 row->cpuTime += call.cpuDuration;
100 if (!row->longestGpu || row->longestGpu->gpuDuration < call.gpuDuration) {
101 row->longestGpu = &call;
104 if (!row->longestCpu || row->longestCpu->cpuDuration < call.cpuDuration) {
105 row->longestCpu = &call;
108 if (!row->longestPixel || row->longestPixel->pixels < call.pixels) {
109 row->longestPixel = &call;
117 * Get the appropriate call associated with an item in the table
119 const DrawCall* ProfileTableModel::getJumpCall(const QModelIndex & index) const {
120 const ProfileTableRow& row = m_rowData[index.row()];
122 switch(index.column()) {
123 case COLUMN_GPU_TIME:
124 case COLUMN_GPU_AVERAGE:
125 return row.longestGpu;
126 case COLUMN_CPU_TIME:
127 case COLUMN_CPU_AVERAGE:
128 return row.longestCpu;
129 case COLUMN_PIXELS_DRAWN:
130 case COLUMN_PIXELS_AVERAGE:
131 return row.longestPixel;
138 ProfileTableRow* ProfileTableModel::getRow(unsigned program) {
139 for (QList<ProfileTableRow>::iterator itr = m_rowData.begin(); itr != m_rowData.end(); ++itr) {
140 if (itr->program == program)
144 m_rowData.append(ProfileTableRow(program));
145 return &m_rowData.back();
149 int ProfileTableModel::rowCount(const QModelIndex & parent) const
151 if (!parent.isValid()) {
152 return m_rowData.size();
159 int ProfileTableModel::columnCount(const QModelIndex & /*parent*/) const
165 QVariant ProfileTableModel::data(const QModelIndex &index, int role) const
167 if (!index.isValid()) {
171 if (role == Qt::DisplayRole) {
172 const ProfileTableRow& row = m_rowData[index.row()];
174 switch(index.column()) {
179 case COLUMN_GPU_TIME:
181 case COLUMN_CPU_TIME:
183 case COLUMN_PIXELS_DRAWN:
185 case COLUMN_GPU_AVERAGE:
186 return (row.uses <= 0) ? 0 : (row.gpuTime / row.uses);
187 case COLUMN_CPU_AVERAGE:
188 return (row.uses <= 0) ? 0 : (row.cpuTime / row.uses);
189 case COLUMN_PIXELS_AVERAGE:
190 return (row.uses <= 0) ? 0 : (row.pixels / row.uses);
192 } else if (role == Qt::TextAlignmentRole) {
193 return Qt::AlignRight;
200 QVariant ProfileTableModel::headerData(int section, Qt::Orientation orientation, int role) const
202 if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
203 if (section >= 0 && section < MAX_COLUMN) {
204 return columnNames[section];
212 class ProgramSorter {
214 ProgramSorter(int column, Qt::SortOrder order)
215 : mSortColumn(column),
220 bool operator()(const ProfileTableRow &p1, const ProfileTableRow &p2) const
224 switch(mSortColumn) {
226 result = p1.program < p2.program;
229 result = p1.uses < p2.uses;
231 case COLUMN_GPU_TIME:
232 result = p1.gpuTime < p2.gpuTime;
234 case COLUMN_CPU_TIME:
235 result = p1.cpuTime < p2.cpuTime;
237 case COLUMN_PIXELS_DRAWN:
238 result = p1.pixels < p2.pixels;
240 case COLUMN_GPU_AVERAGE:
241 result = ((p1.uses <= 0) ? 0 : (p1.gpuTime / p1.uses)) < ((p2.uses <= 0) ? 0 : (p2.gpuTime / p2.uses));
243 case COLUMN_CPU_AVERAGE:
244 result = ((p1.uses <= 0) ? 0 : (p1.cpuTime / p1.uses)) < ((p2.uses <= 0) ? 0 : (p2.cpuTime / p2.uses));
246 case COLUMN_PIXELS_AVERAGE:
247 result = ((p1.uses <= 0) ? 0 : (p1.pixels / p1.uses)) < ((p2.uses <= 0) ? 0 : (p2.pixels / p2.uses));
251 if (mSortOrder == Qt::DescendingOrder) {
260 Qt::SortOrder mSortOrder;
264 void ProfileTableModel::sort(int column, Qt::SortOrder order) {
265 m_sortColumn = column;
267 qSort(m_rowData.begin(), m_rowData.end(), ProgramSorter(column, order));
268 emit dataChanged(createIndex(0, 0), createIndex(m_rowData.size(), MAX_COLUMN));
272 #include "profiletablemodel.moc"