예제 #1
0
        public override void Update()
        {
            NvApi.NvGPUThermalSettings settings = GetThermalSettings();
            foreach (Sensor sensor in _temperatures)
            {
                sensor.Value = settings.Sensor[sensor.Index].CurrentTemp;
            }

            if (_fan != null)
            {
                NvApi.NvAPI_GPU_GetTachReading(_handle, out int value);
                _fan.Value = value;
            }

            uint[] values = GetClocks();
            if (values != null)
            {
                _clocks[1].Value = 0.001f * values[8];
                if (values[30] != 0)
                {
                    _clocks[0].Value = 0.0005f * values[30];
                    _clocks[2].Value = 0.001f * values[30];
                }
                else
                {
                    _clocks[0].Value = 0.001f * values[0];
                    _clocks[2].Value = 0.001f * values[14];
                }
            }

            NvApi.NvPStates states = new NvApi.NvPStates {
                Version = NvApi.GPU_PSTATES_VER, PStates = new NvApi.NvPState[NvApi.MAX_PSTATES_PER_GPU]
            };
            if (NvApi.NvAPI_GPU_GetPStates != null && NvApi.NvAPI_GPU_GetPStates(_handle, ref states) == NvApi.NvStatus.OK)
            {
                for (int i = 0; i < 3; i++)
                {
                    if (states.PStates[i].Present)
                    {
                        _loads[i].Value = states.PStates[i].Percentage;
                        ActivateSensor(_loads[i]);
                    }
                }
            }
            else
            {
                NvApi.NvUsages usages = new NvApi.NvUsages {
                    Version = NvApi.GPU_USAGES_VER, Usage = new uint[NvApi.MAX_USAGES_PER_GPU]
                };
                if (NvApi.NvAPI_GPU_GetUsages != null && NvApi.NvAPI_GPU_GetUsages(_handle, ref usages) == NvApi.NvStatus.OK)
                {
                    _loads[0].Value = usages.Usage[2];
                    _loads[1].Value = usages.Usage[6];
                    _loads[2].Value = usages.Usage[10];
                    for (int i = 0; i < 3; i++)
                    {
                        ActivateSensor(_loads[i]);
                    }
                }
            }

            NvApi.NvGPUCoolerSettings coolerSettings = GetCoolerSettings();
            if (coolerSettings.Count > 0)
            {
                _control.Value = coolerSettings.Cooler[0].CurrentLevel;
                ActivateSensor(_control);
            }

            NvApi.NvMemoryInfo memoryInfo = new NvApi.NvMemoryInfo {
                Version = NvApi.GPU_MEMORY_INFO_VER, Values = new uint[NvApi.MAX_MEMORY_VALUES_PER_GPU]
            };
            if (NvApi.NvAPI_GPU_GetMemoryInfo != null && _displayHandle.HasValue && NvApi.NvAPI_GPU_GetMemoryInfo(_displayHandle.Value, ref memoryInfo) == NvApi.NvStatus.OK)
            {
                uint  totalMemory = memoryInfo.Values[0];
                uint  freeMemory  = memoryInfo.Values[4];
                float usedMemory  = Math.Max(totalMemory - freeMemory, 0);
                _memoryFree.Value  = (float)freeMemory / 1024;
                _memoryAvail.Value = (float)totalMemory / 1024;
                _memoryUsed.Value  = usedMemory / 1024;
                _memoryLoad.Value  = 100f * usedMemory / totalMemory;
                ActivateSensor(_memoryAvail);
                ActivateSensor(_memoryUsed);
                ActivateSensor(_memoryFree);
                ActivateSensor(_memoryLoad);
            }

            if (NvidiaML.IsAvailable && _nvmlDevice.HasValue)
            {
                var result = NvidiaML.NvmlDeviceGetPowerUsage(_nvmlDevice.Value);
                if (result.HasValue)
                {
                    _powerUsage.Value = (float)result.Value / 1000;
                    ActivateSensor(_powerUsage);
                }
            }
        }
