ginebra/gtimer.cpp
branchGCC_SURGE
changeset 8 2e16851ffecd
parent 2 bf4420e9fa4d
parent 6 1c3b8676e58c
equal deleted inserted replaced
2:bf4420e9fa4d 8:2e16851ffecd
     1 /*
       
     2 * Copyright (c) 2010 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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "gtimer.h"
       
    20 #include <QTime>
       
    21 #include <QDebug>
       
    22 #include <QFile>
       
    23 #include <QTextStream>
       
    24 #include <assert.h>
       
    25 
       
    26 GTimer::GTimer()
       
    27   : m_time(0)
       
    28 {
       
    29 }
       
    30 
       
    31 
       
    32 void GTimer::start(QString op){
       
    33   if(!m_time){
       
    34     m_time = new QTime();
       
    35   }
       
    36   m_op = op;
       
    37   m_start = QTime::currentTime().toString("hh:mm:ss:zzz");
       
    38   m_time->start();
       
    39 }
       
    40 
       
    41 
       
    42 void GTimer::stop(){
       
    43   int elapsed = m_time->elapsed();
       
    44   //qDebug() << m_op << ": " << elapsed << " ms";
       
    45   m_log += m_op + ": " + m_start + QString(": %1ms\n").arg(elapsed);
       
    46 }
       
    47 
       
    48 void GTimer::save(){
       
    49   /*  FILE* fp = fopen("c:\\data\\ginebra_log.txt", "a");
       
    50     if (fp) {
       
    51       char* str = m_log.toLatin1().data();
       
    52       fwrite(str, strlen(str), 1, fp);
       
    53       fclose(fp);
       
    54 
       
    55       }*/
       
    56 
       
    57   QFile l("c:\\data\\ginebra_log.txt");
       
    58   if(l.open(QFile::ReadWrite | QFile::Append )){
       
    59     QTextStream out(&l);
       
    60     out << m_log;
       
    61     l.close();
       
    62   }else{
       
    63     assert(0);
       
    64   }
       
    65 
       
    66 }
       
    67 
       
    68 
       
    69 QString GTimer::log(){
       
    70   return m_log;
       
    71 }