|
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.Runtime.InteropServices; |
|
40 using Microsoft.Office.Interop.Excel; |
|
41 using SymbianExcelUtils; |
|
42 |
|
43 namespace HeapComparisonLib.CSV.Comparers |
|
44 { |
|
45 internal class Fragmentation : ComparerBase |
|
46 { |
|
47 #region Constructors & destructor |
|
48 public Fragmentation( Worksheet aSheet, string aFileName1, string aFileName2 ) |
|
49 : base( aSheet, aFileName1, aFileName2 ) |
|
50 { |
|
51 } |
|
52 #endregion |
|
53 |
|
54 #region API |
|
55 public override string DeltaFormula( int aIndex ) |
|
56 { |
|
57 int column = 4; |
|
58 return Utils.MakeSummationFormula( 3, Row - 2, column, Sheet ); |
|
59 } |
|
60 |
|
61 public override void PrepareWorksheetReadyForData() |
|
62 { |
|
63 Sheet.Name = "Fragmentation"; |
|
64 // |
|
65 Range r = null; |
|
66 // |
|
67 Utils.SetValue( Row, 1, Sheet, "Thread" ); |
|
68 r = Utils.SetValue( Row, 2, Sheet, "Fragmentation" ); |
|
69 r.AddComment( FileName1 ); |
|
70 r = Utils.SetValue( Row, 3, Sheet, "Fragmentation" ); |
|
71 r.AddComment( FileName2 ); |
|
72 Utils.SetValue( Row, 4, Sheet, "Delta" ); |
|
73 // |
|
74 Utils.MakeBoxedTitleRow( Row, 4, Sheet, 0xFF0000 ); |
|
75 // |
|
76 NextRow(); |
|
77 NextRow(); |
|
78 } |
|
79 |
|
80 public override void FinaliseWorksheet() |
|
81 { |
|
82 // Make totals |
|
83 NextRow(); |
|
84 Utils.SetValue( Row, 1, Sheet, "Totals:" ); |
|
85 Utils.SetValue( Row, 2, Sheet, "=SUM(" + Utils.ColumnAndRowAsExcelIdentifier( 3, 2) + ":" + Utils.ColumnAndRowAsExcelIdentifier( Row - 2, 2) + ")" ); |
|
86 Utils.SetValue( Row, 3, Sheet, "=SUM(" + Utils.ColumnAndRowAsExcelIdentifier( 3, 3) + ":" + Utils.ColumnAndRowAsExcelIdentifier( Row - 2, 3) + ")" ); |
|
87 Utils.SetValue( Row, 4, Sheet, DeltaFormula( 0 ) ); |
|
88 Utils.BoldRow( Row, Sheet ); |
|
89 |
|
90 // Format cells as percentages |
|
91 Range r = Utils.GetRangeByColumnAndRow( 3, 2, Row, 4, Sheet ); |
|
92 r.NumberFormat = "0.00%"; |
|
93 |
|
94 // Calculate column sizes |
|
95 Utils.AutoFitColumn( 1, Sheet, 70.0 ); |
|
96 Utils.AutoFitColumn( 2, Sheet ); |
|
97 Utils.AutoFitColumn( 3, Sheet ); |
|
98 Utils.AutoFitColumn( 4, Sheet ); |
|
99 } |
|
100 |
|
101 public override void Compare( CSVThread aMaster, CSVThread aOther ) |
|
102 { |
|
103 Utils.SetValue( Row, 1, Sheet, aMaster.FullName ); |
|
104 // |
|
105 float frag1Value = (float) aMaster.FreeSpaceTotal / (float) aMaster.SizeCurrent; |
|
106 string frag1 = "=" + aMaster.FreeSpaceTotal.ToString() + " / " + aMaster.SizeCurrent.ToString(); |
|
107 if ( aMaster.SizeCurrent == 0 ) |
|
108 { |
|
109 frag1Value = 0.0F; |
|
110 frag1 = "=0"; |
|
111 } |
|
112 if ( !aMaster.IsDefault ) |
|
113 Utils.SetValue( Row, 2, Sheet, frag1 ); |
|
114 // |
|
115 float frag2Value = (float) aOther.FreeSpaceTotal / (float) aOther.SizeCurrent; |
|
116 string frag2 = "=" + aOther.FreeSpaceTotal.ToString() + " / " + aOther.SizeCurrent.ToString(); |
|
117 if ( aOther.SizeCurrent == 0 ) |
|
118 { |
|
119 frag2Value = 0.0F; |
|
120 frag2 = "=0"; |
|
121 } |
|
122 if ( !aOther.IsDefault ) |
|
123 Utils.SetValue( Row, 3, Sheet, frag2 ); |
|
124 |
|
125 if ( aMaster.IsDefault || aOther.IsDefault ) |
|
126 { |
|
127 Utils.GetRangeByColumnAndRow( Row, 1, Row, 1, Sheet ).Font.Bold = true; |
|
128 } |
|
129 |
|
130 // Delta |
|
131 float delta = frag1Value - frag2Value; |
|
132 Utils.SetValue( Row, 4, Sheet, ( delta * -1.0).ToString() ); |
|
133 |
|
134 // Colourise line according to difference |
|
135 int colour = 0x000000; // black |
|
136 if ( frag2Value > frag1Value ) |
|
137 { |
|
138 // Original size was smaller than new size => heap has grown |
|
139 colour = 0x0000FF; // red |
|
140 } |
|
141 else if ( frag2Value < frag1Value ) |
|
142 { |
|
143 // Original size was bigger than new size => heap has shrunk |
|
144 colour = 0xFF0000; // blue |
|
145 } |
|
146 Utils.SetRangeFontColour( Row, 4, Row, 4, Sheet, colour ); |
|
147 // |
|
148 NextRow(); |
|
149 } |
|
150 #endregion |
|
151 } |
|
152 } |