1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/windowing/windowserver/debuglog/DEBUGLOG.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,231 @@
1.4 +// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// Common code for all debug logging variants
1.18 +//
1.19 +//
1.20 +
1.21 +#include "../SERVER/w32cmd.h"
1.22 +#include "DEBUGLOG.H"
1.23 +
1.24 +//#define __LIMIT_LOGGING yes //These should be turned off for released code
1.25 +//#define __FORCE_ASCII yes
1.26 +
1.27 +#if defined(__LIMIT_LOGGING)
1.28 +_LIT(limitLogging,"!!");
1.29 +#endif
1.30 +
1.31 +_LIT(KDebugLogFound,"Found");
1.32 +_LIT(KDebugLogSearchedFor,"Searched for");
1.33 +
1.34 +EXPORT_C CDebugLog::CDebugLog(CDebugLogDevice *aDevice) : iDevice(aDevice), iLevel(ELogEverything)
1.35 + {
1.36 + __DECLARE_NAME(_S("CDebugLog"));
1.37 + }
1.38 +
1.39 +CDebugLog::~CDebugLog()
1.40 + {
1.41 + delete iDevice;
1.42 + }
1.43 +
1.44 +EXPORT_C void CDebugLog::ConstructL(TBool aIsFirst, TDesC &aParams)
1.45 + {
1.46 + _LIT(LogLine,"=================");
1.47 + iDevice->ConstructL(aIsFirst, aParams);
1.48 + iPrevTime.HomeTime();
1.49 + iExtraLen=0; // Indicates don't print time part to log
1.50 + MiscMessage(LogLine);
1.51 + MiscMessage(_L("[Logging Enabled]"));
1.52 + TBuf<32> timeBuf;
1.53 + iPrevTime.FormatL(timeBuf,_L("[ %:0%H%:1%T%:2%S%.%*C2%:3 ]"));
1.54 + MiscMessage(timeBuf);
1.55 + MiscMessage(LogLine);
1.56 + }
1.57 +
1.58 +void CDebugLog::CommandBuf(TInt aApp)
1.59 + {
1.60 + if (aApp==iLastApp)
1.61 + return;
1.62 + TPtrC text(iWsDecoder.CommandBuf(aApp));
1.63 + WriteToLog(text);
1.64 + iLastApp=aApp;
1.65 + }
1.66 +
1.67 +void CDebugLog::Command(TInt aClass, TInt aOpcode, const TAny *aCmdData, TInt aHandle)
1.68 + {
1.69 + TPtrC text(iWsDecoder.Command(aClass, aOpcode, aCmdData, aHandle));
1.70 + if (text!=KNullDesC)
1.71 + WriteToLog(text);
1.72 + }
1.73 +
1.74 +void CDebugLog::NewClient(TUint aConnectionHandle)
1.75 + {
1.76 + TPtrC text(iWsDecoder.NewClient(aConnectionHandle));
1.77 + WriteToLog(text,ELogImportant);
1.78 + }
1.79 +
1.80 +void CDebugLog::Reply(TInt aData)
1.81 + {
1.82 + TPtrC text(iWsDecoder.CommandReply(aData));
1.83 + WriteToLog(text);
1.84 + }
1.85 +
1.86 +void CDebugLog::ReplyBuf(const TDesC8 &aDes)
1.87 + {
1.88 + TPtrC text(iWsDecoder.CommandReplyBuf(aDes));
1.89 + if (text!=KNullDesC)
1.90 + WriteToLog(text);
1.91 + }
1.92 +
1.93 +void CDebugLog::ReplyBuf(const TDesC16 &aDes)
1.94 + {
1.95 + TPtrC text(iWsDecoder.CommandReplyBuf(aDes));
1.96 + if (text!=KNullDesC)
1.97 + WriteToLog(text);
1.98 + }
1.99 +
1.100 +void CDebugLog::SignalEvent(TInt aApp)
1.101 + {
1.102 + TPtrC text(iWsDecoder.SignalEvent(aApp));
1.103 + WriteToLog(text);
1.104 + }
1.105 +
1.106 +void CDebugLog::Panic(TInt aApp, TInt aReason)
1.107 + {
1.108 + TPtrC text(iWsDecoder.Panic(aApp, aReason));
1.109 + WriteToLog(text,ELogImportant);
1.110 + }
1.111 +
1.112 +void CDebugLog::MiscMessage(TInt aPriority,const TDesC &aFormat,TInt aParam)
1.113 + {
1.114 + if (aPriority>=iLevel)
1.115 + MiscMessage(aFormat,aParam);
1.116 + }
1.117 +
1.118 +void CDebugLog::MiscMessage(const TDesC &aFormat,TInt aParam)
1.119 + {
1.120 + TPtrC text(iWsDecoder.MiscMessage(aFormat,aParam));
1.121 + WriteToLog(text,iLevel);
1.122 + }
1.123 +
1.124 +void CDebugLog::IniFileSettingRead(TInt aScreen, const TDesC& aVarName, TBool aFound, const TDesC& aResult)
1.125 + {
1.126 + if (!aFound && (iLevel != ELogEverything))
1.127 + { // nothing to print
1.128 + return;
1.129 + }
1.130 +
1.131 + TBuf<256> buf;
1.132 +
1.133 + buf.Format(_L("%S .ini setting { "), &(aFound ? KDebugLogFound() : KDebugLogSearchedFor()));
1.134 +
1.135 + if (aScreen >= 0)
1.136 + {
1.137 + buf.AppendFormat(_L("Screen %i, "), aScreen);
1.138 + }
1.139 + else
1.140 + {
1.141 + buf.Append(_L("Default, "));
1.142 + }
1.143 +
1.144 + if (aFound)
1.145 + {
1.146 + buf.AppendFormat(_L("\"%S\", \"%S\" }"), &aVarName, &aResult);
1.147 + }
1.148 + else
1.149 + {
1.150 + buf.AppendFormat(_L("\"%S\" }"), &aVarName);
1.151 + }
1.152 +
1.153 + MiscMessage(buf);
1.154 + }
1.155 +
1.156 +
1.157 +void CDebugLog::WriteToLog(const TDesC &aDes,TInt aLevel/*=ELogEverything*/)
1.158 + {
1.159 + if (aLevel<iLevel)
1.160 + return;
1.161 +#if defined(__LIMIT_LOGGING)
1.162 + TBuf<8> start(limitLogging);
1.163 + if (start!=aDes.Left(start.Length()))
1.164 + return;
1.165 +#endif
1.166 + if (iErr==KErrNone)
1.167 + {
1.168 + TBuf<80> timeBuf;
1.169 + TTime time;
1.170 + time.HomeTime();
1.171 + TTimeIntervalMicroSeconds diff(time.MicroSecondsFrom(iPrevTime));
1.172 + TInt diffi = I64LOW(diff.Int64());
1.173 +//
1.174 + if (iExtraLen>0)
1.175 + timeBuf.Format(_L("%+ *p%d.%03d"),iExtraLen,diffi/1000000,(diffi%1000000)/1000);
1.176 + iExtraLen=74-aDes.Length();
1.177 + if (iExtraLen<1)
1.178 + iExtraLen=1;
1.179 +/* Old version, logs current time
1.180 + TBuf<256> buf(aDes);
1.181 + time.FormatL(timeBuf,_L("%:0%H%:1%T%:2%S%.%*C2%:3"));
1.182 + buf.Format(_L("%+ *p%S"),len,&timeBuf);
1.183 +*/
1.184 +#if defined(__FORCE_ASCII)
1.185 + TBuf8<80> timeBuf8;
1.186 + TBuf8<128> des8;
1.187 + timeBuf8.Copy(timeBuf);
1.188 + des8.Copy(aDes);
1.189 + TRAP(iErr,iDevice->WriteToLog8L(timeBuf8, des8));
1.190 +#else
1.191 + TRAP(iErr,iDevice->WriteToLogL(timeBuf, aDes));
1.192 +#endif
1.193 + iPrevTime.HomeTime();
1.194 + iLastApp=0;
1.195 + }
1.196 + }
1.197 +
1.198 +
1.199 +void CDebugLog::HeapDump()
1.200 + {
1.201 + _LIT(LogLine,"===========");
1.202 + MiscMessage(LogLine);
1.203 + TBuf<128> buf;
1.204 + TInt biggestblock;
1.205 + buf.Format(_L("Heap size=%d, available=%d, count=%d"),User::Heap().Size(),User::Heap().Available(biggestblock),User::Heap().Count());
1.206 + MiscMessage(buf);
1.207 +//
1.208 + MiscMessage(LogLine);
1.209 +//
1.210 + MiscMessage(LogLine);
1.211 +//
1.212 +// Plus profile information for now
1.213 +//
1.214 + LogProfiles();
1.215 + }
1.216 +
1.217 +void CDebugLog::SetLoggingLevel(TInt aLevel)
1.218 + {
1.219 + iLevel=aLevel;
1.220 + }
1.221 +
1.222 +void CDebugLog::AppendProfileNum(TDes &aDes, TInt aNum)
1.223 + {
1.224 + aDes.AppendFormat(_L("%d.%02d, "),aNum/1000000,(aNum%1000000)/10000);
1.225 + }
1.226 +
1.227 +void CDebugLog::AppendProfileCount(TDes &aDes, TInt aNum)
1.228 + {
1.229 + aDes.AppendFormat(_L("[%d], "),aNum);
1.230 + }
1.231 +
1.232 +void CDebugLog::LogProfiles()
1.233 + {
1.234 + }