49 import com.nokia.carbide.cdt.builder.CarbideBuilderPlugin; |
51 import com.nokia.carbide.cdt.builder.CarbideBuilderPlugin; |
50 import com.nokia.carbide.cdt.builder.project.ICarbideProjectInfo; |
52 import com.nokia.carbide.cdt.builder.project.ICarbideProjectInfo; |
51 import com.nokia.cdt.debug.cw.symbian.symbolreader.IFunction; |
53 import com.nokia.cdt.debug.cw.symbian.symbolreader.IFunction; |
52 import com.nokia.cdt.debug.cw.symbian.symbolreader.ISourceLocation; |
54 import com.nokia.cdt.debug.cw.symbian.symbolreader.ISourceLocation; |
53 import com.nokia.cdt.debug.cw.symbian.symbolreader.ISymbolFile; |
55 import com.nokia.cdt.debug.cw.symbian.symbolreader.ISymbolFile; |
|
56 import com.nokia.s60tools.analyzetool.Activator; |
|
57 import com.nokia.s60tools.analyzetool.engine.ICallstackManager; |
54 import com.nokia.s60tools.analyzetool.engine.statistic.AllocCallstack; |
58 import com.nokia.s60tools.analyzetool.engine.statistic.AllocCallstack; |
55 import com.nokia.s60tools.analyzetool.engine.statistic.AllocInfo; |
59 import com.nokia.s60tools.analyzetool.engine.statistic.AllocInfo; |
56 import com.nokia.s60tools.analyzetool.engine.statistic.BaseInfo; |
60 import com.nokia.s60tools.analyzetool.engine.statistic.BaseInfo; |
57 import com.nokia.s60tools.analyzetool.engine.statistic.DllLoad; |
61 import com.nokia.s60tools.analyzetool.engine.statistic.DllLoad; |
58 import com.nokia.s60tools.analyzetool.engine.statistic.SourceFile; |
62 import com.nokia.s60tools.analyzetool.engine.statistic.SourceFile; |
69 @SuppressWarnings("restriction") |
73 @SuppressWarnings("restriction") |
70 class MemOpDescriptor implements IPropertySource { |
74 class MemOpDescriptor implements IPropertySource { |
71 BaseInfo memInfo; |
75 BaseInfo memInfo; |
72 |
76 |
73 /** process Id descriptor */ |
77 /** process Id descriptor */ |
74 private static final String PID_ID = "pid"; |
78 private static final String PID_ID = "pid"; //$NON-NLS-1$ |
75 private final DotTextPropertyDescriptor PID_DESCRIPTOR = new DotTextPropertyDescriptor(PID_ID, "Process Id"); |
79 private final DotTextPropertyDescriptor PID_DESCRIPTOR = new DotTextPropertyDescriptor(PID_ID, Messages.MemOpDescriptor_1); |
76 |
80 |
77 /** Memory operation type Allocation/Leak/Free descriptor */ |
81 /** Memory operation type Allocation/Leak/Free descriptor */ |
78 private static final String TYPE_ID = "type"; |
82 private static final String TYPE_ID = "type"; //$NON-NLS-1$ |
79 private final DotTextPropertyDescriptor TYPE_DESCRIPTOR = new DotTextPropertyDescriptor(TYPE_ID, "Operation Type"); |
83 private final DotTextPropertyDescriptor TYPE_DESCRIPTOR = new DotTextPropertyDescriptor(TYPE_ID, Messages.MemOpDescriptor_3); |
80 |
84 |
81 /** Time descriptor */ |
85 /** Time descriptor */ |
82 private static final String TIME_ID = "time"; |
86 private static final String TIME_ID = "time"; //$NON-NLS-1$ |
83 private final DotTextPropertyDescriptor TIME_DESCRIPTOR = new DotTextPropertyDescriptor(TIME_ID, "Time"); |
87 private final DotTextPropertyDescriptor TIME_DESCRIPTOR = new DotTextPropertyDescriptor(TIME_ID, Messages.MemOpDescriptor_5); |
84 |
88 |
85 /** size descriptor */ |
89 /** size descriptor */ |
86 private static final String SIZE_ID = "size"; |
90 private static final String SIZE_ID = "size"; //$NON-NLS-1$ |
87 private final DotTextPropertyDescriptor SIZE_DESCRIPTOR = new DotTextPropertyDescriptor(SIZE_ID, "Size"); |
91 private final DotTextPropertyDescriptor SIZE_DESCRIPTOR = new DotTextPropertyDescriptor(SIZE_ID, Messages.MemOpDescriptor_7); |
88 |
92 |
89 /** memory address descriptor */ |
93 /** memory address descriptor */ |
90 private static final String ADDR_ID = "address"; |
94 private static final String ADDR_ID = "address"; //$NON-NLS-1$ |
91 private final DotTextPropertyDescriptor ADDR_DESCRIPTOR = new DotTextPropertyDescriptor(ADDR_ID, "Address"); |
95 private final DotTextPropertyDescriptor ADDR_DESCRIPTOR = new DotTextPropertyDescriptor(ADDR_ID, Messages.MemOpDescriptor_9); |
92 |
96 |
93 /** total memory size consumed by the process descriptor */ |
97 /** total memory size consumed by the process descriptor */ |
94 private static final String TSIZE_ID = "total"; |
98 private static final String TSIZE_ID = "total"; //$NON-NLS-1$ |
95 private final DotTextPropertyDescriptor TSIZE_DESCRIPTOR = new DotTextPropertyDescriptor(TSIZE_ID, "Total Size"); |
99 private final DotTextPropertyDescriptor TSIZE_DESCRIPTOR = new DotTextPropertyDescriptor(TSIZE_ID, Messages.MemOpDescriptor_11); |
96 |
100 |
97 /** life time of an allocation descriptor. This applies only to non Leaked allocations */ |
101 /** life time of an allocation descriptor. This applies only to non Leaked allocations */ |
98 private static final String LIFETIME_ID = "lifetime"; |
102 private static final String LIFETIME_ID = "lifetime"; //$NON-NLS-1$ |
99 private final DotTextPropertyDescriptor LIFETIME_DESCRIPTOR = new DotTextPropertyDescriptor(LIFETIME_ID, "Life Time"); |
103 private final DotTextPropertyDescriptor LIFETIME_DESCRIPTOR = new DotTextPropertyDescriptor(LIFETIME_ID, Messages.MemOpDescriptor_13); |
100 private static final String ATTRIBUTES_GROUP = "Attributes"; |
104 private static final String ATTRIBUTES_GROUP = "Attributes"; //$NON-NLS-1$ |
101 /** used for making absolute time values relative */ |
105 /** used for making absolute time values relative */ |
102 private long baseTime; |
106 private long baseTime; |
103 |
107 |
104 /** callstack item descriptor id*/ |
108 /** callstack item descriptor id*/ |
105 private static final String CALL_STACK_ID = "callstack"; |
109 private static final String CALL_STACK_ID = "callstack"; //$NON-NLS-1$ |
106 |
110 |
107 /** current project */ |
111 /** current project */ |
108 IProject iCurrentProject = null; |
112 IProject iCurrentProject = null; |
109 /** Symbol Reader */ |
113 /** Symbol Reader */ |
110 SymReader iSymReader = null; |
114 SymReader iSymReader = null; |
111 /** c++ files from the current project */ |
115 /** c++ files from the current project */ |
112 AbstractList<String> cppFileNames; |
116 AbstractList<String> cppFileNames; |
113 static final String LINE_SEPARATOR = " :: "; |
117 static final String LINE_SEPARATOR = " :: "; //$NON-NLS-1$ |
|
118 |
|
119 private ICallstackManager callstackManager; |
114 /** |
120 /** |
115 * Constructor |
121 * Constructor |
116 * @param baseTime usually process start time, used for making absolute time values relative |
122 * @param newBaseTime usually process start time, used for making absolute time values relative |
117 * @param info the alloc or free info |
123 * @param info the alloc or free info |
118 * @param project IProject to use for locating source file |
124 * @param project IProject to use for locating source file |
119 * @param symReader the SymReader to use for pinpointing |
125 * @param symReader the SymReader to use for pinpointing |
120 * @param cppFiles |
126 * @param cppFiles |
121 */ |
127 * @param callstackManager CallstackManager for reading callstacks from BaseInfo |
122 public MemOpDescriptor(Long baseTime, BaseInfo info, IProject project, SymReader symReader, AbstractList<String> cppFiles) { |
128 */ |
|
129 public MemOpDescriptor(Long newBaseTime, BaseInfo info, IProject project, SymReader symReader, AbstractList<String> cppFiles, ICallstackManager callstackManager) { |
123 memInfo = info; |
130 memInfo = info; |
124 iCurrentProject = project; |
131 iCurrentProject = project; |
125 iSymReader = symReader; |
132 iSymReader = symReader; |
126 cppFileNames = cppFiles; |
133 cppFileNames = cppFiles; |
127 this.baseTime = baseTime; |
134 this.baseTime = newBaseTime; |
|
135 this.callstackManager = callstackManager; |
128 } |
136 } |
129 |
137 |
130 /* (non-Javadoc) |
138 /* (non-Javadoc) |
131 * @see org.eclipse.ui.views.properties.IPropertySource#getEditableValue() |
139 * @see org.eclipse.ui.views.properties.IPropertySource#getEditableValue() |
132 */ |
140 */ |
157 if (memInfo instanceof AllocInfo && ((AllocInfo)memInfo).isFreed()) { |
165 if (memInfo instanceof AllocInfo && ((AllocInfo)memInfo).isFreed()) { |
158 LIFETIME_DESCRIPTOR.setCategory(ATTRIBUTES_GROUP); |
166 LIFETIME_DESCRIPTOR.setCategory(ATTRIBUTES_GROUP); |
159 completeList.add(LIFETIME_DESCRIPTOR); //only non leaks |
167 completeList.add(LIFETIME_DESCRIPTOR); //only non leaks |
160 } |
168 } |
161 // add callstack descriptors |
169 // add callstack descriptors |
162 AbstractList<AllocCallstack> callstack = memInfo.getCallstack(); |
170 if (callstackManager != null && callstackManager.hasCallstack(memInfo)){ |
163 for (int i = 0; i < callstack.size(); i++) { |
171 try { |
164 |
172 List<AllocCallstack> callstack = callstackManager.readCallstack(memInfo); |
165 final DotTextPropertyDescriptor propDesc = new DotTextPropertyDescriptor(i, CALL_STACK_ID); |
173 if (callstack != null){ |
166 propDesc.setCategory("CallStack"); |
174 for (int i = 0; i < callstack.size(); i++) { |
167 completeList.add(propDesc); |
175 |
|
176 final DotTextPropertyDescriptor propDesc = new DotTextPropertyDescriptor(i, CALL_STACK_ID); |
|
177 propDesc.setCategory("CallStack"); //$NON-NLS-1$ |
|
178 completeList.add(propDesc); |
|
179 } |
|
180 } |
|
181 } catch (IOException e) { |
|
182 //since callstacks aren't fatal and we can't handle it usefully here, log this to the error log |
|
183 Activator.getDefault().log(IStatus.ERROR, Messages.MemOpDescriptor_18, e); |
|
184 } |
168 } |
185 } |
169 return completeList.toArray(new TextPropertyDescriptor[completeList.size()]); |
186 return completeList.toArray(new TextPropertyDescriptor[completeList.size()]); |
170 } |
187 } |
171 |
188 |
172 /* (non-Javadoc) |
189 /* (non-Javadoc) |
176 //Note, this method must return String values for the CellEditor to work |
193 //Note, this method must return String values for the CellEditor to work |
177 if (PID_ID.equals(id)) { |
194 if (PID_ID.equals(id)) { |
178 return String.valueOf(memInfo.getProcessID());//process ids are usually decimal values |
195 return String.valueOf(memInfo.getProcessID());//process ids are usually decimal values |
179 } |
196 } |
180 if (TYPE_ID.equals(id)) |
197 if (TYPE_ID.equals(id)) |
181 return memInfo instanceof AllocInfo ? ((AllocInfo)memInfo).isFreed() ? "Allocation" : "Leak" : "Free"; |
198 return memInfo instanceof AllocInfo ? ((AllocInfo)memInfo).isFreed() ? Messages.MemOpDescriptor_19 : Messages.MemOpDescriptor_20 : Messages.MemOpDescriptor_21; |
182 if (TIME_ID.equals(id)) |
199 if (TIME_ID.equals(id)) |
183 return GraphUtils.renderTime(memInfo.getTime() - baseTime); |
200 return GraphUtils.renderTime(memInfo.getTime() - baseTime); |
184 if (SIZE_ID.equals(id)) |
201 if (SIZE_ID.equals(id)) |
185 return String.format("%,d B",memInfo.getSizeInt()); |
202 return String.format(Messages.MemOpDescriptor_22,memInfo.getSizeInt()); |
186 if (ADDR_ID.equals(id)) |
203 if (ADDR_ID.equals(id)) |
187 return Long.toString(memInfo.getMemoryAddress(),16); |
204 return Long.toString(memInfo.getMemoryAddress(),16); |
188 if (TSIZE_ID.equals(id)) |
205 if (TSIZE_ID.equals(id)) |
189 return String.format("%,d B",memInfo.getTotalMem()); |
206 return String.format(Messages.MemOpDescriptor_23,memInfo.getTotalMem()); |
190 if (LIFETIME_ID.equals(id)) { |
207 if (LIFETIME_ID.equals(id)) { |
191 if (memInfo instanceof AllocInfo && ((AllocInfo)memInfo).isFreed()) { |
208 if (memInfo instanceof AllocInfo && ((AllocInfo)memInfo).isFreed()) { |
192 AllocInfo info = (AllocInfo) memInfo; |
209 AllocInfo info = (AllocInfo) memInfo; |
193 return GraphUtils.renderTime(info.getFreedBy().getTime() - info.getTime()); |
210 return GraphUtils.renderTime(info.getFreedBy().getTime() - info.getTime()); |
194 } |
211 } |
195 throw new IllegalStateException("Should not happen because we did not provide a lifetime descriptor for leak and free"); |
212 throw new IllegalStateException("Should not happen because we did not provide a lifetime descriptor for leak and free"); //$NON-NLS-1$ |
196 } |
213 } |
197 if (id instanceof Integer && memInfo.getCallstack() != null){ |
214 if (id instanceof Integer && callstackManager.hasCallstack(memInfo)){ |
198 int callstackId = (Integer)id; |
215 int callstackId = (Integer)id; |
199 if (callstackId < memInfo.getCallstack().size()){ |
216 try { |
200 AllocCallstack callstackItem = memInfo.getCallstack().get(callstackId); |
217 List<AllocCallstack> callstackList = callstackManager.readCallstack(memInfo); |
201 DllLoad tempLoad = callstackItem.getDllLoad(); |
218 if (callstackId < callstackList.size()){ |
202 long addr = callstackItem.getMemoryAddress(); |
219 AllocCallstack callstackItem = callstackList.get(callstackId); |
203 |
220 DllLoad tempLoad = callstackItem.getDllLoad(); |
204 String name = String.format("%1$08x",addr); |
221 long addr = callstackItem.getMemoryAddress(); |
205 if (tempLoad != null && callstackItem.getMemoryAddress()!= tempLoad.getStartAddress()) { |
222 |
206 SourceFile aSourcefile = pinpoint(callstackItem.getMemoryAddress(), |
223 String name = String.format(Messages.MemOpDescriptor_25,addr); |
207 callstackItem.getDllLoad()); |
224 if (tempLoad != null && callstackItem.getMemoryAddress()!= tempLoad.getStartAddress()) { |
208 if (aSourcefile != null) { //callstack resolved to a file-function-line |
225 SourceFile aSourcefile = pinpoint(callstackItem.getMemoryAddress(), |
209 return name + LINE_SEPARATOR + callstackItem.getDllLoad().getName() + LINE_SEPARATOR + aSourcefile.getFileName()+ LINE_SEPARATOR + aSourcefile.getFunctionName() + LINE_SEPARATOR + aSourcefile.getLineNumber(); |
226 callstackItem.getDllLoad()); |
|
227 if (aSourcefile != null) { //callstack resolved to a file-function-line |
|
228 return name + LINE_SEPARATOR + callstackItem.getDllLoad().getName() + LINE_SEPARATOR + aSourcefile.getFileName()+ LINE_SEPARATOR + aSourcefile.getFunctionName() + LINE_SEPARATOR + aSourcefile.getLineNumber(); |
|
229 } |
210 } |
230 } |
|
231 return name + (tempLoad != null ? LINE_SEPARATOR + tempLoad.getName() : ""); //$NON-NLS-1$ |
211 } |
232 } |
212 return name + (tempLoad != null ? LINE_SEPARATOR + tempLoad.getName() : ""); |
233 } catch (IOException e) { |
213 } |
234 //since callstacks aren't fatal and we can't handle it usefully here, log this to the error log |
214 } |
235 Activator.getDefault().log(IStatus.ERROR, Messages.MemOpDescriptor_27, e); |
|
236 } |
|
237 } |
215 return null; |
238 return null; |
216 } |
239 } |
217 |
240 |
218 /* (non-Javadoc) |
241 /* (non-Javadoc) |
219 * @see org.eclipse.ui.views.properties.IPropertySource#isPropertySet(java.lang.Object) |
242 * @see org.eclipse.ui.views.properties.IPropertySource#isPropertySet(java.lang.Object) |