perfsrv/memspy/Driver/Kernel/Include/MemSpyDriverInspectedProcess.h
changeset 48 516af714ebb4
child 54 a151135b0cf9
equal deleted inserted replaced
45:185201be11b0 48:516af714ebb4
       
     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 MEMSPYINSPECTEDPROCESS_H
       
    19 #define MEMSPYINSPECTEDPROCESS_H
       
    20 
       
    21 // System includes
       
    22 #include <kern_priv.h>
       
    23 
       
    24 // Shared includes
       
    25 #include <memspy/driver/memspydriverobjectsshared.h>
       
    26 
       
    27 // User includes
       
    28 #include "MemSpyDriverUtils.h"
       
    29 #include "MemSpyDriverEventMonitor.h"
       
    30 
       
    31 // Classes referenced
       
    32 class DMemSpyInspectedProcessManager;
       
    33 class TMemSpyDriverProcessInspectionInfo;
       
    34 
       
    35 
       
    36 
       
    37 class TMemSpyTrackedChunk
       
    38 	{
       
    39 public:
       
    40     enum TType
       
    41         {
       
    42         ETypeNotRelevant = -1,
       
    43         //
       
    44         ETypeChunkHeap = 0,
       
    45         ETypeChunkLocal,
       
    46         ETypeChunkGlobalData,
       
    47         ETypeChunkProcessGlobalDataAndUserStack,
       
    48         ETypeChunkShared
       
    49         };
       
    50 
       
    51 public:
       
    52 	TMemSpyTrackedChunk( DChunk* aChunk, TType aType );
       
    53 
       
    54 public: // API
       
    55     void SetSize( TInt aSize );
       
    56     TInt Size() const { return iSize; }
       
    57     //
       
    58     void SetUnused( TBool aUnused );
       
    59     TBool Unused() const { return iUnused; }
       
    60     //
       
    61     TAny* Handle() const { return iChunk; }
       
    62     //
       
    63     inline TType Type() const { return iType; }
       
    64     inline void SetType( TType aType ) { iType = aType; }
       
    65 
       
    66 public: // Data members
       
    67 	SDblQueLink iLink;
       
    68     DChunk* iChunk;
       
    69     TType iType;
       
    70     TInt iSize;
       
    71     TBool iUnused;
       
    72 	};
       
    73 
       
    74 
       
    75 class TMemSpyTrackedChunkChangeInfo
       
    76     {
       
    77 public: // Data members
       
    78     TMemSpyDriverProcessInspectionInfo iInfo;
       
    79 	SDblQueLink iLink;
       
    80     };
       
    81 
       
    82 
       
    83 
       
    84 
       
    85 
       
    86 class DMemSpyInspectedProcess : public DBase, public MMemSpyEventMonitorObserver
       
    87     {
       
    88 public: // Construct / destruct
       
    89 	DMemSpyInspectedProcess( DMemSpyDriverDevice& aDevice );
       
    90 	~DMemSpyInspectedProcess();
       
    91 
       
    92 public: // API
       
    93     TInt Open( DProcess* aProcess );
       
    94     inline TUint ProcessId() const { return iProcessId; }
       
    95 
       
    96 public: // Change notification API
       
    97 	TInt NotifyOnChange( DThread* aThread, TRequestStatus* aRequestStatus, TMemSpyDriverProcessInspectionInfo* aInfo );
       
    98 	TInt NotifyOnChangeCancel();
       
    99     TBool NotifyOnChangeQueued() const;
       
   100 
       
   101 public: // Queue link
       
   102 	SDblQueLink iLink;
       
   103 
       
   104 public: // From MMemSpyEventMonitorObserver
       
   105     TUint EMTypeMask() const;
       
   106     void EMHandleProcessUpdated( DProcess& aProcess );
       
   107     void EMHandleProcessRemoved( DProcess& aProcess );
       
   108     void EMHandleThreadAdd( DThread& aThread );
       
   109     void EMHandleThreadRemoved( DThread& aThread );
       
   110     void EMHandleThreadKilled( DThread& aThread );
       
   111     void EMHandleChunkAdd( DChunk& aChunk );
       
   112     void EMHandleChunkUpdated( DChunk& aChunk );
       
   113     void EMHandleChunkDeleted( DChunk& aChunk );
       
   114 
       
   115     // Internal helper
       
   116     void EMHandleThreadChanged( DThread& aThread );
       
   117 
       
   118 private: // Tracked item management
       
   119     void ResetTrackedList();
       
   120     void SetTrackedListUnused();
       
   121     void SetTrackedListUnusedStatusByType( TMemSpyTrackedChunk::TType aType, TBool aUnusedStatus );
       
   122     void DiscardUnusedTrackListItems();
       
   123     void AddTrackedChunk( DChunk* aChunk, TMemSpyTrackedChunk::TType aType );
       
   124     TMemSpyTrackedChunk* TrackedChunkByHandle( TAny* aHandle );
       
   125 
       
   126 private: // Internal methods
       
   127     DMemSpyInspectedProcessManager& PManager();
       
   128     DMemSpyEventMonitor& EventMonitor();
       
   129     TMemSpyTrackedChunk::TType ChunkType( DObject* aObject ) const;
       
   130     TBool IsHeapChunk( DChunk& aChunk, const TName& aName ) const;
       
   131     static TUint32 TotalStatistics( const TMemSpyDriverProcessInspectionInfo& aStats, TBool aIncludeShared = ETrue );
       
   132     static TBool IsEqual( const TMemSpyDriverProcessInspectionInfo& aLeft, const TMemSpyDriverProcessInspectionInfo& aRight );
       
   133     void ResetStatistics( TMemSpyDriverProcessInspectionInfo& aStats );
       
   134     TBool UpdateStatistics();
       
   135     void CompleteClientsRequest( TInt aCompletionCode, TMemSpyDriverProcessInspectionInfo* aInfo = NULL );
       
   136     void FindChunks( DProcess& aProcess );
       
   137     TInt StackSize( DProcess& aProcess );
       
   138     void ResetPendingChanges();
       
   139     void PrintChunkInfo( DChunk& aChunk ) const;
       
   140     TBool IsChunkRelevantToOurProcess( DChunk& aChunk ) const;
       
   141 	void Lock() const;
       
   142 	void Unlock() const;
       
   143 
       
   144 public: // Queue link for process manager
       
   145 	SDblQueLink iPMLink;
       
   146 
       
   147 private: // Data members
       
   148     DMemSpyDriverDevice& iDevice;
       
   149 	DMutex* iLock;
       
   150     TUint iProcessId;
       
   151     DProcess* iProcess;
       
   152     TBool iAmDead;
       
   153 
       
   154     // This differs from the 'inspection info' iMemoryStack field
       
   155     // because it just contains the size of all user-thread stacks
       
   156     // within the process.
       
   157     TInt iUserThreadStackSize;
       
   158 
       
   159     // Tracking chunks mapped into process
       
   160 	SDblQue iTrackedChunks;
       
   161 	
       
   162 	// Changes that have occurred whilst the client was AWOL
       
   163 	SDblQue iPendingChanges;
       
   164 
       
   165     // Tracking totals
       
   166     TMemSpyDriverProcessInspectionInfo iInfoLast;
       
   167     TMemSpyDriverProcessInspectionInfo iInfoCurrent;
       
   168     TMemSpyDriverProcessInspectionInfo iInfoPeaks;
       
   169     TMemSpyDriverProcessInspectionInfo iInfoHWMIncShared;
       
   170     TMemSpyDriverProcessInspectionInfo iInfoHWMExcShared;
       
   171 
       
   172     // For change notification
       
   173     TInt iChangeDeliveryCounter;
       
   174 	DThread* iChangeObserverThread;
       
   175 	TRequestStatus* iChangeObserverRS;
       
   176     TMemSpyDriverProcessInspectionInfo* iChangeObserverInfo;
       
   177     TBool iEventReceivedWhilstObserverWasAWOL;
       
   178     };
       
   179 
       
   180 
       
   181 #endif