Skip to content

Commit

Permalink
Fetch CPU info
Browse files Browse the repository at this point in the history
  • Loading branch information
paberr committed Apr 3, 2024
1 parent 7bf728c commit bed564e
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 28 deletions.
84 changes: 80 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ regex = { version = "1.9.3", features = [
"unicode-case",
] } # required as workaround

[target.'cfg(not(target_arch = "aarch64"))'.dependencies]
sysinfo = { version = "0.29" }
sysinfo = { version = "0.30" }

[features]
default = []
Expand Down
4 changes: 2 additions & 2 deletions src/data_structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ pub struct Response<T> {

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ProcessorData {
pub struct CpuData {
pub name: String,
pub brand: String,
pub frequency: String,
Expand All @@ -221,7 +221,7 @@ pub struct ContributedData {
pub challenge_hash: String,
pub response_hash: String,
pub contribution_duration: Option<u64>,
pub processor_data: Option<Vec<ProcessorData>>,
pub processor_data: Option<Vec<CpuData>>,
}

#[derive(Debug, Clone)]
Expand Down
33 changes: 13 additions & 20 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub const BEACON_HASH_LENGTH: usize = 32;

use crate::blobstore::{upload_access_key, upload_sas};
use crate::data_structs::{
Attestation, Ceremony, NimiqSetupKeys, Parameters, ParticipantId, ProcessorData, Response,
Attestation, Ceremony, CpuData, NimiqSetupKeys, Parameters, ParticipantId, Response,
};
use crate::error::{UtilsError, VerifyTranscriptError};
use age::{
Expand All @@ -27,6 +27,7 @@ use std::{
io::{Read, Write},
path::Path,
};
use sysinfo::{CpuRefreshKind, MemoryRefreshKind, System};

Check failure on line 30 in src/utils.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

unused import: `MemoryRefreshKind`
use tracing::warn;

pub const PHASE2_INIT_FILENAME: &str = "phase2_init";
Expand Down Expand Up @@ -468,25 +469,17 @@ pub fn read_keys(
Ok((nimiq_seed, nimiq_key_pair_from_file, keys.attestation))
}

pub fn collect_processor_data() -> Result<Vec<ProcessorData>> {
cfg_if::cfg_if! {
if #[cfg(not(target_arch = "aarch64"))] {
use sysinfo::{CpuExt, System, SystemExt};
let s = System::new();
let processors = s
.cpus()
.iter()
.map(|p| ProcessorData {
name: p.name().to_string(),
brand: p.brand().to_string(),
frequency: p.frequency().to_string(),
})
.collect();
Ok(processors)
} else {
Ok(vec![])
}
}
pub fn collect_processor_data() -> Result<Vec<CpuData>> {
// Retrieve cpu data.
let mut system = System::new();
system.refresh_cpu_specifics(CpuRefreshKind::everything());

let cpus = system.cpus().iter().map(|p| CpuData {
name: p.name().to_string(),
brand: p.brand().to_string(),
frequency: p.frequency().to_string(),
});
Ok(cpus)

Check failure on line 482 in src/utils.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

mismatched types
}

pub struct MaxRetriesHandler {
Expand Down

0 comments on commit bed564e

Please sign in to comment.