public static void GetCounterAndInstanceList()

in Source/Tx.Windows/PerfCounters/PdhUtils.cs [108:156]


        public static void GetCounterAndInstanceList(
            string logFilename,
            string machineName,
            string objectName,
            out List<string> counterList,
            out List<string> instanceList)
        {
            uint counterBufferLength = 0;
            uint instanceBufferLength = 0;

            PdhStatus pdhStatus = PdhNativeMethods.PdhEnumObjectItems(
                logFilename,
                machineName,
                objectName,
                null,
                ref counterBufferLength,
                null,
                ref instanceBufferLength,
                PdhDetailLevel.PERF_DETAIL_WIZARD,
                0);

            CheckStatus(pdhStatus, PdhStatus.PDH_CSTATUS_NO_OBJECT, PdhStatus.PDH_MORE_DATA, PdhStatus.PDH_CSTATUS_VALID_DATA);
            if (pdhStatus == PdhStatus.PDH_MORE_DATA)
            {
                var counterListBuffer = new char[counterBufferLength];
                var instanceListBuffer = new char[instanceBufferLength];

                pdhStatus = PdhNativeMethods.PdhEnumObjectItems(
                    logFilename,
                    machineName,
                    objectName,
                    counterListBuffer,
                    ref counterBufferLength,
                    instanceListBuffer,
                    ref instanceBufferLength,
                    PdhDetailLevel.PERF_DETAIL_WIZARD,
                    0);

                CheckStatus(pdhStatus, PdhStatus.PDH_CSTATUS_VALID_DATA);

                counterList = MultiSzToStringList(counterListBuffer);
                instanceList = MultiSzToStringList(instanceListBuffer);
            }
            else
            {
                counterList = new List<string>();
                instanceList = new List<string>();
            }
        }