Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
PerformanceCounterLib.cs
Go to the documentation of this file.
6using System.IO;
9
10namespace System.Diagnostics;
11
12internal sealed class PerformanceCounterLib
13{
14 internal sealed class PerformanceMonitor
15 {
16 private RegistryKey _perfDataKey;
17
18 private readonly string _machineName;
19
21 {
23 Init();
24 }
25
26 [MemberNotNull("_perfDataKey")]
27 private void Init()
28 {
30 {
31 _perfDataKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.PerformanceData, _machineName);
32 }
33 else
34 {
35 _perfDataKey = Registry.PerformanceData;
36 }
37 }
38
39 internal byte[] GetData(string item)
40 {
41 int num = 17;
42 int num2 = 0;
43 byte[] array = null;
44 int num3 = 0;
45 while (num > 0)
46 {
47 try
48 {
49 return (byte[])_perfDataKey.GetValue(item);
50 }
51 catch (IOException ex)
52 {
53 num3 = ex.HResult;
54 if (num3 <= 167)
55 {
56 if (num3 == 6)
57 {
58 goto IL_0078;
59 }
60 if (num3 == 21 || num3 == 167)
61 {
62 goto IL_007e;
63 }
64 }
65 else if (num3 <= 258)
66 {
67 if (num3 == 170 || num3 == 258)
68 {
69 goto IL_007e;
70 }
71 }
72 else if (num3 == 1722 || num3 == 1726)
73 {
74 goto IL_0078;
75 }
76 throw new Win32Exception(num3);
77 IL_007e:
78 num--;
79 if (num2 == 0)
80 {
81 num2 = 10;
82 continue;
83 }
85 num2 *= 2;
86 goto end_IL_0029;
87 IL_0078:
88 Init();
89 goto IL_007e;
91 }
93 {
95 }
96 }
97 throw new Win32Exception(num3);
98 }
99 }
100
101 private static string s_computerName;
102
104
105 private readonly string _machineName;
106
107 private readonly string _perfLcid;
108
110
112
113 private readonly object _nameTableLock = new object();
114
115 private static object s_internalSyncObject;
116
117 internal static string ComputerName => LazyInitializer.EnsureInitialized(ref s_computerName, ref s_internalSyncObject, () => global::Interop.Kernel32.GetComputerName() ?? "");
118
120 {
121 get
122 {
123 if (_nameTable == null)
124 {
126 {
127 if (_nameTable == null)
128 {
130 }
131 }
132 }
133 return _nameTable;
134 }
135 }
136
137 internal PerformanceCounterLib(string machineName, string lcid)
138 {
140 _perfLcid = lcid;
141 }
142
143 internal string GetCounterName(int index)
144 {
146 {
147 return "";
148 }
149 return value;
150 }
151
153 {
154 string item = culture.Name.ToLowerInvariant();
155 machineName = ((machineName.CompareTo(".") != 0) ? machineName.ToLowerInvariant() : ComputerName.ToLowerInvariant());
157 return s_libraryTable.GetOrAdd((machineName, item), ((string machineName, string lcidString) key) => new PerformanceCounterLib(key.machineName, key.lcidString));
158 }
159
160 internal byte[] GetPerformanceData(string item)
161 {
162 if (_performanceMonitor == null)
163 {
164 lock (LazyInitializer.EnsureInitialized(ref s_internalSyncObject))
165 {
166 if (_performanceMonitor == null)
167 {
169 }
170 }
171 }
173 }
174
176 {
177 RegistryKey performanceData = Registry.PerformanceData;
179 try
180 {
181 string[] array = null;
182 int num = 14;
183 int num2 = 0;
184 while (num > 0)
185 {
186 try
187 {
188 array = (isHelp ? ((string[])performanceData.GetValue("Explain " + _perfLcid)) : ((string[])performanceData.GetValue("Counter " + _perfLcid)));
189 if (array == null || array.Length == 0)
190 {
191 num--;
192 if (num2 == 0)
193 {
194 num2 = 10;
195 continue;
196 }
198 num2 *= 2;
199 continue;
200 }
201 }
202 catch (IOException)
203 {
204 array = null;
205 }
207 {
208 array = null;
209 }
210 break;
211 }
212 if (array == null)
213 {
215 }
216 else
217 {
218 dictionary = new Dictionary<int, string>(array.Length / 2);
219 for (int i = 0; i < array.Length / 2; i++)
220 {
221 string text = array[i * 2 + 1];
222 if (text == null)
223 {
224 text = string.Empty;
225 }
226 if (!int.TryParse(array[i * 2], NumberStyles.Integer, CultureInfo.InvariantCulture, out var result))
227 {
228 if (isHelp)
229 {
231 }
233 }
234 dictionary[result] = text;
235 }
236 }
237 }
238 finally
239 {
240 performanceData.Dispose();
241 }
242 return dictionary;
243 }
244}
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
Dictionary< int, string > GetStringTable(bool isHelp)
PerformanceCounterLib(string machineName, string lcid)
static ConcurrentDictionary<(string machineName, string lcidString), PerformanceCounterLib > s_libraryTable
static PerformanceCounterLib GetPerformanceCounterLib(string machineName, CultureInfo culture)
static bool IsRemoteMachine(string machineName)
static CultureInfo InvariantCulture
static string CounterDataCorrupt
Definition SR.cs:84
static string CounterNameCorrupt
Definition SR.cs:82
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string CategoryHelpCorrupt
Definition SR.cs:80
Definition SR.cs:7
static void Sleep(int millisecondsTimeout)
Definition Thread.cs:658