memspy/Driver/Kernel/Include/MemSpyDriverHeapWalker.h
branchRCL_3
changeset 20 ca8a1b6995f6
parent 0 a03f92240627
child 21 52e343bb8f80
equal deleted inserted replaced
19:07b41fa8d1dd 20:ca8a1b6995f6
    27 
    27 
    28 // User includes
    28 // User includes
    29 #include "MemSpyDriverHeap.h"
    29 #include "MemSpyDriverHeap.h"
    30 #include "MemSpyDriverHeapStatistics.h"
    30 #include "MemSpyDriverHeapStatistics.h"
    31 
    31 
       
    32 #include "heaputils.h"
       
    33 using namespace LtkUtils;
    32 
    34 
    33 // Heap walker observer interface - can be used to make a record of each cell
    35 // Heap walker observer interface - can be used to make a record of each cell
    34 class MMemSpyHeapWalkerObserver
    36 class MMemSpyHeapWalkerObserver
    35     {
    37     {
    36 public:
    38 public:
    37     virtual TBool HandleHeapCell( TInt aCellType, TAny* aCellAddress, TInt aLength, TInt aNestingLevel, TInt aAllocNumber ) = 0;
    39     virtual TBool HandleHeapCell(TMemSpyDriverCellType aCellType, TAny* aCellAddress, TInt aLength, TInt aNestingLevel, TInt aAllocNumber) = 0;
    38     virtual void HandleHeapWalkInit() = 0;
    40     virtual void HandleHeapWalkInit() = 0;
    39     };
       
    40 
       
    41 
       
    42 
       
    43 // A null observer that is used to collect basic statistics
       
    44 class TMemSpyHeapWalkerNullObserver : public MMemSpyHeapWalkerObserver
       
    45     {
       
    46 public:
       
    47     TBool HandleHeapCell( TInt /*aCellType*/, TAny* /*aCellAddress*/, TInt /*aLength*/, TInt /*aNestingLevel*/, TInt /*aAllocNumber*/ ) { return ETrue; }
       
    48     void HandleHeapWalkInit() { }
       
    49     };
    41     };
    50 
    42 
    51 
    43 
    52 // Heap walker - allows in-place walking of any heap
    44 // Heap walker - allows in-place walking of any heap
    53 class RMemSpyDriverHeapWalker
    45 class RMemSpyDriverHeapWalker
    54     {
    46     {
    55 public:
    47 public:
    56     RMemSpyDriverHeapWalker( RMemSpyDriverRHeapBase& aHeap, TBool aDebugAllocator );
    48 	RMemSpyDriverHeapWalker(RMemSpyDriverRHeapBase& aHeap, MMemSpyHeapWalkerObserver* aObserver=NULL);
    57     RMemSpyDriverHeapWalker( RMemSpyDriverRHeapBase& aHeap, TBool aDebugAllocator, MMemSpyHeapWalkerObserver& aObserver );
       
    58 		
    49 		
    59 public: // API
    50 public: // API
    60     TInt Traverse();
    51     TInt Traverse();
    61     void CopyStatsTo( TMemSpyHeapStatisticsRHeap& aStats );
    52     void CopyStatsTo( TMemSpyHeapStatisticsRHeap& aStats );
    62     void SetObserver( MMemSpyHeapWalkerObserver* aObserver );
    53     void SetObserver( MMemSpyHeapWalkerObserver* aObserver );
    63     inline void SetPrintDebug() { iPrintDebug = ETrue; }
    54     inline void SetPrintDebug() { iPrintDebug = ETrue; }
    64     inline const TMemSpyHeapWalkStatistics& Stats() const { return iStats; }
    55     inline const TMemSpyHeapWalkStatistics& Stats() const { return iStats; }
    65 
    56 
    66 public: // Utility functions
       
    67     static TAny* KernelAddress( TAny* aUserAddress, TUint aDelta );
       
    68     static TAny* UserAddress( TAny* aKernelAddress, TUint aDelta );
       
    69     static RMemSpyDriverRHeapBase::SCell* CellByUserAddress( TAny* aAddress, TUint aDelta );
       
    70 
       
    71 private: // Internal methods
    57 private: // Internal methods
       
    58 	static TBool CellCallback(RAllocatorHelper& aHelper, TAny* aContext, RAllocatorHelper::TExtendedCellType aCellType, TLinAddr aCellAddress, TInt aLength);
       
    59 	TBool DoCellCallback(RAllocatorHelper& aHelper, RAllocatorHelper::TExtendedCellType aCellType, TLinAddr aCellAddress, TInt aLength);
    72     TBool NotifyCell( TMemSpyDriverCellType aType, TAny* aCellAddress, TInt aLength, TInt aNestingLevel = -1, TInt aAllocNumber = -1 );
    60     TBool NotifyCell( TMemSpyDriverCellType aType, TAny* aCellAddress, TInt aLength, TInt aNestingLevel = -1, TInt aAllocNumber = -1 );
    73     //
    61     //
    74     void UpdateStats( TMemSpyDriverCellType aType, TAny* aCellAddress, TInt aLength, TInt aNestingLevel, TInt aAllocNumber );
    62     void UpdateStats( TMemSpyDriverCellType aType, TAny* aCellAddress, TInt aLength, TInt aNestingLevel, TInt aAllocNumber );
    75     void InitialiseStats();
    63     void InitialiseStats();
    76     void FinaliseStats();
    64     void FinaliseStats();
    77     void PrintStats();
    65     void PrintStats();
    78     //
    66     //
    79     TAny* KernelAddress( TAny* aUserAddress ) const;
       
    80     TAny* UserAddress( TAny* aKernelAddress ) const;
       
    81     //
       
    82     inline TBool PrintDebug() const { return iPrintDebug; }
    67     inline TBool PrintDebug() const { return iPrintDebug; }
    83 
    68 
    84 private:
    69 private:
    85     RMemSpyDriverRHeapBase& iHeap;
    70     RMemSpyDriverRHeapBase& iHeap;
    86     TBool iIsDebugAllocator;
       
    87     TBool iPrintDebug;
    71     TBool iPrintDebug;
    88     MMemSpyHeapWalkerObserver* iObserver;
    72     MMemSpyHeapWalkerObserver* iObserver;
    89     TMemSpyHeapWalkStatistics iStats;
    73     TMemSpyHeapWalkStatistics iStats;
    90     };
    74     };
    91 
    75