mmappfw_plat/mpx_common_definition_api/inc/mpxlog.h
changeset 0 a2952bb97e68
equal deleted inserted replaced
-1:000000000000 0:a2952bb97e68
       
     1 /*
       
     2 * Copyright (c) 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 print macros
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef MPXLOG_H
       
    21 #define MPXLOG_H
       
    22 
       
    23 // INCLUDES
       
    24 #include <e32std.h>
       
    25 #include <e32svr.h>
       
    26 #include <e32property.h>
       
    27 
       
    28 #ifdef _DEBUG
       
    29 #define MPX_PERFORMANCE_LOG
       
    30 #endif
       
    31 
       
    32 // MACROS
       
    33 #ifdef _DEBUG
       
    34 #define MPX_DEBUG1(s)               RDebug::Print(_L(#s))
       
    35 #define MPX_DEBUG2(s, a)            RDebug::Print(_L(#s), a)
       
    36 #define MPX_DEBUG3(s, a, b)         RDebug::Print(_L(#s), a, b)
       
    37 #define MPX_DEBUG4(s, a, b, c)      RDebug::Print(_L(#s), a, b, c)
       
    38 #define MPX_DEBUG5(s, a, b, c, d)   RDebug::Print(_L(#s), a, b, c, d)
       
    39 #define MPX_FUNC(fn)                TFunctionTrace _s(_L(fn));
       
    40 #define MPX_FUNC_EX(fn)             TFunctionTrace _s(_L(fn), this);
       
    41 class TFunctionTrace
       
    42     {
       
    43     public:
       
    44         TFunctionTrace(TRefByValue<const TDesC> aName, TAny* aThis=NULL):
       
    45             iStr(aName), iThis(aThis)
       
    46             {
       
    47             iThis ? MPX_DEBUG3("-->%S, 0x%08x",&iStr, iThis) : MPX_DEBUG2("-->%S",&iStr);
       
    48             }
       
    49         ~TFunctionTrace()
       
    50             {
       
    51             iThis ? MPX_DEBUG3("<--%S, 0x%08x",&iStr, iThis) : MPX_DEBUG2("<--%S",&iStr);
       
    52             }
       
    53     private:
       
    54         TPtrC iStr;
       
    55         TAny* iThis;
       
    56     };
       
    57 
       
    58 // print out (index, id) for each level and the first 15 ids at top level
       
    59 #define MPX_DEBUG_PATH(aPath) { \
       
    60     TInt dlevels = (aPath).Levels();\
       
    61     TInt dcount = (aPath).Count();\
       
    62     MPX_DEBUG3("Collection Path debug: levels=  %d, count = %d", dlevels, dcount);\
       
    63     for (TInt i=0; i<dlevels;++i)\
       
    64         {\
       
    65         MPX_DEBUG4("Collection Path debug: Level[%d] = (index %d, id 0x%08x)", i, (aPath).Index(i), (aPath).Id(i).iId1);\
       
    66         }\
       
    67     if (dcount > 0)\
       
    68         {\
       
    69         TInt index = (aPath).Index();\
       
    70         MPX_DEBUG2("Collection Path debug current index %d", index);\
       
    71         if (index>=0 && index<dcount)\
       
    72             {\
       
    73             CMPXCollectionPath* dpath = const_cast<CMPXCollectionPath*>(&aPath);\
       
    74             dpath->SetToFirst();\
       
    75             TInt ditem(0);\
       
    76             do\
       
    77                 {\
       
    78                 MPX_DEBUG3("Collection Path debug top level: item %d = id 0x%08x", ditem, dpath->Id().iId1);\
       
    79                 } while (++(*dpath) && ++ditem < 15 );\
       
    80             dpath->Set(index);\
       
    81             }\
       
    82         else\
       
    83             {\
       
    84             MPX_DEBUG1("Collection Path debug: Invalid current index");\
       
    85             }\
       
    86         }\
       
    87     }
       
    88 
       
    89 #define MPX_DEBUG_THREAD(ss) { \
       
    90     RProcess process; \
       
    91     TFullName fullName; \
       
    92     process.FullName( fullName ); \
       
    93     RThread thisThread; \
       
    94     _LIT(_ss, ss); \
       
    95     MPX_DEBUG5("%S: process=%S, thread=%d, this=0x%08x", &_ss, &fullName, (TUint)thisThread.Id(), this); \
       
    96     }
       
    97 
       
    98 _LIT(_KMPXErrorInfo, "##MPX Error##: error %d file %s line %d");
       
    99 #define MPX_S(a) _S(a)
       
   100 #define MPX_ERROR_LOG(aErr) {\
       
   101     if (aErr) RDebug::Print(_KMPXErrorInfo, aErr, MPX_S(__FILE__), __LINE__);\
       
   102     }
       
   103 #else
       
   104 #define MPX_DEBUG1(s)
       
   105 #define MPX_DEBUG2(s, a)
       
   106 #define MPX_DEBUG3(s, a, b)
       
   107 #define MPX_DEBUG4(s, a, b, c)
       
   108 #define MPX_DEBUG5(s, a, b, c, d)
       
   109 #define MPX_FUNC(s)
       
   110 #define MPX_FUNC_EX(fn)
       
   111 #define MPX_DEBUG_PATH(aPath)
       
   112 #define MPX_DEBUG_THREAD(ss)
       
   113 // Copy constant _KMPXErrorInfo and Macros MPX_S and MPX_ERROR_LOG from
       
   114 // _DEBUG section if intend to log error in release build.
       
   115 #define MPX_ERROR_LOG(aErr)
       
   116 #endif
       
   117 
       
   118 #ifdef MPX_PERFORMANCE_LOG
       
   119 #define MPX_PERF_CHECKPT(s)     RDebug::Print(_L("--- PERFORMANCE CHECK POINT ---"));\
       
   120                                 RDebug::Print(_L(#s));
       
   121 #define MPX_PERF_START(fn) TPerfTrace perf__##fn (_L(#fn)); perf__##fn.Start();
       
   122 #define MPX_PERF_END(fn) perf__##fn.End();
       
   123 
       
   124 #define MPX_PERF_START_EX(fn) TPerfTrace perf__##fn (_L(#fn)); perf__##fn.StartEx();
       
   125 #define MPX_PERF_END_EX(fn) TPerfTrace perf__##fn (_L(#fn)); perf__##fn.EndEx();
       
   126 #define KAppUidMusicPlayerPerf 300000
       
   127 #define KMPXPerfTop32 1
       
   128 #define KMPXPerfBottom32 2 
       
   129 
       
   130 class TPerfTrace
       
   131     {
       
   132     public:
       
   133         TPerfTrace(TRefByValue<const TDesC> aName):
       
   134             iStr(aName)
       
   135             {
       
   136             }
       
   137         void TPerfTrace::Start()
       
   138             {
       
   139             iTime.UniversalTime();
       
   140             MPX_DEBUG2("-->%S",&iStr);
       
   141             }
       
   142         void TPerfTrace::End()
       
   143             {
       
   144             TTime now;
       
   145             now.UniversalTime();
       
   146             TInt delta = I64INT(now.MicroSecondsFrom(iTime).Int64());
       
   147             MPX_DEBUG3("<--%S, time taken %d us", &iStr, delta);
       
   148             }
       
   149         void TPerfTrace::StartEx()
       
   150             {
       
   151             MPX_DEBUG2(">>> MPXPerf started %S",&iStr);
       
   152             TTime time;
       
   153             time.UniversalTime();
       
   154             TInt64 start = time.Int64();
       
   155 
       
   156             TInt err( RProperty::Define(TUid::Uid(KAppUidMusicPlayerPerf), KMPXPerfTop32, RProperty::EInt ) );
       
   157             if ( err == KErrNone || err == KErrAlreadyExists)
       
   158                 {
       
   159                 err = RProperty::Define(TUid::Uid(KAppUidMusicPlayerPerf), KMPXPerfBottom32, RProperty::EInt );
       
   160                 }
       
   161                 
       
   162             if ( err == KErrNone || err == KErrAlreadyExists )
       
   163                 {
       
   164                 TInt top32( start >> 32 );
       
   165                 TInt bottom32( start & 0xFFFFFFFF );
       
   166                 err = RProperty::Set( TUid::Uid(KAppUidMusicPlayerPerf),
       
   167                             KMPXPerfTop32,
       
   168                             top32 );
       
   169                 err = RProperty::Set( TUid::Uid(KAppUidMusicPlayerPerf),
       
   170                             KMPXPerfBottom32,
       
   171                             bottom32 );
       
   172                 }
       
   173             }
       
   174             
       
   175             
       
   176         void TPerfTrace::EndEx()
       
   177             {
       
   178             TTime end;
       
   179             end.UniversalTime();
       
   180             TInt ret( 0 );
       
   181             TInt64 s( 0 );
       
   182             TInt err( RProperty::Get( TUid::Uid(KAppUidMusicPlayerPerf), KMPXPerfTop32, ret ) );
       
   183             if ( err == KErrNone )
       
   184                 {
       
   185                 s = TInt64( ret ) << 32;
       
   186                 err = RProperty::Get( TUid::Uid(KAppUidMusicPlayerPerf), KMPXPerfBottom32, ret );
       
   187                 if ( err == KErrNone )
       
   188                     {
       
   189                     s += ret;
       
   190                     }
       
   191                 else
       
   192                     {
       
   193                     s = 0;
       
   194                     }
       
   195                 }
       
   196             TTime start(s);
       
   197             TInt delta = I64INT(end.MicroSecondsFrom(start).Int64());
       
   198             MPX_DEBUG3(">>> MPXPerf %S, time taken %d us", &iStr, delta);
       
   199             }            
       
   200     private:
       
   201         TPtrC iStr;
       
   202         TTime iTime;
       
   203     };
       
   204     
       
   205    
       
   206 #else
       
   207 #define MPX_PERF_CHECKPT(s)
       
   208 #define MPX_PERF_START(fn)
       
   209 #define MPX_PERF_END(fn)
       
   210 #define MPX_PERF_START_EX(fn)
       
   211 #define MPX_PERF_END_EX(fn)
       
   212 #endif
       
   213 
       
   214 #define MPX_TRAP(_r, _s) TRAP(_r,_s);MPX_ERROR_LOG(_r);
       
   215 #define MPX_TRAPD(_r, _s) TRAPD(_r,_s);MPX_ERROR_LOG(_r);
       
   216 
       
   217 #endif  // MPXLOG_H
       
   218 
       
   219 // End of File