memana/analyzetoolclient/dynamicmemoryhook/inc/analyzetoolmainallocator.h
changeset 2 6a82cd05fb1e
parent 1 3ff3fecb12fe
equal deleted inserted replaced
1:3ff3fecb12fe 2:6a82cd05fb1e
     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:  Declaration of the class RAnalyzeToolMainAllocator.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef ANALYZETOOLMAINALLOCATOR_H
       
    20 #define ANALYZETOOLMAINALLOCATOR_H
       
    21 
       
    22 // INCLUDES
       
    23 #include <u32std.h>
       
    24 #include "codeblock.h"
       
    25 #include <analyzetool/atstorageserverclnt.h>
       
    26 #include <analyzetool/analyzetool.h>
       
    27 #include <analyzetool/atcommon.h>
       
    28 #include "analyzetoolmemoryallocator.h"
       
    29 #include "analyzetooleventhandlernotifier.h"
       
    30 
       
    31 // FORWARD DECLARATIONS
       
    32 class CLibraryEventHandler;
       
    33 
       
    34 // CLASS DECLARATION
       
    35 
       
    36 /**
       
    37 *  Class which overloads the RAlloctor functions and provides access to 
       
    38 *  the overloaded functions  
       
    39 */
       
    40 class RAnalyzeToolMainAllocator : public RAnalyzeToolMemoryAllocator, 
       
    41 								  public MAnalyzeToolEventhandlerNotifier
       
    42     {
       
    43 
       
    44     public:
       
    45 
       
    46         /**
       
    47         * C++ default constructor.
       
    48         * @param aNotFirst Is this first thread using this heap
       
    49         * @param aFileName The name of the log file
       
    50         * @param aLogOption The logging option for storage server
       
    51         * @param aIsDebug Determines whether a binary is UDEB or UREL
       
    52         * @param aAllocCallStackSize Max number of stored callstack items when memory allocated
       
    53         * @param aFreeCallStackSize Max number of stored callstack items when memory freed
       
    54         */
       
    55         RAnalyzeToolMainAllocator( TBool aNotFirst,
       
    56                 const TFileName aFileName,
       
    57                 TUint32 aLogOption, TUint32 aIsDebug,
       
    58                 TUint32 aAllocCallStackSize,
       
    59                 TUint32 aFreeCallStackSize );
       
    60 
       
    61         /**
       
    62         * Destructor.
       
    63         */
       
    64         ~RAnalyzeToolMainAllocator();
       
    65 
       
    66         /**
       
    67         * Allocates a cell of specified size from the heap.
       
    68         * @param aSize The size of the cell to be allocated from the heap. 
       
    69         * @return TAny* A pointer to the allocated cell.
       
    70         */
       
    71         TAny* Alloc( TInt aSize );
       
    72 
       
    73         /**
       
    74         * Frees the specified cell and returns it to the heap.
       
    75         * @param aPtr A pointer to a cell to be freed.
       
    76         */
       
    77         void Free( TAny* aPtr );
       
    78 
       
    79         /**
       
    80         * Increases or decreases the size of an existing cell.
       
    81         * @param aPtr A pointer to the cell to be reallocated.
       
    82         * @param aSize The new size of the cell. This may be bigger 
       
    83         *              or smaller than the size of the original cell.
       
    84         * @param aMode Flags controlling the reallocation.
       
    85         * @return TAny* A pointer to the reallocated cell. This may be the 
       
    86         *               same as the original pointer supplied through aCell.
       
    87         */
       
    88         TAny* ReAlloc( TAny* aPtr, TInt aSize, TInt aMode = 0 );
       
    89         
       
    90         /**
       
    91         * Gets the length of the available space in the specified 
       
    92         * allocated cell.
       
    93         * @param aCell A pointer to the allocated cell.
       
    94         * @return TInt The length of the available space in the allocated cell.
       
    95         */
       
    96         TInt AllocLen(const TAny* aCell) const;
       
    97 
       
    98     #ifndef __KERNEL_MODE__
       
    99 
       
   100         /**	
       
   101         * Opens this heap for shared access. Opening the heap increases 
       
   102         * the heap's access count by one.
       
   103         */
       
   104         TInt Open();
       
   105         
       
   106         /**
       
   107         * Closes this shared heap. Closing the heap decreases the heap's 
       
   108         * access count by one.
       
   109         */  	
       
   110         void Close();
       
   111 
       
   112         /**
       
   113         * The function frees excess committed space from the top of the heap.
       
   114         * The size of the heap is never reduced below the minimum size 
       
   115         * specified during creation of the heap.
       
   116         * @return TInt The space reclaimed. If no space can be reclaimed, 
       
   117                        then this value is zero.
       
   118         */
       
   119         TInt Compress();
       
   120 
       
   121         /**
       
   122         * Frees all allocated cells on this heap. 
       
   123         */
       
   124         void Reset();
       
   125 
       
   126         /**
       
   127         * Gets the number of cells allocated on this heap, and 
       
   128         * the total space allocated to them.
       
   129         * @param aTotalAllocSize On return, contains the total 
       
   130         *						 space allocated to the cells.
       
   131         * @return TInt The number of cells allocated on this heap.
       
   132         */
       
   133         TInt AllocSize( TInt& aTotalAllocSize ) const;
       
   134         
       
   135         /**
       
   136         * Gets the total free space currently available on the heap and the 
       
   137         * space available in the largest free block. The space available 
       
   138         * represents the total space which can be allocated. Note that 
       
   139         * compressing the heap may reduce the total free space available 
       
   140         * and the space available in the largest free block.
       
   141         * @param aBiggestBlock On return, contains the space available 
       
   142         *                      in the largest free block on the heap.
       
   143  
       
   144         * @return TInt The total free space currently available on the heap.
       
   145 
       
   146         */
       
   147         TInt Available( TInt& aBiggestBlock ) const;
       
   148 
       
   149 	#endif
       
   150         
       
   151         /**
       
   152         * Invocates specified debug funtionality.
       
   153         * @param aFunc The debug function
       
   154         * @param a1 Debug function specific paramenter.
       
   155         * @param a2 Debug function specific paramenter.
       
   156         * @return TInt Returns KErrNone, if successful otherwise one 
       
   157         *              of the other system-wide error codes.
       
   158         */
       
   159         TInt DebugFunction( TInt aFunc, TAny* a1 = NULL, TAny* a2 = NULL );
       
   160         
       
   161         // From MAnalyzeToolEventhandlerNotifier
       
   162         
       
   163         /**
       
   164 		* Remove killed thread from threads array.
       
   165 		* @param aThreadId - Thread Id
       
   166 		*/
       
   167 		void RemoveKilledThread( const TUint aThreadId );
       
   168 		
       
   169     protected:
       
   170 
       
   171         /**
       
   172         * Extension function
       
   173         * @param aExtensionId The extension id
       
   174         * @param a0 Extension specific paramenter.
       
   175         * @param a1 Extension specific paramenter.
       
   176         * @return TInt Returns KErrNone, if successful otherwise one 
       
   177         *              of the other system-wide error codes. 
       
   178         */
       
   179         TInt Extension_( TUint aExtensionId, TAny*& a0, TAny* a1 );
       
   180 
       
   181     public: // from RAnalyzeToolMemoryAllocator
       
   182         
       
   183         /**
       
   184         * Installs the RTraceAllocator allocator
       
   185         */
       
   186         void Uninstall();
       
   187         
       
   188         /**
       
   189         * Shares the heap
       
   190         */
       
   191         void ShareHeap();
       
   192 
       
   193     public: // inlines
       
   194     
       
   195         /**
       
   196         * Acquires the open RATStorageServer handle
       
   197         * @return RATStorageServer& The open RATStorageServer handle
       
   198         */
       
   199         inline RATStorageServer& StorageServer();
       
   200         
       
   201         /**
       
   202         * Acquires the codeblocks of the process
       
   203         * @return RArray<TCodeblock>& The process codeblocks
       
   204         */
       
   205         inline RArray<TCodeblock>& Codeblocks();
       
   206         
       
   207         /**
       
   208         * Acquires the mutex used to access shared objects
       
   209         * @return RMutex& A reference to open mutex
       
   210         */
       
   211         inline RMutex& Mutex();
       
   212         
       
   213         /**
       
   214         * Acquires the current process id
       
   215         * @return TInt The process id
       
   216         */
       
   217         inline TInt ProcessId();
       
   218 
       
   219         /**
       
   220 		* Acquires the logical channel handle
       
   221 		* @return RAnalyzeTool A reference to logical channel
       
   222 		*/
       
   223         inline RAnalyzeTool& AnalyzeTool();
       
   224  
       
   225          /**
       
   226         * Acquires information if storage server is open
       
   227         * @return TBool iStorageServerOpen
       
   228         */
       
   229         inline TBool StorageServerOpen();
       
   230                 
       
   231         /**
       
   232         * Acquires the log option type 
       
   233         * @return TUint32 iLogOption
       
   234         */        
       
   235         inline TUint32 LogOption();
       
   236         
       
   237         /**
       
   238         * Acquires the max size of call stack when memory allocated
       
   239         * @return TUint32 iAllocMaxCallStack
       
   240         */        
       
   241         inline TUint32 AllocMaxCallStack();
       
   242         
       
   243         /**
       
   244          * Acquires the max size of call stack when memory freed
       
   245          * @return TUint32 iFreeMaxCallStack
       
   246          */
       
   247         inline TUint32 FreeMaxCallStack();
       
   248 
       
   249     private: // private functions
       
   250 
       
   251         /**
       
   252         * Log the process initial information
       
   253         * @param aFileName The name of the log file
       
   254         * @param aLogOption The logging option for storage serve
       
   255         * @param aIsDebug Determines whether a binary is UDEB or UREL
       
   256         */
       
   257         void LogProcessInformation( const TFileName aFileName, TUint32 aLogOption,
       
   258                                                                 TUint32 aIsDebug );
       
   259 
       
   260         /**
       
   261         * Find the current thread which is using the heap
       
   262         * @param aStackStart A reference where the stack start is stored
       
   263         * @return TBool ETrue if a thread can be found, EFalse otherwise
       
   264         */
       
   265         TBool FindCurrentThreadStack( TUint32& aStackStart );
       
   266         
       
   267         /**
       
   268         * Installs the eventhandler, if possible
       
   269         */
       
   270         void InstallEventHandler();
       
   271 
       
   272     private: // member variables
       
   273             
       
   274         /* Handle to the RATStorageServer */
       
   275         RATStorageServer iStorageServer;
       
   276 
       
   277         /* Handle to the RAnalyzeTool */		
       
   278         RAnalyzeTool iAnalyzeTool;           
       
   279         
       
   280         /* A flag for indicating that the RAnalyzeTool is open */
       
   281         TBool iAnalyzeToolOpen;
       
   282 
       
   283         /* A flag for indicating that the device driver is loaded */
       
   284         TBool iDeviceDriverLoaded;
       
   285         
       
   286         /* The codeblocks of the process */
       
   287         RArray<TCodeblock> iCodeblocks;
       
   288 
       
   289         /* The handler for kerner events */
       
   290         CLibraryEventHandler* iEventHandler;
       
   291 
       
   292         /* The mutex for serializing access to the shared resources */
       
   293         mutable RMutex iMutex;	
       
   294         	
       
   295         /* Array for storing the callstack */	
       
   296         TFixedArray <TUint32, KATMaxCallstackLength> iCallStack;
       
   297 
       
   298         /* Array for storing the reallocation callstack */	
       
   299         TFixedArray <TUint32, KATMaxCallstackLength> iReCallStack;
       
   300 
       
   301         /* Array for storing the reallocation callstack */	
       
   302         TFixedArray<TUint32, KATMaxFreeCallstackLength> iFreeCallStack;
       
   303                 
       
   304         /* Array of threads using this heap */
       
   305         RArray<TThreadStack> iThreadArray;
       
   306 
       
   307         /* A flag for indicating that the RATStorageServer is open */
       
   308         TBool iStorageServerOpen;
       
   309         
       
   310         /* Log option */
       
   311         TUint32 iLogOption;
       
   312 
       
   313         /* The process id */
       
   314         TUint iProcessId;	
       
   315         
       
   316         /* Max items on stored call stack when memory allocated */
       
   317         TUint32 iAllocMaxCallStack;
       
   318         
       
   319         /* Max items on stored call stack when memory freed */
       
   320         TUint32 iFreeMaxCallStack;
       
   321         
       
   322     };
       
   323 
       
   324 // INLINES
       
   325 #include "analyzetoolmainallocator.inl"
       
   326 
       
   327 #endif // ANALYZETOOLMAINALLOCATOR_H
       
   328 
       
   329 // End of File