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 /gui/profiledialog.cpp | |
parent | 4c4896f8490aca7f32956e402ffdf413d04c36dd (diff) |
Improve number formatting in profile gui.
Diffstat (limited to 'gui/profiledialog.cpp')
-rw-r--r-- | gui/profiledialog.cpp | 48 |
1 files changed, 48 insertions, 0 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" |