1
-
2
-
3
- using System ;
1
+ using System ;
4
2
using System . Collections . Generic ;
5
3
using System . Globalization ;
6
4
using System . IO ;
@@ -13,8 +11,22 @@ public class PmipReader
13
11
private static List < Range > _rangesSortedByIp = new List < Range > ( ) ;
14
12
private static List < Range > _legacyRanges = new List < Range > ( ) ;
15
13
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 > ( ) ;
18
30
19
31
public static void Sort ( )
20
32
{
@@ -24,46 +36,56 @@ public static void Sort()
24
36
25
37
public static void DisposeStreams ( )
26
38
{
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 ( ) ;
32
42
33
43
_rangesSortedByIp . Clear ( ) ;
44
+ _legacyRanges . Clear ( ) ;
34
45
}
35
46
public static bool ReadPmipFile ( string filePath )
36
47
{
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 ) )
40
55
{
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 ) ;
46
64
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" ) ;
49
67
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" ) ;
52
70
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 ) ;
61
81
}
62
82
63
83
try
64
84
{
65
85
string line ;
66
- while ( ( line = _fileStreamReader . ReadLine ( ) ) != null )
86
+ int count = 0 ;
87
+ int legacyCount = 0 ;
88
+ while ( ( line = pmipStreams . fileStreamReader . ReadLine ( ) ) != null )
67
89
{
68
90
const char delemiter = ';' ;
69
91
var tokens = line . Split ( delemiter ) ;
@@ -89,16 +111,27 @@ public static bool ReadPmipFile(string filePath)
89
111
{
90
112
// legacy stored in new pmip file
91
113
_legacyRanges . Add ( new Range ( ) { Name = description , File = file , Start = startiplong , End = endipint } ) ;
114
+ legacyCount ++ ;
92
115
}
93
116
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
+ }
95
125
}
96
126
}
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
98
131
}
99
132
catch ( Exception ex )
100
133
{
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 " ) ;
102
135
DisposeStreams ( ) ;
103
136
return false ;
104
137
}
0 commit comments