diff options
author | James Benton <jbenton@vmware.com> | 2012-08-22 12:18:09 +0100 |
---|---|---|
committer | James Benton <jbenton@vmware.com> | 2012-08-22 14:18:01 +0100 |
commit | 902626cc60d258582a843f318a2fd5f5a76c511f (patch) | |
tree | 5206efe0750985f7c3c7828e52a5384641e06117 | |
parent | 4c4896f8490aca7f32956e402ffdf413d04c36dd (diff) |
Improve number formatting in profile gui.
-rw-r--r-- | gui/profiledialog.cpp | 48 | ||||
-rw-r--r-- | gui/profiledialog.h | 2 | ||||
-rw-r--r-- | gui/profiletablemodel.cpp | 17 | ||||
-rw-r--r-- | gui/timelinewidget.cpp | 16 |
4 files changed, 69 insertions, 14 deletions
diff --git a/gui/profiledialog.cpp b/gui/profiledialog.cpp index 5568b541..bfe08812 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 39f8699d..8a2f39ea 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 a305709f..5b9d4847 100644 --- a/gui/profiletablemodel.cpp +++ b/gui/profiletablemodel.cpp @@ -1,4 +1,7 @@ #include "profiletablemodel.h" +#include "profiledialog.h" + +#include <QLocale> 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 b6a52f87..03758318 100644 --- a/gui/timelinewidget.cpp +++ b/gui/timelinewidget.cpp @@ -1,8 +1,10 @@ #include "timelinewidget.h" +#include "profiledialog.h" #include "trace_profiler.hpp" #include <math.h> #include <QColor> +#include <QLocale> #include <QPainter> #include <QToolTip> #include <QMouseEvent> @@ -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; |