|
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.IO; |
|
40 using System.Text; |
|
41 using System.Text.RegularExpressions; |
|
42 using System.Collections; |
|
43 using System.Collections.Generic; |
|
44 using SymbianUtils.FileSystem.FilePair; |
|
45 using HeapLib.Reconstructor.DataSources.Analyser.Interpreter; |
|
46 using HeapLib.Reconstructor.DataSources.Analyser.Extractor; |
|
47 |
|
48 namespace HeapLib.Reconstructor.DataSources |
|
49 { |
|
50 public class DataSource |
|
51 { |
|
52 #region Enumerations |
|
53 public enum TSourceType |
|
54 { |
|
55 ESourceTypeTextTrace = 0, |
|
56 ESourceTypeTextDynamic, |
|
57 ESourceTypeBinary |
|
58 } |
|
59 |
|
60 [Flags] |
|
61 public enum TErrorTypes |
|
62 { |
|
63 EErrorTypeNone = 0, |
|
64 EErrorTypeInvalidFreeCellIndexInFreeList = 1, |
|
65 EErrorTypeFreeCellAddressOutOfBounds = 2, |
|
66 EErrorTypeDataMissing = 4, |
|
67 } |
|
68 #endregion |
|
69 |
|
70 #region Constructors & destructor |
|
71 internal DataSource( string aFileName, long aLineNumber ) |
|
72 { |
|
73 iFileName = aFileName; |
|
74 iLineNumber = aLineNumber; |
|
75 } |
|
76 #endregion |
|
77 |
|
78 #region API |
|
79 internal void AddLine( string aLine ) |
|
80 { |
|
81 iLines.Add( aLine ); |
|
82 } |
|
83 |
|
84 internal void AddError( TErrorTypes aError ) |
|
85 { |
|
86 iErrorType |= aError; |
|
87 } |
|
88 |
|
89 public bool ErrorsDetected() |
|
90 { |
|
91 string msg = string.Empty; |
|
92 return ErrorsDetected( out msg ); |
|
93 } |
|
94 |
|
95 public bool ErrorsDetected( out string aMessage ) |
|
96 { |
|
97 StringBuilder msg = new StringBuilder(); |
|
98 // |
|
99 if ( ( iErrorType & TErrorTypes.EErrorTypeDataMissing ) == TErrorTypes.EErrorTypeDataMissing ) |
|
100 { |
|
101 msg.AppendLine( "ERROR: Data is incomplete." ); |
|
102 } |
|
103 if ( ( iErrorType & TErrorTypes.EErrorTypeInvalidFreeCellIndexInFreeList ) == TErrorTypes.EErrorTypeInvalidFreeCellIndexInFreeList ) |
|
104 { |
|
105 msg.AppendLine( "ERROR: Mis-match between free cell list and free cell count." ); |
|
106 } |
|
107 if ( ( iErrorType & TErrorTypes.EErrorTypeFreeCellAddressOutOfBounds ) == TErrorTypes.EErrorTypeFreeCellAddressOutOfBounds ) |
|
108 { |
|
109 msg.AppendLine( "ERROR: Free cell address falls outside heap bounds." ); |
|
110 } |
|
111 // |
|
112 aMessage = msg.ToString(); |
|
113 return ( iErrorType != TErrorTypes.EErrorTypeNone ); |
|
114 } |
|
115 |
|
116 public FileNamePair PrepareSourceFileDataForZip() |
|
117 { |
|
118 FileNamePair ret = new FileNamePair( FileName ); |
|
119 |
|
120 // Need to make a temporary file |
|
121 string tempFileName = Path.GetTempFileName(); |
|
122 using ( StreamWriter writer = new StreamWriter( tempFileName, false ) ) |
|
123 { |
|
124 foreach ( string line in iLines ) |
|
125 { |
|
126 writer.WriteLine( line ); |
|
127 } |
|
128 } |
|
129 |
|
130 ret = new FileNamePair( tempFileName ); |
|
131 ret.Destination = "HeapData/SourceData.txt"; |
|
132 ret.DeleteFile = true; |
|
133 // |
|
134 return ret; |
|
135 } |
|
136 #endregion |
|
137 |
|
138 #region Properties |
|
139 public TSourceType SourceType |
|
140 { |
|
141 get |
|
142 { |
|
143 TSourceType ret = TSourceType.ESourceTypeTextDynamic; |
|
144 // |
|
145 if ( FileName.Length > 0 ) |
|
146 { |
|
147 ret = TSourceType.ESourceTypeTextTrace; |
|
148 } |
|
149 // |
|
150 return ret; |
|
151 } |
|
152 } |
|
153 |
|
154 public string FileName |
|
155 { |
|
156 get { return iFileName; } |
|
157 } |
|
158 |
|
159 public string ThreadName |
|
160 { |
|
161 get { return iThreadName; } |
|
162 set { iThreadName = value; } |
|
163 } |
|
164 |
|
165 public Elements.MetaData MetaData |
|
166 { |
|
167 get { return iMetaData; } |
|
168 } |
|
169 |
|
170 internal bool IsEmpty |
|
171 { |
|
172 get |
|
173 { |
|
174 bool empty = iMetaData.HeapData.Count == 0; |
|
175 return empty; |
|
176 } |
|
177 } |
|
178 |
|
179 public long LineNumber |
|
180 { |
|
181 get { return iLineNumber; } |
|
182 } |
|
183 #endregion |
|
184 |
|
185 #region From System.Object |
|
186 public override string ToString() |
|
187 { |
|
188 StringBuilder ret = new StringBuilder(); |
|
189 ret.AppendFormat( "{0} @ line {1:d6}, {2} bytes, {3} allocs", ThreadName, LineNumber, MetaData.Heap.ChunkSize, MetaData.Heap.InfoAlloc.AllocCellCount ); |
|
190 return ret.ToString(); |
|
191 } |
|
192 #endregion |
|
193 |
|
194 #region Data members |
|
195 private readonly string iFileName; |
|
196 private readonly long iLineNumber; |
|
197 private TErrorTypes iErrorType = TErrorTypes.EErrorTypeNone; |
|
198 private string iThreadName = string.Empty; |
|
199 private List<string> iLines = new List<string>(); |
|
200 private Elements.MetaData iMetaData = new HeapLib.Reconstructor.DataSources.Elements.MetaData(); |
|
201 #endregion |
|
202 } |
|
203 } |