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