sl@0
|
1 |
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#ifndef TE_LIGHTLOGGER_H_
|
sl@0
|
17 |
#define TE_LIGHTLOGGER_H_
|
sl@0
|
18 |
|
sl@0
|
19 |
//************
|
sl@0
|
20 |
//test version of LightLogger
|
sl@0
|
21 |
//ver. 0.2
|
sl@0
|
22 |
//************
|
sl@0
|
23 |
|
sl@0
|
24 |
#include <f32file.h>
|
sl@0
|
25 |
#include <hal.h> //if you are going to use __TEST_HIRES_RESOLUTION or __TEST_GET_Resolution
|
sl@0
|
26 |
//use "hal.lib" in your project
|
sl@0
|
27 |
|
sl@0
|
28 |
|
sl@0
|
29 |
//<LightLogger output file>
|
sl@0
|
30 |
#ifdef __WINSCW__
|
sl@0
|
31 |
_LIT(KTeLogFile,"c:\\test_light_log.txt");
|
sl@0
|
32 |
#else
|
sl@0
|
33 |
_LIT(KTeLogFile,"e:\\test_light_log.txt");
|
sl@0
|
34 |
#endif
|
sl@0
|
35 |
//</LightLogger output file>
|
sl@0
|
36 |
|
sl@0
|
37 |
|
sl@0
|
38 |
//<const>
|
sl@0
|
39 |
_LIT8(KTeLLNewLine, "\n");
|
sl@0
|
40 |
//</const>
|
sl@0
|
41 |
|
sl@0
|
42 |
|
sl@0
|
43 |
//<Record Ids>
|
sl@0
|
44 |
/*
|
sl@0
|
45 |
* Record id decribes type of LightLogger record and can be used by external tools to manage logs views
|
sl@0
|
46 |
* or automate timestamp calculations.
|
sl@0
|
47 |
* */
|
sl@0
|
48 |
const int gLL_TestMachineResolutionId = 0;
|
sl@0
|
49 |
const int gLL_TestTimestampHiResId = 1;
|
sl@0
|
50 |
const int gLL_TestTimestampLoResId = 2;
|
sl@0
|
51 |
//</Record Ids>
|
sl@0
|
52 |
|
sl@0
|
53 |
|
sl@0
|
54 |
#if defined __TEST_LIGHTLOGGER_ENABLED
|
sl@0
|
55 |
//This code must be called before other macros. It just create fresh log file.
|
sl@0
|
56 |
/*
|
sl@0
|
57 |
if you want to reset file use: __TEST_CREATE_LOG(true), otherwise __TEST_CREATE_LOG(false)
|
sl@0
|
58 |
*/
|
sl@0
|
59 |
#define __TEST_CREATE_LOG(replace) {TBool r(replace);RFs fs;RFile f;fs.Connect();\
|
sl@0
|
60 |
if(r){f.Replace(fs, KTeLogFile, EFileWrite);}else{\
|
sl@0
|
61 |
if(f.Open(fs, KTeLogFile, EFileWrite)==KErrNotFound){\
|
sl@0
|
62 |
f.Replace(fs, KTeLogFile, EFileWrite);}\
|
sl@0
|
63 |
}f.Close(); fs.Close();}
|
sl@0
|
64 |
|
sl@0
|
65 |
//Log text object to file
|
sl@0
|
66 |
//example: __TEST_LOG("ty text")
|
sl@0
|
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();}
|
sl@0
|
68 |
|
sl@0
|
69 |
//Log number object to file.
|
sl@0
|
70 |
//exaple: TInt i=4; __TEST_LOG(i);
|
sl@0
|
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();}
|
sl@0
|
72 |
|
sl@0
|
73 |
//Log buffer to file.
|
sl@0
|
74 |
//Example:
|
sl@0
|
75 |
/*
|
sl@0
|
76 |
* TBuf<128> b;
|
sl@0
|
77 |
* b.Append(_L("some text"));
|
sl@0
|
78 |
* __TEST_LOGBUF(b)
|
sl@0
|
79 |
* */
|
sl@0
|
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();}
|
sl@0
|
81 |
|
sl@0
|
82 |
//Log timestamp (low resolution) with additional text object to file .
|
sl@0
|
83 |
//Time stamp format: hour:minute:second:microsecond - user text comment
|
sl@0
|
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); \
|
sl@0
|
85 |
TDateTime dt = time.DateTime();\
|
sl@0
|
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);\
|
sl@0
|
87 |
f.Write(b);\
|
sl@0
|
88 |
f.Close();} fs.Close();\
|
sl@0
|
89 |
}
|
sl@0
|
90 |
|
sl@0
|
91 |
//Log tick count to file.
|
sl@0
|
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); \
|
sl@0
|
93 |
b.AppendFormat(KTick, User::TickCount()); b.Append(KTeLLNewLine); f.Write(b); f.Close();} fs.Close();\
|
sl@0
|
94 |
}
|
sl@0
|
95 |
|
sl@0
|
96 |
//Log high resolution time stamp to file with additional user comment.
|
sl@0
|
97 |
/*
|
sl@0
|
98 |
This is the current value of the machine's high resolution timer.
|
sl@0
|
99 |
If a high resolution timer is not available, it uses the millisecond timer instead.
|
sl@0
|
100 |
*/
|
sl@0
|
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); \
|
sl@0
|
102 |
b.AppendFormat(_L8("<[%d]> <[%u]> %S"), gLL_TestTimestampHiResId, __TEST_GET_HiResTimestamp(), &_L8(x)); b.Append(KTeLLNewLine);\
|
sl@0
|
103 |
f.Write(b);\
|
sl@0
|
104 |
f.Close();} fs.Close();\
|
sl@0
|
105 |
}
|
sl@0
|
106 |
|
sl@0
|
107 |
//Fast counter resolution
|
sl@0
|
108 |
//tick per second
|
sl@0
|
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); \
|
sl@0
|
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();\
|
sl@0
|
111 |
}
|
sl@0
|
112 |
|
sl@0
|
113 |
/**This function returns resolution of fast counter
|
sl@0
|
114 |
* tick per second
|
sl@0
|
115 |
*/
|
sl@0
|
116 |
inline TUint32 __TEST_GET_Resolution()
|
sl@0
|
117 |
{
|
sl@0
|
118 |
TInt freq = 0;
|
sl@0
|
119 |
HAL::Get(HALData::EFastCounterFrequency, freq);
|
sl@0
|
120 |
return freq;
|
sl@0
|
121 |
}
|
sl@0
|
122 |
|
sl@0
|
123 |
/**This function returns hi resolution counter (timestamp)
|
sl@0
|
124 |
*
|
sl@0
|
125 |
*/
|
sl@0
|
126 |
inline TUint32 __TEST_GET_HiResTimestamp() {return User::FastCounter();}
|
sl@0
|
127 |
|
sl@0
|
128 |
|
sl@0
|
129 |
/**Method marker class
|
sl@0
|
130 |
*
|
sl@0
|
131 |
*/
|
sl@0
|
132 |
class TTestMethodMarker
|
sl@0
|
133 |
{
|
sl@0
|
134 |
public:
|
sl@0
|
135 |
TTestMethodMarker(const TDesC8& aMethod)
|
sl@0
|
136 |
{
|
sl@0
|
137 |
__TEST_LOGBUF(aMethod)
|
sl@0
|
138 |
}
|
sl@0
|
139 |
~TTestMethodMarker()
|
sl@0
|
140 |
{
|
sl@0
|
141 |
__TEST_LOG("}")
|
sl@0
|
142 |
}
|
sl@0
|
143 |
};
|
sl@0
|
144 |
|
sl@0
|
145 |
|
sl@0
|
146 |
/**This macro is logging entry and exit points from method specified as parameter.
|
sl@0
|
147 |
*/
|
sl@0
|
148 |
#define __TEST_MARK_METHOD(x) TBuf8<128> b; b.AppendFormat(_L8("%S\n{"), &_L8(x)); TTestMethodMarker m(b);
|
sl@0
|
149 |
|
sl@0
|
150 |
#else
|
sl@0
|
151 |
|
sl@0
|
152 |
//empty definitions
|
sl@0
|
153 |
#define __TEST_CREATE_LOG(replace)
|
sl@0
|
154 |
#define __TEST_LOG(x)
|
sl@0
|
155 |
#define __TEST_LOGNUM(x)
|
sl@0
|
156 |
#define __TEST_LOGBUF(x)
|
sl@0
|
157 |
#define __TEST_LOGTIMESTAMP(x)
|
sl@0
|
158 |
#define __TEST_LOGTICKCOUNT
|
sl@0
|
159 |
#define __TEST_LOGTIMESTAMP_HIRES(x)
|
sl@0
|
160 |
#define __TEST_HIRES_RESOLUTION
|
sl@0
|
161 |
inline TUint32 __TEST_GET_Resolution(){return 0;}
|
sl@0
|
162 |
inline TUint32 __TEST_GET_HiResTimestamp(){return 0;}
|
sl@0
|
163 |
#define __TEST_MARK_METHOD(x)
|
sl@0
|
164 |
|
sl@0
|
165 |
#endif //__TEST_LIGHLOGGER_ENABLED
|
sl@0
|
166 |
#endif /*TE_LIGHTLOGGER_H_*/
|
sl@0
|
167 |
|
sl@0
|
168 |
|
sl@0
|
169 |
/*Documentation:
|
sl@0
|
170 |
*
|
sl@0
|
171 |
* Special data format for certain macros (__TEST_HIRES_RESOLUTION; __TEST_LOGTIMESTAMP; __TEST_LOGTIMESTAMP_HIRES):
|
sl@0
|
172 |
* "<[record_id]> <[value]> description>"
|
sl@0
|
173 |
* where:
|
sl@0
|
174 |
* record_id - is an integer value
|
sl@0
|
175 |
* value - is an integer value
|
sl@0
|
176 |
* description - is a string value
|
sl@0
|
177 |
*/
|