1 #include "profiletablemodel.h"
3 typedef trace::Profile::Call Call;
4 typedef trace::Profile::Frame Frame;
5 typedef trace::Profile::Program Program;
15 COLUMN_PIXELS_AVERAGE,
19 static QString columnNames[] = {
22 QString("Total GPU Time"),
23 QString("Total CPU Time"),
24 QString("Total Pixels Drawn"),
25 QString("Avg GPU Time"),
26 QString("Avg CPU Time"),
27 QString("Avg Pixels Drawn")
30 ProfileTableModel::ProfileTableModel(QObject *parent)
31 : QAbstractTableModel(parent),
33 m_sortColumn(COLUMN_GPU_TIME),
34 m_sortOrder(Qt::DescendingOrder)
39 void ProfileTableModel::setProfile(trace::Profile* profile)
42 m_timeMin = m_profile->frames.front().cpuStart;
43 m_timeMax = m_profile->frames.back().cpuStart + m_profile->frames.back().cpuDuration;
48 void ProfileTableModel::setTimeSelection(int64_t start, int64_t end)
53 sort(m_sortColumn, m_sortOrder);
58 * Creates the row data from trace profile
60 void ProfileTableModel::updateModel()
62 if (m_timeMin == m_timeMax) {
63 m_timeMin = m_profile->frames.front().cpuStart;
64 m_timeMax = m_profile->frames.back().cpuStart + m_profile->frames.back().cpuDuration;
67 for (QList<ProfileTableRow>::iterator itr = m_rowData.begin(); itr != m_rowData.end(); ++itr) {
68 ProfileTableRow& row = *itr;
74 row.longestCpu = NULL;
75 row.longestGpu = NULL;
76 row.longestPixel = NULL;
79 for (std::vector<Program>::const_iterator itr = m_profile->programs.begin(); itr != m_profile->programs.end(); ++itr) {
80 ProfileTableRow* row = NULL;
81 const Program& program = *itr;
83 for (std::vector<unsigned>::const_iterator jtr = program.calls.begin(); jtr != program.calls.end(); ++jtr) {
84 const Call& call = m_profile->calls[*jtr];
86 if (call.cpuStart > m_timeMax) {
90 if (call.cpuStart + call.cpuDuration < m_timeMin) {
95 row = getRow(itr - m_profile->programs.begin());
99 row->pixels += call.pixels;
100 row->gpuTime += call.gpuDuration;
101 row->cpuTime += call.cpuDuration;
103 if (!row->longestGpu || row->longestGpu->gpuDuration < call.gpuDuration) {
104 row->longestGpu = &call;
107 if (!row->longestCpu || row->longestCpu->cpuDuration < call.cpuDuration) {
108 row->longestCpu = &call;
111 if (!row->longestPixel || row->longestPixel->pixels < call.pixels) {
112 row->longestPixel = &call;
120 * Get the appropriate call associated with an item in the table
122 const trace::Profile::Call *ProfileTableModel::getJumpCall(const QModelIndex & index) const {
123 const ProfileTableRow& row = m_rowData[index.row()];
125 switch(index.column()) {
126 case COLUMN_GPU_TIME:
127 case COLUMN_GPU_AVERAGE:
128 return row.longestGpu;
129 case COLUMN_CPU_TIME:
130 case COLUMN_CPU_AVERAGE:
131 return row.longestCpu;
132 case COLUMN_PIXELS_DRAWN:
133 case COLUMN_PIXELS_AVERAGE:
134 return row.longestPixel;
141 ProfileTableRow* ProfileTableModel::getRow(unsigned program) {
142 for (QList<ProfileTableRow>::iterator itr = m_rowData.begin(); itr != m_rowData.end(); ++itr) {
143 if (itr->program == program)
147 m_rowData.append(ProfileTableRow(program));
148 return &m_rowData.back();
152 int ProfileTableModel::rowCount(const QModelIndex & parent) const
154 if (!parent.isValid()) {
155 return m_rowData.size();
162 int ProfileTableModel::columnCount(const QModelIndex & /*parent*/) const
168 QVariant ProfileTableModel::data(const QModelIndex &index, int role) const
170 if (!index.isValid()) {
174 if (role == Qt::DisplayRole) {
175 const ProfileTableRow& row = m_rowData[index.row()];
177 switch(index.column()) {
182 case COLUMN_GPU_TIME:
184 case COLUMN_CPU_TIME:
186 case COLUMN_PIXELS_DRAWN:
188 case COLUMN_GPU_AVERAGE:
189 return (row.uses <= 0) ? 0 : (row.gpuTime / row.uses);
190 case COLUMN_CPU_AVERAGE:
191 return (row.uses <= 0) ? 0 : (row.cpuTime / row.uses);
192 case COLUMN_PIXELS_AVERAGE:
193 return (row.uses <= 0) ? 0 : (row.pixels / row.uses);
195 } else if (role == Qt::TextAlignmentRole) {
196 return Qt::AlignRight;
203 QVariant ProfileTableModel::headerData(int section, Qt::Orientation orientation, int role) const
205 if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
206 if (section >= 0 && section < MAX_COLUMN) {
207 return columnNames[section];
215 class ProgramSorter {
217 ProgramSorter(int column, Qt::SortOrder order)
218 : mSortColumn(column),
223 bool operator()(const ProfileTableRow &p1, const ProfileTableRow &p2) const
227 switch(mSortColumn) {
229 result = p1.program < p2.program;
232 result = p1.uses < p2.uses;
234 case COLUMN_GPU_TIME:
235 result = p1.gpuTime < p2.gpuTime;
237 case COLUMN_CPU_TIME:
238 result = p1.cpuTime < p2.cpuTime;
240 case COLUMN_PIXELS_DRAWN:
241 result = p1.pixels < p2.pixels;
243 case COLUMN_GPU_AVERAGE:
244 result = ((p1.uses <= 0) ? 0 : (p1.gpuTime / p1.uses)) < ((p2.uses <= 0) ? 0 : (p2.gpuTime / p2.uses));
246 case COLUMN_CPU_AVERAGE:
247 result = ((p1.uses <= 0) ? 0 : (p1.cpuTime / p1.uses)) < ((p2.uses <= 0) ? 0 : (p2.cpuTime / p2.uses));
249 case COLUMN_PIXELS_AVERAGE:
250 result = ((p1.uses <= 0) ? 0 : (p1.pixels / p1.uses)) < ((p2.uses <= 0) ? 0 : (p2.pixels / p2.uses));
254 if (mSortOrder == Qt::DescendingOrder) {
263 Qt::SortOrder mSortOrder;
267 void ProfileTableModel::sort(int column, Qt::SortOrder order) {
268 m_sortColumn = column;
270 qSort(m_rowData.begin(), m_rowData.end(), ProgramSorter(column, order));
271 emit dataChanged(createIndex(0, 0), createIndex(m_rowData.size(), MAX_COLUMN));
275 #include "profiletablemodel.moc"