Skip to content

Commit 26ad1b7

Browse files
authored
Merge pull request #27 from aliasaria/add-soc-info-to-pipe-output-json
adds soc info to pipe json
2 parents 119c992 + 6f14bf5 commit 26ad1b7

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/main.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ enum Commands {
1717
/// Number of samples to run for. Set to 0 to run indefinitely
1818
#[arg(short, long, default_value_t = 0)]
1919
samples: u32,
20+
21+
/// Include SoC information in the output
22+
#[arg(long, default_value_t = false)]
23+
soc_info: bool,
2024
},
2125

2226
/// Print debug information
@@ -40,14 +44,23 @@ fn main() -> Result<(), Box<dyn Error>> {
4044
let args = Cli::parse();
4145

4246
match &args.command {
43-
Some(Commands::Pipe { samples }) => {
47+
Some(Commands::Pipe { samples, soc_info }) => {
4448
let mut sampler = Sampler::new()?;
4549
let mut counter = 0u32;
4650

51+
let soc_info_val = if *soc_info {
52+
Some(sampler.get_soc_info().clone())
53+
} else {
54+
None
55+
};
56+
4757
loop {
4858
let doc = sampler.get_metrics(args.interval.max(100))?;
4959

5060
let mut doc = serde_json::to_value(&doc)?;
61+
if let Some(ref soc) = soc_info_val {
62+
doc["soc"] = serde_json::to_value(soc)?;
63+
}
5164
doc["timestamp"] = serde_json::to_value(chrono::Utc::now().to_rfc3339())?;
5265
let doc = serde_json::to_string(&doc)?;
5366

src/metrics.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,4 +296,9 @@ impl Sampler {
296296

297297
Ok(rs)
298298
}
299+
300+
/// Getter for the `soc` field
301+
pub fn get_soc_info(&self) -> &SocInfo {
302+
&self.soc
303+
}
299304
}

src/sources.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use core_foundation::{
2121
number::{CFNumberCreate, CFNumberRef, kCFNumberSInt32Type},
2222
string::{CFStringCreateWithBytesNoCopy, CFStringGetCString, CFStringRef, kCFStringEncodingUTF8},
2323
};
24+
use serde::Serialize;
2425

2526
pub type WithError<T> = Result<T, Box<dyn std::error::Error>>;
2627
pub type CVoidRef = *const std::ffi::c_void;
@@ -368,7 +369,7 @@ pub fn libc_swap() -> WithError<(u64, u64)> {
368369

369370
// MARK: SockInfo
370371

371-
#[derive(Debug, Default, Clone)]
372+
#[derive(Debug, Default, Clone, Serialize)]
372373
pub struct SocInfo {
373374
pub mac_model: String,
374375
pub chip_name: String,

0 commit comments

Comments
 (0)