private void QueryBasicAndIoAccounting()
        {
            NativeMethods.JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION accounting = new NativeMethods.JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION();
            accounting.BasicInfo = new NativeMethods.JOBOBJECT_BASIC_ACCOUNTING_INFORMATION();
            accounting.IoInfo    = new NativeMethods.IO_COUNTERS();

            int    accountingLength = Marshal.SizeOf(typeof(NativeMethods.JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION));
            IntPtr accountingPtr    = Marshal.AllocHGlobal(accountingLength);

            try
            {
                bool success = NativeMethods.QueryInformationJobObject(this.jobHandle, NativeMethods.JobObjectInfoClass.JobObjectBasicAndIoAccountingInformation, accountingPtr, (uint)accountingLength, IntPtr.Zero);

                if (success == false)
                {
                    int error = Marshal.GetLastWin32Error();
                    throw new Win32Exception(error, "QueryInformationJobObject failed.");
                }

                accounting = (NativeMethods.JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION)Marshal.PtrToStructure(accountingPtr, typeof(NativeMethods.JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION));

                this.userProcessorTime        = (ulong)accounting.BasicInfo.TotalUserTime;
                this.kernelProcessorTime      = (ulong)accounting.BasicInfo.TotalKernelTime;
                this.totalProcesses           = (uint)accounting.BasicInfo.TotalProcesses;
                this.activeProcesses          = (uint)accounting.BasicInfo.ActiveProcesses;
                this.totalTerminatedProcesses = (uint)accounting.BasicInfo.TotalTerminatedProcesses;

                this.ioReadBytes            = (long)accounting.IoInfo.ReadTransferCount;
                this.ioWriteBytes           = (long)accounting.IoInfo.WriteTransferCount;
                this.ioOtherBytes           = (long)accounting.IoInfo.OtherTransferCount;
                this.ioReadOperationsCount  = (long)accounting.IoInfo.ReadOperationCount;
                this.ioWriteOperationsCount = (long)accounting.IoInfo.WriteOperationCount;
                this.ioOtherOperationsCount = (long)accounting.IoInfo.OtherOperationCount;
            }
            finally
            {
                Marshal.FreeHGlobal(accountingPtr);
            }
        }
Exemple #2
0
        private void QueryBasicAndIoAccounting()
        {
            NativeMethods.JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION accounting = new NativeMethods.JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION();
            accounting.BasicInfo = new NativeMethods.JOBOBJECT_BASIC_ACCOUNTING_INFORMATION();
            accounting.IoInfo = new NativeMethods.IO_COUNTERS();

            int accountingLength = Marshal.SizeOf(typeof(NativeMethods.JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION));
            IntPtr accountingPtr = Marshal.AllocHGlobal(accountingLength);

            try
            {
                bool success = NativeMethods.QueryInformationJobObject(this.jobHandle, NativeMethods.JobObjectInfoClass.JobObjectBasicAndIoAccountingInformation, accountingPtr, (uint)accountingLength, IntPtr.Zero);

                if (success == false)
                {
                    int error = Marshal.GetLastWin32Error();
                    throw new Win32Exception(error, "QueryInformationJobObject failed.");
                }

                accounting = (NativeMethods.JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION)Marshal.PtrToStructure(accountingPtr, typeof(NativeMethods.JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION));

                this.userProcessorTime = (ulong)accounting.BasicInfo.TotalUserTime;
                this.kernelProcessorTime = (ulong)accounting.BasicInfo.TotalKernelTime;

                this.ioReadBytes = (long)accounting.IoInfo.ReadTransferCount;
                this.ioWriteBytes = (long)accounting.IoInfo.WriteTransferCount;
                this.ioOtherBytes = (long)accounting.IoInfo.OtherTransferCount;
                this.ioReadOperationsCount = (long)accounting.IoInfo.ReadOperationCount;
                this.ioWriteOperationsCount = (long)accounting.IoInfo.WriteOperationCount;
                this.ioOtherOperationsCount = (long)accounting.IoInfo.OtherOperationCount;
            }
            finally
            {
                Marshal.FreeHGlobal(accountingPtr);
            }
        }