From: James Benton Date: Wed, 22 Aug 2012 11:18:09 +0000 (+0100) Subject: Improve number formatting in profile gui. X-Git-Url: https://git.notmuchmail.org/git?a=commitdiff_plain;h=902626cc60d258582a843f318a2fd5f5a76c511f;p=apitrace Improve number formatting in profile gui. --- diff --git a/gui/profiledialog.cpp b/gui/profiledialog.cpp index 5568b54..bfe0881 100644 --- a/gui/profiledialog.cpp +++ b/gui/profiledialog.cpp @@ -80,4 +80,52 @@ void ProfileDialog::setHorizontalScrollMax(int max) } } + +/** + * Convert a CPU / GPU time to a textual representation. + * This includes automatic unit selection. + */ +QString getTimeString(int64_t time, int64_t unitTime) +{ + QString text; + QString unit = " ns"; + double unitScale = 1; + + if (unitTime == 0) { + unitTime = time; + } + + if (unitTime >= 60e9) { + int64_t mins = time / 60e9; + text += QString("%1 m ").arg(mins); + + time -= mins * 60e9; + unit = " s"; + unitScale = 1e9; + } else if (unitTime >= 1e9) { + unit = " s"; + unitScale = 1e9; + } else if (unitTime >= 1e6) { + unit = " ms"; + unitScale = 1e6; + } else if (unitTime >= 1e3) { + unit = " us"; + unitScale = 1e3; + } + + /* 3 decimal places */ + text += QString("%1").arg(time / unitScale, 0, 'f', 3); + + /* Remove trailing 0 */ + while(text.endsWith('0')) + text.truncate(text.length() - 1); + + /* Remove trailing decimal point */ + if (text.endsWith(QLocale::system().decimalPoint())) + text.truncate(text.length() - 1); + + return text + unit; +} + + #include "profiledialog.moc" diff --git a/gui/profiledialog.h b/gui/profiledialog.h index 39f8699..8a2f39e 100644 --- a/gui/profiledialog.h +++ b/gui/profiledialog.h @@ -31,4 +31,6 @@ private: trace::Profile *m_profile; }; +QString getTimeString(int64_t time, int64_t unitTime = 0); + #endif diff --git a/gui/profiletablemodel.cpp b/gui/profiletablemodel.cpp index a305709..5b9d484 100644 --- a/gui/profiletablemodel.cpp +++ b/gui/profiletablemodel.cpp @@ -1,4 +1,7 @@ #include "profiletablemodel.h" +#include "profiledialog.h" + +#include typedef trace::Profile::Call Call; typedef trace::Profile::Frame Frame; @@ -178,19 +181,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 getTimeString(row.gpuTime); case COLUMN_CPU_TIME: - return row.cpuTime; + return 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 getTimeString((row.uses <= 0) ? 0 : (row.gpuTime / row.uses)); case COLUMN_CPU_AVERAGE: - return (row.uses <= 0) ? 0 : (row.cpuTime / row.uses); + return 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; diff --git a/gui/timelinewidget.cpp b/gui/timelinewidget.cpp index b6a52f8..0375831 100644 --- a/gui/timelinewidget.cpp +++ b/gui/timelinewidget.cpp @@ -1,8 +1,10 @@ #include "timelinewidget.h" +#include "profiledialog.h" #include "trace_profiler.hpp" #include #include +#include #include #include #include @@ -402,8 +404,8 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *e) QString text; text = QString::fromStdString(call->name); text += QString("\nCall: %1").arg(call->no); - text += QString("\nCPU Start: %1").arg(call->cpuStart); - text += QString("\nCPU Duration: %1").arg(call->cpuDuration); + text += QString("\nCPU Start: %1").arg(getTimeString(call->cpuStart)); + text += QString("\nCPU Duration: %1").arg(getTimeString(call->cpuDuration)); QToolTip::showText(e->globalPos(), text); tooltip = true; @@ -418,11 +420,11 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *e) QString text; text = QString::fromStdString(call->name); text += QString("\nCall: %1").arg(call->no); - text += QString("\nGPU Start: %1").arg(call->gpuStart); - text += QString("\nCPU Start: %1").arg(call->cpuStart); - text += QString("\nGPU Duration: %1").arg(call->gpuDuration); - text += QString("\nCPU Duration: %1").arg(call->cpuDuration); - text += QString("\nPixels Drawn: %1").arg(call->pixels); + text += QString("\nCPU Start: %1").arg(getTimeString(call->cpuStart)); + text += QString("\nGPU Start: %1").arg(getTimeString(call->gpuStart)); + text += QString("\nCPU Duration: %1").arg(getTimeString(call->cpuDuration)); + text += QString("\nGPU Duration: %1").arg(getTimeString(call->gpuDuration)); + text += QString("\nPixels Drawn: %1").arg(QLocale::system().toString((qlonglong)call->pixels)); QToolTip::showText(e->globalPos(), text); tooltip = true;