messagingapp/msgappfw/utils/src/ccsdebug.cpp
changeset 23 238255e8b033
child 25 84d9eb65b26f
equal deleted inserted replaced
5:4697dfb2d7ad 23:238255e8b033
       
     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:  CS general debug class 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 // SYSTEM INCLUDES
       
    22 
       
    23 // USER INCLUDES
       
    24 #include "ccsdebug.h"
       
    25 
       
    26 // ============================== MEMBER FUNCTIONS ============================
       
    27 
       
    28 // ----------------------------------------------------------------------------
       
    29 // CCsDebugWrapper::__LatencyMarkStart
       
    30 // Marks the start time for latency measurement
       
    31 // ----------------------------------------------------------------------------
       
    32 EXPORT_C void CCsDebugWrapper::__LatencyMarkStartL(TRefByValue<const TDesC> str) 
       
    33 {
       
    34     CCsDebugArr* dbgArr = 0;
       
    35     
       
    36 	// Check thread local storage:
       
    37 	if ( !(Dll::Tls()))
       
    38 	{	 
       
    39 		dbgArr = CCsDebugArr::NewL();
       
    40 		User::LeaveIfError ( Dll::SetTls( dbgArr ) );
       
    41 	}
       
    42 	else
       
    43 	{
       
    44 	  	dbgArr = static_cast<CCsDebugArr*>( Dll::Tls() );
       
    45 	}
       
    46 
       
    47 	CCsDebug *dbg = CCsDebug::NewL();
       
    48 	dbg->Mark(str);
       
    49     
       
    50     dbgArr->Push(*dbg);
       
    51 }
       
    52 
       
    53 // ----------------------------------------------------------------------------
       
    54 // CCsDebugWrapper::__LatencyMarkEnd
       
    55 // Marks the end time for latency measurement
       
    56 // Displays the difference from Latency Mark start
       
    57 // ----------------------------------------------------------------------------
       
    58 EXPORT_C void CCsDebugWrapper::__LatencyMarkEnd(TRefByValue<const TDesC> str) 
       
    59 {
       
    60     CCsDebugArr* dbgArr = 0;
       
    61     
       
    62 	// Check thread local storage:
       
    63 	if ( !(Dll::Tls()) )
       
    64 	{	 
       
    65 	  	return;
       
    66 	}
       
    67 	else
       
    68 	{
       
    69 	  	dbgArr = static_cast<CCsDebugArr*>( Dll::Tls() );
       
    70 	}
       
    71 
       
    72     if ( dbgArr->IsEmpty() )
       
    73     {
       
    74         delete dbgArr;
       
    75         Dll::SetTls( NULL );
       
    76     }
       
    77     else
       
    78     {
       
    79     	CCsDebug* dbg = dbgArr->Pop();
       
    80 		dbg->UnMark(str);
       
    81 		delete dbg;			  	
       
    82     }
       
    83     
       
    84     if ( dbgArr->IsEmpty() )
       
    85     {
       
    86         delete dbgArr;
       
    87         Dll::SetTls( NULL );
       
    88     }
       
    89 }
       
    90 
       
    91 // ----------------------------------------------------------------------------
       
    92 // CCsDebug::NewL
       
    93 // Two Phase Construction
       
    94 // ----------------------------------------------------------------------------
       
    95 EXPORT_C CCsDebug* CCsDebug::NewL()
       
    96 {
       
    97     CCsDebug* self = new (ELeave) CCsDebug();
       
    98     CleanupStack::PushL(self);
       
    99     self->ConstructL();
       
   100     CleanupStack::Pop(self); 
       
   101     return self;
       
   102 }
       
   103 
       
   104 // ----------------------------------------------------------------------------
       
   105 // CCsDebug::ConstructL
       
   106 // Two Phase Construction
       
   107 // ----------------------------------------------------------------------------
       
   108 void CCsDebug::ConstructL()
       
   109 {
       
   110 }
       
   111 
       
   112 // ----------------------------------------------------------------------------
       
   113 // CCsDebug::Mark
       
   114 // Marks the start time for latency measurement
       
   115 // ----------------------------------------------------------------------------
       
   116 void CCsDebug::Mark(TRefByValue<const TDesC> str,...)
       
   117 {
       
   118 	VA_LIST list;
       
   119     VA_START(list, str);
       
   120 
       
   121     // Print to log file
       
   122     TBuf<MAX_BUFF_LENGTH> buf;
       
   123     buf.FormatList(str, list);
       
   124     PRINT_LATENCY1 ( _L("#### [%S] Latency Measurement Start ####"), &buf );
       
   125     
       
   126 	startTime.HomeTime();
       
   127 }
       
   128 
       
   129 // ----------------------------------------------------------------------------
       
   130 // CCsDebug::UnMark
       
   131 // Marks the end time for latency measurement
       
   132 // Displays the difference from Latency Mark start
       
   133 // ----------------------------------------------------------------------------
       
   134 void CCsDebug::UnMark(TRefByValue<const TDesC> str,...)
       
   135 {
       
   136 	endTime.HomeTime();
       
   137 	VA_LIST list;
       
   138     VA_START(list, str);
       
   139 
       
   140     // Print to log file
       
   141     TBuf<MAX_BUFF_LENGTH> buf;
       
   142     buf.FormatList(str, list);
       
   143 	
       
   144 	TTimeIntervalMicroSeconds diff = endTime.MicroSecondsFrom(startTime);
       
   145 	TInt mytime = (diff.Int64()) / TIME_FACTOR;
       
   146 
       
   147 	PRINT_LATENCY2 ( _L("#### [%S] Latency Measurement End, Time taken = %d (ms) ####"), &buf, mytime );
       
   148 }
       
   149 
       
   150 
       
   151 // ----------------------------------------------------------------------------
       
   152 // CCsDebugArr::NewL
       
   153 // Two Phase Construction
       
   154 // ----------------------------------------------------------------------------
       
   155 EXPORT_C CCsDebugArr* CCsDebugArr::NewL()
       
   156 {
       
   157     CCsDebugArr* self = new (ELeave) CCsDebugArr();
       
   158     return self;
       
   159 }
       
   160 
       
   161 // ----------------------------------------------------------------------------
       
   162 // CCsDebugArr::Push
       
   163 // Push an element into the array
       
   164 // ----------------------------------------------------------------------------
       
   165 EXPORT_C void CCsDebugArr::Push(CCsDebug& dbg)
       
   166 {
       
   167     debugArray.Append(&dbg);
       
   168 }
       
   169 
       
   170 // ----------------------------------------------------------------------------
       
   171 // CCsDebugArr::Pop
       
   172 // Pop an element from the array
       
   173 // ----------------------------------------------------------------------------
       
   174 EXPORT_C CCsDebug* CCsDebugArr::Pop()
       
   175 {
       
   176      TInt index = debugArray.Count() - 1;
       
   177      CCsDebug* dbg = debugArray[index];
       
   178      debugArray.Remove(index);
       
   179 	 return (dbg);
       
   180 }
       
   181 
       
   182 // ----------------------------------------------------------------------------
       
   183 // CCsDebugArr::IsEmpty
       
   184 // Check if array is empty
       
   185 // ----------------------------------------------------------------------------
       
   186 EXPORT_C TBool CCsDebugArr::IsEmpty()
       
   187 {
       
   188      if ( debugArray.Count() == 0 )
       
   189           return ETrue;
       
   190      else 
       
   191           return EFalse;
       
   192 }
       
   193 
       
   194 // ----------------------------------------------------------------------------
       
   195 // CCsDebugArr::~CCsDebugArr
       
   196 // Destructor
       
   197 // ----------------------------------------------------------------------------
       
   198 CCsDebugArr::~CCsDebugArr()
       
   199 {
       
   200 	debugArray.ResetAndDestroy();
       
   201 }
       
   202 
       
   203 // End of file