|
1 // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of the License "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #ifndef __SPACE__ |
|
17 #define __SPACE__ |
|
18 |
|
19 #include "trace.h" |
|
20 #include "symbols.h" |
|
21 #include <vector> |
|
22 #include <map> |
|
23 |
|
24 // This class define the interface used by the distribution sampler to allocate |
|
25 // a 'bucket' for a given PC value |
|
26 // |
|
27 // This also provide a minimual implementation that allocates all samples to 'other' |
|
28 |
|
29 class CodeSpace |
|
30 { |
|
31 public: |
|
32 enum {KOtherBucket = 0}; |
|
33 enum TOrder {ERandom, EOrdered, ELinear}; |
|
34 public: |
|
35 // the number of buckets (including the 'other' bucket) |
|
36 virtual int Size() const; |
|
37 // map a PC to a bucket |
|
38 virtual int Bucket(PC aPc) const; |
|
39 // name a bucket |
|
40 virtual const char* Name(int aBucket) const; |
|
41 // determine whether the results should be ordered |
|
42 virtual TOrder Ordering() const; |
|
43 }; |
|
44 |
|
45 class AddressCodeSpace : public CodeSpace |
|
46 { |
|
47 public: |
|
48 enum TType {EAbsolute, ERelative}; |
|
49 public: |
|
50 AddressCodeSpace(PC aBase, PC aLimit, unsigned aBucketSize, TType aType); |
|
51 private: |
|
52 int Size() const; |
|
53 int Bucket(PC aPc) const; |
|
54 const char* Name(int aBucket) const; |
|
55 TOrder Ordering() const; |
|
56 private: |
|
57 PC iBase; |
|
58 unsigned iBucketShift; |
|
59 unsigned iBuckets; |
|
60 TType iType; |
|
61 mutable char iBuffer[10]; |
|
62 }; |
|
63 |
|
64 class MappedCodeSpace : public CodeSpace |
|
65 { |
|
66 friend class NonXIP; |
|
67 struct Element |
|
68 { |
|
69 inline Element() |
|
70 {} |
|
71 inline Element(PC aBase, PC aLimit, const char* aName) |
|
72 :iBase(aBase), iLimit(aLimit), iName(aName), iBucket(0), iUnloaded(false) |
|
73 {} |
|
74 // |
|
75 PC iBase; |
|
76 PC iLimit; |
|
77 const char* iName; |
|
78 int iBucket; |
|
79 bool iUnloaded; |
|
80 }; |
|
81 typedef std::multimap<PC, Element> Map; |
|
82 |
|
83 struct IdNames |
|
84 { |
|
85 IdNames(int aId, int aIndex) : iId(aId), iIndex(aIndex) {} |
|
86 int iId; |
|
87 int iIndex; |
|
88 }; |
|
89 typedef std::multimap<const char*, IdNames> NamesMap; |
|
90 |
|
91 public: |
|
92 class Partition : public SymbolFile::Parser |
|
93 { |
|
94 friend class MappedCodeSpace; |
|
95 friend class NonXIP; |
|
96 protected: |
|
97 inline Partition() |
|
98 {} |
|
99 inline void Add(PC aBase, PC aLimit, const char* aName) |
|
100 {iCodeSpace->Add(aBase, aLimit, aName);} |
|
101 inline void Done(PC aFirstPc=0, PC aLastPc=0, int aModuleId=0) |
|
102 {iCodeSpace->Done(aFirstPc, aLastPc, aModuleId);} |
|
103 private: |
|
104 MappedCodeSpace* iCodeSpace; |
|
105 }; |
|
106 friend class Partition; |
|
107 public: |
|
108 MappedCodeSpace(); |
|
109 MappedCodeSpace(const SymbolFile& aSymbols, Partition& aPartition); |
|
110 std::pair<const char*,unsigned> Lookup(PC aPc) const; |
|
111 protected: |
|
112 // MappedCodeSpace(); |
|
113 void Add(PC aBase, PC aLimit, const char* aName); |
|
114 void Done(PC aFirstPc, PC aLastPc, int aModuleId); |
|
115 private: |
|
116 const Element* Find(PC aPc) const; |
|
117 // |
|
118 int Size() const; |
|
119 int Bucket(PC aPc) const; |
|
120 const char* Name(int aBucket) const; |
|
121 private: |
|
122 Map iMap; |
|
123 std::vector<const char*> iNames; |
|
124 NamesMap iNamesMap; |
|
125 }; |
|
126 |
|
127 class PartitionByFunction : public MappedCodeSpace::Partition |
|
128 { |
|
129 public: |
|
130 PartitionByFunction(const char* aFile, const char* aFunction); |
|
131 private: |
|
132 void File(const char* aName); |
|
133 bool Symbol(const char* aName, PC aPc, int aLength); |
|
134 private: |
|
135 const char* iFile; |
|
136 const char* iFunction; |
|
137 bool iActive; |
|
138 }; |
|
139 |
|
140 class PartitionByDll : public MappedCodeSpace::Partition |
|
141 { |
|
142 public: |
|
143 PartitionByDll(const char* aFile) |
|
144 :iMatch(aFile), iLastFile(0), iLastFileAddress(0), iCurrentFile(0) |
|
145 {} |
|
146 private: |
|
147 void File(const char* aName); |
|
148 bool Symbol(const char* aName, PC aPc, int aLength); |
|
149 private: |
|
150 const char* iMatch; |
|
151 const char* iLastFile; |
|
152 PC iLastFileAddress; |
|
153 const char* iCurrentFile; |
|
154 }; |
|
155 |
|
156 #endif // __SPACE__ |