calendarui/inc/debug.h
changeset 0 f979ecb2b13e
child 29 12af337248b1
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 /*
       
     2 * Copyright (c) 2006-2006 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:  Debug file of Calendar Application.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __DEBUG_H__
       
    20 #define __DEBUG_H__
       
    21 
       
    22 /*
       
    23 #ifndef _DEBUG
       
    24 
       
    25 #define __TIME_MARK(_var)
       
    26 #define __TIME_ENDMARK(_msg, _var)
       
    27 #define __TIME(_msg, _code) _code;
       
    28 #define __TICK(_msg)
       
    29 #define __HEAP(_msg)
       
    30 #define __PRINT(_fmt, args...)
       
    31 #define __PRINT8(_fmt, args...)
       
    32 #define __PRINTS(_str)
       
    33 #define __PRINT_IF_ERROR(_stmt, _fmt) _stmt;
       
    34 #define __TRAP_AND_PRINT_IF_ERROR(_stmt, _fmt) TRAP_IGNORE(_stmt);
       
    35 
       
    36 
       
    37 #else
       
    38 */
       
    39 // ========== INCLUDE FILES ===================================================
       
    40 #include <flogger.h>
       
    41 //#pragma message "Warning: Logging enabled, binary fotprint increased!!!"
       
    42 
       
    43 // ========== CONSTANTS =======================================================
       
    44 #ifndef D_LOG_DIR
       
    45 #define D_LOG_DIR _L("cal")
       
    46 #endif
       
    47 
       
    48 //
       
    49 // Log file for heap usage
       
    50 //
       
    51 #ifndef D_LOG_FILE
       
    52 #define D_LOG_FILE _L("debug.log")
       
    53 #endif
       
    54 
       
    55 
       
    56 // ========== LOCAL FUNCTIONS =================================================
       
    57 
       
    58 // ----------------------------------------------------------------------------
       
    59 //
       
    60 // Performance logging operation, give results in microseconds 10^-6
       
    61 // The metricts are based on the measurment current value of microseconds in 
       
    62 // the begining of operation and in the end. The time difference is actual result
       
    63 //
       
    64 // The logging operations take about 5ms, which should be considered if inner
       
    65 // tag are used.
       
    66 //
       
    67 // Examples:
       
    68 //
       
    69 // __TIME_MARK(t)
       
    70 // DoOperation(...);
       
    71 // __TIME_ENDMARK(_L("Message 1"), t);
       
    72 //
       
    73 // __TIME(_L("Message 1"), DoOperation(...))
       
    74 //
       
    75 // ----------------------------------------------------------------------------
       
    76 //
       
    77 
       
    78 //
       
    79 // Actual implementation of 
       
    80 // Logs the microsecond difference between current value and stored earlier
       
    81 // aMsg - textual message stored to the log file
       
    82 // aStart - the start time, the value is set by previous macros
       
    83 //
       
    84 inline void __impl_time_endmark(const TDesC& aMsg, TTime aStart)
       
    85 {
       
    86 	TTime now;
       
    87 	now.UniversalTime();
       
    88 	TTimeIntervalMicroSeconds delta = now.MicroSecondsFrom(aStart);
       
    89 	RFileLogger::WriteFormat(D_LOG_DIR, D_LOG_FILE, EFileLoggingModeAppend, _L("\t[T]\t%S\tTime:\t%Ld"), &aMsg, delta.Int64());	
       
    90 }
       
    91 
       
    92 //
       
    93 // Prints the message and current ms value to the log file
       
    94 //
       
    95 inline void __impl_tick(const TDesC& aMsg)
       
    96 {
       
    97 	//Gets the nanokernel tick count. This is the current value of the machine's millisecond tick counter.
       
    98     TUint32 nTick = User::NTickCount();
       
    99 	RFileLogger::WriteFormat(D_LOG_DIR, D_LOG_FILE, EFileLoggingModeAppend, _L("\t[T]\t%S\tMicro Sec:\t%d000"), &aMsg, nTick);	
       
   100 }
       
   101 
       
   102 //
       
   103 // Stores the current microsecond value
       
   104 // _var - A name, which will be declared as a TInt, and will receive the current time value.
       
   105 // After the macro, _var remains in scope until the end of its enclosing block.
       
   106 //
       
   107 #define __TIME_MARK(_var) TTime _var;_var.UniversalTime();
       
   108 
       
   109 //
       
   110 // Logs the microsecond difference between current value and stored earlier
       
   111 // _msg - textual message stored to the log file
       
   112 // _var - the start time, the value is set by previous macros
       
   113 //
       
   114 #define __TIME_ENDMARK(_msg, _var) __impl_time_endmark(_L(_msg), _var);
       
   115 
       
   116 //
       
   117 // Measures the execution of code statement
       
   118 // _msg - textual message stored to the log file
       
   119 // _code - code statements to be measured
       
   120 //
       
   121 #define __TIME(_msg, _code) {TTime _time;_time.UniversalTime();_code;__impl_time_endmark(_L(_msg),_time);};
       
   122 
       
   123 //
       
   124 //  the message and current ms value to the log file
       
   125 //
       
   126 #define __TICK(_msg) __impl_tick(_L(_msg));
       
   127 // ----------------------------------------------------------------------------
       
   128 //
       
   129 // Logs the amout of used heap to log file. Notes that the Heap value equals
       
   130 // to the result provided by Goofy tool.
       
   131 //
       
   132 // ----------------------------------------------------------------------------
       
   133 //
       
   134 inline void __impl_heap(const TDesC& aMsg)
       
   135 {
       
   136 	//Log Memory	
       
   137     TInt size;
       
   138     User::Heap().AllocSize(size);
       
   139     RFileLogger::WriteFormat(D_LOG_DIR, D_LOG_FILE, EFileLoggingModeAppend, _L("\t[M]\t%S\tAlloc:\t%d\tHeap:\t%d"), &aMsg, size, User::Heap().Size());	
       
   140 }
       
   141 
       
   142 #define __HEAP(_msg) __impl_heap(_L(_msg));
       
   143 // ----------------------------------------------------------------------------
       
   144 //
       
   145 //
       
   146 //
       
   147 // ----------------------------------------------------------------------------
       
   148 //
       
   149 inline void __impl_print(TRefByValue<const TDesC16> aFmt, ...)
       
   150 {
       
   151 	VA_LIST list;
       
   152 	VA_START(list,aFmt);
       
   153 	
       
   154 	//Log event
       
   155     RFileLogger::WriteFormat(D_LOG_DIR, D_LOG_FILE, EFileLoggingModeAppend, aFmt, list);
       
   156 }
       
   157 
       
   158 inline void __impl_print8(TRefByValue<const TDesC8> aFmt, ...)
       
   159 {
       
   160 	VA_LIST list;
       
   161 	VA_START(list,aFmt);
       
   162 	
       
   163 	//Log event
       
   164     RFileLogger::WriteFormat(D_LOG_DIR, D_LOG_FILE, EFileLoggingModeAppend, aFmt, list);
       
   165 }
       
   166 
       
   167 
       
   168 inline void __impl_prints(const TDesC& aMsg)
       
   169 {
       
   170 	RFileLogger::WriteFormat(D_LOG_DIR, D_LOG_FILE, EFileLoggingModeAppend, _L("\t[I]\t%S"), &aMsg);	
       
   171 }
       
   172 
       
   173 // It is a correct approach to define function-like macroses but GCC give
       
   174 // compilatoin error.
       
   175 // #define __PRINT(_fmt, ...) __impl_print(_L(_fmt), __VA_ARGS__);
       
   176 //#define __PRINT8(_fmt, ...) __impl_print8(_L8(_fmt), __VA_ARGS__);
       
   177 //#define __PRINT(_fmt, args...) __impl_print(_L(_fmt), args);
       
   178 //#define __PRINT8(_fmt, args...) __impl_print8(_L8(_fmt), args);
       
   179 #define __PRINTS(_str) __impl_prints(_L(_str));
       
   180 
       
   181 //#define __PRINT_IF_ERROR(_stmt, _fmt) { TInt _error = _stmt; if (_error != KErrNone) __PRINT(_fmt, _error); };
       
   182 //#define __TRAP_AND_PRINT_IF_ERROR(_stmt, _fmt) { TRAPD(_error, _stmt); if (_error != KErrNone) __PRINT(_fmt, _error); };
       
   183 
       
   184 //#endif //_DEBUG
       
   185 
       
   186 #endif