mmserv/sts/tsrc/ststester/src/profileutilmacro.h
changeset 14 80975da52420
equal deleted inserted replaced
12:5a06f39ad45b 14:80975da52420
       
     1 /*
       
     2  * Copyright (c) 2010 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:
       
    15  * This file defines macros for different types of performance
       
    16  * measurement traces.
       
    17  */
       
    18 
       
    19 #ifndef PROFILEUTILMACRO_H_
       
    20 #define PROFILEUTILMACRO_H_
       
    21 
       
    22 /*
       
    23  MACROS to be defined to use profiling
       
    24  PROFILE_TIME
       
    25  PROFILE_RAM_USAGE
       
    26  PROFILE_HEAP_USAGE
       
    27  PRINT_TO_CONSOLE_HEAP_DIFF
       
    28  PRINT_TO_CONSOLE_RAM_DIFF
       
    29  PRINT_TO_CONSOLE_HEAP_DIFF
       
    30  */
       
    31 #if defined(PROFILE_TIME) || defined(PROFILE_RAM_USAGE) || defined(PROFILE_HEAP_USAGE)
       
    32 #include <e32debug.h>
       
    33 #include <hal.h>
       
    34 #endif
       
    35 
       
    36 #ifdef PROFILE_TIME
       
    37 #define TAG_TIME_PROFILING_BEGIN \
       
    38     TTime beginProfilingTime; \
       
    39     beginProfilingTime.HomeTime()
       
    40 
       
    41 #define TAG_TIME_PROFILING_END \
       
    42     TTime endProfilingTime; \
       
    43     endProfilingTime.HomeTime(); \
       
    44     TTimeIntervalMicroSeconds diffInMicroSecs = endProfilingTime.MicroSecondsFrom(beginProfilingTime)
       
    45 
       
    46 #define PRINT_TO_CONSOLE_TIME_DIFF \
       
    47     RDebug::Printf("VPROFILEDAT: %s : Time taken[%u]microseconds ", __PRETTY_FUNCTION__, diffInMicroSecs.Int64())
       
    48 #else /* Empty macros */
       
    49 #define TAG_TIME_PROFILING_BEGIN
       
    50 #define TAG_TIME_PROFILING_END
       
    51 #define PRINT_TO_CONSOLE_TIME_DIFF
       
    52 #endif /*PROFILE_TIME*/
       
    53 
       
    54 #ifdef PROFILE_RAM_USAGE
       
    55 #define TAG_RAM_PROFILING_BEGIN \
       
    56     TInt beginProfilingRAM; \
       
    57     TInt err1 = HAL::Get(HALData::EMemoryRAMFree, beginProfilingRAM)
       
    58 
       
    59 #define TAG_RAM_PROFILING_END \
       
    60     TInt endProfilingRAM; \
       
    61     TInt err2 = HAL::Get(HALData::EMemoryRAMFree, endProfilingRAM)
       
    62 
       
    63 #define PRINT_TO_CONSOLE_RAM_DIFF \
       
    64     if ((err1 == KErrNone) && (err2 == KErrNone)) \
       
    65         { \
       
    66         TInt diffRAM = (beginProfilingRAM - endProfilingRAM); \
       
    67         if ( diffRAM > 0 ) \
       
    68             { \
       
    69             RDebug::Printf("VPROFILEDAT: %s : RAM used[%u]bytes ", __PRETTY_FUNCTION__, diffRAM); \
       
    70             } \
       
    71         else \
       
    72             { \
       
    73             RDebug::Printf("VPROFILEDAT: %s : RAM freed[%u]bytes ", __PRETTY_FUNCTION__, (-diffRAM)); \
       
    74             } \
       
    75         } \
       
    76     else \
       
    77         { \
       
    78         RDebug::Printf("VPROFILEDAT: %s : Error1[%d] Error2[%d] ", __PRETTY_FUNCTION__, err1, err2); \
       
    79         }
       
    80 
       
    81 #else /* Empty macros */
       
    82 #define TAG_RAM_PROFILING_BEGIN
       
    83 #define TAG_RAM_PROFILING_END
       
    84 #define PRINT_TO_CONSOLE_RAM_DIFF
       
    85 #endif /*PROFILE_RAM_USAGE*/
       
    86 
       
    87 #ifdef PROFILE_HEAP_USAGE
       
    88 #define TAG_DEFAULT_HEAP_PROFILING_BEGIN \
       
    89     TInt beginProfilingHEAPBiggestBlock; \
       
    90     TInt beginProfilingHEAP = User::Available(beginProfilingHEAPBiggestBlock) \
       
    91 
       
    92 #define TAG_DEFAULT_HEAP_PROFILING_END \
       
    93     TInt endProfilingHEAPBiggestBlock; \
       
    94     TInt endProfilingHEAP = User::Available(endProfilingHEAPBiggestBlock) \
       
    95 
       
    96 #define PRINT_TO_CONSOLE_HEAP_DIFF \
       
    97     TInt diffHEAP = beginProfilingHEAP - endProfilingHEAP; \
       
    98     if ( diffHEAP > 0 ) \
       
    99         { \
       
   100         RDebug::Printf("VPROFILEDAT: %s : HEAP used[%u]bytes ", __PRETTY_FUNCTION__, diffHEAP); \
       
   101         } \
       
   102     else \
       
   103         { \
       
   104         RDebug::Printf("VPROFILEDAT: %s : HEAP freed[%u]bytes ", __PRETTY_FUNCTION__, (-diffHEAP)); \
       
   105         }
       
   106 #else /* Empty macros */
       
   107 #define TAG_DEFAULT_HEAP_PROFILING_BEGIN
       
   108 #define TAG_DEFAULT_HEAP_PROFILING_END
       
   109 #define PRINT_TO_CONSOLE_HEAP_DIFF
       
   110 #endif /*PROFILE_HEAP_USAGE*/
       
   111 
       
   112 #endif /*PROFILEUTILMACRO_H_*/