1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32utils/analyse/codespace.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,156 @@
1.4 +// Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#ifndef __SPACE__
1.20 +#define __SPACE__
1.21 +
1.22 +#include "trace.h"
1.23 +#include "symbols.h"
1.24 +#include <vector>
1.25 +#include <map>
1.26 +
1.27 +// This class define the interface used by the distribution sampler to allocate
1.28 +// a 'bucket' for a given PC value
1.29 +//
1.30 +// This also provide a minimual implementation that allocates all samples to 'other'
1.31 +
1.32 +class CodeSpace
1.33 + {
1.34 +public:
1.35 + enum {KOtherBucket = 0};
1.36 + enum TOrder {ERandom, EOrdered, ELinear};
1.37 +public:
1.38 + // the number of buckets (including the 'other' bucket)
1.39 + virtual int Size() const;
1.40 + // map a PC to a bucket
1.41 + virtual int Bucket(PC aPc) const;
1.42 + // name a bucket
1.43 + virtual const char* Name(int aBucket) const;
1.44 + // determine whether the results should be ordered
1.45 + virtual TOrder Ordering() const;
1.46 + };
1.47 +
1.48 +class AddressCodeSpace : public CodeSpace
1.49 + {
1.50 +public:
1.51 + enum TType {EAbsolute, ERelative};
1.52 +public:
1.53 + AddressCodeSpace(PC aBase, PC aLimit, unsigned aBucketSize, TType aType);
1.54 +private:
1.55 + int Size() const;
1.56 + int Bucket(PC aPc) const;
1.57 + const char* Name(int aBucket) const;
1.58 + TOrder Ordering() const;
1.59 +private:
1.60 + PC iBase;
1.61 + unsigned iBucketShift;
1.62 + unsigned iBuckets;
1.63 + TType iType;
1.64 + mutable char iBuffer[10];
1.65 + };
1.66 +
1.67 +class MappedCodeSpace : public CodeSpace
1.68 + {
1.69 + friend class NonXIP;
1.70 + struct Element
1.71 + {
1.72 + inline Element()
1.73 + {}
1.74 + inline Element(PC aBase, PC aLimit, const char* aName)
1.75 + :iBase(aBase), iLimit(aLimit), iName(aName), iBucket(0), iUnloaded(false)
1.76 + {}
1.77 + //
1.78 + PC iBase;
1.79 + PC iLimit;
1.80 + const char* iName;
1.81 + int iBucket;
1.82 + bool iUnloaded;
1.83 + };
1.84 + typedef std::multimap<PC, Element> Map;
1.85 +
1.86 + struct IdNames
1.87 + {
1.88 + IdNames(int aId, int aIndex) : iId(aId), iIndex(aIndex) {}
1.89 + int iId;
1.90 + int iIndex;
1.91 + };
1.92 + typedef std::multimap<const char*, IdNames> NamesMap;
1.93 +
1.94 +public:
1.95 + class Partition : public SymbolFile::Parser
1.96 + {
1.97 + friend class MappedCodeSpace;
1.98 + friend class NonXIP;
1.99 + protected:
1.100 + inline Partition()
1.101 + {}
1.102 + inline void Add(PC aBase, PC aLimit, const char* aName)
1.103 + {iCodeSpace->Add(aBase, aLimit, aName);}
1.104 + inline void Done(PC aFirstPc=0, PC aLastPc=0, int aModuleId=0)
1.105 + {iCodeSpace->Done(aFirstPc, aLastPc, aModuleId);}
1.106 + private:
1.107 + MappedCodeSpace* iCodeSpace;
1.108 + };
1.109 + friend class Partition;
1.110 +public:
1.111 + MappedCodeSpace();
1.112 + MappedCodeSpace(const SymbolFile& aSymbols, Partition& aPartition);
1.113 + std::pair<const char*,unsigned> Lookup(PC aPc) const;
1.114 +protected:
1.115 +// MappedCodeSpace();
1.116 + void Add(PC aBase, PC aLimit, const char* aName);
1.117 + void Done(PC aFirstPc, PC aLastPc, int aModuleId);
1.118 +private:
1.119 + const Element* Find(PC aPc) const;
1.120 +//
1.121 + int Size() const;
1.122 + int Bucket(PC aPc) const;
1.123 + const char* Name(int aBucket) const;
1.124 +private:
1.125 + Map iMap;
1.126 + std::vector<const char*> iNames;
1.127 + NamesMap iNamesMap;
1.128 + };
1.129 +
1.130 +class PartitionByFunction : public MappedCodeSpace::Partition
1.131 + {
1.132 +public:
1.133 + PartitionByFunction(const char* aFile, const char* aFunction);
1.134 +private:
1.135 + void File(const char* aName);
1.136 + bool Symbol(const char* aName, PC aPc, int aLength);
1.137 +private:
1.138 + const char* iFile;
1.139 + const char* iFunction;
1.140 + bool iActive;
1.141 + };
1.142 +
1.143 +class PartitionByDll : public MappedCodeSpace::Partition
1.144 + {
1.145 +public:
1.146 + PartitionByDll(const char* aFile)
1.147 + :iMatch(aFile), iLastFile(0), iLastFileAddress(0), iCurrentFile(0)
1.148 + {}
1.149 +private:
1.150 + void File(const char* aName);
1.151 + bool Symbol(const char* aName, PC aPc, int aLength);
1.152 +private:
1.153 + const char* iMatch;
1.154 + const char* iLastFile;
1.155 + PC iLastFileAddress;
1.156 + const char* iCurrentFile;
1.157 + };
1.158 +
1.159 +#endif // __SPACE__
1.160 \ No newline at end of file