Skip to content

Commit 6bffa36

Browse files
Peter Hartmannphartmann
Peter Hartmann
authored andcommitted
[BB10-internal] Revert "[BB10-internal] Remove QPerformanceTimer now that QElapsedTimer contains the necessary bits"
This reverts commit 8896651. This apparently caused regressions in Cascades. Change-Id: I004a89ff387fa4af6e11d77ff271e437d2f8e170 Signed-off-by: Peter Hartmann <[email protected]>
1 parent 297b332 commit 6bffa36

File tree

10 files changed

+554
-13
lines changed

10 files changed

+554
-13
lines changed

src/declarative/debugger/qdeclarativedebugtrace.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ Q_GLOBAL_STATIC(QDeclarativeDebugTrace, traceInstance);
109109

110110
// convert to a QByteArray that can be sent to the debug client
111111
// use of QDataStream can skew results if m_deferredSend == false
112-
// (see tst_qdeclarativedebugtrace::trace() benchmark)
112+
// (see tst_qperformancetimer::trace() benchmark)
113113
QByteArray QDeclarativeDebugData::toByteArray() const
114114
{
115115
QByteArray data;
@@ -182,7 +182,7 @@ void QDeclarativeDebugTrace::addEventImpl(EventType event)
182182
if (status() != Enabled || !m_enabled)
183183
return;
184184

185-
QDeclarativeDebugData ed = {m_timer.nsecsElapsed(), (int)Event, (int)event, QString(), -1};
185+
QDeclarativeDebugData ed = {m_timer.elapsed(), (int)Event, (int)event, QString(), -1};
186186
processMessage(ed);
187187
}
188188

@@ -191,7 +191,7 @@ void QDeclarativeDebugTrace::startRangeImpl(RangeType range)
191191
if (status() != Enabled || !m_enabled)
192192
return;
193193

194-
QDeclarativeDebugData rd = {m_timer.nsecsElapsed(), (int)RangeStart, (int)range, QString(), -1};
194+
QDeclarativeDebugData rd = {m_timer.elapsed(), (int)RangeStart, (int)range, QString(), -1};
195195
processMessage(rd);
196196
}
197197

@@ -200,7 +200,7 @@ void QDeclarativeDebugTrace::rangeDataImpl(RangeType range, const QString &rData
200200
if (status() != Enabled || !m_enabled)
201201
return;
202202

203-
QDeclarativeDebugData rd = {m_timer.nsecsElapsed(), (int)RangeData, (int)range, rData, -1};
203+
QDeclarativeDebugData rd = {m_timer.elapsed(), (int)RangeData, (int)range, rData, -1};
204204
processMessage(rd);
205205
}
206206

@@ -209,7 +209,7 @@ void QDeclarativeDebugTrace::rangeDataImpl(RangeType range, const QUrl &rData)
209209
if (status() != Enabled || !m_enabled)
210210
return;
211211

212-
QDeclarativeDebugData rd = {m_timer.nsecsElapsed(), (int)RangeData, (int)range, rData.toString(QUrl::FormattingOption(0x100)), -1};
212+
QDeclarativeDebugData rd = {m_timer.elapsed(), (int)RangeData, (int)range, rData.toString(QUrl::FormattingOption(0x100)), -1};
213213
processMessage(rd);
214214
}
215215

@@ -218,7 +218,7 @@ void QDeclarativeDebugTrace::rangeLocationImpl(RangeType range, const QString &f
218218
if (status() != Enabled || !m_enabled)
219219
return;
220220

221-
QDeclarativeDebugData rd = {m_timer.nsecsElapsed(), (int)RangeLocation, (int)range, fileName, line};
221+
QDeclarativeDebugData rd = {m_timer.elapsed(), (int)RangeLocation, (int)range, fileName, line};
222222
processMessage(rd);
223223
}
224224

@@ -227,7 +227,7 @@ void QDeclarativeDebugTrace::rangeLocationImpl(RangeType range, const QUrl &file
227227
if (status() != Enabled || !m_enabled)
228228
return;
229229

230-
QDeclarativeDebugData rd = {m_timer.nsecsElapsed(), (int)RangeLocation, (int)range, fileName.toString(QUrl::FormattingOption(0x100)), line};
230+
QDeclarativeDebugData rd = {m_timer.elapsed(), (int)RangeLocation, (int)range, fileName.toString(QUrl::FormattingOption(0x100)), line};
231231
processMessage(rd);
232232
}
233233