예제 #2
0
        public override void Update()
        {
            NvApi.NvGPUThermalSettings settings = GetThermalSettings();
            foreach (Sensor sensor in _temperatures)
            {
                sensor.Value = settings.Sensor[sensor.Index].CurrentTemp;
            }

            bool readTach = false;

            if (_fan != null)
            {
                if (NvApi.NvAPI_GPU_GetTachReading(_handle, out int value) == NvApi.NvStatus.OK)
                {
                    _fan.Value = value;
                    ActivateSensor(_fan);

                    readTach = true;
                }
            }

            uint[] values = GetClocks();
            if (values != null)
            {
                _clocks[1].Value = 0.001f * values[8];
                if (values[30] != 0)
                {
                    _clocks[0].Value = 0.0005f * values[30];
                    _clocks[2].Value = 0.001f * values[30];
                }
                else
                {
                    _clocks[0].Value = 0.001f * values[0];
                    _clocks[2].Value = 0.001f * values[14];
                }
            }

            NvApi.NvPStates states = new NvApi.NvPStates {
                Version = NvApi.GPU_PSTATES_VER, PStates = new NvApi.NvPState[NvApi.MAX_PSTATES_PER_GPU]
            };
            if (NvApi.NvAPI_GPU_GetPStates != null && NvApi.NvAPI_GPU_GetPStates(_handle, ref states) == NvApi.NvStatus.OK)
            {
                for (int i = 0; i < _loads.Length; i++)
                {
                    if (states.PStates[i].Present)
                    {
                        _loads[i].Value = states.PStates[i].Percentage;
                        ActivateSensor(_loads[i]);
                    }
                }
            }
            else
            {
                NvApi.NvUsages usages = new NvApi.NvUsages {
                    Version = NvApi.GPU_USAGES_VER, Usage = new uint[NvApi.MAX_USAGES_PER_GPU]
                };
                if (NvApi.NvAPI_GPU_GetUsages != null && NvApi.NvAPI_GPU_GetUsages(_handle, ref usages) == NvApi.NvStatus.OK)
                {
                    _loads[0].Value = usages.Usage[2];
                    _loads[1].Value = usages.Usage[6];
                    _loads[2].Value = usages.Usage[10];
                    for (int i = 0; i < 3; i++)
                    {
                        ActivateSensor(_loads[i]);
                    }
                }
            }

            bool readCoolerSettings = false;

            NvApi.NvGPUCoolerSettings coolerSettings = GetCoolerSettings();
            if (coolerSettings.Count > 0)
            {
                _control.Value = coolerSettings.Cooler[0].CurrentLevel;
                ActivateSensor(_control);

                readCoolerSettings = true;
            }

            if (!readTach || !readCoolerSettings)
            {
                NvApi.NvFanCoolersStatus coolersStatus = GetFanCoolersStatus();
                if (coolersStatus.Count > 0)
                {
                    if (!readCoolerSettings)
                    {
                        _control.Value = coolersStatus.Items[0].CurrentLevel;
                        ActivateSensor(_control);
                    }

                    if (!readTach && _fan != null)
                    {
                        _fan.Value = coolersStatus.Items[0].CurrentRpm;
                        ActivateSensor(_fan);
                    }
                }
            }

            NvApi.NvMemoryInfo memoryInfo = new NvApi.NvMemoryInfo {
                Version = NvApi.GPU_MEMORY_INFO_VER, Values = new uint[NvApi.MAX_MEMORY_VALUES_PER_GPU]
            };
            if (NvApi.NvAPI_GPU_GetMemoryInfo != null && _displayHandle.HasValue && NvApi.NvAPI_GPU_GetMemoryInfo(_displayHandle.Value, ref memoryInfo) == NvApi.NvStatus.OK)
            {
                uint  totalMemory = memoryInfo.Values[0];
                uint  freeMemory  = memoryInfo.Values[4];
                float usedMemory  = Math.Max(totalMemory - freeMemory, 0);
                _memoryFree.Value  = (float)freeMemory / 1024;
                _memoryAvail.Value = (float)totalMemory / 1024;
                _memoryUsed.Value  = usedMemory / 1024;
                _memoryLoad.Value  = 100f * usedMemory / totalMemory;
                ActivateSensor(_memoryAvail);
                ActivateSensor(_memoryUsed);
                ActivateSensor(_memoryFree);
                ActivateSensor(_memoryLoad);
            }

            if (NvidiaML.IsAvailable && _nvmlDevice.HasValue)
            {
                int?result = NvidiaML.NvmlDeviceGetPowerUsage(_nvmlDevice.Value);
                if (result.HasValue)
                {
                    _powerUsage.Value = (float)result.Value / 1000;
                    ActivateSensor(_powerUsage);
                }

                // In MB/s, throughput sensors are passed as in KB/s.
                uint?rx = NvidiaML.NvmlDeviceGetPcieThroughput(_nvmlDevice.Value, NvidiaML.NvmlPcieUtilCounter.RxBytes);
                if (rx.HasValue)
                {
                    _pcieThroughputRx.Value = rx * 1024;
                    ActivateSensor(_pcieThroughputRx);
                }

                uint?tx = NvidiaML.NvmlDeviceGetPcieThroughput(_nvmlDevice.Value, NvidiaML.NvmlPcieUtilCounter.TxBytes);
                if (tx.HasValue)
                {
                    _pcieThroughputTx.Value = tx * 1024;
                    ActivateSensor(_pcieThroughputTx);
                }
            }
        }
