os/persistentdata/traceservices/tracefw/common_utils/lightlogger/inc/te_lightlogger.h
Update contrib.
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #ifndef TE_LIGHTLOGGER_H_
17 #define TE_LIGHTLOGGER_H_
20 //test version of LightLogger
25 #include <hal.h> //if you are going to use __TEST_HIRES_RESOLUTION or __TEST_GET_Resolution
26 //use "hal.lib" in your project
29 //<LightLogger output file>
31 _LIT(KTeLogFile,"c:\\test_light_log.txt");
33 _LIT(KTeLogFile,"e:\\test_light_log.txt");
35 //</LightLogger output file>
39 _LIT8(KTeLLNewLine, "\n");
45 * Record id decribes type of LightLogger record and can be used by external tools to manage logs views
46 * or automate timestamp calculations.
48 const int gLL_TestMachineResolutionId = 0;
49 const int gLL_TestTimestampHiResId = 1;
50 const int gLL_TestTimestampLoResId = 2;
54 #if defined __TEST_LIGHTLOGGER_ENABLED
55 //This code must be called before other macros. It just create fresh log file.
57 if you want to reset file use: __TEST_CREATE_LOG(true), otherwise __TEST_CREATE_LOG(false)
59 #define __TEST_CREATE_LOG(replace) {TBool r(replace);RFs fs;RFile f;fs.Connect();\
60 if(r){f.Replace(fs, KTeLogFile, EFileWrite);}else{\
61 if(f.Open(fs, KTeLogFile, EFileWrite)==KErrNotFound){\
62 f.Replace(fs, KTeLogFile, EFileWrite);}\
63 }f.Close(); fs.Close();}
65 //Log text object to file
66 //example: __TEST_LOG("ty text")
67 #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();}
69 //Log number object to file.
70 //exaple: TInt i=4; __TEST_LOG(i);
71 #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();}
77 * b.Append(_L("some text"));
80 #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();}
82 //Log timestamp (low resolution) with additional text object to file .
83 //Time stamp format: hour:minute:second:microsecond - user text comment
84 #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); \
85 TDateTime dt = time.DateTime();\
86 b.AppendFormat(_L8("<[%d]> <[%d:%d:%d:%d]> %S"), gLL_TestTimestampLoResId, dt.Hour(), dt.Minute(), dt.Second(), dt.MicroSecond(), &_L8(x)); b.Append(KTeLLNewLine);\
88 f.Close();} fs.Close();\
91 //Log tick count to file.
92 #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); \
93 b.AppendFormat(KTick, User::TickCount()); b.Append(KTeLLNewLine); f.Write(b); f.Close();} fs.Close();\
96 //Log high resolution time stamp to file with additional user comment.
98 This is the current value of the machine's high resolution timer.
99 If a high resolution timer is not available, it uses the millisecond timer instead.
101 #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); \
102 b.AppendFormat(_L8("<[%d]> <[%u]> %S"), gLL_TestTimestampHiResId, __TEST_GET_HiResTimestamp(), &_L8(x)); b.Append(KTeLLNewLine);\
104 f.Close();} fs.Close();\
107 //Fast counter resolution
109 #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); \
110 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();\
113 /**This function returns resolution of fast counter
116 inline TUint32 __TEST_GET_Resolution()
119 HAL::Get(HALData::EFastCounterFrequency, freq);
123 /**This function returns hi resolution counter (timestamp)
126 inline TUint32 __TEST_GET_HiResTimestamp() {return User::FastCounter();}
129 /**Method marker class
132 class TTestMethodMarker
135 TTestMethodMarker(const TDesC8& aMethod)
137 __TEST_LOGBUF(aMethod)
146 /**This macro is logging entry and exit points from method specified as parameter.
148 #define __TEST_MARK_METHOD(x) TBuf8<128> b; b.AppendFormat(_L8("%S\n{"), &_L8(x)); TTestMethodMarker m(b);
153 #define __TEST_CREATE_LOG(replace)
154 #define __TEST_LOG(x)
155 #define __TEST_LOGNUM(x)
156 #define __TEST_LOGBUF(x)
157 #define __TEST_LOGTIMESTAMP(x)
158 #define __TEST_LOGTICKCOUNT
159 #define __TEST_LOGTIMESTAMP_HIRES(x)
160 #define __TEST_HIRES_RESOLUTION
161 inline TUint32 __TEST_GET_Resolution(){return 0;}
162 inline TUint32 __TEST_GET_HiResTimestamp(){return 0;}
163 #define __TEST_MARK_METHOD(x)
165 #endif //__TEST_LIGHLOGGER_ENABLED
166 #endif /*TE_LIGHTLOGGER_H_*/
171 * Special data format for certain macros (__TEST_HIRES_RESOLUTION; __TEST_LOGTIMESTAMP; __TEST_LOGTIMESTAMP_HIRES):
172 * "<[record_id]> <[value]> description>"
174 * record_id - is an integer value
175 * value - is an integer value
176 * description - is a string value