applayerprotocols/httptransportfw/utils/TimerLogger.cpp
changeset 0 b16258d2340f
child 49 b91bcc4b38e4
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <f32file.h> // for TParse, in Flogger stuff
       
    17 #include <e32std.h>
       
    18 
       
    19 #include "timerlogger.h"
       
    20 
       
    21 #define KTestHeader				_L8("HTTP PERFORMANCE LOGGER\n\n\n")
       
    22 #define KTestLogs				_L8("TEST NAME,METHOD NAME,TIME IN MICROSECONDS\n\n")
       
    23 #define KTestCommentPrepend		_L("\t")
       
    24 
       
    25 _LIT(KFileName, "c:\\logs\\http\\peformance_logger.csv");
       
    26 _LIT(KFilePath, "c:\\logs\\http\\");
       
    27 
       
    28 #define KMaxLogLineLength 128
       
    29 
       
    30 /**
       
    31  Destructor
       
    32 */
       
    33 EXPORT_C TTimerLogger::~TTimerLogger()
       
    34 	{
       
    35 #if defined (__LOG_PERFORMANCE) && !defined (_DEBUG)
       
    36 	iFile.Close();
       
    37 	iFs.Close();
       
    38 #endif
       
    39 	}
       
    40 
       
    41 void TTimerLogger::LogIt(const TDesC& aComment)
       
    42 	{
       
    43 	TInt err = iFs.Connect();
       
    44 	if(err == KErrNone)
       
    45 		{
       
    46 		iFs.MkDirAll(KFilePath);
       
    47 		err = iFile.Open(iFs, KFileName, EFileWrite);
       
    48 		if(err == KErrNotFound)
       
    49 			{
       
    50 			iFile.Create(iFs, KFileName, EFileWrite);
       
    51 			iFile.Write(KTestHeader);
       
    52 			iFile.Write(KTestLogs);
       
    53 			}
       
    54 		TFileText file;
       
    55 	    file.Set(iFile);
       
    56 		file.Write(aComment);
       
    57 		iFile.Close();
       
    58 		iFs.Close();
       
    59 		}
       
    60 	else	
       
    61 		{
       
    62 		User::InfoPrint(_L("Cannot write to file"));
       
    63 		}
       
    64 	}
       
    65 	
       
    66 
       
    67 /** 
       
    68     Initiates the timer
       
    69 */
       
    70 EXPORT_C void TTimerLogger::StartTimer()
       
    71 	{
       
    72 	#if defined (__LOG_PERFORMANCE) && !defined (_DEBUG)
       
    73 	iStartTime.UniversalTime();
       
    74 	#endif
       
    75 	}
       
    76 
       
    77 
       
    78 /** 
       
    79   Terminates the timer
       
    80   @param aComment Name of API.
       
    81 */
       
    82 EXPORT_C void TTimerLogger::EndTimer(const TDesC& aComment)
       
    83 	{
       
    84     #if defined (__LOG_PERFORMANCE) && !defined (_DEBUG)
       
    85 	iEndTime.UniversalTime();
       
    86 	TTimeIntervalMicroSeconds iTimeDifference = iEndTime.MicroSecondsFrom(iStartTime);	
       
    87 	_LIT(KTimeDiff, ",%d microseconds\n");
       
    88 	RBuf myBuf;
       
    89 	myBuf.Create (aComment.Length()+64);
       
    90 	myBuf.Append (aComment );
       
    91 	myBuf.AppendFormat(KTimeDiff, iTimeDifference.Int64());
       
    92     LogIt(myBuf);
       
    93 	myBuf.Close();	
       
    94 	iStartTime = 0;
       
    95 	iEndTime = 0;
       
    96 	#endif
       
    97 	}
       
    98 
       
    99 
       
   100 /** Methods from TDesOverflow
       
   101 	@param aDes modifiable descriptor whose overflow results in the call to this overflow handler.
       
   102 */
       
   103 EXPORT_C void TTimerLogger::Overflow(TDes& aDes)
       
   104 	{
       
   105 	#if defined (__LOG_PERFORMANCE) && !defined (_DEBUG)
       
   106 	// Overflow has occured - end log line with '...'
       
   107 	_LIT(KErrOverflowMsg, "...");
       
   108 	if( aDes.MaxLength() >= KErrOverflowMsg().Length() + aDes.Length() )
       
   109 		aDes.Append(KErrOverflowMsg);
       
   110 	#endif
       
   111 	}
       
   112 
       
   113 /**
       
   114  Displays the test case name
       
   115  @param aComment Name of API.
       
   116 */
       
   117 EXPORT_C void TTimerLogger::TestName(const TDesC& aComment)
       
   118 	{
       
   119 	#if defined (__LOG_PERFORMANCE) && !defined (_DEBUG)
       
   120     LogIt(aComment);
       
   121 	#endif
       
   122 	}