os/persistentdata/traceservices/tracefw/common_utils/lightlogger/inc/te_lightlogger.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #ifndef TE_LIGHTLOGGER_H_
    17 #define TE_LIGHTLOGGER_H_
    18 
    19 //************
    20 //test version of LightLogger
    21 //ver. 0.2
    22 //************
    23 
    24 #include <f32file.h>
    25 #include <hal.h> //if you are going to use __TEST_HIRES_RESOLUTION or __TEST_GET_Resolution 
    26 				 //use "hal.lib" in your project
    27 
    28 
    29 //<LightLogger output file>
    30 #ifdef __WINSCW__
    31 _LIT(KTeLogFile,"c:\\test_light_log.txt");
    32 #else
    33 _LIT(KTeLogFile,"e:\\test_light_log.txt");
    34 #endif
    35 //</LightLogger output file>
    36 
    37 
    38 //<const>
    39 _LIT8(KTeLLNewLine, "\n");
    40 //</const>
    41 
    42 
    43 //<Record Ids>
    44 /*
    45  * Record id decribes type of LightLogger record and can be used by external tools to manage logs views
    46  * or automate timestamp calculations.
    47  * */
    48 const int gLL_TestMachineResolutionId = 0;
    49 const int gLL_TestTimestampHiResId = 1;
    50 const int gLL_TestTimestampLoResId = 2;
    51 //</Record Ids>
    52 
    53 
    54 #if defined __TEST_LIGHTLOGGER_ENABLED
    55 //This code must be called before other macros. It just create fresh log file. 
    56 /*
    57 if you want to reset file use: __TEST_CREATE_LOG(true), otherwise __TEST_CREATE_LOG(false)
    58 */
    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();}
    64 
    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();}
    68 
    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();}
    72 
    73 //Log buffer to file.
    74 //Example:
    75 /*
    76  * TBuf<128> b;
    77  * b.Append(_L("some text"));
    78  * __TEST_LOGBUF(b)
    79  * */
    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();}
    81 
    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);\
    87 							f.Write(b);\
    88 							f.Close();} fs.Close();\
    89 					   }
    90 					   
    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();\
    94 					   }
    95 					   
    96 //Log high resolution time stamp to file with additional user comment.
    97 /*
    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.
   100 */
   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);\
   103 								f.Write(b);\
   104 								f.Close();} fs.Close();\
   105 					 	  }
   106 					 	  
   107 //Fast counter resolution
   108 //tick per second
   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();\
   111 					 	  }
   112 					 	  
   113 /**This function returns resolution of fast counter
   114  * tick per second
   115 */				 	  
   116 inline TUint32 __TEST_GET_Resolution()
   117 	{
   118 	TInt freq = 0; 
   119 	HAL::Get(HALData::EFastCounterFrequency, freq);
   120 	return freq;
   121 	}
   122 	
   123 /**This function returns hi resolution counter (timestamp)
   124  * 
   125 */
   126 inline TUint32 __TEST_GET_HiResTimestamp() {return User::FastCounter();}
   127 	
   128 	
   129 /**Method marker class
   130  * 
   131 */
   132 class TTestMethodMarker
   133 	{
   134 	public:
   135 		TTestMethodMarker(const TDesC8& aMethod)
   136 			{
   137 			__TEST_LOGBUF(aMethod)
   138 			}	
   139 		~TTestMethodMarker()
   140 			{
   141 			__TEST_LOG("}")
   142 			}
   143 	};
   144 	
   145 	
   146 /**This macro is logging entry and exit points from method specified as parameter.
   147 */
   148 #define __TEST_MARK_METHOD(x) TBuf8<128> b; b.AppendFormat(_L8("%S\n{"), &_L8(x)); TTestMethodMarker m(b);
   149 
   150 #else
   151 	
   152 //empty definitions
   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)
   164 
   165 #endif //__TEST_LIGHLOGGER_ENABLED
   166 #endif /*TE_LIGHTLOGGER_H_*/
   167 
   168 
   169 /*Documentation:
   170  * 
   171  * Special data format for certain macros (__TEST_HIRES_RESOLUTION; __TEST_LOGTIMESTAMP; __TEST_LOGTIMESTAMP_HIRES):
   172  * "<[record_id]> <[value]> description>"
   173  * where:
   174  * record_id - is an integer value
   175  * value - is an integer value
   176  * description - is a string value
   177 */