memana/analyzetoolclient/dynamicmemoryhook/inc/analyzetoolallocator.h
changeset 0 f0f2b8682603
equal deleted inserted replaced
-1:000000000000 0:f0f2b8682603
       
     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 RAnalyzeToolAllocator.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef ANALYZETOOLALLOCATOR_H
       
    20 #define ANALYZETOOLALLOCATOR_H
       
    21 
       
    22 // INCLUDES
       
    23 #include <u32std.h>
       
    24 #include "codeblock.h"
       
    25 #include "threadstack.h"
       
    26 #include "analyzetoolmemoryallocator.h"
       
    27 #include <analyzetool/atstorageserverclnt.h>
       
    28 #include <analyzetool/analyzetool.h>
       
    29 #include <analyzetool/atcommon.h>
       
    30 
       
    31 // CLASS DECLARATION
       
    32 
       
    33 /**
       
    34 *  Class which overloads the RAlloctor functions and provides access to 
       
    35 *  the overloaded functions  
       
    36 */
       
    37 class RAnalyzeToolAllocator : public RAnalyzeToolMemoryAllocator
       
    38     {
       
    39 
       
    40     public:
       
    41 
       
    42         /**
       
    43         * C++ default constructor.
       
    44         * @param aNotFirst Is this first thread using this heap
       
    45         * @param aStorageServer A reference to the 
       
    46         *                       <code>RATStorageServer</code> which is 
       
    47         *                       used to store kernel events
       
    48         * @param aCodeblocks A reference to array of code segments
       
    49         * @param aMutex A reference to mutex for schedule access to the 
       
    50         *                   shared resources
       
    51         * @param aProcessId A reference to the observed process id
       
    52         * @param aAnalyzeTool Reference to device driver
       
    53         * @param aStorageServerOpen Variable to check if Storage server is connected
       
    54         * @param aLogOption The logging option for storage server
       
    55         * @param aAllocCallStackSize Max number of stored callstack items when memory allocated
       
    56         * @param aFreeCallStackSize Max number of stored callstack items when memory freed
       
    57         */
       
    58         RAnalyzeToolAllocator( TBool aNotFirst,
       
    59                                RATStorageServer& aStorageServer, 
       
    60                                RArray<TCodeblock>& aCodeblocks, 
       
    61                                RMutex& aMutex, 
       
    62                                TUint aProcessId,
       
    63                                RAnalyzeTool& aAnalyzeTool,
       
    64                                TBool aStorageServerOpen,
       
    65                                TUint32 aLogOption,
       
    66                                TUint32 aAllocCallStackSize,
       
    67                                TUint32 aFreeCallStackSize );
       
    68         /**
       
    69         * Destructor.
       
    70         */                     
       
    71         ~RAnalyzeToolAllocator();
       
    72 
       
    73         /**
       
    74         * Allocates a cell of specified size from the heap.
       
    75         * @param aSize The size of the cell to be allocated from the heap. 
       
    76         * @return TAny* A pointer to the allocated cell.
       
    77         */
       
    78         TAny* Alloc( TInt aSize );
       
    79 
       
    80         /**
       
    81         * Frees the specified cell and returns it to the heap.
       
    82         * @param aPtr A pointer to a cell to be freed.
       
    83         */
       
    84         void Free( TAny* aPtr );
       
    85 
       
    86         /**
       
    87         * Increases or decreases the size of an existing cell.
       
    88         * @param aPtr A pointer to the cell to be reallocated.
       
    89         * @param aSize The new size of the cell. This may be bigger 
       
    90         *              or smaller than the size of the original cell.
       
    91         * @param aMode Flags controlling the reallocation.
       
    92         * @return TAny* A pointer to the reallocated cell. This may be the 
       
    93         *               same as the original pointer supplied through aCell.
       
    94         */
       
    95         //lint --e{1735} suppress "Virtual function has default parameter"
       
    96         TAny* ReAlloc( TAny* aPtr, TInt aSize, TInt aMode = 0 );
       
    97         
       
    98         /**
       
    99         * Gets the length of the available space in the specified 
       
   100         * allocated cell.
       
   101         * @param aCell A pointer to the allocated cell.
       
   102         * @return TInt The length of the available space in the allocated cell.
       
   103         */
       
   104         TInt AllocLen( const TAny* aCell ) const;
       
   105 
       
   106     #ifndef __KERNEL_MODE__
       
   107 
       
   108         /**
       
   109         * Opens this heap for shared access. Opening the heap increases 
       
   110         * the heap's access count by one.
       
   111         */
       
   112         TInt Open();
       
   113         
       
   114         /**
       
   115         * Closes this shared heap. Closing the heap decreases the heap's 
       
   116         * access count by one.
       
   117         */
       
   118         void Close();
       
   119 
       
   120         /**
       
   121         * The function frees excess committed space from the top of the heap.
       
   122         * The size of the heap is never reduced below the minimum size 
       
   123         * specified during creation of the heap.
       
   124         * @return TInt The space reclaimed. If no space can be reclaimed, 
       
   125                        then this value is zero.
       
   126         */
       
   127         TInt Compress();
       
   128 
       
   129         /**
       
   130         * Frees all allocated cells on this heap. 
       
   131         */
       
   132         void Reset();
       
   133 
       
   134         /**
       
   135         * Gets the number of cells allocated on this heap, and 
       
   136         * the total space allocated to them.
       
   137         * @param aTotalAllocSize On return, contains the total 
       
   138         *                        space allocated to the cells.
       
   139         * @return TInt The number of cells allocated on this heap.
       
   140         */
       
   141         TInt AllocSize( TInt& aTotalAllocSize ) const;
       
   142         
       
   143         /**
       
   144         * Gets the total free space currently available on the heap and the 
       
   145         * space available in the largest free block. The space available 
       
   146         * represents the total space which can be allocated. Note that 
       
   147         * compressing the heap may reduce the total free space available 
       
   148         * and the space available in the largest free block.
       
   149         * @param aBiggestBlock On return, contains the space available 
       
   150         *                      in the largest free block on the heap.
       
   151  
       
   152         * @return TInt The total free space currently available on the heap.
       
   153 
       
   154         */
       
   155         TInt Available( TInt& aBiggestBlock ) const;
       
   156         
       
   157     #endif
       
   158 
       
   159         /**
       
   160         * Invocates specified debug funtionality.
       
   161         * @param aFunc The debug function
       
   162         * @param a1 Debug function specific paramenter.
       
   163         * @param a2 Debug function specific paramenter.
       
   164         * @return TInt Returns KErrNone, if successful otherwise one 
       
   165         *              of the other system-wide error codes.
       
   166         */
       
   167         //lint --e{1735} suppress "Virtual function has default parameter"
       
   168         TInt DebugFunction( TInt aFunc, TAny* a1 = NULL, TAny* a2 = NULL );
       
   169 
       
   170     protected:
       
   171 
       
   172         /**
       
   173         * Extension function
       
   174         * @param aExtensionId The extension id
       
   175         * @param a0 Extension specific paramenter.
       
   176         * @param a1 Extension specific paramenter.
       
   177         * @return TInt Returns KErrNone, if successful otherwise one 
       
   178         *              of the other system-wide error codes. 
       
   179         */
       
   180         TInt Extension_( TUint aExtensionId, TAny*& a0, TAny* a1 );
       
   181 
       
   182     public: // from RAnalyzeToolMemoryAllocator
       
   183         
       
   184         /**
       
   185         * Installs the RTraceAllocator allocator
       
   186         */
       
   187         void Uninstall();
       
   188         
       
   189         /**
       
   190         * Shares the heap
       
   191         */
       
   192         void ShareHeap();
       
   193 
       
   194     private:
       
   195     
       
   196         /**
       
   197         * Find the current thread which is using the heap
       
   198         * @param aStackStart A reference where the stack start is stored
       
   199         * @return TBool ETrue if a thread can be found, EFalse otherwise
       
   200         */
       
   201         TBool FindCurrentThreadStack( TUint32& aStackStart );
       
   202 
       
   203     private: 
       
   204     
       
   205         /* Handle to the storage server*/
       
   206         RATStorageServer& iStorageServer;
       
   207 
       
   208         /* A reference to codeblocks of the observed process */            
       
   209         RArray<TCodeblock>& iCodeblocks;
       
   210 
       
   211         /* The mutex for serializing access to the shared resources */
       
   212         RMutex& iMutex;
       
   213 
       
   214         /* The process id */
       
   215         TUint iProcessId;
       
   216 
       
   217         /* Array for storing the callstack */
       
   218         TFixedArray<TUint32, KATMaxCallstackLength> iCallStack;
       
   219 
       
   220         /* Array for storing the reallocation callstack */
       
   221         TFixedArray <TUint32, KATMaxCallstackLength> iReCallStack;
       
   222 
       
   223         /* Array for storing the reallocation callstack */	
       
   224         TFixedArray<TUint32, KATMaxFreeCallstackLength> iFreeCallStack;
       
   225                 
       
   226         /* Array of threads using this heap */
       
   227         RArray<TThreadStack> iThreadArray;
       
   228 
       
   229         RAnalyzeTool& iAnalyzeTool;
       
   230 
       
   231         /* A flag for indicating that the RATStorageServer is open */
       
   232         TBool iStorageServerOpen;
       
   233 
       
   234         /* Log option */
       
   235         TUint32 iLogOption;
       
   236         
       
   237         /* Max items on stored call stack when memory allocated */
       
   238         TUint32 iAllocMaxCallStack;
       
   239         
       
   240         /* Max items on stored call stack when memory freed */
       
   241         TUint32 iFreeMaxCallStack;
       
   242         
       
   243     };
       
   244 
       
   245 #endif // ANALYZETOOLALLOCATOR_H
       
   246 
       
   247 // End of File