@@ -236,7 +236,7 @@ void QDeclarativeDebugTrace::endRangeImpl(RangeType range)
236236
if (status() != Enabled || !m_enabled)
237237
return;
238238

239-
QDeclarativeDebugData rd = {m_timer.nsecsElapsed(), (int)RangeEnd, (int)range, QString(), -1};
239+
QDeclarativeDebugData rd = {m_timer.elapsed(), (int)RangeEnd, (int)range, QString(), -1};
240240
processMessage(rd);
241241
}
242242

src/declarative/debugger/qdeclarativedebugtrace_p.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
#define QDECLARATIVEDEBUGTRACE_P_H
4444

4545
#include <private/qdeclarativedebugservice_p.h>
46-
#include <qelapsedtimer.h>
46+
#include <private/qperformancetimer_p.h>
47+
#include <QtCore/qglobal.h>
4748

4849
QT_BEGIN_HEADER
4950

@@ -133,7 +134,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeDebugTrace : public QDeclarativeDebugServ
133134
#endif
134135
void processMessage(const QDeclarativeDebugData &);
135136
void sendMessages();
136-
QElapsedTimer m_timer;
137+
QPerformanceTimer m_timer;
137138
bool m_enabled;
138139
bool m_deferredSend;
139140
bool m_messageReceived;

src/declarative/qml/qml.pri

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ SOURCES += \
5454
$$PWD/qdeclarativedirparser.cpp \
5555
$$PWD/qdeclarativeextensionplugin.cpp \
5656
$$PWD/qdeclarativeimport.cpp \
57-
$$PWD/qdeclarativelist.cpp
57+
$$PWD/qdeclarativelist.cpp \
58+
$$PWD/qperformancetimer.cpp
5859

5960
HEADERS += \
6061
$$PWD/qdeclarativeparser_p.h \
@@ -127,7 +128,8 @@ HEADERS += \
127128
$$PWD/qdeclarativedirparser_p.h \
128129
$$PWD/qdeclarativeextensioninterface.h \
129130
$$PWD/qdeclarativeimport_p.h \
130-
$$PWD/qdeclarativeextensionplugin.h
131+
$$PWD/qdeclarativeextensionplugin.h \
132+
$$PWD/qperformancetimer_p.h
131133