예제 #3
0
        public override void Update()
        {
            if (_windowsDeviceName != null && D3DDisplayDevice.GetDeviceInfoByIdentifier(_windowsDeviceName, out D3DDisplayDevice.D3DDeviceInfo deviceInfo))
            {
                _gpuDedicatedMemoryUsage.Value = 1f * deviceInfo.GpuDedicatedUsed / 1024 / 1024;
                _gpuSharedMemoryUsage.Value    = 1f * deviceInfo.GpuSharedUsed / 1024 / 1024;
                ActivateSensor(_gpuDedicatedMemoryUsage);
                ActivateSensor(_gpuSharedMemoryUsage);

                foreach (D3DDisplayDevice.D3DDeviceNodeInfo node in deviceInfo.Nodes)
                {
                    long runningTimeDiff = node.RunningTime - _gpuNodeUsagePrevValue[node.Id];
                    long timeDiff        = node.QueryTime.Ticks - _gpuNodeUsagePrevTick[node.Id].Ticks;

                    _gpuNodeUsage[node.Id].Value    = 100f * runningTimeDiff / timeDiff;
                    _gpuNodeUsagePrevValue[node.Id] = node.RunningTime;
                    _gpuNodeUsagePrevTick[node.Id]  = node.QueryTime;
                    ActivateSensor(_gpuNodeUsage[node.Id]);
                }
            }

            NvApi.NvGPUThermalSettings settings = GetThermalSettings();
            // settings.Count is 0 when no valid data available, this happens when you try to read out this value with a high polling interval.
            if (settings.Count > 0)
            {
                foreach (Sensor sensor in _temperatures)
                {
                    sensor.Value = settings.Sensor[sensor.Index].CurrentTemp;
                }
            }

            bool readTach = false;

            if (_fan != null)
            {
                if (NvApi.NvAPI_GPU_GetTachReading(_handle, out int value) == NvApi.NvStatus.OK)
                {
                    _fan.Value = value;
                    ActivateSensor(_fan);

                    readTach = true;
                }
            }

            uint[] values = GetClocks();
            if (values != null)
            {
                _clocks[1].Value = 0.001f * values[8];
                if (values[30] != 0)
                {
                    _clocks[0].Value = 0.0005f * values[30];
                    _clocks[2].Value = 0.001f * values[30];
                }
                else
                {
                    _clocks[0].Value = 0.001f * values[0];
                    _clocks[2].Value = 0.001f * values[14];
                }
            }

            NvApi.NvPStates states = new() { Version = NvApi.GPU_PSTATES_VER, PStates = new NvApi.NvPState[NvApi.MAX_PSTATES_PER_GPU] };
            if (NvApi.NvAPI_GPU_GetPStates != null && NvApi.NvAPI_GPU_GetPStates(_handle, ref states) == NvApi.NvStatus.OK)
            {
                for (int i = 0; i < _loads.Length; i++)
                {
                    if (states.PStates[i].Present)
                    {
                        _loads[i].Value = states.PStates[i].Percentage;
                        ActivateSensor(_loads[i]);
                    }
                }
            }
            else
            {
                NvApi.NvUsages usages = new() { Version = NvApi.GPU_USAGES_VER, Usage = new uint[NvApi.MAX_USAGES_PER_GPU] };
                if (NvApi.NvAPI_GPU_GetUsages != null && NvApi.NvAPI_GPU_GetUsages(_handle, ref usages) == NvApi.NvStatus.OK)
                {
                    _loads[0].Value = usages.Usage[2];
                    _loads[1].Value = usages.Usage[6];
                    _loads[2].Value = usages.Usage[10];
                    for (int i = 0; i < 3; i++)
                    {
                        ActivateSensor(_loads[i]);
                    }
                }
            }

            bool readCoolerSettings = false;

            NvApi.NvGPUCoolerSettings coolerSettings = GetCoolerSettings();
            if (coolerSettings.Count > 0)
            {
                _control.Value = coolerSettings.Cooler[0].CurrentLevel;
                ActivateSensor(_control);

                readCoolerSettings = true;
            }

            if (!readTach || !readCoolerSettings)
            {
                NvApi.NvFanCoolersStatus coolersStatus = GetFanCoolersStatus();
                if (coolersStatus.Count > 0)
                {
                    if (!readCoolerSettings)
                    {
                        _control.Value = coolersStatus.Items[0].CurrentLevel;
                        ActivateSensor(_control);
                    }

                    if (!readTach && _fan != null)
                    {
                        _fan.Value = coolersStatus.Items[0].CurrentRpm;
                        ActivateSensor(_fan);
                    }
                }
            }

            NvApi.NvMemoryInfo memoryInfo = new() { Version = NvApi.GPU_MEMORY_INFO_VER, Values = new uint[NvApi.MAX_MEMORY_VALUES_PER_GPU] };
            if (NvApi.NvAPI_GPU_GetMemoryInfo != null && _displayHandle.HasValue && NvApi.NvAPI_GPU_GetMemoryInfo(_displayHandle.Value, ref memoryInfo) == NvApi.NvStatus.OK)
            {
                uint  totalMemory = memoryInfo.Values[0];
                uint  freeMemory  = memoryInfo.Values[4];
                float usedMemory  = Math.Max(totalMemory - freeMemory, 0);
                _memoryFree.Value  = (float)freeMemory / 1024;
                _memoryAvail.Value = (float)totalMemory / 1024;
                _memoryUsed.Value  = usedMemory / 1024;
                _memoryLoad.Value  = 100f * usedMemory / totalMemory;
                ActivateSensor(_memoryAvail);
                ActivateSensor(_memoryUsed);
                ActivateSensor(_memoryFree);
                ActivateSensor(_memoryLoad);
            }

            if (NvidiaML.IsAvailable && _nvmlDevice.HasValue)
            {
                int?result = NvidiaML.NvmlDeviceGetPowerUsage(_nvmlDevice.Value);
                if (result.HasValue)
                {
                    _powerUsage.Value = (float)result.Value / 1000;
                    ActivateSensor(_powerUsage);
                }

                // In MB/s, throughput sensors are passed as in KB/s.
                uint?rx = NvidiaML.NvmlDeviceGetPcieThroughput(_nvmlDevice.Value, NvidiaML.NvmlPcieUtilCounter.RxBytes);
                if (rx.HasValue)
                {
                    _pcieThroughputRx.Value = rx * 1024;
                    ActivateSensor(_pcieThroughputRx);
                }

                uint?tx = NvidiaML.NvmlDeviceGetPcieThroughput(_nvmlDevice.Value, NvidiaML.NvmlPcieUtilCounter.TxBytes);
                if (tx.HasValue)
                {
                    _pcieThroughputTx.Value = tx * 1024;
                    ActivateSensor(_pcieThroughputTx);
                }
            }
        }

        public override string GetReport()