|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * |
|
5 * Redistribution and use in source and binary forms, with or without |
|
6 * modification, are permitted provided that the following conditions are met: |
|
7 * |
|
8 * - Redistributions of source code must retain the above copyright notice, |
|
9 * this list of conditions and the following disclaimer. |
|
10 * - Redistributions in binary form must reproduce the above copyright notice, |
|
11 * this list of conditions and the following disclaimer in the documentation |
|
12 * and/or other materials provided with the distribution. |
|
13 * - Neither the name of Nokia Corporation nor the names of its contributors |
|
14 * may be used to endorse or promote products derived from this software |
|
15 * without specific prior written permission. |
|
16 * |
|
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 * POSSIBILITY OF SUCH DAMAGE. |
|
28 * |
|
29 * Initial Contributors: |
|
30 * Nokia Corporation - initial contribution. |
|
31 * |
|
32 * Contributors: |
|
33 * |
|
34 * Description: |
|
35 * |
|
36 */ |
|
37 |
|
38 using System; |
|
39 using System.Collections.Generic; |
|
40 using System.Text; |
|
41 using Microsoft.Office.Interop.Excel; |
|
42 using Excel = Microsoft.Office.Interop.Excel; |
|
43 using SymbianExcelUtils; |
|
44 using HeapLib.Cells; |
|
45 using HeapLib.Array; |
|
46 using HeapLib.Statistics; |
|
47 |
|
48 namespace HeapComparisonLib.Data.Pages |
|
49 { |
|
50 internal class PageSimpleListing : PageBase |
|
51 { |
|
52 #region Constructors & destructor |
|
53 public PageSimpleListing( HeapCellArrayWithStatistics aArray, Workbook aWorkbook, string aCaption ) |
|
54 : this( aArray, aWorkbook, aCaption, true ) |
|
55 { |
|
56 } |
|
57 |
|
58 public PageSimpleListing( HeapCellArrayWithStatistics aArray, Workbook aWorkbook, string aCaption, bool aMakeStats ) |
|
59 : this( aArray, aWorkbook, aCaption, 1, 2 ) |
|
60 { |
|
61 iMakeStats = aMakeStats; |
|
62 } |
|
63 |
|
64 public PageSimpleListing( HeapCellArrayWithStatistics aArray, Workbook aWorkbook, string aCaption, int aMasterCol, int aOtherCol ) |
|
65 : base( aArray, aWorkbook, aCaption ) |
|
66 { |
|
67 iMasterCol = aMasterCol; |
|
68 iOtherCol = aOtherCol; |
|
69 iMakeStats = true; |
|
70 } |
|
71 #endregion |
|
72 |
|
73 #region New framework |
|
74 protected virtual int MakeExtraColumns( int aRow ) |
|
75 { |
|
76 return 0; |
|
77 } |
|
78 |
|
79 protected virtual void OnTableComplete( int aLastRow ) |
|
80 { |
|
81 } |
|
82 |
|
83 protected virtual void OnRowComplete( HeapCell aCell, int aRow, int aNextFreeColumn ) |
|
84 { |
|
85 } |
|
86 #endregion |
|
87 |
|
88 #region API |
|
89 public override void SaveToPage() |
|
90 { |
|
91 int row = 1; |
|
92 if ( iMakeStats ) |
|
93 { |
|
94 MakeStats( ref row ); |
|
95 } |
|
96 |
|
97 Utils.SetValue( row, 1, Worksheet, "Alloc Cell Address" ); |
|
98 Utils.SetValue( row, 2, Worksheet, "Original Length" ); |
|
99 Utils.SetValue( row, 3, Worksheet, "New Length" ); |
|
100 Utils.SetValue( row, 4, Worksheet, "Symbol" ); |
|
101 |
|
102 // Make row bold |
|
103 Utils.BoldRow( row, Worksheet ); |
|
104 |
|
105 // Add border and cell colours |
|
106 int maxCol = Math.Max( 4, MakeExtraColumns( row ) ); |
|
107 Utils.MakeBoxedTitleRow( row, maxCol, Worksheet, 0xFF0000 ); |
|
108 |
|
109 // Set column alignments |
|
110 Utils.SetColumnHorizontalAlignment( 2, Worksheet, XlHAlign.xlHAlignRight ); |
|
111 Utils.SetColumnHorizontalAlignment( 3, Worksheet, XlHAlign.xlHAlignRight ); |
|
112 Utils.SetColumnHorizontalAlignment( 4, Worksheet, XlHAlign.xlHAlignLeft ); |
|
113 |
|
114 // Create rows for allocs |
|
115 row++; |
|
116 |
|
117 int startRowAlloc = row; |
|
118 foreach ( HeapCell cell in Array ) |
|
119 { |
|
120 if ( cell.Type == HeapCell.TType.EAllocated ) |
|
121 { |
|
122 object[ , ] items = new object[ 1, 4 ]; |
|
123 // |
|
124 items[ 0, 0 ] = "0x" + cell.Address.ToString( "x8" ); |
|
125 |
|
126 // Put the length in the master cell and then |
|
127 // if we have a value for the other column, put it's value too |
|
128 items[ 0, iMasterCol ] = cell.Length.ToString(); |
|
129 if ( cell.Tag != null && cell.Tag is HeapCell ) |
|
130 { |
|
131 HeapCell newCell = (HeapCell) cell.Tag; |
|
132 items[ 0, iOtherCol ] = newCell.Length; |
|
133 } |
|
134 else |
|
135 { |
|
136 items[ 0, iOtherCol ] = "?"; |
|
137 } |
|
138 |
|
139 // Cell description |
|
140 if ( !cell.IsUnknown ) |
|
141 { |
|
142 items[ 0, 3 ] = cell.SymbolStringWithoutDescriptorPrefix; |
|
143 } |
|
144 else if ( cell.IsDescriptor ) |
|
145 { |
|
146 items[ 0, 3 ] = cell.SymbolStringWithoutDescriptorPrefix; |
|
147 } |
|
148 else |
|
149 { |
|
150 StringBuilder body = new StringBuilder(); |
|
151 body.AppendFormat( "[?] I[{0:d3}] O[{1:d3}] {2}", cell.RelationshipManager.ReferencedBy.Count, cell.RelationshipManager.EmbeddedReferencesTo.Count, cell.RawItems.FirstLine ); |
|
152 items[ 0, 3 ] = body.ToString(); |
|
153 } |
|
154 // |
|
155 Range range = Utils.GetRangeByColumnAndRow( row, 1, row, 4, Worksheet ); |
|
156 range.Value2 = items; |
|
157 OnRowComplete( cell, row, 5 ); |
|
158 ++row; |
|
159 } |
|
160 } |
|
161 |
|
162 // Sort allocations by symbol |
|
163 Excel.Range sortRange = Utils.GetRangeByColumnAndRow( startRowAlloc, 1, row, maxCol, Worksheet ); |
|
164 sortRange.Sort( |
|
165 Worksheet.Columns[ 4, Type.Missing ], Microsoft.Office.Interop.Excel.XlSortOrder.xlDescending, |
|
166 Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSortOrder.xlDescending, |
|
167 Type.Missing, Microsoft.Office.Interop.Excel.XlSortOrder.xlDescending, Microsoft.Office.Interop.Excel.XlYesNoGuess.xlNo, |
|
168 Type.Missing, Type.Missing, |
|
169 Microsoft.Office.Interop.Excel.XlSortOrientation.xlSortColumns, |
|
170 Microsoft.Office.Interop.Excel.XlSortMethod.xlPinYin, |
|
171 Microsoft.Office.Interop.Excel.XlSortDataOption.xlSortNormal, |
|
172 Microsoft.Office.Interop.Excel.XlSortDataOption.xlSortNormal, |
|
173 Microsoft.Office.Interop.Excel.XlSortDataOption.xlSortNormal ); |
|
174 |
|
175 // Write totals |
|
176 ++row; |
|
177 Utils.SetValue( row, 1, Worksheet, "Total" ); |
|
178 Utils.SetValue( row, 1 + iMasterCol, Worksheet, "=SUM(" + Utils.ColumnAndRowAsExcelIdentifier( startRowAlloc, 1 + iMasterCol ) + ":" + Utils.ColumnAndRowAsExcelIdentifier( row - 1, 1 + iMasterCol ) + ")" ); |
|
179 Utils.SetValue( row, 1 + iOtherCol, Worksheet, "=SUM(" + Utils.ColumnAndRowAsExcelIdentifier( startRowAlloc, 1 + iOtherCol ) + ":" + Utils.ColumnAndRowAsExcelIdentifier( row - 1, 1 + iOtherCol ) + ")" ); |
|
180 Utils.SetValue( row, 4, Worksheet, "=" + Utils.ColumnAndRowAsExcelIdentifier( row, 1 + iMasterCol ) + "-" + Utils.ColumnAndRowAsExcelIdentifier( row, 1 + iOtherCol ) ); |
|
181 Utils.BoldRow( row, Worksheet ); |
|
182 |
|
183 // Spacers |
|
184 row += 3; |
|
185 |
|
186 // Do the same for free cells |
|
187 Utils.SetValue( row, 1, Worksheet, "Free Cell Address" ); |
|
188 Utils.SetValue( row, 2, Worksheet, "Original Length" ); |
|
189 Utils.SetValue( row, 3, Worksheet, "New Length" ); |
|
190 Utils.SetValue( row, 4, Worksheet, "Symbol" ); |
|
191 |
|
192 // Make row bold |
|
193 Utils.BoldRow( row, Worksheet ); |
|
194 |
|
195 // Add border and cell colours |
|
196 Utils.MakeBoxedTitleRow( row, 4, Worksheet, 0xFF0000 ); |
|
197 |
|
198 // Create rows for frees |
|
199 ++row; |
|
200 int startRowFree = row; |
|
201 foreach ( HeapCell cell in Array ) |
|
202 { |
|
203 if ( cell.Type == HeapCell.TType.EFree ) |
|
204 { |
|
205 object[ , ] items = new object[ 1, 4 ]; |
|
206 // |
|
207 items[ 0, 0 ] = "0x" + cell.Address.ToString( "x8" ); |
|
208 |
|
209 // Put the length in the master cell and then |
|
210 // if we have a value for the other column, put it's value too |
|
211 items[ 0, iMasterCol ] = cell.Length.ToString(); |
|
212 if ( cell.Tag != null && cell.Tag is HeapCell ) |
|
213 { |
|
214 HeapCell newCell = (HeapCell) cell.Tag; |
|
215 items[ 0, iOtherCol ] = newCell.Length; |
|
216 } |
|
217 else |
|
218 { |
|
219 items[ 0, iOtherCol ] = "?"; |
|
220 } |
|
221 items[ 0, 3 ] = cell.SymbolStringWithoutDescriptorPrefix; |
|
222 // |
|
223 Range range = Utils.GetRangeByColumnAndRow( row, 1, row, 4, Worksheet ); |
|
224 range.Value2 = items; |
|
225 ++row; |
|
226 } |
|
227 } |
|
228 |
|
229 // Write totals |
|
230 ++row; |
|
231 Utils.SetValue( row, 1, Worksheet, "Total" ); |
|
232 Utils.SetValue( row, 1 + iMasterCol, Worksheet, "=SUM(" + Utils.ColumnAndRowAsExcelIdentifier( startRowFree, 1 + iMasterCol ) + ":" + Utils.ColumnAndRowAsExcelIdentifier( row - 1, 1 + iMasterCol ) + ")" ); |
|
233 Utils.SetValue( row, 1 + iOtherCol, Worksheet, "=SUM(" + Utils.ColumnAndRowAsExcelIdentifier( startRowFree, 1 + iOtherCol ) + ":" + Utils.ColumnAndRowAsExcelIdentifier( row - 1, 1 + iOtherCol ) + ")" ); |
|
234 Utils.SetValue( row, 4, Worksheet, "=" + Utils.ColumnAndRowAsExcelIdentifier( row, 1 + iMasterCol ) + "-" + Utils.ColumnAndRowAsExcelIdentifier( row, 1 + iOtherCol ) ); |
|
235 Utils.BoldRow( row, Worksheet ); |
|
236 |
|
237 // Auto fit the columns |
|
238 AutoFitColumns( 1, 4 ); |
|
239 OnTableComplete( row ); |
|
240 } |
|
241 #endregion |
|
242 |
|
243 #region Internal methods |
|
244 private void MakeStats( ref int aRow ) |
|
245 { |
|
246 Utils.SetValue( aRow, 1, Worksheet, "Type" ); |
|
247 Utils.SetValue( aRow, 2, Worksheet, "Amount" ); |
|
248 |
|
249 // Make row bold |
|
250 Utils.BoldRow( aRow, Worksheet ); |
|
251 |
|
252 // Add border and cell colours |
|
253 Utils.MakeBoxedTitleRow( aRow, 2, Worksheet, 0xFF0000 ); |
|
254 |
|
255 // Set column alignments |
|
256 Utils.SetColumnHorizontalAlignment( 2, Worksheet, XlHAlign.xlHAlignRight ); |
|
257 |
|
258 // Spacer |
|
259 aRow++; |
|
260 int firstRealRow = aRow; |
|
261 |
|
262 HeapStatistics stats = Array.Statistics; |
|
263 |
|
264 { |
|
265 Utils.SetValue( aRow, 1, Worksheet, "Total" ); |
|
266 Utils.SetValue( aRow, 2, Worksheet, stats.SizeTotal.ToString() ); |
|
267 } |
|
268 |
|
269 // Spacer |
|
270 aRow++; |
|
271 |
|
272 { |
|
273 aRow++; |
|
274 Utils.SetValue( aRow, 1, Worksheet, "Allocated Space" ); |
|
275 Utils.SetValue( aRow, 2, Worksheet, stats.StatsAllocated.TypeSize.ToString() ); |
|
276 aRow++; |
|
277 Utils.SetValue( aRow, 1, Worksheet, "Allocated Cell Count" ); |
|
278 Utils.SetValue( aRow, 2, Worksheet, stats.StatsAllocated.TypeCount.ToString() ); |
|
279 } |
|
280 |
|
281 // Spacer |
|
282 aRow++; |
|
283 |
|
284 { |
|
285 aRow++; |
|
286 Utils.SetValue( aRow, 1, Worksheet, "\"Unknown\" Allocated Space" ); |
|
287 Utils.SetValue( aRow, 2, Worksheet, stats.StatsAllocated.TrackerUnknown.AssociatedMemory.ToString() ); |
|
288 aRow++; |
|
289 Utils.SetValue( aRow, 1, Worksheet, "\"Unknown\" Allocated Cell Count" ); |
|
290 Utils.SetValue( aRow, 2, Worksheet, stats.StatsAllocated.TrackerUnknown.AssociatedCellCount.ToString() ); |
|
291 } |
|
292 |
|
293 // Spacer |
|
294 aRow++; |
|
295 |
|
296 { |
|
297 aRow++; |
|
298 Utils.SetValue( aRow, 1, Worksheet, "Descriptor Allocated Space" ); |
|
299 Utils.SetValue( aRow, 2, Worksheet, stats.StatsAllocated.TrackerDescriptors.AssociatedMemory.ToString() ); |
|
300 aRow++; |
|
301 Utils.SetValue( aRow, 1, Worksheet, "Descriptor Allocated Cell Count" ); |
|
302 Utils.SetValue( aRow, 2, Worksheet, stats.StatsAllocated.TrackerDescriptors.AssociatedCellCount.ToString() ); |
|
303 } |
|
304 |
|
305 // Spacer |
|
306 aRow++; |
|
307 |
|
308 { |
|
309 aRow++; |
|
310 Utils.SetValue( aRow, 1, Worksheet, "\"With Symbols\" Allocated Space" ); |
|
311 Utils.SetValue( aRow, 2, Worksheet, stats.StatsAllocated.TrackerSymbols.TypeSize.ToString() ); |
|
312 aRow++; |
|
313 Utils.SetValue( aRow, 1, Worksheet, "\"With Symbols\" Allocated Cell Count" ); |
|
314 Utils.SetValue( aRow, 2, Worksheet, stats.StatsAllocated.TrackerSymbols.CellMatchCount.ToString() ); |
|
315 } |
|
316 |
|
317 // Spacer |
|
318 aRow++; |
|
319 int freeaRow = aRow; |
|
320 |
|
321 { |
|
322 aRow++; |
|
323 Utils.SetValue( aRow, 1, Worksheet, "Free Space" ); |
|
324 Utils.SetValue( aRow, 2, Worksheet, stats.StatsFree.TypeSize.ToString() ); |
|
325 aRow++; |
|
326 Utils.SetValue( aRow, 1, Worksheet, "Free Cell Count" ); |
|
327 Utils.SetValue( aRow, 2, Worksheet, stats.StatsFree.TypeCount.ToString() ); |
|
328 } |
|
329 |
|
330 Utils.GetRangeByColumnAndRow( firstRealRow, 1, aRow, 1, Worksheet ).Font.Bold = true; |
|
331 |
|
332 // Spacer |
|
333 aRow++; |
|
334 aRow++; |
|
335 } |
|
336 #endregion |
|
337 |
|
338 #region Data members |
|
339 private readonly int iMasterCol; |
|
340 private readonly int iOtherCol; |
|
341 private readonly bool iMakeStats; |
|
342 #endregion |
|
343 } |
|
344 } |