sl@0: // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #ifndef __SPACE__ sl@0: #define __SPACE__ sl@0: sl@0: #include "trace.h" sl@0: #include "symbols.h" sl@0: #include sl@0: #include sl@0: sl@0: // This class define the interface used by the distribution sampler to allocate sl@0: // a 'bucket' for a given PC value sl@0: // sl@0: // This also provide a minimual implementation that allocates all samples to 'other' sl@0: sl@0: class CodeSpace sl@0: { sl@0: public: sl@0: enum {KOtherBucket = 0}; sl@0: enum TOrder {ERandom, EOrdered, ELinear}; sl@0: public: sl@0: // the number of buckets (including the 'other' bucket) sl@0: virtual int Size() const; sl@0: // map a PC to a bucket sl@0: virtual int Bucket(PC aPc) const; sl@0: // name a bucket sl@0: virtual const char* Name(int aBucket) const; sl@0: // determine whether the results should be ordered sl@0: virtual TOrder Ordering() const; sl@0: }; sl@0: sl@0: class AddressCodeSpace : public CodeSpace sl@0: { sl@0: public: sl@0: enum TType {EAbsolute, ERelative}; sl@0: public: sl@0: AddressCodeSpace(PC aBase, PC aLimit, unsigned aBucketSize, TType aType); sl@0: private: sl@0: int Size() const; sl@0: int Bucket(PC aPc) const; sl@0: const char* Name(int aBucket) const; sl@0: TOrder Ordering() const; sl@0: private: sl@0: PC iBase; sl@0: unsigned iBucketShift; sl@0: unsigned iBuckets; sl@0: TType iType; sl@0: mutable char iBuffer[10]; sl@0: }; sl@0: sl@0: class MappedCodeSpace : public CodeSpace sl@0: { sl@0: friend class NonXIP; sl@0: struct Element sl@0: { sl@0: inline Element() sl@0: {} sl@0: inline Element(PC aBase, PC aLimit, const char* aName) sl@0: :iBase(aBase), iLimit(aLimit), iName(aName), iBucket(0), iUnloaded(false) sl@0: {} sl@0: // sl@0: PC iBase; sl@0: PC iLimit; sl@0: const char* iName; sl@0: int iBucket; sl@0: bool iUnloaded; sl@0: }; sl@0: typedef std::multimap Map; sl@0: sl@0: struct IdNames sl@0: { sl@0: IdNames(int aId, int aIndex) : iId(aId), iIndex(aIndex) {} sl@0: int iId; sl@0: int iIndex; sl@0: }; sl@0: typedef std::multimap NamesMap; sl@0: sl@0: public: sl@0: class Partition : public SymbolFile::Parser sl@0: { sl@0: friend class MappedCodeSpace; sl@0: friend class NonXIP; sl@0: protected: sl@0: inline Partition() sl@0: {} sl@0: inline void Add(PC aBase, PC aLimit, const char* aName) sl@0: {iCodeSpace->Add(aBase, aLimit, aName);} sl@0: inline void Done(PC aFirstPc=0, PC aLastPc=0, int aModuleId=0) sl@0: {iCodeSpace->Done(aFirstPc, aLastPc, aModuleId);} sl@0: private: sl@0: MappedCodeSpace* iCodeSpace; sl@0: }; sl@0: friend class Partition; sl@0: public: sl@0: MappedCodeSpace(); sl@0: MappedCodeSpace(const SymbolFile& aSymbols, Partition& aPartition); sl@0: std::pair Lookup(PC aPc) const; sl@0: protected: sl@0: // MappedCodeSpace(); sl@0: void Add(PC aBase, PC aLimit, const char* aName); sl@0: void Done(PC aFirstPc, PC aLastPc, int aModuleId); sl@0: private: sl@0: const Element* Find(PC aPc) const; sl@0: // sl@0: int Size() const; sl@0: int Bucket(PC aPc) const; sl@0: const char* Name(int aBucket) const; sl@0: private: sl@0: Map iMap; sl@0: std::vector iNames; sl@0: NamesMap iNamesMap; sl@0: }; sl@0: sl@0: class PartitionByFunction : public MappedCodeSpace::Partition sl@0: { sl@0: public: sl@0: PartitionByFunction(const char* aFile, const char* aFunction); sl@0: private: sl@0: void File(const char* aName); sl@0: bool Symbol(const char* aName, PC aPc, int aLength); sl@0: private: sl@0: const char* iFile; sl@0: const char* iFunction; sl@0: bool iActive; sl@0: }; sl@0: sl@0: class PartitionByDll : public MappedCodeSpace::Partition sl@0: { sl@0: public: sl@0: PartitionByDll(const char* aFile) sl@0: :iMatch(aFile), iLastFile(0), iLastFileAddress(0), iCurrentFile(0) sl@0: {} sl@0: private: sl@0: void File(const char* aName); sl@0: bool Symbol(const char* aName, PC aPc, int aLength); sl@0: private: sl@0: const char* iMatch; sl@0: const char* iLastFile; sl@0: PC iLastFileAddress; sl@0: const char* iCurrentFile; sl@0: }; sl@0: sl@0: #endif // __SPACE__