sysperfana/heapanalyser/Libraries/Engine/HeapComparisonLib/CSV/Thread/CSVThread.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.Text;
       
    40 using System.Text.RegularExpressions;
       
    41 using System.Collections.Generic;
       
    42 using SymbianUtils;
       
    43 
       
    44 namespace HeapComparisonLib.CSV
       
    45 {
       
    46     internal class CSVThread
       
    47     {
       
    48         #region Enumerations
       
    49         public enum TFileFormatVersion
       
    50         {
       
    51             EFileFormatVersion1 = 1,
       
    52             EFileFormatVersion2,
       
    53         }
       
    54         #endregion
       
    55 
       
    56         #region Static constructor
       
    57         static public CSVThread New()
       
    58         {
       
    59             CSVThread ret = new CSVThread();
       
    60             return ret;
       
    61         }
       
    62 
       
    63 		static public CSVThread NewDefault( string aThreadName )
       
    64 		{
       
    65 			CSVThread ret = new CSVThread();
       
    66 			ret.iThreadName = aThreadName;
       
    67 			ret.iIsDefault = true;
       
    68 			return ret;
       
    69 		}
       
    70 		#endregion
       
    71 
       
    72         #region Constructor
       
    73 		private CSVThread()
       
    74 		{
       
    75 		}
       
    76 		#endregion
       
    77 
       
    78         #region API
       
    79         public void AddThreadWithCommonHeapChunkHandle( CSVThread aOtherThread )
       
    80         {
       
    81             if ( aOtherThread != this )
       
    82             {
       
    83                 if ( iThreadsWithCommonHeapChunk == null )
       
    84                 {
       
    85                     iThreadsWithCommonHeapChunk = new List<CSVThread>();
       
    86                 }
       
    87                 iThreadsWithCommonHeapChunk.Add( aOtherThread );
       
    88             }
       
    89         }
       
    90         #endregion
       
    91 
       
    92         #region Properties
       
    93         public TFileFormatVersion Version
       
    94         {
       
    95             get
       
    96             {
       
    97                 TFileFormatVersion ret = TFileFormatVersion.EFileFormatVersion1;
       
    98                 if ( ProcessName != string.Empty && ThreadId != 0 )
       
    99                 {
       
   100                     ret = TFileFormatVersion.EFileFormatVersion2;
       
   101                 }
       
   102                 return ret;
       
   103             }
       
   104         }
       
   105 
       
   106         public bool IsDefault { get { return iIsDefault; } set { iIsDefault = value; } }
       
   107         public bool IsSharedHeap
       
   108         { 
       
   109             get 
       
   110             { 
       
   111                 return iIsSharedHeap; 
       
   112             }
       
   113             set { iIsSharedHeap = value; } 
       
   114         }
       
   115 
       
   116         public string FullName
       
   117         {
       
   118             get
       
   119             {
       
   120                 StringBuilder ret = new StringBuilder();
       
   121                 //
       
   122                 if ( Version == TFileFormatVersion.EFileFormatVersion2 )
       
   123                 {
       
   124                     ret.AppendFormat( "{0}::{1}", ProcessName, ThreadName );
       
   125                 }
       
   126                 else
       
   127                 {
       
   128                     // Old format doesn't support process name
       
   129                     ret.Append( ThreadName );
       
   130                 }
       
   131                 //
       
   132                 return ret.ToString();
       
   133             }
       
   134         }
       
   135 
       
   136         public string ThreadName { get { return iThreadName; } set { iThreadName = value; } }
       
   137         public string ProcessName { get { return iProcessName; } set { iProcessName = value; } }
       
   138         public string ChunkName { get { return iChunkName; } set { iChunkName = value; } }
       
   139 
       
   140         public long ThreadId { get { return iThreadId; } set { iThreadId = value; } }
       
   141 
       
   142         public long ChunkHandle { get { return iChunkHandle; } set { iChunkHandle = value; } }
       
   143         public long ChunkBaseAddress { get { return iChunkBaseAddress; } set { iChunkBaseAddress = value; } }
       
   144 
       
   145         public long SizeCurrent { get { return iSizeCurrent; } set { iSizeCurrent = value; } }
       
   146         public long SizeMin { get { return iSizeMin; } set { iSizeMin = value; } }
       
   147         public long SizeMax { get { return iSizeMax; } set { iSizeMax = value; } }
       
   148 
       
   149         public long FirstFreeCellAddress { get { return iFirstFreeCellAddress; } set { iFirstFreeCellAddress = value; } }
       
   150         public long FirstFreeCellLength { get { return iFirstFreeCellLength; } set { iFirstFreeCellLength = value; } }
       
   151 
       
   152         public long FreeCellCount { get { return iFreeCellCount; } set { iFreeCellCount = value; } }
       
   153         public long FreeCellLargest { get { return iFreeCellLargest; } set { iFreeCellLargest = value; } }
       
   154         public long FreeSpaceTotal { get { return iFreeSpaceTotal; } set { iFreeSpaceTotal = value; } }
       
   155         public long FreeSpaceSlack { get { return iFreeSpaceSlack; } set { iFreeSpaceSlack = value; } }
       
   156 
       
   157         public long AllocCellLargest { get { return iAllocCellLargest; } set { iAllocCellLargest = value; } }
       
   158         public long AllocCellCount { get { return iAllocCellCount; } set { iAllocCellCount = value; } }
       
   159         public long AllocSpaceTotal { get { return iAllocSpaceTotal; } set { iAllocSpaceTotal = value; } }
       
   160 
       
   161         public long MinCellSize { get { return iMinCellSize; } set { iMinCellSize = value; } }
       
   162         #endregion
       
   163 
       
   164 		#region From System.Object
       
   165 		public override string ToString()
       
   166 		{
       
   167 			return iThreadName;
       
   168 		}
       
   169 
       
   170 		public override Int32 GetHashCode()
       
   171 		{
       
   172 			return iThreadName.GetHashCode();
       
   173 		}
       
   174 		#endregion
       
   175 
       
   176 		#region Internal methods
       
   177 		private static long ParseHexValue( string aItem )
       
   178 		{
       
   179 			long ret = 0;
       
   180 			//
       
   181 			if	( aItem.Length > 0 )
       
   182 			{
       
   183 				const string KHexPrefix = "0x";
       
   184 				if	( aItem.IndexOf( KHexPrefix ) == 0 )
       
   185 				{
       
   186 					aItem = aItem.Substring( KHexPrefix.Length );
       
   187 				}
       
   188 
       
   189 				ret = System.Convert.ToInt32( aItem, 16 );
       
   190 			}
       
   191 			//
       
   192 			return ret;
       
   193 		}
       
   194 
       
   195 		private static long ParseDecimalValue( string aItem )
       
   196 		{
       
   197 			long ret = 0;
       
   198 			//
       
   199 			if	( aItem.Length > 0 ) 
       
   200 			{
       
   201 				ret = System.Convert.ToInt32( aItem );
       
   202 			}
       
   203 			//
       
   204 			return ret;
       
   205 		}
       
   206 		#endregion
       
   207 
       
   208         #region Internal constants
       
   209         private const int KExpectedItemCount = 16;
       
   210         private const string KRDebugLinePrefix = "[Heap Summary] ";
       
   211         #endregion
       
   212 
       
   213         #region Data members
       
   214         private bool iIsDefault = false;
       
   215         private bool iIsSharedHeap = false;
       
   216         
       
   217         private string iThreadName = string.Empty;
       
   218         private string iProcessName = string.Empty;
       
   219         private string iChunkName = string.Empty;
       
   220 
       
   221         private long iThreadId = 0;
       
   222 
       
   223         private long iChunkHandle = 0;
       
   224         private long iChunkBaseAddress = 0;
       
   225 
       
   226         private long iSizeCurrent = 0;
       
   227         private long iSizeMin = 0;
       
   228         private long iSizeMax = 0;
       
   229 
       
   230         private long iFirstFreeCellAddress = 0;
       
   231         private long iFirstFreeCellLength = 0;
       
   232         //
       
   233         private long iFreeCellCount = 0;
       
   234         private long iFreeCellLargest = 0;
       
   235 
       
   236         private long iFreeSpaceTotal = 0;
       
   237         private long iFreeSpaceSlack = 0;
       
   238 
       
   239         private long iAllocCellLargest = 0;
       
   240         private long iAllocCellCount = 0;
       
   241         private long iAllocSpaceTotal = 0;
       
   242 
       
   243         private long iMinCellSize = 0;
       
   244 
       
   245         private List<CSVThread> iThreadsWithCommonHeapChunk;
       
   246 		#endregion
       
   247 	}
       
   248 }