sl@0: // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #ifndef TE_LIGHTLOGGER_H_ sl@0: #define TE_LIGHTLOGGER_H_ sl@0: sl@0: //************ sl@0: //test version of LightLogger sl@0: //ver. 0.2 sl@0: //************ sl@0: sl@0: #include sl@0: #include //if you are going to use __TEST_HIRES_RESOLUTION or __TEST_GET_Resolution sl@0: //use "hal.lib" in your project sl@0: sl@0: sl@0: // sl@0: #ifdef __WINSCW__ sl@0: _LIT(KTeLogFile,"c:\\test_light_log.txt"); sl@0: #else sl@0: _LIT(KTeLogFile,"e:\\test_light_log.txt"); sl@0: #endif sl@0: // sl@0: sl@0: sl@0: // sl@0: _LIT8(KTeLLNewLine, "\n"); sl@0: // sl@0: sl@0: sl@0: // sl@0: /* sl@0: * Record id decribes type of LightLogger record and can be used by external tools to manage logs views sl@0: * or automate timestamp calculations. sl@0: * */ sl@0: const int gLL_TestMachineResolutionId = 0; sl@0: const int gLL_TestTimestampHiResId = 1; sl@0: const int gLL_TestTimestampLoResId = 2; sl@0: // sl@0: sl@0: sl@0: #if defined __TEST_LIGHTLOGGER_ENABLED sl@0: //This code must be called before other macros. It just create fresh log file. sl@0: /* sl@0: if you want to reset file use: __TEST_CREATE_LOG(true), otherwise __TEST_CREATE_LOG(false) sl@0: */ sl@0: #define __TEST_CREATE_LOG(replace) {TBool r(replace);RFs fs;RFile f;fs.Connect();\ sl@0: if(r){f.Replace(fs, KTeLogFile, EFileWrite);}else{\ sl@0: if(f.Open(fs, KTeLogFile, EFileWrite)==KErrNotFound){\ sl@0: f.Replace(fs, KTeLogFile, EFileWrite);}\ sl@0: }f.Close(); fs.Close();} sl@0: sl@0: //Log text object to file sl@0: //example: __TEST_LOG("ty text") sl@0: #define __TEST_LOG(x) {TBuf8<512> b;RFs fs;RFile f;b.Zero(); b.Copy(_L(x)); b.Append(KTeLLNewLine); fs.Connect(); if(f.Open(fs, KTeLogFile, EFileWrite)==KErrNone){TInt s; f.Size(s); f.Seek(ESeekStart,s); f.Write(b); f.Close();} fs.Close();} sl@0: sl@0: //Log number object to file. sl@0: //exaple: TInt i=4; __TEST_LOG(i); sl@0: #define __TEST_LOGNUM(x) {TBuf8<256> b;RFs fs;RFile f;b.Zero(); b.Num(x);b.Append(KTeLLNewLine); fs.Connect(); if(f.Open(fs, KTeLogFile, EFileWrite)==KErrNone){TInt s; f.Size(s); f.Seek(ESeekStart,s); f.Write(b); f.Close();} fs.Close();} sl@0: sl@0: //Log buffer to file. sl@0: //Example: sl@0: /* sl@0: * TBuf<128> b; sl@0: * b.Append(_L("some text")); sl@0: * __TEST_LOGBUF(b) sl@0: * */ sl@0: #define __TEST_LOGBUF(x) {TBuf8<512> b;RFs fs;RFile f;b.Copy(x);b.Append(KTeLLNewLine); fs.Connect(); if(f.Open(fs, KTeLogFile, EFileWrite)==KErrNone){ TInt s; f.Size(s); f.Seek(ESeekStart,s); f.Write(b); f.Close();} fs.Close();} sl@0: sl@0: //Log timestamp (low resolution) with additional text object to file . sl@0: //Time stamp format: hour:minute:second:microsecond - user text comment sl@0: #define __TEST_LOGTIMESTAMP(x) {TTime time; time.HomeTime(); TBuf8<256> b; RFs fs; RFile f; fs.Connect(); if(f.Open(fs, KTeLogFile, EFileWrite)==KErrNone){ TInt s; f.Size(s); f.Seek(ESeekStart,s); \ sl@0: TDateTime dt = time.DateTime();\ sl@0: b.AppendFormat(_L8("<[%d]> <[%d:%d:%d:%d]> %S"), gLL_TestTimestampLoResId, dt.Hour(), dt.Minute(), dt.Second(), dt.MicroSecond(), &_L8(x)); b.Append(KTeLLNewLine);\ sl@0: f.Write(b);\ sl@0: f.Close();} fs.Close();\ sl@0: } sl@0: sl@0: //Log tick count to file. sl@0: #define __TEST_LOGTICKCOUNT {_LIT8(KTick,"TickCount: %u"); TBuf8<256> b; RFs fs; RFile f; fs.Connect(); if(f.Open(fs, KTeLogFile, EFileWrite)==KErrNone){ TInt s; f.Size(s); f.Seek(ESeekStart,s); \ sl@0: b.AppendFormat(KTick, User::TickCount()); b.Append(KTeLLNewLine); f.Write(b); f.Close();} fs.Close();\ sl@0: } sl@0: sl@0: //Log high resolution time stamp to file with additional user comment. sl@0: /* sl@0: This is the current value of the machine's high resolution timer. sl@0: If a high resolution timer is not available, it uses the millisecond timer instead. sl@0: */ sl@0: #define __TEST_LOGTIMESTAMP_HIRES(x){TBuf8<256> b; RFs fs; RFile f; fs.Connect(); if(f.Open(fs, KTeLogFile, EFileWrite)==KErrNone){ TInt s; f.Size(s); f.Seek(ESeekStart,s); \ sl@0: b.AppendFormat(_L8("<[%d]> <[%u]> %S"), gLL_TestTimestampHiResId, __TEST_GET_HiResTimestamp(), &_L8(x)); b.Append(KTeLLNewLine);\ sl@0: f.Write(b);\ sl@0: f.Close();} fs.Close();\ sl@0: } sl@0: sl@0: //Fast counter resolution sl@0: //tick per second sl@0: #define __TEST_HIRES_RESOLUTION { TInt _tmp_=gLL_TestMachineResolutionId; RFs fs; RFile f; fs.Connect(); if(f.Open(fs, KTeLogFile, EFileWrite)==KErrNone){TInt s;f.Size(s);f.Seek(ESeekStart,s); \ sl@0: TBuf8<256> b;b.AppendFormat(_L8("<[%d]> <[%d]> Fast timer resolution"), _tmp_, __TEST_GET_Resolution());b.Append(KTeLLNewLine);f.Write(b); f.Close();} fs.Close();\ sl@0: } sl@0: sl@0: /**This function returns resolution of fast counter sl@0: * tick per second sl@0: */ sl@0: inline TUint32 __TEST_GET_Resolution() sl@0: { sl@0: TInt freq = 0; sl@0: HAL::Get(HALData::EFastCounterFrequency, freq); sl@0: return freq; sl@0: } sl@0: sl@0: /**This function returns hi resolution counter (timestamp) sl@0: * sl@0: */ sl@0: inline TUint32 __TEST_GET_HiResTimestamp() {return User::FastCounter();} sl@0: sl@0: sl@0: /**Method marker class sl@0: * sl@0: */ sl@0: class TTestMethodMarker sl@0: { sl@0: public: sl@0: TTestMethodMarker(const TDesC8& aMethod) sl@0: { sl@0: __TEST_LOGBUF(aMethod) sl@0: } sl@0: ~TTestMethodMarker() sl@0: { sl@0: __TEST_LOG("}") sl@0: } sl@0: }; sl@0: sl@0: sl@0: /**This macro is logging entry and exit points from method specified as parameter. sl@0: */ sl@0: #define __TEST_MARK_METHOD(x) TBuf8<128> b; b.AppendFormat(_L8("%S\n{"), &_L8(x)); TTestMethodMarker m(b); sl@0: sl@0: #else sl@0: sl@0: //empty definitions sl@0: #define __TEST_CREATE_LOG(replace) sl@0: #define __TEST_LOG(x) sl@0: #define __TEST_LOGNUM(x) sl@0: #define __TEST_LOGBUF(x) sl@0: #define __TEST_LOGTIMESTAMP(x) sl@0: #define __TEST_LOGTICKCOUNT sl@0: #define __TEST_LOGTIMESTAMP_HIRES(x) sl@0: #define __TEST_HIRES_RESOLUTION sl@0: inline TUint32 __TEST_GET_Resolution(){return 0;} sl@0: inline TUint32 __TEST_GET_HiResTimestamp(){return 0;} sl@0: #define __TEST_MARK_METHOD(x) sl@0: sl@0: #endif //__TEST_LIGHLOGGER_ENABLED sl@0: #endif /*TE_LIGHTLOGGER_H_*/ sl@0: sl@0: sl@0: /*Documentation: sl@0: * sl@0: * Special data format for certain macros (__TEST_HIRES_RESOLUTION; __TEST_LOGTIMESTAMP; __TEST_LOGTIMESTAMP_HIRES): sl@0: * "<[record_id]> <[value]> description>" sl@0: * where: sl@0: * record_id - is an integer value sl@0: * value - is an integer value sl@0: * description - is a string value sl@0: */