Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ GetProcessInfos() [2/3]

static ProcessInfo[] System.Diagnostics.NtProcessManager.GetProcessInfos ( PerformanceCounterLib library,
int processIndex,
int threadIndex,
ReadOnlySpan< byte > data )
inlinestaticprivate

Definition at line 215 of file NtProcessManager.cs.

216 {
219 ref readonly global::Interop.Advapi32.PERF_DATA_BLOCK reference = ref MemoryMarshal.AsRef<global::Interop.Advapi32.PERF_DATA_BLOCK>(data);
220 int num = reference.HeaderLength;
221 for (int i = 0; i < reference.NumObjectTypes; i++)
222 {
223 ref readonly global::Interop.Advapi32.PERF_OBJECT_TYPE reference2 = ref MemoryMarshal.AsRef<global::Interop.Advapi32.PERF_OBJECT_TYPE>(data.Slice(num));
224 global::Interop.Advapi32.PERF_COUNTER_DEFINITION[] array = new global::Interop.Advapi32.PERF_COUNTER_DEFINITION[reference2.NumCounters];
225 int num2 = num + reference2.HeaderLength;
226 for (int j = 0; j < reference2.NumCounters; j++)
227 {
228 ref readonly global::Interop.Advapi32.PERF_COUNTER_DEFINITION reference3 = ref MemoryMarshal.AsRef<global::Interop.Advapi32.PERF_COUNTER_DEFINITION>(data.Slice(num2));
229 string counterName = library.GetCounterName(reference3.CounterNameTitleIndex);
230 array[j] = reference3;
231 if (reference2.ObjectNameTitleIndex == processIndex)
232 {
233 array[j].CounterNameTitlePtr = (int)GetValueId(counterName);
234 }
235 else if (reference2.ObjectNameTitleIndex == threadIndex)
236 {
237 array[j].CounterNameTitlePtr = (int)GetValueId(counterName);
238 }
239 num2 += reference3.ByteLength;
240 }
241 int num3 = num + reference2.DefinitionLength;
242 for (int k = 0; k < reference2.NumInstances; k++)
243 {
244 ref readonly global::Interop.Advapi32.PERF_INSTANCE_DEFINITION reference4 = ref MemoryMarshal.AsRef<global::Interop.Advapi32.PERF_INSTANCE_DEFINITION>(data.Slice(num3));
245 ReadOnlySpan<char> span = global::Interop.Advapi32.PERF_INSTANCE_DEFINITION.GetName(in reference4, data.Slice(num3));
246 if (!MemoryExtensions.Equals(span, "_Total", StringComparison.Ordinal))
247 {
248 if (reference2.ObjectNameTitleIndex == processIndex)
249 {
250 ProcessInfo processInfo = GetProcessInfo(data.Slice(num3 + reference4.ByteLength), array);
251 if ((processInfo.ProcessId != 0 || MemoryExtensions.Equals(span, "Idle", StringComparison.OrdinalIgnoreCase)) && !dictionary.ContainsKey(processInfo.ProcessId))
252 {
253 if (span.Length == 15)
254 {
255 if (span.EndsWith(".", StringComparison.Ordinal))
256 {
257 span = span.Slice(0, 14);
258 }
259 else if (span.EndsWith(".e", StringComparison.Ordinal))
260 {
261 span = span.Slice(0, 13);
262 }
263 else if (span.EndsWith(".ex", StringComparison.Ordinal))
264 {
265 span = span.Slice(0, 12);
266 }
267 }
268 processInfo.ProcessName = span.ToString();
270 }
271 }
272 else if (reference2.ObjectNameTitleIndex == threadIndex)
273 {
274 ThreadInfo threadInfo = GetThreadInfo(data.Slice(num3 + reference4.ByteLength), array);
275 if (threadInfo._threadId != 0L)
276 {
277 list.Add(threadInfo);
278 }
279 }
280 }
281 num3 += reference4.ByteLength;
282 num3 += MemoryMarshal.AsRef<global::Interop.Advapi32.PERF_COUNTER_BLOCK>(data.Slice(num3)).ByteLength;
283 }
284 num += reference2.TotalByteLength;
285 }
286 for (int l = 0; l < list.Count; l++)
287 {
288 ThreadInfo threadInfo2 = list[l];
289 if (dictionary.TryGetValue(threadInfo2._processId, out var value))
290 {
291 value._threadInfoList.Add(threadInfo2);
292 }
293 }
294 ProcessInfo[] array2 = new ProcessInfo[dictionary.Values.Count];
296 return array2;
297 }
void Add(TKey key, TValue value)
static ThreadInfo GetThreadInfo(ReadOnlySpan< byte > instanceData, global::Interop.Advapi32.PERF_COUNTER_DEFINITION[] counters)
static ProcessInfo GetProcessInfo(ReadOnlySpan< byte > instanceData, global::Interop.Advapi32.PERF_COUNTER_DEFINITION[] counters)
static ValueId GetValueId(string counterName)
ReadOnlySpan< T > Slice(int start)

References System.Collections.Generic.Dictionary< TKey, TValue >.Add(), System.array, System.Collections.Generic.Dictionary< TKey, TValue >.Count, System.dictionary, System.MemoryExtensions.Equals(), System.Diagnostics.NtProcessManager.GetProcessInfo(), System.Diagnostics.NtProcessManager.GetThreadInfo(), System.Diagnostics.NtProcessManager.GetValueId(), System.L, System.list, and System.value.