#include "profiletablemodel.h"
+#include "profiledialog.h"
+#include "profiling.h"
+
+#include <QLocale>
typedef trace::Profile::Call Call;
typedef trace::Profile::Frame Frame;
+typedef trace::Profile::Program Program;
enum {
COLUMN_PROGRAM,
void ProfileTableModel::setProfile(trace::Profile* profile)
{
m_profile = profile;
- m_timeMin = m_profile->frames.front().gpuStart;
- m_timeMax = m_profile->frames.back().gpuStart + m_profile->frames.back().gpuDuration;
+ m_timeMin = m_profile->frames.front().cpuStart;
+ m_timeMax = m_profile->frames.back().cpuStart + m_profile->frames.back().cpuDuration;
updateModel();
}
-void ProfileTableModel::setTimeSelection(int64_t start, int64_t end)
+/**
+ * Set selection to nothing
+ */
+void ProfileTableModel::selectNone()
+{
+ m_timeMin = m_timeMax = 0;
+ updateModel();
+ sort(m_sortColumn, m_sortOrder);
+}
+
+
+/**
+ * Set selection to program
+ */
+void ProfileTableModel::selectProgram(unsigned /*program*/)
+{
+ /* We have no program based selection for table */
+ selectNone();
+}
+
+
+/**
+ * Set selection to a period of time
+ */
+void ProfileTableModel::selectTime(int64_t start, int64_t end)
{
m_timeMin = start;
m_timeMax = end;
+
updateModel();
sort(m_sortColumn, m_sortOrder);
}
void ProfileTableModel::updateModel()
{
if (m_timeMin == m_timeMax) {
- m_timeMin = m_profile->frames.front().gpuStart;
- m_timeMax = m_profile->frames.back().gpuStart + m_profile->frames.back().gpuDuration;
+ m_timeMin = m_profile->frames.front().cpuStart;
+ m_timeMax = m_profile->frames.back().cpuStart + m_profile->frames.back().cpuDuration;
}
for (QList<ProfileTableRow>::iterator itr = m_rowData.begin(); itr != m_rowData.end(); ++itr) {
row.longestPixel = NULL;
}
- for (Frame::const_iterator itr = m_profile->frames.begin(); itr != m_profile->frames.end(); ++itr) {
- const Frame& frame = *itr;
+ for (std::vector<Program>::const_iterator itr = m_profile->programs.begin(); itr != m_profile->programs.end(); ++itr) {
+ ProfileTableRow* row = NULL;
+ const Program& program = *itr;
- if (frame.gpuStart > m_timeMax) {
- break;
- }
-
- if ((frame.gpuStart + frame.gpuDuration) < m_timeMin) {
- continue;
- }
+ for (std::vector<unsigned>::const_iterator jtr = program.calls.begin(); jtr != program.calls.end(); ++jtr) {
+ const Call& call = m_profile->calls[*jtr];
- for (Call::const_iterator jtr = frame.calls.begin(); jtr != frame.calls.end(); ++jtr) {
- const Call& call = *jtr;
-
- if (call.gpuStart > m_timeMax) {
+ if (call.cpuStart > m_timeMax) {
break;
}
- if ((call.gpuStart + call.gpuDuration) < m_timeMin) {
+ if (call.cpuStart + call.cpuDuration < m_timeMin) {
continue;
}
- ProfileTableRow* row = getRow(call.program);
if (!row) {
- m_rowData.append(ProfileTableRow());
- row = &m_rowData.back();
+ row = getRow(itr - m_profile->programs.begin());
}
row->uses++;
- row->program = call.program;
+ row->pixels += call.pixels;
row->gpuTime += call.gpuDuration;
row->cpuTime += call.cpuDuration;
- row->pixels += call.pixels;
if (!row->longestGpu || row->longestGpu->gpuDuration < call.gpuDuration) {
row->longestGpu = &call;
/**
* Get the appropriate call associated with an item in the table
*/
-const Call* ProfileTableModel::getJumpCall(const QModelIndex & index) const {
+const trace::Profile::Call *ProfileTableModel::getJumpCall(const QModelIndex & index) const {
const ProfileTableRow& row = m_rowData[index.row()];
switch(index.column()) {
}
+/**
+ * Get the shader program associated with an item in the table
+ */
+unsigned ProfileTableModel::getProgram(const QModelIndex & index) const
+{
+ const ProfileTableRow& row = m_rowData[index.row()];
+ return row.program;
+}
+
+
+/**
+ * Get the row index for a shader program
+ */
+int ProfileTableModel::getRowIndex(unsigned program) const
+{
+ for (int i = 0; i < m_rowData.size(); ++i) {
+ if (m_rowData[i].program == program)
+ return i;
+ }
+
+ return -1;
+}
+
+
+/**
+ * Get the row data for a shader program
+ */
ProfileTableRow* ProfileTableModel::getRow(unsigned program) {
for (QList<ProfileTableRow>::iterator itr = m_rowData.begin(); itr != m_rowData.end(); ++itr) {
if (itr->program == program)
return &*itr;
}
- return NULL;
+ m_rowData.append(ProfileTableRow(program));
+ return &m_rowData.back();
}
case COLUMN_PROGRAM:
return row.program;
case COLUMN_USAGES:
- return row.uses;
+ return QLocale::system().toString(row.uses);
case COLUMN_GPU_TIME:
- return row.gpuTime;
+ return Profiling::getTimeString(row.gpuTime);
case COLUMN_CPU_TIME:
- return row.cpuTime;
+ return Profiling::getTimeString(row.cpuTime);
case COLUMN_PIXELS_DRAWN:
- return row.pixels;
+ return QLocale::system().toString((qlonglong)row.pixels);
case COLUMN_GPU_AVERAGE:
- return (row.uses <= 0) ? 0 : (row.gpuTime / row.uses);
+ return Profiling::getTimeString((row.uses <= 0) ? 0 : (row.gpuTime / row.uses));
case COLUMN_CPU_AVERAGE:
- return (row.uses <= 0) ? 0 : (row.cpuTime / row.uses);
+ return Profiling::getTimeString((row.uses <= 0) ? 0 : (row.cpuTime / row.uses));
case COLUMN_PIXELS_AVERAGE:
- return (row.uses <= 0) ? 0 : (row.pixels / row.uses);
+ return QLocale::system().toString((row.uses <= 0) ? 0 : (row.pixels / row.uses));
}
} else if (role == Qt::TextAlignmentRole) {
return Qt::AlignRight;
result = p1.pixels < p2.pixels;
break;
case COLUMN_GPU_AVERAGE:
- result = (p1.gpuTime / p1.uses) < (p2.gpuTime / p2.uses);
+ result = ((p1.uses <= 0) ? 0 : (p1.gpuTime / p1.uses)) < ((p2.uses <= 0) ? 0 : (p2.gpuTime / p2.uses));
break;
case COLUMN_CPU_AVERAGE:
- result = (p1.cpuTime / p1.uses) < (p2.cpuTime / p2.uses);
+ result = ((p1.uses <= 0) ? 0 : (p1.cpuTime / p1.uses)) < ((p2.uses <= 0) ? 0 : (p2.cpuTime / p2.uses));
break;
case COLUMN_PIXELS_AVERAGE:
- result = (p1.pixels / p1.uses) < (p2.pixels / p2.uses);
+ result = ((p1.uses <= 0) ? 0 : (p1.pixels / p1.uses)) < ((p2.uses <= 0) ? 0 : (p2.pixels / p2.uses));
break;
}