Home · All Classes · Grouped Classes · Annotated · Functions

QPerformanceLog Class Reference

The QPerformanceLog class implements a performance logging mechanism available to all Qtopia applications. More...

    #include <QPerformanceLog>

Public Types

Public Functions

Static Public Members


Detailed Description

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.


Member Type Documentation

enum QPerformanceLog::EventType
flags QPerformanceLog::Event

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:

ConstantValueDescription
QPerformanceLog::NoEvent0x00Log message is not related to any event described by QPerformanceLog::EventType.
QPerformanceLog::Begin0x01Log message signifies the beginning of a specific event.
QPerformanceLog::End0x02Log message signifies the end of a specific event.
QPerformanceLog::LibraryLoading0x04Log message is related to the loading of shared libraries. This value is used internally by Qtopia.
QPerformanceLog::EventLoop0x08Log message is related to the application's global event loop. This value is used internally by Qtopia.
QPerformanceLog::MainWindow0x10Log 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.


Member Function Documentation

QPerformanceLog::QPerformanceLog ( QString const & applicationName = QString() )

Construct a performance logger for application applicationName. If applicationName is empty, the name of the current application is used.

QPerformanceLog::~QPerformanceLog ()

Destroy the performance log object and output the performance data.

bool QPerformanceLog::enabled ()   [static]

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".

QString QPerformanceLog::stringFromEvent ( Event const & event )   [static]

Returns a string representation of event.

QPerformanceLog & QPerformanceLog::operator<< ( QString const & string )

Append string to the log message.

QPerformanceLog & QPerformanceLog::operator<< ( Event const & event )

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