Beispiel #1
0
 internal CategoryEntry(NativeMethods.PERF_OBJECT_TYPE perfObject)
 {
     this.NameIndex      = perfObject.ObjectNameTitleIndex;
     this.HelpIndex      = perfObject.ObjectHelpTitleIndex;
     this.CounterIndexes = new int[perfObject.NumCounters];
     this.HelpIndexes    = new int[perfObject.NumCounters];
 }
Beispiel #2
0
        private static ThreadInfo GetThreadInfo(NativeMethods.PERF_OBJECT_TYPE type, IntPtr instancePtr, NativeMethods.PERF_COUNTER_DEFINITION[] counters)
        {
            ThreadInfo threadInfo = new ThreadInfo();

            for (int i = 0; i < counters.Length; i++)
            {
                NativeMethods.PERF_COUNTER_DEFINITION pERF_COUNTER_DEFINITION = counters[i];
                long num = NtProcessManager.ReadCounterValue(pERF_COUNTER_DEFINITION.CounterType, (IntPtr)((long)instancePtr + (long)pERF_COUNTER_DEFINITION.CounterOffset));
                switch (pERF_COUNTER_DEFINITION.CounterNameTitlePtr)
                {
                case 11:
                    threadInfo.threadId = (int)num;
                    break;

                case 12:
                    threadInfo.processId = (int)num;
                    break;

                case 13:
                    threadInfo.basePriority = (int)num;
                    break;

                case 14:
                    threadInfo.currentPriority = (int)num;
                    break;

                case 17:
                    threadInfo.startAddress = (IntPtr)num;
                    break;

                case 18:
                    threadInfo.threadState = (System.Diagnostics.ThreadState)num;
                    break;

                case 19:
                    threadInfo.threadWaitReason = NtProcessManager.GetThreadWaitReason((int)num);
                    break;
                }
            }
            return(threadInfo);
        }
Beispiel #3
0
        /// <include file='doc\PerformanceCounterManager.uex' path='docs/doc[@for="PerformanceCounterManager.InitPerfObjectType"]/*' />
        /// <devdoc>
        ///     Initializes the PERF_OBJECT_TYPE structure
        /// </devdoc>
        /// <internalonly/>
        private static void InitPerfObjectType(IntPtr ptr, ObjectData data, int numInstances, int totalByteLength)
        {
            NativeMethods.PERF_OBJECT_TYPE perfObjType = (NativeMethods.PERF_OBJECT_TYPE) new NativeMethods.PERF_OBJECT_TYPE();

            perfObjType.TotalByteLength  = totalByteLength;
            perfObjType.DefinitionLength = Marshal.SizeOf(typeof(NativeMethods.PERF_OBJECT_TYPE)) + data.CounterNameHashCodes.Length *
                                           Marshal.SizeOf(typeof(NativeMethods.PERF_COUNTER_DEFINITION));
            perfObjType.HeaderLength         = Marshal.SizeOf(typeof(NativeMethods.PERF_OBJECT_TYPE));
            perfObjType.ObjectNameTitleIndex = data.FirstCounterId;
            perfObjType.ObjectNameTitlePtr   = 0;
            perfObjType.ObjectHelpTitleIndex = data.FirstHelpId;
            perfObjType.ObjectHelpTitlePtr   = 0;
            perfObjType.DetailLevel          = NativeMethods.PERF_DETAIL_NOVICE;
            perfObjType.NumCounters          = data.CounterNameHashCodes.Length;
            perfObjType.DefaultCounter       = 0;
            perfObjType.NumInstances         = numInstances;
            perfObjType.CodePage             = 0;
            perfObjType.PerfTime             = GetCurrentPerfTime();
            perfObjType.PerfFreq             = GetFrequency();
            Marshal.StructureToPtr(perfObjType, ptr, false);
        }
Beispiel #4
0
        private static ProcessInfo GetProcessInfo(NativeMethods.PERF_OBJECT_TYPE type, IntPtr instancePtr, NativeMethods.PERF_COUNTER_DEFINITION[] counters)
        {
            ProcessInfo processInfo = new ProcessInfo();

            for (int i = 0; i < counters.Length; i++)
            {
                NativeMethods.PERF_COUNTER_DEFINITION pERF_COUNTER_DEFINITION = counters[i];
                long num = NtProcessManager.ReadCounterValue(pERF_COUNTER_DEFINITION.CounterType, (IntPtr)((long)instancePtr + (long)pERF_COUNTER_DEFINITION.CounterOffset));
                switch (pERF_COUNTER_DEFINITION.CounterNameTitlePtr)
                {
                case 0:
                    processInfo.handleCount = (int)num;
                    break;

                case 1:
                    processInfo.poolPagedBytes = num;
                    break;

                case 2:
                    processInfo.poolNonpagedBytes = num;
                    break;

                case 4:
                    processInfo.virtualBytesPeak = num;
                    break;

                case 5:
                    processInfo.virtualBytes = num;
                    break;

                case 6:
                    processInfo.privateBytes = num;
                    break;

                case 7:
                    processInfo.pageFileBytes = num;
                    break;

                case 8:
                    processInfo.pageFileBytesPeak = num;
                    break;

                case 9:
                    processInfo.workingSetPeak = num;
                    break;

                case 10:
                    processInfo.workingSet = num;
                    break;

                case 12:
                    processInfo.processId = (int)num;
                    break;

                case 13:
                    processInfo.basePriority = (int)num;
                    break;
                }
            }
            return(processInfo);
        }