predictivesearch/PcsUtils/src/CPcsDebug.cpp
changeset 0 e686773b3f54
child 15 e8e3147d53eb
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  PCS general debug class 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <e32std.h>
       
    21 #include <CPcsDefs.h>
       
    22 #include "CPcsDebug.h"
       
    23 #include "CPsQueryItem.h"
       
    24 #include "CPsQuery.h"
       
    25 
       
    26 
       
    27 // ============================== MEMBER FUNCTIONS ============================
       
    28 
       
    29 // ----------------------------------------------------------------------------
       
    30 // CPcsDebugWrapper::__LatencyMarkStart
       
    31 // Marks the start time for latency measurement
       
    32 // ----------------------------------------------------------------------------
       
    33 EXPORT_C void CPcsDebugWrapper::__LatencyMarkStartL(TRefByValue<const TDesC> str) 
       
    34 {
       
    35     CPcsDebugArr* dbgArr = 0;
       
    36     
       
    37 	// Check thread local storage:
       
    38 	if ( Dll::Tls() == NULL )
       
    39 	{	 
       
    40 		dbgArr = CPcsDebugArr::NewL();
       
    41 		User::LeaveIfError ( Dll::SetTls( dbgArr ) );
       
    42 	}
       
    43 	else
       
    44 	{
       
    45 	  	dbgArr = static_cast<CPcsDebugArr*>( Dll::Tls() );
       
    46 	}
       
    47 
       
    48 	CPcsDebug *dbg = CPcsDebug::NewL();
       
    49 	dbg->Mark(str);
       
    50     
       
    51     dbgArr->Push(*dbg);
       
    52 }
       
    53 
       
    54 // ----------------------------------------------------------------------------
       
    55 // CPcsDebugWrapper::__LatencyMarkEnd
       
    56 // Marks the end time for latency measurement
       
    57 // Displays the difference from Latency Mark start
       
    58 // ----------------------------------------------------------------------------
       
    59 EXPORT_C void CPcsDebugWrapper::__LatencyMarkEnd(TRefByValue<const TDesC> str) 
       
    60 {
       
    61     CPcsDebugArr* dbgArr = 0;
       
    62     
       
    63 	// Check thread local storage:
       
    64 	if ( Dll::Tls() == NULL )
       
    65 	{	 
       
    66 	  	return;
       
    67 	}
       
    68 	else
       
    69 	{
       
    70 	  	dbgArr = static_cast<CPcsDebugArr*>( Dll::Tls() );
       
    71 	}
       
    72 
       
    73     if ( dbgArr->IsEmpty() )
       
    74     {
       
    75         delete dbgArr;
       
    76         Dll::SetTls( NULL );
       
    77 		return;
       
    78     }
       
    79     else
       
    80     {
       
    81     	CPcsDebug* dbg = dbgArr->Pop();
       
    82 		dbg->UnMark(str);
       
    83 		delete dbg;			  	
       
    84     }
       
    85     
       
    86     if ( dbgArr->IsEmpty() )
       
    87     {
       
    88         delete dbgArr;
       
    89         Dll::SetTls( NULL );
       
    90     }
       
    91 }
       
    92 
       
    93 // ----------------------------------------------------------------------------
       
    94 // CPcsDebug::NewL
       
    95 // Two Phase Construction
       
    96 // ----------------------------------------------------------------------------
       
    97 EXPORT_C CPcsDebug* CPcsDebug::NewL()
       
    98 {
       
    99     CPcsDebug* self = new (ELeave) CPcsDebug();
       
   100     CleanupStack::PushL(self);
       
   101     self->ConstructL();
       
   102     CleanupStack::Pop(); // self
       
   103     return self;
       
   104 }
       
   105 
       
   106 // ----------------------------------------------------------------------------
       
   107 // CPcsDebug::ConstructL
       
   108 // Two Phase Construction
       
   109 // ----------------------------------------------------------------------------
       
   110 void CPcsDebug::ConstructL()
       
   111 {
       
   112 }
       
   113 
       
   114 // ----------------------------------------------------------------------------
       
   115 // CPcsDebug::Mark
       
   116 // Marks the start time for latency measurement
       
   117 // ----------------------------------------------------------------------------
       
   118 void CPcsDebug::Mark(TRefByValue<const TDesC> str,...)
       
   119 {
       
   120 	VA_LIST list;
       
   121     VA_START(list, str);
       
   122 
       
   123     // Print to log file
       
   124     TBuf<255> buf;
       
   125     buf.FormatList(str, list);
       
   126     PRINT1 ( _L("#### [%S] Latency Measurement Start ####"), &buf );
       
   127     
       
   128 	startTime.HomeTime();
       
   129 }
       
   130 
       
   131 // ----------------------------------------------------------------------------
       
   132 // CPcsDebug::UnMark
       
   133 // Marks the end time for latency measurement
       
   134 // Displays the difference from Latency Mark start
       
   135 // ----------------------------------------------------------------------------
       
   136 void CPcsDebug::UnMark(TRefByValue<const TDesC> str,...)
       
   137 {
       
   138 	endTime.HomeTime();
       
   139 	VA_LIST list;
       
   140     VA_START(list, str);
       
   141 
       
   142     // Print to log file
       
   143     TBuf<255> buf;
       
   144     buf.FormatList(str, list);
       
   145 	
       
   146 	TTimeIntervalMicroSeconds diff = endTime.MicroSecondsFrom(startTime);
       
   147 	TInt mytime = (diff.Int64()) / 1000;
       
   148 
       
   149 	PRINT2 ( _L("#### [%S] Latency Measurement End, Time taken = %d (ms) ####"), &buf, mytime );
       
   150 }
       
   151 
       
   152 // ----------------------------------------------------------------------------
       
   153 // CPcsDebug::PrintQuery
       
   154 // Prints the query as array of query items (query items cannot be spaces)
       
   155 // Used only for debugging
       
   156 // ----------------------------------------------------------------------------
       
   157 EXPORT_C void CPcsDebug::PrintQueryL(const TDesC& aPreTxt, CPsQuery& aQuery)
       
   158 {
       
   159     for ( TInt i = 0; i < aQuery.Count(); i++ )
       
   160     {
       
   161         TUint inputKey = aQuery.GetItemAtL(i).Character().GetUpperCase();
       
   162         TBuf<2> buffer;
       
   163         buffer.Format(_L("%c"), inputKey);
       
   164         switch ( aQuery.GetItemAtL(i).Mode() )
       
   165         {
       
   166             case EItut:
       
   167                 PRINT3 ( _L("%SQuery[%d].{Character.Up=%S, Mode=EItut}"), &aPreTxt, i, &buffer);
       
   168                 break;
       
   169             case EQwerty:
       
   170                 PRINT3 ( _L("%SQuery[%d].{Character.Up=%S, Mode=EQwerty}"), &aPreTxt, i, &buffer);
       
   171                 break;          
       
   172             default:
       
   173                 PRINT3 ( _L("%SQuery[%d].{Character.Up=%S, Mode=EModeUndefined}"), &aPreTxt, i, &buffer);
       
   174                 break;
       
   175         }
       
   176     }
       
   177 }
       
   178 
       
   179 // ----------------------------------------------------------------------------
       
   180 // CPcsDebug::PrintQueryList
       
   181 // Prints the query list as array of queries (queries cannot contain spaces)
       
   182 // Used only for debugging
       
   183 // ----------------------------------------------------------------------------
       
   184 EXPORT_C void CPcsDebug::PrintQueryListL(const TDesC& aPreTxt, RPointerArray<CPsQuery>& aPsQueryList)
       
   185 {
       
   186     for ( TInt i = 0; i < aPsQueryList.Count(); i++ )
       
   187     {
       
   188         TPtrC queryPtr = aPsQueryList[i]->QueryAsStringLC();        
       
   189         PRINT3 ( _L("%SQueryList[%d] = %S"), &aPreTxt, i, &queryPtr );
       
   190         CleanupStack::PopAndDestroy();
       
   191     }
       
   192 }
       
   193 
       
   194 // ----------------------------------------------------------------------------
       
   195 // CPcsDebug::PrintMatchLoc
       
   196 // Prints the array of match locations
       
   197 // Used only for debugging
       
   198 // ----------------------------------------------------------------------------
       
   199 EXPORT_C void CPcsDebug::PrintMatchLoc(const TDesC& aPreTxt, RArray<TPsMatchLocation>& aMatchLocs)
       
   200 {
       
   201     for ( TInt i = 0; i < aMatchLocs.Count(); i++ )
       
   202     {
       
   203         PRINT5 ( _L("%SMatchLoc[%d].{index=%d, length=%d, direction=%d}"),
       
   204                  &aPreTxt, i, aMatchLocs[i].index, aMatchLocs[i].length, (TInt) aMatchLocs[i].direction );
       
   205     }
       
   206 }
       
   207 
       
   208 // ----------------------------------------------------------------------------
       
   209 // CPcsDebug::PrintMatchSet
       
   210 // Prints the array of match sequences
       
   211 // Used only for debugging
       
   212 // ----------------------------------------------------------------------------
       
   213 EXPORT_C void CPcsDebug::PrintMatchSet(const TDesC& aPreTxt, RPointerArray<TDesC>& aMatchSet)
       
   214 {
       
   215     for ( TInt i = 0; i < aMatchSet.Count(); i++ )
       
   216     {
       
   217         PRINT4 ( _L("%SMatchSet[%d]=%S, Length=%d"), &aPreTxt, i, aMatchSet[i], aMatchSet[i]->Length() );
       
   218     }
       
   219 }
       
   220 
       
   221 // ----------------------------------------------------------------------------
       
   222 // CPcsDebug::PrintMatchSet
       
   223 // Prints the array of match sequences
       
   224 // Used only for debugging
       
   225 // ----------------------------------------------------------------------------
       
   226 EXPORT_C void CPcsDebug::PrintMatchSet(const TDesC& aPreTxt, CDesCArray& aMatchSet)
       
   227 {
       
   228     for ( TInt i = 0; i < aMatchSet.Count(); i++ )
       
   229     {
       
   230         PRINT4 ( _L("%SMatchSet[%d]=%S, Length=%d"), &aPreTxt, i, &aMatchSet[i], aMatchSet[i].Length() );
       
   231     }
       
   232 }
       
   233 
       
   234 // ----------------------------------------------------------------------------
       
   235 // CPcsDebugArr::NewL
       
   236 // Two Phase Construction
       
   237 // ----------------------------------------------------------------------------
       
   238 EXPORT_C CPcsDebugArr* CPcsDebugArr::NewL()
       
   239 {
       
   240     CPcsDebugArr* self = new (ELeave) CPcsDebugArr();
       
   241     return self;
       
   242 }
       
   243 
       
   244 // ----------------------------------------------------------------------------
       
   245 // CPcsDebugArr::Push
       
   246 // Push an element into the array
       
   247 // ----------------------------------------------------------------------------
       
   248 EXPORT_C void CPcsDebugArr::Push(CPcsDebug& dbg)
       
   249 {
       
   250     debugArray.Append(&dbg);
       
   251 }
       
   252 
       
   253 // ----------------------------------------------------------------------------
       
   254 // CPcsDebugArr::Pop
       
   255 // Pop an element from the array
       
   256 // ----------------------------------------------------------------------------
       
   257 EXPORT_C CPcsDebug* CPcsDebugArr::Pop()
       
   258 {
       
   259      TInt index = debugArray.Count() - 1;
       
   260      CPcsDebug* dbg = debugArray[index];
       
   261      debugArray.Remove(index);
       
   262 	 return (dbg);
       
   263 }
       
   264 
       
   265 // ----------------------------------------------------------------------------
       
   266 // CPcsDebugArr::IsEmpty
       
   267 // Check if array is empty
       
   268 // ----------------------------------------------------------------------------
       
   269 EXPORT_C TBool CPcsDebugArr::IsEmpty()
       
   270 {
       
   271      if ( debugArray.Count() == 0 )
       
   272           return ETrue;
       
   273      else 
       
   274           return EFalse;
       
   275 }
       
   276 
       
   277 // ----------------------------------------------------------------------------
       
   278 // CPcsDebugArr::~CPcsDebugArr
       
   279 // Destructor
       
   280 // ----------------------------------------------------------------------------
       
   281 CPcsDebugArr::~CPcsDebugArr()
       
   282 {
       
   283 	debugArray.ResetAndDestroy();
       
   284 }
       
   285