Timeline: Move printTime() into Timeline and add hours, minutes, nanos

We should use it for all time printing instead of duplicating the code
everywhere.

Change-Id: I530baa31fd7044aefce6201fec0ab27c99a61a1d
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Ulf Hermann
2016-09-16 16:10:19 +02:00
parent c2b89ae3b2
commit 18332d15b5
17 changed files with 176 additions and 32 deletions

View File

@@ -25,6 +25,7 @@
#include "debugmessagesmodel.h"
#include "qmlprofilerconstants.h"
#include <timeline/timelineformattime.h>
namespace QmlProfiler {
namespace Internal {
@@ -78,7 +79,7 @@ QVariantMap DebugMessagesModel::details(int index) const
QVariantMap result;
result.insert(QLatin1String("displayName"), messageType(type.detailType()));
result.insert(tr("Timestamp"), QmlProfilerDataModel::formatTime(startTime(index)));
result.insert(tr("Timestamp"), Timeline::formatTime(startTime(index)));
result.insert(tr("Message"), m_data[index].text);
result.insert(tr("Location"), type.displayName());
return result;

View File

@@ -27,6 +27,8 @@
#include "qmlprofilermodelmanager.h"
#include "qmlprofilereventtypes.h"
#include <timeline/timelineformattime.h>
#include <QKeyEvent>
#include <QMouseEvent>
#include <QMetaEnum>
@@ -75,7 +77,7 @@ QMetaEnum InputEventsModel::metaEnum(const char *name)
QVariantMap InputEventsModel::details(int index) const
{
QVariantMap result;
result.insert(tr("Timestamp"), QmlProfilerDataModel::formatTime(startTime(index)));
result.insert(tr("Timestamp"), Timeline::formatTime(startTime(index)));
QString type;
const InputEvent &event = m_data[index];
switch (event.type) {

View File

@@ -27,6 +27,8 @@
#include "qmlprofilermodelmanager.h"
#include "qmlprofilereventtypes.h"
#include <timeline/timelineformattime.h>
namespace QmlProfiler {
namespace Internal {
@@ -119,7 +121,7 @@ QVariantMap PixmapCacheModel::details(int index) const
result.insert(QLatin1String("displayName"), tr("Image Loaded"));
if (m_pixmaps[ev->urlIndex].sizes[ev->sizeIndex].loadState != Finished)
result.insert(tr("Result"), tr("Load Error"));
result.insert(tr("Duration"), QmlProfilerDataModel::formatTime(duration(index)));
result.insert(tr("Duration"), Timeline::formatTime(duration(index)));
}
result.insert(tr("Cache Size"), QString::fromLatin1("%1 px").arg(ev->cacheSize));

View File

@@ -28,6 +28,7 @@
#include "qmlprofilerdatamodel.h"
#include <utils/qtcassert.h>
#include <timeline/timelineformattime.h>
#include <QCoreApplication>
#include <QVector>
@@ -182,7 +183,7 @@ QVariantMap QmlProfilerAnimationsModel::details(int index) const
QVariantMap result;
result.insert(QStringLiteral("displayName"), displayName());
result.insert(tr("Duration"), QmlProfilerDataModel::formatTime(duration(index)));
result.insert(tr("Duration"), Timeline::formatTime(duration(index)));
result.insert(tr("Framerate"), QString::fromLatin1("%1 FPS").arg(m_data[index].framerate));
result.insert(tr("Animations"), QString::number(m_data[index].animationcount));
result.insert(tr("Context"), selectionId(index) == GuiThread ? tr("GUI Thread") :

View File

@@ -92,16 +92,6 @@ QString getInitialDetails(const QmlEventType &event)
return details;
}
QString QmlProfilerDataModel::formatTime(qint64 timestamp)
{
if (timestamp < 1e6)
return QString::number(timestamp/1e3f,'f',3) + trUtf8(" \xc2\xb5s");
if (timestamp < 1e9)
return QString::number(timestamp/1e6f,'f',3) + tr(" ms");
return QString::number(timestamp/1e9f,'f',3) + tr(" s");
}
QmlProfilerDataModel::QmlProfilerDataModel(Utils::FileInProjectFinder *fileFinder,
QmlProfilerModelManager *parent) :
QObject(parent), d_ptr(new QmlProfilerDataModelPrivate)

View File

@@ -39,8 +39,6 @@ class QMLPROFILER_EXPORT QmlProfilerDataModel : public QObject
{
Q_OBJECT
public:
static QString formatTime(qint64 timestamp);
explicit QmlProfilerDataModel(Utils::FileInProjectFinder *fileFinder,
QmlProfilerModelManager *parent);
~QmlProfilerDataModel();

View File

@@ -31,6 +31,7 @@
#include "timeline/timelinenotesrenderpass.h"
#include "timeline/timelineitemsrenderpass.h"
#include "timeline/timelineselectionrenderpass.h"
#include "timeline/timelineformattime.h"
#include <QCoreApplication>
#include <QVector>
@@ -223,7 +224,7 @@ QVariantMap QmlProfilerRangeModel::details(int index) const
result.insert(QStringLiteral("displayName"),
tr(QmlProfilerModelManager::featureName(mainFeature())));
result.insert(tr("Duration"), QmlProfilerDataModel::formatTime(duration(index)));
result.insert(tr("Duration"), Timeline::formatTime(duration(index)));
result.insert(tr("Details"), types[id].data());
result.insert(tr("Location"), types[id].displayName());

View File

@@ -29,6 +29,7 @@
#include <coreplugin/minisplitter.h>
#include <utils/qtcassert.h>
#include <timeline/timelineformattime.h>
#include <QUrl>
#include <QHash>
@@ -573,7 +574,7 @@ void QmlProfilerStatisticsMainView::parseModel()
}
if (d->m_fieldShown[TotalTime]) {
newRow << new StatisticsViewItem(QmlProfilerDataModel::formatTime(stats.duration),
newRow << new StatisticsViewItem(Timeline::formatTime(stats.duration),
stats.duration);
}
@@ -583,7 +584,7 @@ void QmlProfilerStatisticsMainView::parseModel()
}
if (d->m_fieldShown[SelfTime]) {
newRow << new StatisticsViewItem(QmlProfilerDataModel::formatTime(stats.durationSelf),
newRow << new StatisticsViewItem(Timeline::formatTime(stats.durationSelf),
stats.durationSelf);
}
@@ -591,22 +592,22 @@ void QmlProfilerStatisticsMainView::parseModel()
newRow << new StatisticsViewItem(QString::number(stats.calls), stats.calls);
if (d->m_fieldShown[TimePerCall]) {
newRow << new StatisticsViewItem(QmlProfilerDataModel::formatTime(stats.timePerCall),
newRow << new StatisticsViewItem(Timeline::formatTime(stats.timePerCall),
stats.timePerCall);
}
if (d->m_fieldShown[MedianTime]) {
newRow << new StatisticsViewItem(QmlProfilerDataModel::formatTime(stats.medianTime),
newRow << new StatisticsViewItem(Timeline::formatTime(stats.medianTime),
stats.medianTime);
}
if (d->m_fieldShown[MaxTime]) {
newRow << new StatisticsViewItem(QmlProfilerDataModel::formatTime(stats.maxTime),
newRow << new StatisticsViewItem(Timeline::formatTime(stats.maxTime),
stats.maxTime);
}
if (d->m_fieldShown[MinTime]) {
newRow << new StatisticsViewItem(QmlProfilerDataModel::formatTime(stats.minTime),
newRow << new StatisticsViewItem(Timeline::formatTime(stats.minTime),
stats.minTime);
}
@@ -848,7 +849,7 @@ void QmlProfilerStatisticsRelativesView::rebuildTree(
type.displayName());
const QString typeName = QmlProfilerStatisticsMainView::nameForType(type.rangeType());
newRow << new StatisticsViewItem(typeName, typeName);
newRow << new StatisticsViewItem(QmlProfilerDataModel::formatTime(stats.duration),
newRow << new StatisticsViewItem(Timeline::formatTime(stats.duration),
stats.duration);
newRow << new StatisticsViewItem(QString::number(stats.calls), stats.calls);
newRow << new StatisticsViewItem(type.data().isEmpty() ? tr("Source code not available") :

View File

@@ -27,6 +27,8 @@
#include "qmlprofilermodelmanager.h"
#include "qmlprofilereventtypes.h"
#include <timeline/timelineformattime.h>
#include <QCoreApplication>
#include <QDebug>
@@ -122,7 +124,7 @@ QVariantMap SceneGraphTimelineModel::details(int index) const
result.insert(QLatin1String("displayName"), tr(threadLabel(stage)));
result.insert(tr("Stage"), tr(StageLabels[stage]));
result.insert(tr("Duration"), QmlProfilerDataModel::formatTime(duration(index)));
result.insert(tr("Duration"), Timeline::formatTime(duration(index)));
const int glyphCount = m_data[index].glyphCount;
if (glyphCount >= 0)

View File

@@ -24,6 +24,9 @@
****************************************************************************/
#include "debugmessagesmodel_test.h"
#include <timeline/timelineformattime.h>
#include <QtTest>
namespace QmlProfiler {
@@ -93,7 +96,7 @@ void DebugMessagesModelTest::testDetails()
QCOMPARE(details.value(QLatin1String("displayName")).toString(),
model.tr(messageTypes[i % (QtMsgType::QtInfoMsg + 1)]));
QCOMPARE(details.value(model.tr("Timestamp")).toString(),
QmlProfilerDataModel::formatTime(i));
Timeline::formatTime(i));
QCOMPARE(details.value(model.tr("Message")).toString(),
QString::fromLatin1("message %1").arg(i));
QCOMPARE(details.value(model.tr("Location")).toString(),

View File

@@ -25,6 +25,8 @@
#include "inputeventsmodel_test.h"
#include "timeline/timelinemodel_p.h"
#include "timeline/timelineformattime.h"
#include <QtTest>
namespace QmlProfiler {
@@ -105,7 +107,7 @@ void InputEventsModelTest::testDetails()
{
for (int i = 0; i < 10; ++i) {
const QVariantMap details = model.details(i);
QCOMPARE(details[model.tr("Timestamp")].toString(), QmlProfilerDataModel::formatTime(i));
QCOMPARE(details[model.tr("Timestamp")].toString(), Timeline::formatTime(i));
QString displayName = details[QString("displayName")].toString();
QVERIFY(!displayName.isEmpty());
switch (static_cast<InputEventType>(i % MaximumInputEventType)) {

View File

@@ -24,6 +24,7 @@
****************************************************************************/
#include "pixmapcachemodel_test.h"
#include <timeline/timelineformattime.h>
#include <QtTest>
namespace QmlProfiler {
@@ -248,7 +249,7 @@ void PixmapCacheModelTest::testConsistency()
QVERIFY(expandedRow < model.expandedRowCount());
QVERIFY(details[QLatin1String("displayName")].toString() == model.tr("Image Loaded"));
QCOMPARE(details[model.tr("Duration")].toString(),
QmlProfilerDataModel::formatTime(model.duration(i)));
Timeline::formatTime(model.duration(i)));
// In expanded view pixmaps of the same URL but different sizes are allowed to overlap.
// It looks bad, but that should be a rare thing.
break;

View File

@@ -24,6 +24,7 @@
****************************************************************************/
#include "qmlprofileranimationsmodel_test.h"
#include <timeline/timelineformattime.h>
#include <QtTest>
namespace QmlProfiler {
@@ -127,7 +128,7 @@ void QmlProfilerAnimationsModelTest::testDetails()
QVariantMap details = model.details(i);
QCOMPARE(details["displayName"].toString(), model.displayName());
QCOMPARE(details[QmlProfilerAnimationsModel::tr("Duration")].toString(),
QmlProfilerDataModel::formatTime(1));
Timeline::formatTime(1));
QCOMPARE(details[QmlProfilerAnimationsModel::tr("Framerate")].toString(),
QString::fromLatin1("%1 FPS").arg(frameRate(i)));
QCOMPARE(details[QmlProfilerAnimationsModel::tr("Animations")].toString(),