|
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 HeapLib.Cells; |
|
40 using HeapLib.Statistics.Distribution; |
|
41 using HeapLib.Array; |
|
42 |
|
43 namespace HeapLib.Statistics.Types |
|
44 { |
|
45 public class HeapStatisticsBase |
|
46 { |
|
47 #region Constructors & destructor |
|
48 public HeapStatisticsBase( HeapCell.TType aType ) |
|
49 { |
|
50 iType = aType; |
|
51 } |
|
52 #endregion |
|
53 |
|
54 #region Framework API |
|
55 internal virtual void Finalise( HeapCellArrayBase aArray ) |
|
56 { |
|
57 // Some operations cannot run until after the relationship inspector has finished it's task. |
|
58 foreach ( HeapCell cell in aArray ) |
|
59 { |
|
60 int newCellCountReferencedBy = cell.RelationshipManager.ReferencedBy.Count; |
|
61 if ( iCellNumberOfReferencesGreatest == null || newCellCountReferencedBy > iCellNumberOfReferencesGreatest.RelationshipManager.ReferencedBy.Count ) |
|
62 { |
|
63 iCellNumberOfReferencesGreatest = cell; |
|
64 } |
|
65 if ( iCellNumberOfReferencesLowest == null || newCellCountReferencedBy < iCellNumberOfReferencesLowest.RelationshipManager.ReferencedBy.Count ) |
|
66 { |
|
67 iCellNumberOfReferencesLowest = cell; |
|
68 } |
|
69 |
|
70 int newCellCountEmbeddedReferences = cell.RelationshipManager.EmbeddedReferencesTo.Count; |
|
71 if ( iCellNumberOfEmbeddedReferencesMost == null || newCellCountEmbeddedReferences > iCellNumberOfEmbeddedReferencesMost.RelationshipManager.EmbeddedReferencesTo.Count ) |
|
72 { |
|
73 iCellNumberOfEmbeddedReferencesMost = cell; |
|
74 } |
|
75 if ( iCellNumberOfEmbeddedReferencesLeast == null || newCellCountEmbeddedReferences < iCellNumberOfEmbeddedReferencesLeast.RelationshipManager.EmbeddedReferencesTo.Count ) |
|
76 { |
|
77 iCellNumberOfEmbeddedReferencesLeast = cell; |
|
78 } |
|
79 } |
|
80 } |
|
81 |
|
82 internal virtual void HandleCell( HeapCell aCell ) |
|
83 { |
|
84 ++iTypeCount; |
|
85 // |
|
86 iTypeSizeHeader += aCell.HeaderSize; |
|
87 iTypeSizePayload += aCell.PayloadLength; |
|
88 // |
|
89 iDistribution.Register( aCell.Length ); |
|
90 // |
|
91 if ( iCellLargest == null || aCell.Length > iCellLargest.Length ) |
|
92 { |
|
93 iCellLargest = aCell; |
|
94 } |
|
95 if ( iCellSmallest == null || aCell.Length < iCellSmallest.Length ) |
|
96 { |
|
97 iCellSmallest = aCell; |
|
98 } |
|
99 // |
|
100 if ( iCellAllocationNumberLargest == null || aCell.AllocationNumber > iCellAllocationNumberLargest.AllocationNumber ) |
|
101 { |
|
102 iCellAllocationNumberLargest = aCell; |
|
103 } |
|
104 if ( iCellAllocationNumberSmallest == null || aCell.AllocationNumber > iCellAllocationNumberSmallest.AllocationNumber ) |
|
105 { |
|
106 iCellAllocationNumberSmallest = aCell; |
|
107 } |
|
108 } |
|
109 #endregion |
|
110 |
|
111 #region API |
|
112 public float CellLengthAsTypePercentage( HeapCell aCell ) |
|
113 { |
|
114 float ret = (float) aCell.Length / (float) TypeSize; |
|
115 return ret * 100.0f; |
|
116 } |
|
117 #endregion |
|
118 |
|
119 #region Properties |
|
120 public HeapCell.TType Type |
|
121 { |
|
122 get { return iType; } |
|
123 } |
|
124 |
|
125 public int TypeCount |
|
126 { |
|
127 get { return iTypeCount; } |
|
128 } |
|
129 |
|
130 public long TypeSize |
|
131 { |
|
132 get { return iTypeSizeHeader + iTypeSizePayload; } |
|
133 } |
|
134 |
|
135 public long TypeSizeHeader |
|
136 { |
|
137 get { return iTypeSizeHeader; } |
|
138 } |
|
139 |
|
140 public long TypeSizePayload |
|
141 { |
|
142 get { return iTypeSizePayload; } |
|
143 } |
|
144 |
|
145 public HeapCell CellAllocationNumberLargest |
|
146 { |
|
147 get { return iCellAllocationNumberLargest; } |
|
148 } |
|
149 |
|
150 public HeapCell CellAllocationNumberSmallest |
|
151 { |
|
152 get { return iCellAllocationNumberSmallest; } |
|
153 } |
|
154 |
|
155 public HeapCell CellLargest |
|
156 { |
|
157 get { return iCellLargest; } |
|
158 } |
|
159 |
|
160 public HeapCell CellSmallest |
|
161 { |
|
162 get { return iCellSmallest; } |
|
163 } |
|
164 |
|
165 public HeapCell CellNumberOfReferencesLowest |
|
166 { |
|
167 get { return iCellNumberOfReferencesLowest; } |
|
168 } |
|
169 |
|
170 public HeapCell CellNumberOfReferencesGreatest |
|
171 { |
|
172 get { return iCellNumberOfReferencesGreatest; } |
|
173 } |
|
174 |
|
175 public HeapCell CellNumberOfEmbeddedReferencesLeast |
|
176 { |
|
177 get { return iCellNumberOfEmbeddedReferencesLeast; } |
|
178 } |
|
179 |
|
180 public HeapCell CellNumberOfEmbeddedReferencesMost |
|
181 { |
|
182 get { return iCellNumberOfEmbeddedReferencesMost; } |
|
183 } |
|
184 |
|
185 public HeapCellSizeDistribution Distribution |
|
186 { |
|
187 get { return iDistribution; } |
|
188 } |
|
189 #endregion |
|
190 |
|
191 #region Data members |
|
192 private readonly HeapCell.TType iType; |
|
193 private int iTypeCount; |
|
194 private long iTypeSizeHeader; |
|
195 private long iTypeSizePayload; |
|
196 private HeapCell iCellAllocationNumberLargest = null; |
|
197 private HeapCell iCellAllocationNumberSmallest = null; |
|
198 private HeapCell iCellNumberOfReferencesLowest = null; |
|
199 private HeapCell iCellNumberOfReferencesGreatest = null; |
|
200 private HeapCell iCellNumberOfEmbeddedReferencesLeast = null; |
|
201 private HeapCell iCellNumberOfEmbeddedReferencesMost = null; |
|
202 private HeapCell iCellLargest = new HeapCell( 0, uint.MinValue, HeapCell.TType.EAllocated ); |
|
203 private HeapCell iCellSmallest = new HeapCell( 0, uint.MaxValue, HeapCell.TType.EAllocated ); |
|
204 private HeapCellSizeDistribution iDistribution = new HeapCellSizeDistribution(); |
|
205 #endregion |
|
206 } |
|
207 } |