]> git.cworth.org Git - apitrace/blobdiff - gui/profiledialog.cpp
Improve number formatting in profile gui.
[apitrace] / gui / profiledialog.cpp
index d0a55a3400d46423fd5d9413b3d2f706de7697cc..bfe0881261163bb7d64e8bf083a3c091a1a8eca5 100644 (file)
@@ -22,7 +22,7 @@ ProfileDialog::~ProfileDialog()
 void ProfileDialog::tableDoubleClicked(const QModelIndex& index)
 {
     ProfileTableModel* model = (ProfileTableModel*)m_table->model();
-    const trace::Profile::DrawCall* call = model->getJumpCall(index);
+    const trace::Profile::Call* call = model->getJumpCall(index);
 
     if (call) {
         emit jumpToCall(call->no);
@@ -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"