-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: show cpu gpu temperatures (#47)
Description --- Implement monitoring and display for cpu and gpu temperatures Motivation and Context --- As mining is heavy operation for hardware we want to see at least their temperatures to know if it safe to continue mining as high temperatures may cause damages How Has This Been Tested? --- Manually What process can a PR reviewer use to test or verify this change? --- Open settings tab and you should see Hardware temperatures category <!-- Checklist --> <!-- 1. Is the title of your PR in the form that would make nice release notes? The title, excluding the conventional commit tag, will be included exactly as is in the CHANGELOG, so please think about it carefully. --> Breaking Changes --- - [x] None - [ ] Requires data directory on base node to be deleted - [ ] Requires hard fork - [ ] Other - Please specify <!-- Does this include a breaking change? If so, include this line as a footer --> <!-- BREAKING CHANGE: Description what the user should do, e.g. delete a database, resync the chain -->
- Loading branch information
Showing
11 changed files
with
397 additions
and
19 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
use log::info; | ||
use nvml_wrapper::{ | ||
enum_wrappers::device::{TemperatureSensor, TemperatureThreshold}, | ||
Nvml, | ||
}; | ||
|
||
use crate::{GpuMinerHardwareStatus, GpuMinerStatus}; | ||
|
||
const LOG_TARGET: &str = "tari::universe::cpu_miner"; | ||
|
||
pub(crate) struct GpuMiner { | ||
nvml: Nvml, | ||
status: GpuMinerStatus, | ||
} | ||
|
||
impl GpuMiner { | ||
pub fn new() -> Self { | ||
Self { | ||
nvml: Nvml::init().unwrap(), | ||
status: GpuMinerStatus::from(GpuMinerStatus { | ||
hardware_statuses: Vec::new(), | ||
}), | ||
} | ||
} | ||
|
||
pub fn start(&mut self) { | ||
info!(target: LOG_TARGET, "Starting GPU miner"); | ||
// Start the GPU miner | ||
} | ||
|
||
pub fn stop(&mut self) { | ||
info!(target: LOG_TARGET, "Stopping GPU miner"); | ||
// Stop the GPU miner | ||
} | ||
|
||
pub fn status(&mut self) -> GpuMinerStatus { | ||
if self.status.hardware_statuses.is_empty() { | ||
let devices_count = self.nvml.device_count().unwrap(); | ||
|
||
for i in 0..devices_count { | ||
let device = self.nvml.device_by_index(i).unwrap(); | ||
|
||
let uuid = device.uuid().unwrap(); | ||
let name = device.name().unwrap(); | ||
let temperature = device.temperature(TemperatureSensor::Gpu).unwrap(); | ||
let load = device.utilization_rates().unwrap().gpu; | ||
|
||
self.status.hardware_statuses.push(GpuMinerHardwareStatus { | ||
uuid, | ||
name, | ||
temperature, | ||
max_temperature: temperature, | ||
load, | ||
}); | ||
} | ||
} | ||
|
||
self.status.hardware_statuses = self | ||
.status | ||
.hardware_statuses | ||
.iter() | ||
.map(|status| { | ||
let device = self.nvml.device_by_uuid(status.uuid.clone()).unwrap(); | ||
|
||
let temperature = device.temperature(TemperatureSensor::Gpu).unwrap(); | ||
let load = device.utilization_rates().unwrap().gpu; | ||
let max_temperature = status.max_temperature.max(temperature); | ||
|
||
GpuMinerHardwareStatus { | ||
uuid: status.uuid.clone(), | ||
name: status.name.clone(), | ||
temperature, | ||
max_temperature, | ||
load, | ||
} | ||
}) | ||
.collect(); | ||
|
||
self.status.clone() | ||
} | ||
} |
Oops, something went wrong.