1-
2-
3- using System ;
1+ using System ;
42using System . Collections . Generic ;
53using System . Globalization ;
64using System . IO ;
@@ -13,8 +11,22 @@ public class PmipReader
1311 private static List < Range > _rangesSortedByIp = new List < Range > ( ) ;
1412 private static List < Range > _legacyRanges = new List < Range > ( ) ;
1513 private static FuzzyRangeComparer _comparer = new FuzzyRangeComparer ( ) ;
16- private static FileStream _fileStream ;
17- private static StreamReader _fileStreamReader ;
14+
15+ private struct PmipStreams
16+ {
17+ public FileStream fileStream ;
18+ public StreamReader fileStreamReader ;
19+
20+ public void Dispose ( )
21+ {
22+ fileStreamReader . Dispose ( ) ;
23+ fileStreamReader = null ;
24+ fileStream . Dispose ( ) ;
25+ fileStream = null ;
26+ }
27+ }
28+
29+ private static Dictionary < string , PmipStreams > _currentFiles = new Dictionary < string , PmipStreams > ( ) ;
1830
1931 public static void Sort ( )
2032 {
@@ -24,46 +36,56 @@ public static void Sort()
2436
2537 public static void DisposeStreams ( )
2638 {
27- _fileStreamReader ? . Dispose ( ) ;
28- _fileStreamReader = null ;
29-
30- _fileStream ? . Dispose ( ) ;
31- _fileStream = null ;
39+ foreach ( PmipStreams streams in _currentFiles . Values )
40+ streams . Dispose ( ) ;
41+ _currentFiles . Clear ( ) ;
3242
3343 _rangesSortedByIp . Clear ( ) ;
44+ _legacyRanges . Clear ( ) ;
3445 }
3546 public static bool ReadPmipFile ( string filePath )
3647 {
37- //_debugPane?.OutputString("MIXEDCALLSTACK :: Reading pmip file: " + filePath + "\n");
38- DisposeStreams ( ) ;
39- try
48+ var _debugPane = UnityMixedCallstackFilter . _debugPane ;
49+ #if DEBUG
50+ _debugPane ? . OutputString ( "MIXEDCALLSTACK :: Reading pmip file: " + filePath + "\n " ) ;
51+ #endif
52+ //DisposeStreams();
53+
54+ if ( ! _currentFiles . TryGetValue ( filePath , out PmipStreams pmipStreams ) )
4055 {
41- _fileStream = new FileStream ( filePath , FileMode . Open , FileAccess . Read , FileShare . ReadWrite | FileShare . Delete ) ;
42- _fileStreamReader = new StreamReader ( _fileStream ) ;
43- var versionStr = _fileStreamReader . ReadLine ( ) ;
44- const char delimiter = ':' ;
45- var tokens = versionStr . Split ( delimiter ) ;
56+ pmipStreams = new PmipStreams ( ) ;
57+ try
58+ {
59+ pmipStreams . fileStream = new FileStream ( filePath , FileMode . Open , FileAccess . Read , FileShare . ReadWrite | FileShare . Delete ) ;
60+ pmipStreams . fileStreamReader = new StreamReader ( pmipStreams . fileStream ) ;
61+ var versionStr = pmipStreams . fileStreamReader . ReadLine ( ) ;
62+ const char delimiter = ':' ;
63+ var tokens = versionStr . Split ( delimiter ) ;
4664
47- if ( tokens . Length != 2 )
48- throw new Exception ( "Failed reading input file " + filePath + ": Incorrect format" ) ;
65+ if ( tokens . Length != 2 )
66+ throw new Exception ( "Failed reading input file " + filePath + ": Incorrect format" ) ;
4967
50- if ( ! double . TryParse ( tokens [ 1 ] , NumberStyles . AllowDecimalPoint , CultureInfo . InvariantCulture , out var version ) )
51- throw new Exception ( "Failed reading input file " + filePath + ": Incorrect version format" ) ;
68+ if ( ! double . TryParse ( tokens [ 1 ] , NumberStyles . AllowDecimalPoint , CultureInfo . InvariantCulture , out var version ) )
69+ throw new Exception ( "Failed reading input file " + filePath + ": Incorrect version format" ) ;
5270
53- if ( version > 2.0 )
54- throw new Exception ( "Failed reading input file " + filePath + ": A newer version of UnityMixedCallstacks plugin is required to read this file" ) ;
55- }
56- catch ( Exception ex )
57- {
58- //_debugPane?.OutputString("MIXEDCALLSTACK :: Unable to read dumped pmip file: " + ex.Message + "\n");
59- DisposeStreams ( ) ;
60- return false ;
71+ if ( version > 2.0 )
72+ throw new Exception ( "Failed reading input file " + filePath + ": A newer version of UnityMixedCallstacks plugin is required to read this file" ) ;
73+ }
74+ catch ( Exception ex )
75+ {
76+ _debugPane ? . OutputString ( "MIXEDCALLSTACK :: Unable to read dumped pmip file: " + ex . Message + "\n " ) ;
77+ DisposeStreams ( ) ;
78+ return false ;
79+ }
80+ _currentFiles . Add ( filePath , pmipStreams ) ;
6181 }
6282
6383 try
6484 {
6585 string line ;
66- while ( ( line = _fileStreamReader . ReadLine ( ) ) != null )
86+ int count = 0 ;
87+ int legacyCount = 0 ;
88+ while ( ( line = pmipStreams . fileStreamReader . ReadLine ( ) ) != null )
6789 {
6890 const char delemiter = ';' ;
6991 var tokens = line . Split ( delemiter ) ;
@@ -89,16 +111,27 @@ public static bool ReadPmipFile(string filePath)
89111 {
90112 // legacy stored in new pmip file
91113 _legacyRanges . Add ( new Range ( ) { Name = description , File = file , Start = startiplong , End = endipint } ) ;
114+ legacyCount ++ ;
92115 }
93116 else
94- _rangesSortedByIp . Add ( new Range ( ) { Name = description , File = file , Start = startiplong , End = endipint } ) ;
117+ {
118+ Range range = new Range ( ) { Name = description , File = file , Start = startiplong , End = endipint } ;
119+ #if DEBUG
120+ _debugPane ? . OutputString ( $ "MIXEDCALLSTACK :: adding range: { range } \n ") ;
121+ #endif
122+ _rangesSortedByIp . Add ( range ) ;
123+ count ++ ;
124+ }
95125 }
96126 }
97- //_debugPane?.OutputString("MIXEDCALLSTACK :: map now has " + _rangesSortedByIp.Count + " entries! legacy map has: " + _legacyRanges.Count + "\n");
127+ #if DEBUG
128+ if ( count > 0 || legacyCount > 0 )
129+ _debugPane ? . OutputString ( $ "MIXEDCALLSTACK :: added { count } to map for a total of { _rangesSortedByIp . Count } entries! Added { legacyCount } to legacy map for a total of { _legacyRanges . Count } \n ") ;
130+ #endif
98131 }
99132 catch ( Exception ex )
100133 {
101- // _debugPane?.OutputString("MIXEDCALLSTACK :: Unable to read dumped pmip file: " + ex.Message + "\n");
134+ _debugPane ? . OutputString ( "MIXEDCALLSTACK :: Unable to read dumped pmip file: " + ex . Message + "\n " ) ;
102135 DisposeStreams ( ) ;
103136 return false ;
104137 }
0 commit comments