memspy/memspy_plat/memspy_api/include/MemSpyEngineClientInterface.h
changeset 0 a03f92240627
child 20 ca8a1b6995f6
equal deleted inserted replaced
-1:000000000000 0:a03f92240627
       
     1 /*
       
     2 * Copyright (c) 2009 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 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef MEMSPYENGINECLIENTINTERFACE_H
       
    20 #define MEMSPYENGINECLIENTINTERFACE_H
       
    21 
       
    22 
       
    23 // System includes
       
    24 #include <e32base.h>
       
    25 #include <u32std.h>
       
    26 
       
    27 // Constants
       
    28 const TInt KMemSpyClientServerVersion           = 2;
       
    29 const TInt KMemSpyListInfoForAllThreads         = -1;
       
    30 
       
    31 /**
       
    32  * Special constant to be used to indicate kernel thread id
       
    33  * when performing kernel-specific thread agnostic operations.
       
    34  *
       
    35  * Note that the kernel thread is not supported for all thread-specific
       
    36  * operation types. 
       
    37  *
       
    38  * Use this value to indicate that the kernel thread is the target
       
    39  * thread when calling the thread-specific overload of PerformOperation().
       
    40  */
       
    41 const TUint32 KMemSpyClientServerThreadIdKernel = KMaxTUint32;
       
    42 
       
    43 // Internal constants
       
    44 const TInt KMemSpyOpFlagsTypeMask               = 0x0000FFFF;
       
    45 const TInt KMemSpyOpFlagsInclusionMask          = 0xFFFF0000;
       
    46 const TInt KMemSpyOpFlagsIncludesThreadId       = 0x00010000;
       
    47 const TInt KMemSpyOpFlagsIncludesThreadName     = 0x00020000;
       
    48 
       
    49 // Literal constants
       
    50 _LIT( KMemSpyServerName, "MemSpyServer" );
       
    51 _LIT( KMemSpyProcessName1, "MemSpyUI.exe" );
       
    52 _LIT( KMemSpyProcessName2, "MemSpyConsole.exe" );
       
    53 
       
    54 //
       
    55 // Supported MemSpy operation types
       
    56 //
       
    57 // Operations which can only be applied to a specific thread are
       
    58 // prefixed by [TS] - i.e. it is permitted to use the thread-specific 
       
    59 // overload of PerformOperation() for this operation type.
       
    60 //
       
    61 // Operations that can be applied only to the entire device are
       
    62 // prefixed by [ED] - i.e. it is permitted to use the 
       
    63 // thread-agnostic overload of PerformOperation() for this operation type.
       
    64 //
       
    65 // Operations that support kernel-thread-specific requests
       
    66 // are prefixed by [KS] - i.e. it is permitted to use the 
       
    67 // thread-specific overload of PerformOperation() and the thread
       
    68 // identification parameter should correspond to KMemSpyClientServerThreadIdKernel.
       
    69 // NB: The overload of PerformOperation() which supports a descriptor cannot
       
    70 // be used.
       
    71 //
       
    72 // Operations that are not relevant to a thread are prefixed
       
    73 // by [NT] - i.e. use the thread-agnostic overload of
       
    74 // PerformOperation()
       
    75 //
       
    76 // All other op codes are deemed internal and are not to be
       
    77 // used except via provided APIs.
       
    78 //
       
    79 enum TMemSpyClientServerOp
       
    80     {
       
    81     /**
       
    82      * [INTERNAL REQUEST]
       
    83      */
       
    84     EMemSpyClientServerOpMarkerFirst = 0,
       
    85 
       
    86     /**
       
    87      * [TS][ED]
       
    88      * Show basic summary information about a thread/process
       
    89      */
       
    90     EMemSpyClientServerOpSummaryInfo = EMemSpyClientServerOpMarkerFirst,
       
    91 
       
    92     /**
       
    93      * [TS][ED]
       
    94      * Show detailed summary information about a thread/process
       
    95      */
       
    96     EMemSpyClientServerOpSummaryInfoDetailed,
       
    97 
       
    98     /**
       
    99      * [TS][ED][KS]
       
   100      * Show heap information & statistics for a user-side thread
       
   101      */
       
   102     EMemSpyClientServerOpHeapInfo,
       
   103 
       
   104     /**
       
   105      * [TS][ED]
       
   106      * Prvide heap cell listings for a thread
       
   107      */
       
   108     EMemSpyClientServerOpHeapCellListing,
       
   109 
       
   110     /**
       
   111      * [TS][ED][KS]
       
   112      * Dump a thread's heap
       
   113      */
       
   114     EMemSpyClientServerOpHeapData,
       
   115 
       
   116     /**
       
   117      * [TS][ED]
       
   118      * Show summary information about a thread's stack
       
   119      */
       
   120     EMemSpyClientServerOpStackInfo,
       
   121 
       
   122     /**
       
   123      * [TS][ED]
       
   124      * Dump a thread's user-side stack
       
   125      */
       
   126     EMemSpyClientServerOpStackDataUser,
       
   127 
       
   128     /**
       
   129      * [TS][ED]
       
   130      * Dump a thread's kernel-side stack
       
   131      */
       
   132     EMemSpyClientServerOpStackDataKernel,
       
   133 
       
   134     /**
       
   135      * [TS][ED]
       
   136      * List all open files in the OS or then the open files
       
   137      * for a given thread.
       
   138      */
       
   139     EMemSpyClientServerOpOpenFiles,
       
   140     
       
   141     /**
       
   142      * [INTERNAL REQUEST]
       
   143      */
       
   144     EMemSpyClientServerOpMarkerThreadAgnosticFirst,
       
   145 
       
   146     /**
       
   147      * [ED]
       
   148      * Provide compact heap information for the entire device, which
       
   149      * can be compared with other similar listings using Heap Analyser.
       
   150      */
       
   151     EMemSpyClientServerOpHeapInfoCompact = EMemSpyClientServerOpMarkerThreadAgnosticFirst,
       
   152 
       
   153     /**
       
   154      * [ED]
       
   155      * Show compact stack information for the device
       
   156      */
       
   157     EMemSpyClientServerOpStackInfoCompact,
       
   158 
       
   159     /**
       
   160      * [NT]
       
   161      * Start the system wide memory tracker (SWMT) running, so that when
       
   162      * the timer expires, the system characteristics will be sampled
       
   163      * and any changes notified. NB: Starting the SWMT running for the first time
       
   164      * will cause an initial preparatory cycle to be established. Future updates
       
   165      * will then follow when the timer tick period expires
       
   166      */
       
   167     EMemSpyClientServerOpSystemWideMemoryTrackingTimerStart,
       
   168 
       
   169     /** 
       
   170      * [NT]
       
   171      * Stop the system wide memory tracker. No futher automatic timer-based
       
   172      * SWMT cycles will be performed unless "Force update" is utilised or the timer
       
   173      * is started again.
       
   174      */
       
   175     EMemSpyClientServerOpSystemWideMemoryTrackingTimerStop,
       
   176 
       
   177     /** 
       
   178      * [NT]
       
   179      * Reset the SWMT so that all existing cycles are discarded (which can free
       
   180      * quite a lot of memory). All operations are cancelled, the SWMT will be idle.
       
   181      * 
       
   182      * If performing manual "force updates" to the SWMT, then the SWMT should be reset
       
   183      * before starting a new test run. For timer-based SWMT sampling, this operation
       
   184      * is performed internally by MemSpy and therefore is redundant in that situation.
       
   185      */
       
   186     EMemSpyClientServerOpSystemWideMemoryTrackingReset,
       
   187 
       
   188     /**
       
   189      * [NT]
       
   190      * Force the system wide memory tracker (internal to memspy) to
       
   191      * perform a refresh
       
   192      */
       
   193     EMemSpyClientServerOpSystemWideMemoryTrackingForceUpdate,
       
   194 
       
   195     /**
       
   196      * [INTERNAL REQUEST]
       
   197      */
       
   198     EMemSpyClientServerOpSystemWideMemoryTrackingTimerPeriodSet,
       
   199 
       
   200     /**
       
   201      * [INTERNAL REQUEST]
       
   202      */
       
   203     EMemSpyClientServerOpSwitchOutputSinkFile,
       
   204 
       
   205     /**
       
   206      * [INTERNAL REQUEST]
       
   207      */
       
   208     EMemSpyClientServerOpSwitchOutputSinkTrace,
       
   209 
       
   210     /**
       
   211      * [INTERNAL REQUEST]
       
   212      */
       
   213     EMemSpyClientServerOpEnumerateKernelContainer,
       
   214 
       
   215     /**
       
   216      * [INTERNAL REQUEST]
       
   217      */
       
   218     EMemSpyClientServerOpEnumerateKernelContainerAll,
       
   219 
       
   220     /**
       
   221      * [INTERNAL REQUEST]
       
   222      */
       
   223     EMemSpyClientServerOpBitmapsSave,
       
   224 
       
   225     /**
       
   226      * [INTERNAL REQUEST]
       
   227      */
       
   228     EMemSpyClientServerOpDisableAknIconCache,
       
   229 
       
   230     /**
       
   231      * [INTERNAL REQUEST]
       
   232      */
       
   233     EMemSpyClientServerOpSendToBackground,
       
   234 
       
   235     /**
       
   236      * [INTERNAL REQUEST]
       
   237      */
       
   238     EMemSpyClientServerOpBringToForeground,
       
   239 
       
   240     /**
       
   241      * [INTERNAL REQUEST]
       
   242      */
       
   243     EMemSpyClientServerOpExit,
       
   244 
       
   245     /**
       
   246      * [INTERNAL REQUEST]
       
   247      */
       
   248     EMemSpyClientServerOpSystemWideMemoryTrackingCategoriesSet,
       
   249 
       
   250     /**
       
   251      * [INTERNAL REQUEST]
       
   252      */
       
   253     EMemSpyClientServerOpSystemWideMemoryTrackingThreadNameFilterSet,
       
   254 
       
   255     /**
       
   256      * [INTERNAL REQUEST]
       
   257      */
       
   258     EMemSpyClientServerOpSystemWideMemoryTrackingHeapDumpSet,
       
   259     
       
   260     /**
       
   261      * [INTERNAL REQUEST]
       
   262      */
       
   263     EMemSpyClientServerOpMarkerLast,
       
   264     };
       
   265 
       
   266 
       
   267 
       
   268 
       
   269 
       
   270 
       
   271 
       
   272 NONSHARABLE_CLASS( RMemSpyEngineClientInterface ) : public RSessionBase
       
   273     {
       
   274 public:
       
   275     inline RMemSpyEngineClientInterface();
       
   276     inline TInt Connect();
       
   277     inline void Close();
       
   278 
       
   279 public: // API
       
   280 
       
   281     /**
       
   282      * Thread-agnostic request function. Performs the operation in the context of
       
   283      * the entire device.
       
   284      *
       
   285      * I.e. can only be used for [NT] or [ED] requests.
       
   286      */
       
   287     inline TInt PerformOperation( TMemSpyClientServerOp aOperation );
       
   288 
       
   289     /**
       
   290      * Thread-specific request functions. Perform the requested operation in the context
       
   291      * of the specified thread id, or (possibly partial) thread name.
       
   292      *
       
   293      * To perform the operation in the context of the current thread, invoke the
       
   294      * function as follows:
       
   295      *
       
   296      *      PerformOperation( <...>, RThread().Id() );
       
   297      *
       
   298      * I.e. can only be used for [TS] requests.
       
   299      */
       
   300     inline TInt PerformOperation( TMemSpyClientServerOp aOperation, TThreadId aId );
       
   301     inline TInt PerformOperation( TMemSpyClientServerOp aOperation, const TDesC& aThreadName );
       
   302 
       
   303     /**
       
   304      * General functions to switch MemSpy's output mode.
       
   305      */
       
   306     inline TInt SwitchOutputModeFile();
       
   307     inline TInt SwitchOutputModeTrace();
       
   308 
       
   309     /**
       
   310      * Configure the system wide memory tracker timer interval (for automatic timer-based polling).
       
   311      * Change will take effect next time SWMT is started.
       
   312      */
       
   313     inline TInt SystemWideMemoryTrackerTimerIntervalSet( TInt aInterval );
       
   314 
       
   315     /**
       
   316      * Configure the system wide memory tracker categories.
       
   317      * Change will take effect next time SWMT is started.
       
   318      */
       
   319     inline TInt SystemWideMemoryTrackerCategoriesSet( TInt aCategories );
       
   320 
       
   321     /**
       
   322      * Configure the system wide memory tracker for filtering user heaps by thread name.
       
   323      * Change will take effect next time SWMT is started.
       
   324      */
       
   325     inline TInt SystemWideMemoryTrackerThreadFilterSet( const TDesC& aFilter );
       
   326     
       
   327     /**
       
   328      * Configure the system wide memory tracker for enabling/disabling Heap dumps during SWMT.
       
   329      * Change will take effect next time SWMT is started.
       
   330      */
       
   331     inline TInt SystemWideMemoryTrackerHeapDumpSet( TBool aDumpEnabled );
       
   332     
       
   333     /**
       
   334      * List the contents of a specific kernel container. See TObjectType for types.
       
   335      */
       
   336     inline TInt EnumerateKernelContainer( TObjectType aType );
       
   337 
       
   338     /**
       
   339      * List the contents of all kernel containers
       
   340      */
       
   341     inline TInt EnumerateKernelContainerAll();
       
   342 
       
   343     /**
       
   344      * Save bitmaps to memory card
       
   345      */
       
   346     inline TInt SaveAllBitmaps();
       
   347 
       
   348     /**
       
   349      * Disable AknIcon caching
       
   350      */
       
   351     inline TInt DisableAknIconCache();
       
   352 
       
   353     /**
       
   354      * Send MemSpy to the background/bring to foreground
       
   355      */
       
   356     inline TInt SendToBackground();
       
   357     inline TInt BringToForeground();
       
   358 
       
   359     /**
       
   360      * Exit MemSpy
       
   361      */
       
   362     inline TInt Exit();
       
   363     };
       
   364 
       
   365 
       
   366 
       
   367 
       
   368 
       
   369 
       
   370 
       
   371 
       
   372 
       
   373 
       
   374 
       
   375 
       
   376 
       
   377 
       
   378 inline RMemSpyEngineClientInterface::RMemSpyEngineClientInterface()
       
   379     {
       
   380     }
       
   381 
       
   382 
       
   383 inline TInt RMemSpyEngineClientInterface::Connect()
       
   384     {
       
   385     TVersion version( KMemSpyClientServerVersion, 0, 0 );
       
   386     return CreateSession( KMemSpyServerName, version );
       
   387     }
       
   388 
       
   389 
       
   390 inline void RMemSpyEngineClientInterface::Close()
       
   391     {
       
   392     RSessionBase::Close();
       
   393     }
       
   394 
       
   395 
       
   396 inline TInt RMemSpyEngineClientInterface::PerformOperation( TMemSpyClientServerOp aOperation )
       
   397     {
       
   398     TInt error = KErrNotReady;
       
   399     if  ( Handle() != KNullHandle )
       
   400         {
       
   401         const TInt opCode = aOperation;
       
   402         const TIpcArgs args( KMemSpyListInfoForAllThreads );
       
   403         //
       
   404         error = SendReceive( opCode, args );
       
   405         }
       
   406     return error;
       
   407     }
       
   408 
       
   409 
       
   410 inline TInt RMemSpyEngineClientInterface::PerformOperation( TMemSpyClientServerOp aOperation, TThreadId aId )
       
   411     {
       
   412     TInt error = KErrNotReady;
       
   413     if  ( Handle() != KNullHandle )
       
   414         {
       
   415         const TInt opCode = aOperation | KMemSpyOpFlagsIncludesThreadId;
       
   416         const TIpcArgs args( aId );
       
   417         //
       
   418         error = SendReceive( opCode, args );
       
   419         }
       
   420     return error;
       
   421     }
       
   422 
       
   423 
       
   424 inline TInt RMemSpyEngineClientInterface::PerformOperation( TMemSpyClientServerOp aOperation, const TDesC& aThreadName )
       
   425     {
       
   426     TInt error = KErrNotReady;
       
   427     if  ( Handle() != KNullHandle )
       
   428         {
       
   429         const TInt opCode = aOperation | KMemSpyOpFlagsIncludesThreadName;
       
   430         const TIpcArgs args( &aThreadName );
       
   431         //
       
   432         error = SendReceive( opCode, args );
       
   433         }
       
   434     return error;
       
   435     }
       
   436 
       
   437 
       
   438 
       
   439 
       
   440 
       
   441 
       
   442 inline TInt RMemSpyEngineClientInterface::SwitchOutputModeFile()
       
   443     {
       
   444     TInt error = KErrNotReady;
       
   445     if  ( Handle() != KNullHandle )
       
   446         {
       
   447         const TInt opCode = EMemSpyClientServerOpSwitchOutputSinkFile;
       
   448         error = SendReceive( opCode );
       
   449         }
       
   450     return error;
       
   451     }
       
   452 
       
   453 
       
   454 inline TInt RMemSpyEngineClientInterface::SwitchOutputModeTrace()
       
   455     {
       
   456     TInt error = KErrNotReady;
       
   457     if  ( Handle() != KNullHandle )
       
   458         {
       
   459         const TInt opCode = EMemSpyClientServerOpSwitchOutputSinkTrace;
       
   460         error = SendReceive( opCode );
       
   461         }
       
   462     return error;
       
   463     }
       
   464 
       
   465 
       
   466 
       
   467 
       
   468 
       
   469 
       
   470 
       
   471 
       
   472 inline TInt RMemSpyEngineClientInterface::SystemWideMemoryTrackerTimerIntervalSet( TInt aInterval )
       
   473     {
       
   474     TInt error = KErrNotReady;
       
   475     if  ( Handle() != KNullHandle )
       
   476         {
       
   477         const TInt opCode = EMemSpyClientServerOpSystemWideMemoryTrackingTimerPeriodSet;
       
   478         const TIpcArgs args( aInterval );
       
   479         //
       
   480         error = SendReceive( opCode, args );
       
   481         }
       
   482     return error;
       
   483     }
       
   484 
       
   485 
       
   486 inline TInt RMemSpyEngineClientInterface::SystemWideMemoryTrackerCategoriesSet( TInt aCategories )
       
   487     {
       
   488     TInt error = KErrNotReady;
       
   489     if  ( Handle() != KNullHandle )
       
   490         {
       
   491         const TInt opCode = EMemSpyClientServerOpSystemWideMemoryTrackingCategoriesSet;
       
   492         const TIpcArgs args( aCategories );
       
   493         //
       
   494         error = SendReceive( opCode, args );
       
   495         }
       
   496     return error;
       
   497     }
       
   498 
       
   499 
       
   500 inline TInt RMemSpyEngineClientInterface::SystemWideMemoryTrackerThreadFilterSet( const TDesC& aFilter )
       
   501     {
       
   502     TInt error = KErrNotReady;
       
   503     if  ( Handle() != KNullHandle )
       
   504         {
       
   505         const TInt opCode = EMemSpyClientServerOpSystemWideMemoryTrackingThreadNameFilterSet;
       
   506         TIpcArgs args( &aFilter );
       
   507         error = SendReceive( opCode, args );
       
   508         }
       
   509     return error;
       
   510     }
       
   511 
       
   512 
       
   513 inline TInt RMemSpyEngineClientInterface::SystemWideMemoryTrackerHeapDumpSet( TBool aDumpEnabled  )
       
   514     {
       
   515     TInt error = KErrNotReady;
       
   516     if  ( Handle() != KNullHandle )
       
   517         {
       
   518         const TInt opCode = EMemSpyClientServerOpSystemWideMemoryTrackingHeapDumpSet;
       
   519         const TIpcArgs args( aDumpEnabled );
       
   520         error = SendReceive( opCode, args );
       
   521         }
       
   522     return error;
       
   523     }
       
   524 
       
   525 
       
   526 inline TInt RMemSpyEngineClientInterface::EnumerateKernelContainer( TObjectType aType )
       
   527     {
       
   528     TInt error = KErrNotReady;
       
   529     if  ( Handle() != KNullHandle )
       
   530         {
       
   531         const TInt opCode = EMemSpyClientServerOpEnumerateKernelContainer;
       
   532         const TIpcArgs args( aType );
       
   533         //
       
   534         error = SendReceive( opCode, args );
       
   535         }
       
   536     return error;
       
   537     }
       
   538 
       
   539 
       
   540 inline TInt RMemSpyEngineClientInterface::EnumerateKernelContainerAll()
       
   541     {
       
   542     TInt error = KErrNotReady;
       
   543     if  ( Handle() != KNullHandle )
       
   544         {
       
   545         const TInt opCode = EMemSpyClientServerOpEnumerateKernelContainerAll;
       
   546         error = SendReceive( opCode );
       
   547         }
       
   548     return error;
       
   549     }
       
   550 
       
   551 
       
   552 inline TInt RMemSpyEngineClientInterface::SaveAllBitmaps()
       
   553     {
       
   554     TInt error = KErrNotReady;
       
   555     if  ( Handle() != KNullHandle )
       
   556         {
       
   557         const TInt opCode = EMemSpyClientServerOpBitmapsSave;
       
   558         error = SendReceive( opCode );
       
   559         }
       
   560     return error;
       
   561     }
       
   562 
       
   563 
       
   564 inline TInt RMemSpyEngineClientInterface::DisableAknIconCache()
       
   565     {
       
   566     TInt error = KErrNotReady;
       
   567     if  ( Handle() != KNullHandle )
       
   568         {
       
   569         const TInt opCode = EMemSpyClientServerOpDisableAknIconCache;
       
   570         error = SendReceive( opCode );
       
   571         }
       
   572     return error;
       
   573     }
       
   574 
       
   575 
       
   576 inline TInt RMemSpyEngineClientInterface::SendToBackground()
       
   577     {
       
   578     TInt error = KErrNotReady;
       
   579     if  ( Handle() != KNullHandle )
       
   580         {
       
   581         const TInt opCode = EMemSpyClientServerOpSendToBackground;
       
   582         error = SendReceive( opCode );
       
   583         }
       
   584     return error;
       
   585     }
       
   586 
       
   587 
       
   588 inline TInt RMemSpyEngineClientInterface::BringToForeground()
       
   589     {
       
   590     TInt error = KErrNotReady;
       
   591     if  ( Handle() != KNullHandle )
       
   592         {
       
   593         const TInt opCode = EMemSpyClientServerOpBringToForeground;
       
   594         error = SendReceive( opCode );
       
   595         }
       
   596     return error;
       
   597     }
       
   598 
       
   599 
       
   600 inline TInt RMemSpyEngineClientInterface::Exit()
       
   601     {
       
   602     TInt error = KErrNotReady;
       
   603     if  ( Handle() != KNullHandle )
       
   604         {
       
   605         const TInt opCode = EMemSpyClientServerOpExit;
       
   606         error = SendReceive( opCode );
       
   607         }
       
   608     return error;
       
   609     }
       
   610 
       
   611 
       
   612 #endif