132134
QT += sql
133135
include(parser/parser.pri)
Lines changed: 263 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,263 @@
1+
/****************************************************************************
2+
**
3+
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
4+
** Contact: http://www.qt-project.org/legal
5+
**
6+
** This file is part of the QtDeclarative module of the Qt Toolkit.
7+
**
8+
** $QT_BEGIN_LICENSE:LGPL$
9+
** Commercial License Usage
10+
** Licensees holding valid commercial Qt licenses may use this file in
11+
** accordance with the commercial license agreement provided with the
12+
** Software or, alternatively, in accordance with the terms contained in
13+
** a written agreement between you and Digia. For licensing terms and
14+
** conditions see http://qt.digia.com/licensing. For further information
15+
** use the contact form at http://qt.digia.com/contact-us.
16+
**
17+
** GNU Lesser General Public License Usage
18+
** Alternatively, this file may be used under the terms of the GNU Lesser
19+
** General Public License version 2.1 as published by the Free Software
20+
** Foundation and appearing in the file LICENSE.LGPL included in the
21+
** packaging of this file. Please review the following information to
22+
** ensure the GNU Lesser General Public License version 2.1 requirements
23+
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24+
**
25+
** In addition, as a special exception, Digia gives you certain additional
26+
** rights. These rights are described in the Digia Qt LGPL Exception
27+
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28+
**
29+
** GNU General Public License Usage
30+
** Alternatively, this file may be used under the terms of the GNU
31+
** General Public License version 3.0 as published by the Free Software
32+
** Foundation and appearing in the file LICENSE.GPL included in the
33+
** packaging of this file. Please review the following information to
34+
** ensure the GNU General Public License version 3.0 requirements will be
35+
** met: http://www.gnu.org/copyleft/gpl.html.
36+
**
37+
**
38+
** $QT_END_LICENSE$
39+
**
40+
****************************************************************************/
41+
42+
#include "qperformancetimer_p.h"
43+
44+
#if defined(Q_OS_MAC)
45+
#include <sys/time.h>
46+
#include <unistd.h>
47+
#include <mach/mach_time.h>
48+
#elif defined(Q_OS_SYMBIAN)
49+
#include <e32std.h>
50+
#include <sys/time.h>
51+
#include <hal.h>
52+
#include <hal_data.h>
53+
#elif defined(Q_OS_UNIX)
54+
#include <sys/time.h>
55+
#include <time.h>
56+
#include <unistd.h>
57+
#elif defined(Q_OS_WIN)
58+
#include <windows.h>
59+
#endif
60+
61+
// mac/unix code heavily copied from QElapsedTimer
62+
63+
QT_BEGIN_NAMESPACE
64+
65+
////////////////////////////// Mac //////////////////////////////
66+
#if defined(Q_OS_MAC)
67+
68+
static mach_timebase_info_data_t info = {0,0};
69+
static qint64 absoluteToNSecs(qint64 cpuTime)
70+
{
71+
if (info.denom == 0)
72+
mach_timebase_info(&info);
73+
qint64 nsecs = cpuTime * info.numer / info.denom;
74+
return nsecs;
75+
}
76+
77+
void QPerformanceTimer::start()
78+
{
79+
t1 = mach_absolute_time();
80+
}
81+
82+
qint64 QPerformanceTimer::elapsed() const
83+
{
84+
qint64 cpu_time = mach_absolute_time();
85+
return absoluteToNSecs(cpu_time - t1);
86+
}
87+
88+
// return number of nsecs elapsed from timer start time till absoluteMonotonicTimeNs
89+
// elapsedToAbsoluteTime(0) returns negative value of absolute time (ns) when the timer was started
90+
qint64 QPerformanceTimer::elapsedToAbsoluteTime(qint64 absoluteMonotonicTimeNs) const
91+
{
92+
qint64 absolute_t1_ns = absoluteToNSecs(t1);
93+
return absoluteMonotonicTimeNs - absolute_t1_ns;
94+
}
95+
96+
////////////////////////////// Symbian //////////////////////////////
97+
#elif defined(Q_OS_SYMBIAN)
98+
99+
static qint64 getTimeFromTick(quint64 elapsed)
100+
{
101+
static TInt freq = 0;
102+
if (!freq)
103+
HAL::Get(HALData::EFastCounterFrequency, freq);
104+
105+
return (elapsed * 1000000000) / freq;
106+
}
107+
108+
void QPerformanceTimer::start()
109+
{
110+
t1 = User::FastCounter();
111+
}
112+
113+
qint64 QPerformanceTimer::elapsed() const
114+
{
115+
return getTimeFromTick(User::FastCounter() - t1);
116+
}
117+
118+
119+
qint64 QPerformanceTimer::elapsedToAbsoluteTime(qint64 absoluteMonotonicTimeNs) const
120+
{
121+
qint64 absolute_t1_ns = getTimeFromTick(t1);
122+
return absoluteMonotonicTimeNs - absolute_t1_ns;
123+
}
124+
125+
////////////////////////////// Unix //////////////////////////////
126+
#elif defined(Q_OS_UNIX)
127+
128+
#if defined(QT_NO_CLOCK_MONOTONIC) || defined(QT_BOOTSTRAPPED)
129+
// turn off the monotonic clock
130+
# ifdef _POSIX_MONOTONIC_CLOCK
131+
# undef _POSIX_MONOTONIC_CLOCK
132+
# endif
133+
# define _POSIX_MONOTONIC_CLOCK -1
134+
#endif
135+
136+
#if (_POSIX_MONOTONIC_CLOCK-0 != 0)
137+
static const bool monotonicClockChecked = true;
138+
static const bool monotonicClockAvailable = _POSIX_MONOTONIC_CLOCK > 0;
139+
#else
140+
static int monotonicClockChecked = false;
141+
static int monotonicClockAvailable = false;
142+
#endif
143+
144+
#ifdef Q_CC_GNU
145+
# define is_likely(x) __builtin_expect((x), 1)
146+
#else
147+
# define is_likely(x) (x)
148+
#endif
149+
#define load_acquire(x) ((volatile const int&)(x))
150+
#define store_release(x,v) ((volatile int&)(x) = (v))
151+
152+
static void unixCheckClockType()
153+
{
154+
#if (_POSIX_MONOTONIC_CLOCK-0 == 0)
155+
if (is_likely(load_acquire(monotonicClockChecked)))
156+
return;
157+
158+
# if defined(_SC_MONOTONIC_CLOCK)
159+
// detect if the system support monotonic timers
160+
long x = sysconf(_SC_MONOTONIC_CLOCK);
161+
store_release(monotonicClockAvailable, x >= 200112L);
162+
# endif
163+
164+
store_release(monotonicClockChecked, true);
165+
#endif
166+
}
167+
168+
static inline void do_gettime(qint64 *sec, qint64 *frac)
169+
{
170+
#if (_POSIX_MONOTONIC_CLOCK-0 >= 0)
171+
unixCheckClockType();
172+
if (is_likely(monotonicClockAvailable)) {
173+
timespec ts;
174+
clock_gettime(CLOCK_MONOTONIC, &ts);
175+
*sec = ts.tv_sec;
176+
*frac = ts.tv_nsec;
177+
return;
178+
}
179+
#endif
180+
*sec = 0;
181+
*frac = 0;
182+
}
183+
184+
void QPerformanceTimer::start()
185+
{
186+
do_gettime(&t1, &t2);
187+
}
188+
189+
qint64 QPerformanceTimer::elapsed() const
190+
{
191+
qint64 sec, frac;
192+
do_gettime(&sec, &frac);
193+
sec = sec - t1;
194+
frac = frac - t2;
195+
196+
return sec * Q_INT64_C(1000000000) + frac;
197+
}
198+
199+
qint64 QPerformanceTimer::elapsedToAbsoluteTime(qint64 absoluteMonotonicTimeNs) const
200+
{
201+
qint64 sec = absoluteMonotonicTimeNs / Q_INT64_C(1000000000);
202+
qint64 frac = absoluteMonotonicTimeNs % Q_INT64_C(1000000000);
203+
sec = sec - t1;
204+
frac = frac - t2;
205+
206+
return sec * Q_INT64_C(1000000000) + frac;
207+
}
208+
209+
////////////////////////////// Windows //////////////////////////////
210+
#elif defined(Q_OS_WIN)
211+
212+
static qint64 getTimeFromTick(quint64 elapsed)
213+
{
214+
static LARGE_INTEGER freq;
215+
if (!freq.QuadPart)
216+
QueryPerformanceFrequency(&freq);
217+
return 1000000000 * elapsed / freq.QuadPart;
218+
}
219+
220+
void QPerformanceTimer::start()
221+
{
222+
LARGE_INTEGER li;
223+
QueryPerformanceCounter(&li);
224+
t1 = li.QuadPart;
225+
}
226+
227+
qint64 QPerformanceTimer::elapsed() const
228+
{
229+
LARGE_INTEGER li;
230+
QueryPerformanceCounter(&li);
231+
return getTimeFromTick(li.QuadPart - t1);
232+
}
233+
234+
qint64 QPerformanceTimer::elapsedToAbsoluteTime(qint64 absoluteMonotonicTimeNs) const
235+
{
236+
qint64 absolute_t1_ns = getTimeFromTick(t1);
237+
return absoluteMonotonicTimeNs - absolute_t1_ns;
238+
}
239+
240+
////////////////////////////// Default //////////////////////////////
241+
#else
242+
243+
// default implementation (no hi-perf timer) does nothing
244+
void QPerformanceTimer::start()
245+
{
246+
}
247+
248+
qint64 QPerformanceTimer::elapsed() const
249+
{
250+
return 0;
251+
}
252+
253+
qint64 QPerformanceTimer::elapsedToAbsoluteTime(qint64 absoluteMonotonicTimeNs) const
254+
{
255+
Q_UNUSED(absoluteMonotonicTimeNs);
256+
return 0;
257+
}
258+
259+
#endif
260+
261+
QT_END_NAMESPACE
262+
263+

0 commit comments

Comments
 (0)