sysperfana/heapanalyser/Libraries/Engine/HeapLib/Statistics/Tracking/Base/TrackingInfo.cs
changeset 8 15296fd0af4a
equal deleted inserted replaced
7:8e12a575a9b5 8:15296fd0af4a
       
     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;
       
    40 using System.Collections.Generic;
       
    41 using SymbianStructuresLib.Debug.Symbols;
       
    42 using SymbianStructuresLib.Debug.Symbols.Constants;
       
    43 using HeapLib.Cells;
       
    44 using HeapLib.Array;
       
    45 
       
    46 namespace HeapLib.Statistics.Tracking.Base
       
    47 {
       
    48     public class TrackingInfo : IEnumerable<HeapCell>
       
    49     {
       
    50         #region Static 'Null Entry' item
       
    51         internal static TrackingInfo CreateNull()
       
    52         {
       
    53             Symbol defaultSym = Symbol.NewDefault();
       
    54             TrackingInfo self = new TrackingInfo( defaultSym );
       
    55             return self;
       
    56         }
       
    57         #endregion
       
    58 
       
    59         #region Constructors & destructor
       
    60         internal TrackingInfo( Symbol aSymbol )
       
    61         {
       
    62             iSymbol = aSymbol;
       
    63         }
       
    64         #endregion
       
    65 
       
    66         #region Methods
       
    67         internal void Associate( HeapCell aCell )
       
    68         {
       
    69             // Don't track cell associations for items
       
    70             // without symbols.
       
    71             if  ( aCell.Symbol != null )
       
    72             {
       
    73                 iAssociatedCells.Add( aCell );
       
    74             }
       
    75 
       
    76             // Then we'll update the rest of the details
       
    77             // for all types.
       
    78             IncrementCount();
       
    79             iAssociatedMemory += aCell.Length;
       
    80         }
       
    81 
       
    82         internal void IncrementCount()
       
    83         {
       
    84             ++iCount;
       
    85         }
       
    86         #endregion
       
    87 
       
    88         #region Properties
       
    89         public int AssociatedCellCount
       
    90         {
       
    91             get { return iAssociatedCells.Count; }
       
    92         }
       
    93 
       
    94         internal long Key
       
    95         {
       
    96             get
       
    97             {
       
    98                 long key = SymbolConstants.KNullEntryAddress;
       
    99                 //
       
   100                 if ( !IsUnknownSymbolMatchItem )
       
   101                 {
       
   102                     key = iSymbol.Address;
       
   103                 }
       
   104                 //
       
   105                 return key;
       
   106             }
       
   107         }
       
   108 
       
   109         public bool IsUnknownSymbolMatchItem
       
   110         {
       
   111             get { return iSymbol == null; }
       
   112         }
       
   113 
       
   114         public Symbol Symbol
       
   115         {
       
   116             get { return iSymbol; }
       
   117         }
       
   118 
       
   119         public int Count
       
   120         {
       
   121             get { return iCount; }
       
   122         }
       
   123 
       
   124         public long AssociatedMemory
       
   125         {
       
   126             get { return iAssociatedMemory; }
       
   127         }
       
   128 
       
   129         public long PayloadLength
       
   130         {
       
   131             get { return iPayloadLength; }
       
   132             set { iPayloadLength = value; }
       
   133         }
       
   134 
       
   135         public HeapCell this[ int aIndex ]
       
   136         {
       
   137             get { return iAssociatedCells[ aIndex ]; }
       
   138         }
       
   139         #endregion
       
   140 
       
   141         #region From System.Object
       
   142         public override string ToString()
       
   143         {
       
   144             string ret = iSymbol.ToString();
       
   145             return ret;
       
   146         }
       
   147         #endregion
       
   148 
       
   149         #region IEnumerable Members
       
   150         IEnumerator IEnumerable.GetEnumerator()
       
   151         {
       
   152             return iAssociatedCells.CreateEnumerator();
       
   153         }
       
   154 
       
   155         IEnumerator<HeapCell> IEnumerable<HeapCell>.GetEnumerator()
       
   156         {
       
   157             return iAssociatedCells.CreateEnumerator();
       
   158         }
       
   159         #endregion
       
   160 
       
   161         #region Data Members
       
   162         private Symbol iSymbol = null;
       
   163         private int iCount = 0;
       
   164         private long iAssociatedMemory = 0;
       
   165         private long iPayloadLength = 0;
       
   166         private HeapCellArray iAssociatedCells = new HeapCellArray( 10 );
       
   167         #endregion
       
   168     }
       
   169 }