memspy/Driver/Kernel/Include/MemSpyDriverHeapWalker.h
branchRCL_3
changeset 59 8ad140f3dd41
parent 49 7fdc9a71d314
equal deleted inserted replaced
49:7fdc9a71d314 59:8ad140f3dd41
    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;
       
    34 
    32 
    35 // Heap walker observer interface - can be used to make a record of each cell
    33 // Heap walker observer interface - can be used to make a record of each cell
    36 class MMemSpyHeapWalkerObserver
    34 class MMemSpyHeapWalkerObserver
    37     {
    35     {
    38 public:
    36 public:
    39     virtual TBool HandleHeapCell(TMemSpyDriverCellType aCellType, TAny* aCellAddress, TInt aLength, TInt aNestingLevel, TInt aAllocNumber) = 0;
    37     virtual TBool HandleHeapCell( TInt aCellType, TAny* aCellAddress, TInt aLength, TInt aNestingLevel, TInt aAllocNumber ) = 0;
    40     virtual void HandleHeapWalkInit() = 0;
    38     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() { }
    41     };
    49     };
    42 
    50 
    43 
    51 
    44 // Heap walker - allows in-place walking of any heap
    52 // Heap walker - allows in-place walking of any heap
    45 class RMemSpyDriverHeapWalker
    53 class RMemSpyDriverHeapWalker
    46     {
    54     {
    47 public:
    55 public:
    48 	RMemSpyDriverHeapWalker(RMemSpyDriverRHeapBase& aHeap, MMemSpyHeapWalkerObserver* aObserver=NULL);
    56     RMemSpyDriverHeapWalker( RMemSpyDriverRHeapBase& aHeap, TBool aDebugAllocator );
       
    57     RMemSpyDriverHeapWalker( RMemSpyDriverRHeapBase& aHeap, TBool aDebugAllocator, MMemSpyHeapWalkerObserver& aObserver );
    49 		
    58 		
    50 public: // API
    59 public: // API
    51     TInt Traverse();
    60     TInt Traverse();
    52     void CopyStatsTo( TMemSpyHeapStatisticsRHeap& aStats );
    61     void CopyStatsTo( TMemSpyHeapStatisticsRHeap& aStats );
    53     void SetObserver( MMemSpyHeapWalkerObserver* aObserver );
    62     void SetObserver( MMemSpyHeapWalkerObserver* aObserver );
    54     inline void SetPrintDebug() { iPrintDebug = ETrue; }
    63     inline void SetPrintDebug() { iPrintDebug = ETrue; }
    55     inline const TMemSpyHeapWalkStatistics& Stats() const { return iStats; }
    64     inline const TMemSpyHeapWalkStatistics& Stats() const { return iStats; }
    56 
    65 
       
    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 
    57 private: // Internal methods
    71 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);
       
    60     TBool NotifyCell( TMemSpyDriverCellType aType, TAny* aCellAddress, TInt aLength, TInt aNestingLevel = -1, TInt aAllocNumber = -1 );
    72     TBool NotifyCell( TMemSpyDriverCellType aType, TAny* aCellAddress, TInt aLength, TInt aNestingLevel = -1, TInt aAllocNumber = -1 );
    61     //
    73     //
    62     void UpdateStats( TMemSpyDriverCellType aType, TAny* aCellAddress, TInt aLength, TInt aNestingLevel, TInt aAllocNumber );
    74     void UpdateStats( TMemSpyDriverCellType aType, TAny* aCellAddress, TInt aLength, TInt aNestingLevel, TInt aAllocNumber );
    63     void InitialiseStats();
    75     void InitialiseStats();
    64     void FinaliseStats();
    76     void FinaliseStats();
    65     void PrintStats();
    77     void PrintStats();
    66     //
    78     //
       
    79     TAny* KernelAddress( TAny* aUserAddress ) const;
       
    80     TAny* UserAddress( TAny* aKernelAddress ) const;
       
    81     //
    67     inline TBool PrintDebug() const { return iPrintDebug; }
    82     inline TBool PrintDebug() const { return iPrintDebug; }
    68 
    83 
    69 private:
    84 private:
    70     RMemSpyDriverRHeapBase& iHeap;
    85     RMemSpyDriverRHeapBase& iHeap;
       
    86     TBool iIsDebugAllocator;
    71     TBool iPrintDebug;
    87     TBool iPrintDebug;
    72     MMemSpyHeapWalkerObserver* iObserver;
    88     MMemSpyHeapWalkerObserver* iObserver;
    73     TMemSpyHeapWalkStatistics iStats;
    89     TMemSpyHeapWalkStatistics iStats;
    74     };
    90     };
    75 
    91