X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=gui%2Fprofiletablemodel.cpp;h=11a0d0c10901e299b271dfabad75e4948fb0c5f7;hb=HEAD;hp=8da07e02e7a8aca7ffe8a842df0aefefbb704a32;hpb=50f9686913b8fc9f46662b299a9810dee08b0a9c;p=apitrace diff --git a/gui/profiletablemodel.cpp b/gui/profiletablemodel.cpp index 8da07e0..11a0d0c 100644 --- a/gui/profiletablemodel.cpp +++ b/gui/profiletablemodel.cpp @@ -1,7 +1,12 @@ #include "profiletablemodel.h" +#include "profiledialog.h" +#include "profiling.h" + +#include typedef trace::Profile::Call Call; typedef trace::Profile::Frame Frame; +typedef trace::Profile::Program Program; enum { COLUMN_PROGRAM, @@ -38,16 +43,41 @@ ProfileTableModel::ProfileTableModel(QObject *parent) 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); } @@ -59,8 +89,8 @@ void ProfileTableModel::setTimeSelection(int64_t start, int64_t end) 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::iterator itr = m_rowData.begin(); itr != m_rowData.end(); ++itr) { @@ -75,39 +105,29 @@ void ProfileTableModel::updateModel() 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::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::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; @@ -128,7 +148,7 @@ void ProfileTableModel::updateModel() /** * 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()) { @@ -147,13 +167,41 @@ const Call* ProfileTableModel::getJumpCall(const QModelIndex & index) const { } +/** + * 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::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(); } @@ -186,19 +234,19 @@ QVariant ProfileTableModel::data(const QModelIndex &index, int role) const 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;