loggers/loggerqt/src/glxperformancelog.cpp
changeset 23 74c9f037fd5d
child 24 99ad1390cd33
equal deleted inserted replaced
5:f7f0874bfe7d 23:74c9f037fd5d
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 #include <glxperformancelog.h>
       
    19 
       
    20 #define GLX_LOG_PRINT_ITERATION 20
       
    21 QFile GlxPerformanceLog::mLogFile;
       
    22 qint16 GlxPerformanceLog::mObjectCounter = 0;
       
    23 
       
    24 GlxPerformanceLog::GlxPerformanceLog(char *str) : mSpendTime(0), mTotalTime(0), mIteration(0), mInfoMsg (str)
       
    25 { 
       
    26     mTime.start();
       
    27     ++mObjectCounter;
       
    28     if( GlxPerformanceLog::mLogFile.isOpen() == FALSE) {
       
    29 	    GlxPerformanceLog::mLogFile.setFileName("glxperlog.txt");
       
    30 	    QDir::setCurrent("c:\\data\\");
       
    31 	    GlxPerformanceLog::mLogFile.open(QIODevice::Append);
       
    32 	    GlxPerformanceLog::mLogFile.setTextModeEnabled(TRUE);
       
    33     }
       
    34 }
       
    35 
       
    36 void GlxPerformanceLog::start()
       
    37 {
       
    38     mTime.restart();
       
    39 }
       
    40 
       
    41 void GlxPerformanceLog::stop()
       
    42 {
       
    43     mSpendTime = mTime.elapsed();
       
    44     mTotalTime += mSpendTime;
       
    45     ++mIteration;
       
    46     if ( (mIteration % GLX_LOG_PRINT_ITERATION )== 1) {
       
    47         appendPerformanceLog();
       
    48     }
       
    49 }
       
    50 
       
    51 void GlxPerformanceLog::end()
       
    52 {
       
    53     appendPerformanceLog();
       
    54     mSpendTime = mTotalTime = mIteration = 0;
       
    55 }
       
    56 
       
    57 void GlxPerformanceLog::done(char *msg )
       
    58 {
       
    59     mSpendTime = mTime.elapsed();
       
    60     mTotalTime += mSpendTime;
       
    61     ++mIteration;
       
    62     appendPerformanceLog(msg);
       
    63     mSpendTime = mTotalTime = mIteration = 0;
       
    64 }
       
    65 
       
    66 qreal GlxPerformanceLog::getAverageTime()
       
    67 {
       
    68     if( mIteration == 0) {
       
    69         return -1;
       
    70     }
       
    71     return ( (mTotalTime + 0.0) / mIteration );
       
    72 }
       
    73 
       
    74 quint32 GlxPerformanceLog::getTime()
       
    75 {
       
    76     return mSpendTime;
       
    77 }
       
    78 
       
    79 void GlxPerformanceLog::appendPerformanceLog(char *msg)
       
    80 {
       
    81     char logText[255] = {0};
       
    82     sprintf(logText, "%s : %s last time %u : average time : %f iteration %u \n", mInfoMsg, msg, mSpendTime, getAverageTime(), mIteration);
       
    83     GlxPerformanceLog::mLogFile.write(logText);
       
    84 }
       
    85 
       
    86 void GlxPerformanceLog::appendTimeStamp(char *msg)
       
    87 {
       
    88     char logText[255] = {0};
       
    89     QTime t = QTime::currentTime();
       
    90     sprintf(logText, "%s : Time Stamp %d:%d:%d:%d \n", msg, t.hour(), t.minute(), t.second(), t.msec());
       
    91     GlxPerformanceLog::mLogFile.write(logText);
       
    92 }
       
    93 
       
    94 GlxPerformanceLog::~GlxPerformanceLog()
       
    95 {
       
    96     --mObjectCounter;
       
    97     if ( mObjectCounter == 0) {
       
    98         GlxPerformanceLog::mLogFile.close();
       
    99     }
       
   100 }
       
   101 
       
   102 
       
   103