memspy/Driver/Kernel/Include/MemSpyDriverHeapWalker.h
changeset 0 a03f92240627
child 30 86a2e675b80a
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 #ifndef MEMSPYDRIVERHEAPWALKER_H
       
    19 #define MEMSPYDRIVERHEAPWALKER_H
       
    20 
       
    21 // System includes
       
    22 #include <e32cmn.h>
       
    23 #include <kern_priv.h>
       
    24 
       
    25 // Shared includes
       
    26 #include <memspy/driver/memspydriverenumerationsshared.h>
       
    27 
       
    28 // User includes
       
    29 #include "MemSpyDriverHeap.h"
       
    30 #include "MemSpyDriverHeapStatistics.h"
       
    31 
       
    32 
       
    33 // Heap walker observer interface - can be used to make a record of each cell
       
    34 class MMemSpyHeapWalkerObserver
       
    35     {
       
    36 public:
       
    37     virtual TBool HandleHeapCell( TInt aCellType, TAny* aCellAddress, TInt aLength, TInt aNestingLevel, TInt aAllocNumber ) = 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() { }
       
    49     };
       
    50 
       
    51 
       
    52 // Heap walker - allows in-place walking of any heap
       
    53 class RMemSpyDriverHeapWalker
       
    54     {
       
    55 public:
       
    56     RMemSpyDriverHeapWalker( RMemSpyDriverRHeapBase& aHeap, TBool aDebugAllocator );
       
    57     RMemSpyDriverHeapWalker( RMemSpyDriverRHeapBase& aHeap, TBool aDebugAllocator, MMemSpyHeapWalkerObserver& aObserver );
       
    58 		
       
    59 public: // API
       
    60     TInt Traverse();
       
    61     void CopyStatsTo( TMemSpyHeapStatisticsRHeap& aStats );
       
    62     void SetObserver( MMemSpyHeapWalkerObserver* aObserver );
       
    63     inline void SetPrintDebug() { iPrintDebug = ETrue; }
       
    64     inline const TMemSpyHeapWalkStatistics& Stats() const { return iStats; }
       
    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 
       
    71 private: // Internal methods
       
    72     TBool NotifyCell( TMemSpyDriverCellType aType, TAny* aCellAddress, TInt aLength, TInt aNestingLevel = -1, TInt aAllocNumber = -1 );
       
    73     //
       
    74     void UpdateStats( TMemSpyDriverCellType aType, TAny* aCellAddress, TInt aLength, TInt aNestingLevel, TInt aAllocNumber );
       
    75     void InitialiseStats();
       
    76     void FinaliseStats();
       
    77     void PrintStats();
       
    78     //
       
    79     TAny* KernelAddress( TAny* aUserAddress ) const;
       
    80     TAny* UserAddress( TAny* aKernelAddress ) const;
       
    81     //
       
    82     inline TBool PrintDebug() const { return iPrintDebug; }
       
    83 
       
    84 private:
       
    85     RMemSpyDriverRHeapBase& iHeap;
       
    86     TBool iIsDebugAllocator;
       
    87     TBool iPrintDebug;
       
    88     MMemSpyHeapWalkerObserver* iObserver;
       
    89     TMemSpyHeapWalkStatistics iStats;
       
    90     };
       
    91 
       
    92 
       
    93 
       
    94 #endif