| Home · All Classes · Grouped Classes · Annotated · Functions |
The QPerformanceLog class implements a performance logging mechanism available to all Qtopia applications. More...
#include <QPerformanceLog>
The QPerformanceLog class implements a performance logging mechanism available to all Qtopia applications.
It provides a similar behaviour to qDebug() and qLog(), but every message automatically contains two timestamps: milliseconds since the current application has started, and milliseconds since the Qtopia Core window server has started. Messages are output via qLog(Performance), respecting the qLog() settings.
If QtopiaTest is enabled, messages will also be sent to a connected system test if qLog(Performance) is enabled or the QTOPIA_PERFTEST environment variable is set to "1".
Any string data can be output in a performance log. To make log parsing easier, some predefined values are provided for events which are commonly of interest for performance testing. These are represented by the QPerformanceLog::Event flags.
The below example shows how this class can be used to measure the time for a specific task from within a system test.
Example code residing in a Qtopia application named "Dog Walker":
QPerformanceLog() << QPerformanceLog::Begin << "walk to park"; // Outputs 'Dog Walker : <ms_since_appstart> : <ms_since_qpestart> : begin walk to park' while ( !at( Locations::Park ) ) { walk( directionOf(Locations::Park) ); } QPerformanceLog() << QPerformanceLog::End << "walk to park"; // Outputs 'Dog Walker : <ms_since_appstart> : <ms_since_qpestart> : end walk to park'
Example code in a Qtopia system test:
QVERIFY( startWindowedApp("Dog Walker") );
// Add code here to simulate the actions necessary to execute
// the code in the previous example...
waitPerformance();
// Verify that we actually got "walk to park" logs
QVERIFY( -1 != getPerformanceInterval("walk to park") );
// It MUST take less than 2 minutes to walk to the park,
// otherwise fail the test
QVERIFY( getPerformanceInterval("walk to park") < 2*60*1000 );
See also QSystemTest.
This enum provides a simple way of logging common occurrences such as the beginning and ending of a particular task. Each QPerformanceLog instance has an associated event value which is constructed by combining values from the following list using the bitwise OR operator:
| Constant | Value | Description |
|---|---|---|
| QPerformanceLog::NoEvent | 0x00 | Log message is not related to any event described by QPerformanceLog::EventType. |
| QPerformanceLog::Begin | 0x01 | Log message signifies the beginning of a specific event. |
| QPerformanceLog::End | 0x02 | Log message signifies the end of a specific event. |
| QPerformanceLog::LibraryLoading | 0x04 | Log message is related to the loading of shared libraries. This value is used internally by Qtopia. |
| QPerformanceLog::EventLoop | 0x08 | Log message is related to the application's global event loop. This value is used internally by Qtopia. |
| QPerformanceLog::MainWindow | 0x10 | Log message is related to the construction of the application's main window. This value is used internally by Qtopia. |
By streaming these enum values into a QPerformanceLog(), processing of performance data from within a system test is made easier. In particular, using Begin and End, along with a unique identifying string for a particular event in your program, allows the amount of time taken for a particular event to be easily determined.
The Event type is a typedef for QFlags<EventType>. It stores an OR combination of EventType values.
Construct a performance logger for application applicationName. If applicationName is empty, the name of the current application is used.
Destroy the performance log object and output the performance data.
Returns true if QPerformanceLog is enabled. QPerformanceLog is enabled if either qLog(Performance) is enabled or the QTOPIA_PERFTEST environment variable is set to "1".
Returns a string representation of event.
Append string to the log message.
This is an overloaded member function, provided for convenience.
Append event to the log message. If this log message already has an event, the new event will be equal to the old event bitwise OR'd with event.
| Copyright © 2007 Trolltech | Trademarks | Qtopia 4.3.0 |