sysresmonitoring/oommonitor/inc/OomTraces.h
branchRCL_3
changeset 1 0fdb7f6b0309
child 19 924385140d98
equal deleted inserted replaced
0:2e3d3ce01487 1:0fdb7f6b0309
       
     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:  Includes some common defines used in the OOM monitor app.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef OOMTRACES_H
       
    20 #define OOMTRACES_H
       
    21 
       
    22 #include "traceconfiguration.hrh"
       
    23 #include "tracedefs.h"
       
    24 
       
    25 #ifdef TRACE_INTO_FILE
       
    26 #include <flogger.h> // RFileLogger
       
    27 #else
       
    28 #include <e32debug.h> // RDebug
       
    29 #endif
       
    30 
       
    31 //-----------------------------------------------------------------------------
       
    32 // Constants
       
    33 //-----------------------------------------------------------------------------
       
    34 //
       
    35 
       
    36 /**
       
    37 * Prefix error trace
       
    38 */
       
    39 #define _PREFIX_ERROR( aMsg ) _PREFIX_TRACE( "[ERROR: %d]: " L##aMsg )
       
    40 
       
    41 /**
       
    42 * Prefix info trace.
       
    43 */
       
    44 #define _PREFIX_INFO( aMsg ) _PREFIX_TRACE( "[INFO]: " L##aMsg )
       
    45 
       
    46 /**
       
    47 * Define needed directories if TRACE_INTO_FILE macro in use
       
    48 */
       
    49 #ifdef TRACE_INTO_FILE
       
    50 
       
    51     _LIT( KDir, "oommonitor2" );
       
    52     _LIT( KFile, "oommonitor2_log.txt" );
       
    53     _LIT( KFullPath, "c:\\logs\\oommonitor2\\" );
       
    54 
       
    55 #endif
       
    56 
       
    57 //-----------------------------------------------------------------------------
       
    58 // Error trace macros
       
    59 //-----------------------------------------------------------------------------
       
    60 //
       
    61 #ifdef ERROR_TRACE
       
    62 
       
    63     /**
       
    64     * Error trace definitions.
       
    65     */
       
    66     #ifdef TRACE_INTO_FILE
       
    67 
       
    68         #define ERROR( aErr, aMsg )\
       
    69             {\
       
    70             if( aErr < KErrNone )\
       
    71                 {\
       
    72                 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, \
       
    73                     _PREFIX_ERROR( aMsg ), aErr );\
       
    74                 }\
       
    75             }
       
    76         #define ERROR_1( aErr, aMsg, aP1 )\
       
    77             {\
       
    78             if( aErr < KErrNone )\
       
    79                 {\
       
    80                 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, \
       
    81                     _PREFIX_ERROR( aMsg ), aErr, aP1 );\
       
    82                 }\
       
    83             }
       
    84         #define ERROR_2( aErr, aMsg, aP1, aP2 )\
       
    85             {\
       
    86             if( aErr < KErrNone )\
       
    87                 {\
       
    88                 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, \
       
    89                     _PREFIX_ERROR( aMsg ), aErr, aP1, aP2 );\
       
    90                 }\
       
    91             }
       
    92         #define ERROR_3( aErr, aMsg, aP1, aP2, aP3 )\
       
    93             {\
       
    94             if( aErr < KErrNone )\
       
    95                 {\
       
    96                 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, \
       
    97                     _PREFIX_ERROR( aMsg ), aErr, aP1, aP2, aP3 );\
       
    98                 }\
       
    99             }
       
   100 
       
   101     #else//TRACE_INTO_FILE not defined
       
   102 
       
   103         #define ERROR( aErr, aMsg )\
       
   104             {\
       
   105             if( aErr < KErrNone )\
       
   106                 {\
       
   107                 RDebug::Print( _PREFIX_ERROR( aMsg ), aErr );\
       
   108                 }\
       
   109             }
       
   110         #define ERROR_1( aErr, aMsg, aP1 )\
       
   111             {\
       
   112             if( aErr < KErrNone )\
       
   113                 {\
       
   114                 RDebug::Print( _PREFIX_ERROR( aMsg ), aErr, aP1 );\
       
   115                 }\
       
   116             }
       
   117         #define ERROR_2( aErr, aMsg, aP1, aP2 )\
       
   118             {\
       
   119             if( aErr < KErrNone )\
       
   120                 {\
       
   121                 RDebug::Print( _PREFIX_ERROR( aMsg ), aErr, aP1, aP2 );\
       
   122                 }\
       
   123             }
       
   124         #define ERROR_3( aErr, aMsg, aP1, aP2, aP3 )\
       
   125             {\
       
   126             if( aErr < KErrNone )\
       
   127                 {\
       
   128                 RDebug::Print( _PREFIX_ERROR( aMsg ), aErr, aP1, aP2, aP3 );\
       
   129                 }\
       
   130             }
       
   131 
       
   132     #endif//TRACE_INTO_FILE
       
   133 
       
   134     #define ERROR_GEN( aMsg ) ERROR( KErrGeneral, aMsg )
       
   135     #define ERROR_GEN_1( aMsg, aP1 ) ERROR_1( KErrGeneral, aMsg, aP1 )
       
   136     #define ERROR_GEN_2( aMsg, aP1, aP2 ) ERROR_2( KErrGeneral, aMsg, aP1, aP2 )
       
   137     #define ERROR_GEN_3( aMsg, aP1, aP2, aP3 ) ERROR_3( KErrGeneral, aMsg, aP1, aP3 )
       
   138 
       
   139     #define ERROR_PARAM(_p) _p
       
   140 
       
   141     #define TRAPD_ERR( aErr, aStmt ) TRAPD( aErr, aStmt )
       
   142     #define TRAP_ERR( aErr, aStmt ) TRAP( aErr, aStmt )
       
   143 
       
   144     #define TRAP_AND_LEAVE(_s,_t) \
       
   145         { TRAPD(_e,_s); ERROR(_e,_t); User::LeaveIfError(_e); }
       
   146 
       
   147 #else//ERROR_TRACE not defined
       
   148 
       
   149     #define ERROR( aErr, aMsg )
       
   150     #define ERROR_1( aErr, aMsg, aP1 )
       
   151     #define ERROR_2( aErr, aMsg, aP1, aP2 )
       
   152     #define ERROR_3( aErr, aMsg, aP1, aP2, aP3 )
       
   153     #define ERROR_GEN( aMsg )
       
   154     #define ERROR_GEN_1( aMsg, aP1 )
       
   155     #define ERROR_GEN_2( aMsg, aP1, aP2 )
       
   156     #define ERROR_GEN_3( aMsg, aP1, aP2, aP3 )
       
   157 
       
   158     #define ERROR_PARAM(_p)
       
   159 
       
   160     #define TRAPD_ERR( aErr, aStmt ) TRAP_IGNORE( aStmt )
       
   161     #define TRAP_ERR( aErr, aStmt )  TRAP_IGNORE( aStmt )
       
   162 
       
   163     #define TRAP_AND_LEAVE(_s,_t) { _s; }
       
   164 
       
   165 #endif//ERROR_TRACE
       
   166 
       
   167 //-----------------------------------------------------------------------------
       
   168 // Info trace macros
       
   169 //-----------------------------------------------------------------------------
       
   170 //
       
   171 #ifdef INFO_TRACE
       
   172 
       
   173     /**
       
   174     * Info log message definitions.
       
   175     */
       
   176     #ifdef TRACE_INTO_FILE
       
   177 
       
   178         #define TRACES( aMsg )\
       
   179             {\
       
   180             RFileLogger::Write( KDir, KFile, EFileLoggingModeAppend, \
       
   181                 _PREFIX_INFO( aMsg ) );\
       
   182             }
       
   183         #define TRACES1( aMsg, aP1 )\
       
   184             {\
       
   185             RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, \
       
   186                 _PREFIX_INFO( aMsg ), aP1 );\
       
   187             }
       
   188         #define TRACES2( aMsg, aP1, aP2 )\
       
   189             {\
       
   190             RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, \
       
   191                 _PREFIX_INFO( aMsg ), aP1, aP2 );\
       
   192             }
       
   193         #define TRACES3( aMsg, aP1, aP2, aP3 )\
       
   194             {\
       
   195             RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, \
       
   196                 _PREFIX_INFO( aMsg ), aP1, aP2, aP3 );\
       
   197             }
       
   198         #define TRACES4( aMsg, aP1, aP2, aP3, aP4 )\
       
   199             {\
       
   200             RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, \
       
   201                 _PREFIX_INFO( aMsg ), aP1, aP2, aP3, aP4 );\
       
   202             }
       
   203         #define TRACES5( aMsg, aP1, aP2, aP3, aP4, aP5 )\
       
   204             {\
       
   205             RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, \
       
   206                 _PREFIX_INFO( aMsg ), aP1, aP2, aP3, aP4, aP5 );\
       
   207             }
       
   208 
       
   209     #else//TRACE_INTO_FILE not defined
       
   210 
       
   211         #define TRACES( aMsg )\
       
   212             {\
       
   213             RDebug::Print( _PREFIX_INFO( aMsg ) );\
       
   214             }
       
   215         #define TRACES1( aMsg, aP1 )\
       
   216             {\
       
   217             RDebug::Print( _PREFIX_INFO( aMsg ), aP1 );\
       
   218             }
       
   219         #define TRACES2( aMsg, aP1, aP2 )\
       
   220             {\
       
   221             RDebug::Print( _PREFIX_INFO( aMsg ), aP1, aP2 );\
       
   222             }
       
   223         #define TRACES3( aMsg, aP1, aP2, aP3 )\
       
   224             {\
       
   225             RDebug::Print( _PREFIX_INFO( aMsg ), aP1, aP2, aP3 );\
       
   226             }
       
   227         #define TRACES4( aMsg, aP1, aP2, aP3, aP4 )\
       
   228             {\
       
   229             RDebug::Print( _PREFIX_INFO( aMsg ), aP1, aP2, aP3, aP4 );\
       
   230             }
       
   231         #define TRACES5( aMsg, aP1, aP2, aP3, aP4, aP5 )\
       
   232             {\
       
   233             RDebug::Print( _PREFIX_INFO( aMsg ), aP1, aP2, aP3, aP4, aP5 );\
       
   234             }
       
   235 
       
   236     #endif//TRACE_INTO_FILE
       
   237 
       
   238     #define TRACES_PARAM( aParam ) aParam
       
   239 
       
   240 #else//INFO_TRACE not defined
       
   241 
       
   242     #define TRACES( aMsg )
       
   243     #define TRACES1( aMsg, aP1 )
       
   244     #define TRACES2( aMsg, aP1, aP2 )
       
   245     #define TRACES3( aMsg, aP1, aP2, aP3 )
       
   246     #define TRACES4( aMsg, aP1, aP2, aP3, aP4 )
       
   247     #define TRACES5( aMsg, aP1, aP2, aP3, aP4, aP5 )
       
   248     #define TRACES_PARAM( aParam )
       
   249 
       
   250 #endif//INFO_TRACE
       
   251 
       
   252 //-----------------------------------------------------------------------------
       
   253 // Trace current client thread name and process id
       
   254 //-----------------------------------------------------------------------------
       
   255 //
       
   256 #ifdef CLIENT_TRACE
       
   257 
       
   258     #define CLIENT( aMessage )\
       
   259         {\
       
   260         RThread thread;\
       
   261         TInt err = aMessage.Client( thread );\
       
   262         if( err == KErrNone )\
       
   263             {\
       
   264             RProcess process;\
       
   265             err = thread.Process( process );\
       
   266             if( err == KErrNone )\
       
   267                 {\
       
   268                 TPtrC thredName( thread.Name() );\
       
   269                 TUid processUid( process.SecureId() );\
       
   270                 TRACES2( "Current client process UID: [%x], thread name: [%S]",\
       
   271                     processUid,\
       
   272                     &thredName );\
       
   273                 }\
       
   274             process.Close();\
       
   275             }\
       
   276         thread.Close();\
       
   277         }
       
   278 
       
   279 #else
       
   280 
       
   281     #define CLIENT( aMessage )
       
   282 
       
   283 #endif
       
   284 
       
   285 //-----------------------------------------------------------------------------
       
   286 // Function trace macros
       
   287 //-----------------------------------------------------------------------------
       
   288 //
       
   289 #ifdef FUNC_TRACE
       
   290 
       
   291     #include <e32base.h> // TCleanupItem
       
   292 
       
   293     /**
       
   294     * Function logging definitions.
       
   295     */
       
   296     #ifdef TRACE_INTO_FILE
       
   297 
       
   298         #define FUNC( aMsg, aP1 )\
       
   299             {\
       
   300             TPtrC8 trace( _S8( aMsg ) );\
       
   301             RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, trace, aP1 );\
       
   302             }\
       
   303 
       
   304     #else//TRACE_INTO_FILE not defined
       
   305 
       
   306         #define FUNC( aMsg, aP1 )\
       
   307             {\
       
   308             RDebug::Printf( aMsg, aP1 );\
       
   309             }\
       
   310 
       
   311     #endif//TRACE_INTO_FILE
       
   312 
       
   313     /**
       
   314     * Function trace helper class.
       
   315     *
       
   316     * NOTE:
       
   317     * LC -methods cannot be trapped. Therefore if LC -method leaves
       
   318     * END trace is used instead of LEAVE trace.
       
   319     * If you have an idea how to round this problem please tell.
       
   320     */
       
   321     _LIT8( KFuncNameTerminator, "(" );
       
   322     _LIT8( KFuncLeavePatternL, "L" );
       
   323     class TFuncLog
       
   324         {
       
   325         public:
       
   326             static void Cleanup( TAny* aPtr )
       
   327                 {
       
   328                 TFuncLog* self = static_cast< TFuncLog* >( aPtr );
       
   329                 self->iLeft = ETrue;
       
   330                 FUNC( _PREFIX_CHAR("%S-LEAVE"), &self->iFunc ); // Leave detected
       
   331                 }
       
   332             inline TFuncLog( const char* aFunc ) :
       
   333                     iFunc( aFunc ? _S8( aFunc ) : _S8("") ),
       
   334                     iLeft( EFalse ),
       
   335                     iCleanupItem( Cleanup, this ),
       
   336                     iCanLeave( EFalse )
       
   337                 {
       
   338                 TInt pos( iFunc.Find( KFuncNameTerminator ) );
       
   339                 if( pos != KErrNotFound )
       
   340                     {
       
   341                     iFunc.Set( iFunc.Left( pos ) );
       
   342                     iCanLeave = !iFunc.Right(
       
   343                         KFuncLeavePatternL().Length() ).Compare( KFuncLeavePatternL );
       
   344                     if ( iCanLeave )
       
   345                         {
       
   346                         CleanupStack::PushL( iCleanupItem ); // Ignore warnings
       
   347                         }
       
   348                     }
       
   349                 FUNC( _PREFIX_CHAR("%S-START"), &iFunc );
       
   350                 }
       
   351 
       
   352             inline ~TFuncLog()
       
   353                 {
       
   354                 if ( !iLeft )
       
   355                     {
       
   356                     if ( iCanLeave )
       
   357                         {
       
   358                         CleanupStack::Pop( this ); // Pop the cleanup item
       
   359                         }
       
   360                     FUNC( _PREFIX_CHAR("%S-END"), &iFunc ); // Normally finished
       
   361                     }
       
   362                 }
       
   363 
       
   364         private: // Data
       
   365             TPtrC8 iFunc;
       
   366             TBool iLeft;
       
   367             TCleanupItem iCleanupItem;
       
   368             TBool iCanLeave;
       
   369         };
       
   370     #define FUNC_LOG TFuncLog _fl( __PRETTY_FUNCTION__ );
       
   371 
       
   372 #else//FUNC_TRACE not defined
       
   373 
       
   374     #define FUNC_LOG
       
   375 
       
   376 #endif//FUNC_TRACE
       
   377 
       
   378 //-----------------------------------------------------------------------------
       
   379 // Timestamp trace macros
       
   380 //-----------------------------------------------------------------------------
       
   381 //
       
   382 #ifdef TIMESTAMP_TRACE
       
   383 
       
   384     #define PREFIX_TIMESTAMP( aCaption ) _PREFIX_TRACE_2("[TIMESTAMP] (%d:%02d:%02d.%06d us) ",aCaption)
       
   385     #define CURRENT_TIME( aDt ) TDateTime aDt; { TTime t; t.HomeTime(); aDt = t.DateTime(); }
       
   386     #define EXTRACT_TIME( aDt ) aDt.Hour(), aDt.Minute(), aDt.Second(), aDt.MicroSecond()
       
   387 
       
   388     #ifdef TRACE_INTO_FILE
       
   389 
       
   390         #define TIMESTAMP( aCaption )\
       
   391             {\
       
   392             CURRENT_TIME( dt );\
       
   393             RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend,\
       
   394                 PREFIX_TIMESTAMP(aCaption),EXTRACT_TIME( dt ) );\
       
   395             }
       
   396 
       
   397         #define TIMESTAMP_1( aCaption, aP1 )\
       
   398             {\
       
   399             CURRENT_TIME( dt );\
       
   400             RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend,\
       
   401                 PREFIX_TIMESTAMP(aCaption),EXTRACT_TIME( dt ),aP1 );\
       
   402             }
       
   403 
       
   404         #define TIMESTAMP_2( aCaption, aP1, aP2 )\
       
   405             {\
       
   406             CURRENT_TIME( dt );\
       
   407             RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend,\
       
   408                 PREFIX_TIMESTAMP(aCaption),EXTRACT_TIME( dt ),aP1,aP2 );\
       
   409             }
       
   410 
       
   411         #define TIMESTAMP_3( aCaption, aP1, aP2, aP3 )\
       
   412             {\
       
   413             CURRENT_TIME( dt );\
       
   414             RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend,\
       
   415                 PREFIX_TIMESTAMP(aCaption),EXTRACT_TIME( dt ),aP1,aP2,aP3 );\
       
   416             }
       
   417 
       
   418     #else//TRACE_INTO_FILE not defined
       
   419 
       
   420         #define TIMESTAMP( aCaption )\
       
   421             {\
       
   422             CURRENT_TIME( dt );\
       
   423             RDebug::Print( PREFIX_TIMESTAMP(aCaption),EXTRACT_TIME( dt ) );\
       
   424             }
       
   425 
       
   426         #define TIMESTAMP_1( aCaption, aP1 )\
       
   427             {\
       
   428             CURRENT_TIME( dt );\
       
   429             RDebug::Print( PREFIX_TIMESTAMP(aCaption),EXTRACT_TIME( dt ),aP1 );\
       
   430             }
       
   431 
       
   432         #define TIMESTAMP_2( aCaption, aP1, aP2 )\
       
   433             {\
       
   434             CURRENT_TIME( dt );\
       
   435             RDebug::Print( PREFIX_TIMESTAMP(aCaption),EXTRACT_TIME( dt ),aP1,aP2 );\
       
   436             }
       
   437 
       
   438         #define TIMESTAMP_3( aCaption, aP1, aP2, aP3 )\
       
   439             {\
       
   440             CURRENT_TIME( dt );\
       
   441             RDebug::Print( PREFIX_TIMESTAMP(aCaption),EXTRACT_TIME( dt ),aP1,aP2,aP3 );\
       
   442             }
       
   443 
       
   444     #endif//TRACE_INTO_FILE
       
   445 
       
   446 #else//TIMESTAMP_TRACE not defined
       
   447 
       
   448     #define TIMESTAMP( aCaption )
       
   449     #define TIMESTAMP_1( aCaption, aP1 )
       
   450     #define TIMESTAMP_2( aCaption, aP1, aP2 )
       
   451     #define TIMESTAMP_3( aCaption, aP1, aP2, aP3 )
       
   452 
       
   453 #endif//TIMESTAMP_TRACE
       
   454 
       
   455 #ifdef _DEBUG
       
   456 
       
   457     #include <e32debug.h> // RDebug
       
   458 
       
   459     static void Panic( const TDesC8& aFileName, const TInt aLineNum )
       
   460         {
       
   461         TPath name;
       
   462         name.Copy( aFileName );
       
   463         RDebug::Print( _L( "Assertion failed in file=%S, line=%d" ), &name, aLineNum );
       
   464         User::Invariant();
       
   465         }
       
   466 
       
   467     #define ASSERT_ALWAYS_TRACE Panic( _L8(__FILE__), __LINE__ );
       
   468     #define ASSERT_TRACE( _s ) if ( !( _s ) ) { ASSERT_ALWAYS_TRACE; }
       
   469 
       
   470 #else // _DEBUG
       
   471 
       
   472     #define ASSERT_ALWAYS_TRACE
       
   473     #define ASSERT_TRACE( _s )
       
   474 
       
   475 #endif // _DEBUG
       
   476 
       
   477 #define TRACE_MATRIX( aMsg, aMatrix ) \
       
   478     TRACES( aMsg ); \
       
   479     TRACES( "------------------------------------------------" ); \
       
   480     TRACES3( "       [%f %f %f]", (TReal)(aMatrix)[0], (TReal)(aMatrix)[1], (TReal)(aMatrix)[2] ); \
       
   481     TRACES3( "Matrix [%f %f %f]", (TReal)(aMatrix)[3], (TReal)(aMatrix)[4], (TReal)(aMatrix)[5] ); \
       
   482     TRACES3( "       [%f %f %f]", (TReal)(aMatrix)[6], (TReal)(aMatrix)[7], (TReal)(aMatrix)[8] ); \
       
   483     TRACES( "------------------------------------------------" );
       
   484 
       
   485 #endif      // OOMTRACES_H
       
   486             
       
   487 // End of File