os/persistentdata/traceservices/tracefw/common_utils/lightlogger/inc/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 
    17 
    18 /**
    19  @file LightLogger.h
    20  @internalTechnology
    21 */
    22 
    23 #ifndef LIGHTLOGGER_H_
    24 #define LIGHTLOGGER_H_
    25 
    26 //************
    27 //LightLogger
    28 //ver. 0.2
    29 //************
    30 
    31 #include <f32file.h>
    32 #include <hal.h> //if you are going to use __HIRES_RESOLUTION or __GET_Resolution 
    33 				 //use "hal.lib" in your project
    34 
    35 
    36 //<LightLogger output file>
    37 #ifdef __WINSCW__
    38 _LIT(KLogFile,"c:\\light_log.txt");
    39 #else
    40 _LIT(KLogFile,"e:\\light_log.txt");
    41 #endif
    42 //</LightLogger output file>
    43 
    44 
    45 //<const>
    46 _LIT8(KLLNewLine, "\n");
    47 //</const>
    48 
    49 
    50 //<Record Ids>
    51 /*
    52  * Record id decribes type of LightLogger record and can be used by external tools to manage logs views
    53  * or automate timestamp calculations.
    54  * */
    55 const int gLL_MachineResolutionId = 0;
    56 const int gLL_TimestampHiResId = 1;
    57 const int gLL_TimestampLoResId = 2;
    58 //</Record Ids>
    59 
    60 
    61 #if defined __LIGHTLOGGER_ENABLED
    62 //This code must be called before other macros. It just create fresh log file. 
    63 /*
    64 if you want to reset file use: __CREATE_LOG(true), otherwise __CREATE_LOG(false)
    65 */
    66 #define __CREATE_LOG(replace) {TBool r(replace);RFs fs;RFile f;fs.Connect();\
    67 								if(r){f.Replace(fs, KLogFile, EFileWrite);}else{\
    68 									if(f.Open(fs, KLogFile, EFileWrite)==KErrNotFound){\
    69 										f.Replace(fs, KLogFile, EFileWrite);}\
    70 								}f.Close(); fs.Close();}
    71 
    72 //Log text object to file
    73 //example: __LOG("ty text")
    74 #define __LOG(x) {TBuf8<512> b;RFs fs;RFile f;b.Zero(); b.Copy(_L(x)); b.Append(KLLNewLine); fs.Connect(); if(f.Open(fs, KLogFile, EFileWrite)==KErrNone){TInt s; f.Size(s); f.Seek(ESeekStart,s); f.Write(b); f.Close();} fs.Close();}
    75 
    76 //Log number object to file.
    77 //exaple: TInt i=4; __LOG(i);
    78 #define __LOGNUM(x) {TBuf8<256> b;RFs fs;RFile f;b.Zero(); b.Num(x);b.Append(KLLNewLine); fs.Connect(); if(f.Open(fs, KLogFile, EFileWrite)==KErrNone){TInt s; f.Size(s); f.Seek(ESeekStart,s); f.Write(b); f.Close();} fs.Close();}
    79 
    80 //Log buffer to file.
    81 //Example:
    82 /*
    83  * TBuf<128> b;
    84  * b.Append(_L("some text"));
    85  * __LOGBUF(b)
    86  * */
    87 #define __LOGBUF(x) {TBuf8<512> b;RFs fs;RFile f;b.Copy(x);b.Append(KLLNewLine); fs.Connect(); if(f.Open(fs, KLogFile, EFileWrite)==KErrNone){ TInt s; f.Size(s); f.Seek(ESeekStart,s); f.Write(b); f.Close();} fs.Close();}
    88 
    89 //Log timestamp (low resolution) with additional text object to file .
    90 //Time stamp format: hour:minute:second:microsecond - user text comment
    91 #define __LOGTIMESTAMP(x) {TTime time; time.HomeTime(); TBuf8<256> b; RFs fs; RFile f; fs.Connect(); if(f.Open(fs, KLogFile, EFileWrite)==KErrNone){ TInt s; f.Size(s); f.Seek(ESeekStart,s); \
    92 							TDateTime dt = time.DateTime();\
    93 							b.AppendFormat(_L8("<[%d]> <[%d:%d:%d:%d]> %S"), gLL_TimestampLoResId, dt.Hour(), dt.Minute(), dt.Second(), dt.MicroSecond(), &_L8(x)); b.Append(KLLNewLine);\
    94 							f.Write(b);\
    95 							f.Close();} fs.Close();\
    96 					   }
    97 					   
    98 //Log tick count to file.
    99 #define __LOGTICKCOUNT {_LIT8(KTick,"TickCount: %u"); TBuf8<256> b; RFs fs; RFile f; fs.Connect(); if(f.Open(fs, KLogFile, EFileWrite)==KErrNone){ TInt s; f.Size(s); f.Seek(ESeekStart,s); \
   100 						b.AppendFormat(KTick, User::TickCount()); b.Append(KLLNewLine); f.Write(b); f.Close();} fs.Close();\
   101 					   }
   102 					   
   103 //Log high resolution time stamp to file with additional user comment.
   104 /*
   105 This is the current value of the machine's high resolution timer. 
   106 If a high resolution timer is not available, it uses the millisecond timer instead.
   107 */
   108 #define __LOGTIMESTAMP_HIRES(x){TBuf8<256> b; RFs fs; RFile f; fs.Connect(); if(f.Open(fs, KLogFile, EFileWrite)==KErrNone){ TInt s; f.Size(s); f.Seek(ESeekStart,s); \
   109 								b.AppendFormat(_L8("<[%d]> <[%u]> %S"), gLL_TimestampHiResId, __GET_HiResTimestamp(), &_L8(x)); b.Append(KLLNewLine);\
   110 								f.Write(b);\
   111 								f.Close();} fs.Close();\
   112 					 	  }
   113 					 	  
   114 //Fast counter resolution
   115 //tick per second
   116 #define __HIRES_RESOLUTION { TInt _tmp_=gLL_MachineResolutionId; RFs fs; RFile f; fs.Connect(); if(f.Open(fs, KLogFile, EFileWrite)==KErrNone){TInt s;f.Size(s);f.Seek(ESeekStart,s); \
   117 							 TBuf8<256> b;b.AppendFormat(_L8("<[%d]> <[%d]> Fast timer resolution"), _tmp_, __GET_Resolution());b.Append(KLLNewLine);f.Write(b); f.Close();} fs.Close();\
   118 					 	  }
   119 					 	  
   120 /**This function returns resolution of fast counter
   121  * tick per second
   122 */				 	  
   123 inline TUint32 __GET_Resolution()
   124 	{
   125 	TInt freq = 0; 
   126 	HAL::Get(HALData::EFastCounterFrequency, freq);
   127 	return freq;
   128 	}
   129 	
   130 /**This function returns hi resolution counter (timestamp)
   131  * 
   132 */
   133 inline TUint32 __GET_HiResTimestamp() {return User::FastCounter();}
   134 	
   135 	
   136 /**Method marker class
   137  * 
   138 */
   139 class TMethodMarker
   140 	{
   141 	public:
   142 		TMethodMarker(const TDesC8& aMethod)
   143 			{
   144 			__LOGBUF(aMethod)
   145 			}	
   146 		~TMethodMarker()
   147 			{
   148 			__LOG("}")
   149 			}
   150 	};
   151 	
   152 	
   153 /**This macro is logging entry and exit points from method specified as parameter.
   154 */
   155 #define __MARK_METHOD(x) TBuf8<128> b; b.AppendFormat(_L8("%S\n{"), &_L8(x)); TMethodMarker m(b);
   156 
   157 #else
   158 	
   159 //empty definitions
   160 #define __CREATE_LOG(replace)
   161 #define __LOG(x) 
   162 #define __LOGNUM(x)
   163 #define __LOGBUF(x)
   164 #define __LOGTIMESTAMP(x)
   165 #define __LOGTICKCOUNT   
   166 #define __LOGTIMESTAMP_HIRES(x)
   167 #define __HIRES_RESOLUTION
   168 inline TUint32 __GET_Resolution(){return 0;}
   169 inline TUint32 __GET_HiResTimestamp(){return 0;}
   170 #define __MARK_METHOD(x)
   171 
   172 #endif //__LIGHLOGGER_ENABLED
   173 #endif /*LIGHTLOGGER_H_*/
   174 
   175 
   176 /*Documentation:
   177  * 
   178  * Special data format for certain macros (__HIRES_RESOLUTION; __LOGTIMESTAMP; __LOGTIMESTAMP_HIRES):
   179  * "<[record_id]> <[value]> description>"
   180  * where:
   181  * record_id - is an integer value
   182  * value - is an integer value
   183  * description - is a string value
   184 */