predictivesearch/PcsUtils/src/CPcsDebug.cpp
branchRCL_3
changeset 63 f4a778e096c2
child 64 c1e8ba0c2b16
equal deleted inserted replaced
62:5b6f26637ad3 63:f4a778e096c2
       
     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::PrintQueryL
       
   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         CPsQueryItem& item = aQuery.GetItemAtL(i);
       
   162         TUint inputKey = item.Character().GetUpperCase();
       
   163         TBuf<2> buffer;
       
   164         buffer.Format(_L("%c"), inputKey);
       
   165         switch ( item.Mode() )
       
   166         {
       
   167             case ENonPredictive:
       
   168                 PRINT3 ( _L("%SQuery[%d].{Character.Up=%S, Mode=ENonPredictive}"),
       
   169                          &aPreTxt, i, &buffer);
       
   170                 break;
       
   171             case EPredictiveDefaultKeyboard:
       
   172                 PRINT3 ( _L("%SQuery[%d].{Character.Up=%S, Mode=EPredictiveDefaultKeyboard}"),
       
   173                          &aPreTxt, i, &buffer);
       
   174                 break;
       
   175             case EPredictiveItuT:
       
   176                 PRINT3 ( _L("%SQuery[%d].{Character.Up=%S, Mode=EPredictiveItuT}"),
       
   177                          &aPreTxt, i, &buffer);
       
   178                 break;
       
   179             case EPredictiveQwerty:
       
   180                 PRINT3 ( _L("%SQuery[%d].{Character.Up=%S, Mode=EPredictiveQwerty}"),
       
   181                          &aPreTxt, i, &buffer);
       
   182                 break;
       
   183             default:
       
   184                 PRINT4 ( _L("%SQuery[%d].{Character.Up=%S, Mode=%d (Error}"),
       
   185                          &aPreTxt, i, &buffer, item.Mode());
       
   186                 break;
       
   187         }
       
   188     }
       
   189 }
       
   190 
       
   191 // ----------------------------------------------------------------------------
       
   192 // CPcsDebug::PrintQueryList
       
   193 // Prints the query list as array of queries (queries cannot contain spaces)
       
   194 // Used only for debugging
       
   195 // ----------------------------------------------------------------------------
       
   196 EXPORT_C void CPcsDebug::PrintQueryListL(const TDesC& aPreTxt, RPointerArray<CPsQuery>& aPsQueryList)
       
   197 {
       
   198     for ( TInt i = 0; i < aPsQueryList.Count(); i++ )
       
   199     {
       
   200         TPtrC queryPtr = aPsQueryList[i]->QueryAsStringLC();        
       
   201         PRINT3 ( _L("%SQueryList[%d] = %S"), &aPreTxt, i, &queryPtr );
       
   202         CleanupStack::PopAndDestroy();
       
   203     }
       
   204 }
       
   205 
       
   206 // ----------------------------------------------------------------------------
       
   207 // CPcsDebug::PrintMatchLoc
       
   208 // Prints the array of match locations
       
   209 // Used only for debugging
       
   210 // ----------------------------------------------------------------------------
       
   211 EXPORT_C void CPcsDebug::PrintMatchLoc(const TDesC& aPreTxt, RArray<TPsMatchLocation>& aMatchLocs)
       
   212 {
       
   213     for ( TInt i = 0; i < aMatchLocs.Count(); i++ )
       
   214     {
       
   215         PRINT5 ( _L("%SMatchLoc[%d].{index=%d, length=%d, direction=%d}"),
       
   216                  &aPreTxt, i, aMatchLocs[i].index, aMatchLocs[i].length, (TInt) aMatchLocs[i].direction );
       
   217     }
       
   218 }
       
   219 
       
   220 // ----------------------------------------------------------------------------
       
   221 // CPcsDebug::PrintMatchSet
       
   222 // Prints the array of match sequences
       
   223 // Used only for debugging
       
   224 // ----------------------------------------------------------------------------
       
   225 EXPORT_C void CPcsDebug::PrintMatchSet(const TDesC& aPreTxt, RPointerArray<TDesC>& aMatchSet)
       
   226 {
       
   227     for ( TInt i = 0; i < aMatchSet.Count(); i++ )
       
   228     {
       
   229         PRINT4 ( _L("%SMatchSet[%d]=%S, Length=%d"), &aPreTxt, i, aMatchSet[i], aMatchSet[i]->Length() );
       
   230     }
       
   231 }
       
   232 
       
   233 // ----------------------------------------------------------------------------
       
   234 // CPcsDebug::PrintMatchSet
       
   235 // Prints the array of match sequences
       
   236 // Used only for debugging
       
   237 // ----------------------------------------------------------------------------
       
   238 EXPORT_C void CPcsDebug::PrintMatchSet(const TDesC& aPreTxt, CDesCArray& aMatchSet)
       
   239 {
       
   240     for ( TInt i = 0; i < aMatchSet.Count(); i++ )
       
   241     {
       
   242         TPtrC16 ptr = aMatchSet.MdcaPoint(i);
       
   243         PRINT4 ( _L("%SMatchSet[%d]=%S, Length=%d"), &aPreTxt, i, &ptr, aMatchSet[i].Length() );
       
   244     }
       
   245 }
       
   246 
       
   247 // ----------------------------------------------------------------------------
       
   248 // CPcsDebugArr::NewL
       
   249 // Two Phase Construction
       
   250 // ----------------------------------------------------------------------------
       
   251 EXPORT_C CPcsDebugArr* CPcsDebugArr::NewL()
       
   252 {
       
   253     CPcsDebugArr* self = new (ELeave) CPcsDebugArr();
       
   254     return self;
       
   255 }
       
   256 
       
   257 // ----------------------------------------------------------------------------
       
   258 // CPcsDebugArr::Push
       
   259 // Push an element into the array
       
   260 // ----------------------------------------------------------------------------
       
   261 EXPORT_C void CPcsDebugArr::Push(CPcsDebug& dbg)
       
   262 {
       
   263     debugArray.Append(&dbg);
       
   264 }
       
   265 
       
   266 // ----------------------------------------------------------------------------
       
   267 // CPcsDebugArr::Pop
       
   268 // Pop an element from the array
       
   269 // ----------------------------------------------------------------------------
       
   270 EXPORT_C CPcsDebug* CPcsDebugArr::Pop()
       
   271 {
       
   272      TInt index = debugArray.Count() - 1;
       
   273      CPcsDebug* dbg = debugArray[index];
       
   274      debugArray.Remove(index);
       
   275 	 return (dbg);
       
   276 }
       
   277 
       
   278 // ----------------------------------------------------------------------------
       
   279 // CPcsDebugArr::IsEmpty
       
   280 // Check if array is empty
       
   281 // ----------------------------------------------------------------------------
       
   282 EXPORT_C TBool CPcsDebugArr::IsEmpty()
       
   283 {
       
   284      if ( debugArray.Count() == 0 )
       
   285           return ETrue;
       
   286      else 
       
   287           return EFalse;
       
   288 }
       
   289 
       
   290 // ----------------------------------------------------------------------------
       
   291 // CPcsDebugArr::~CPcsDebugArr
       
   292 // Destructor
       
   293 // ----------------------------------------------------------------------------
       
   294 CPcsDebugArr::~CPcsDebugArr()
       
   295 {
       
   296 	debugArray.ResetAndDestroy();
       
   297 }
       
   298