]> git.cworth.org Git - apitrace/commitdiff
Improve number formatting in profile gui.
authorJames Benton <jbenton@vmware.com>
Wed, 22 Aug 2012 11:18:09 +0000 (12:18 +0100)
committerJames Benton <jbenton@vmware.com>
Wed, 22 Aug 2012 13:18:01 +0000 (14:18 +0100)
gui/profiledialog.cpp
gui/profiledialog.h
gui/profiletablemodel.cpp
gui/timelinewidget.cpp

index 5568b54120a905518f97dc50af6e8658722adf47..bfe0881261163bb7d64e8bf083a3c091a1a8eca5 100644 (file)
@@ -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"
index 39f8699db83faaa6cc83dcb900e3a55258dd410a..8a2f39ea175c45b3e7649293fd223ad94d603e69 100644 (file)
@@ -31,4 +31,6 @@ private:
     trace::Profile *m_profile;
 };
 
+QString getTimeString(int64_t time, int64_t unitTime = 0);
+
 #endif
index a305709fa9c9c1cf9903894e574b8c9ea317654e..5b9d48473319a46fdac867184c68bfc51a3fbc64 100644 (file)
@@ -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;
index b6a52f875980322c8306ef8ead5341b8f4583057..0375831871570930eb9d5256aaaecf2e844a4671 100644 (file)
@@ -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;