Skip to content

Commit

Permalink
refactor: move sysinfo behind a feature flag and only enable it for…
Browse files Browse the repository at this point in the history
… non-macos builds (#4750)

## Description
closes #4737.

This PR makes `sysinfo` an optional dependency which is only enabled for
non-macos builds.
Co-authored-by: Sophie Dankel <[email protected]>
  • Loading branch information
kayagokalp authored Jul 5, 2023
1 parent bbb89d1 commit 5dac20e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
4 changes: 3 additions & 1 deletion forc-pkg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ sway-core = { version = "0.41.0", path = "../sway-core" }
sway-error = { version = "0.41.0", path = "../sway-error" }
sway-types = { version = "0.41.0", path = "../sway-types" }
sway-utils = { version = "0.41.0", path = "../sway-utils" }
sysinfo = "0.29.0"
tar = "0.4.38"
toml = "0.5"
tracing = "0.1"
url = { version = "2.2", features = ["serde"] }
vec1 = "1.8.0"
walkdir = "2"

[target.'cfg(not(target_os = "macos"))'.dependencies]
sysinfo = "0.29.0"
1 change: 0 additions & 1 deletion forc-pkg/src/pkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ use sway_core::{
use sway_error::{error::CompileError, warning::CompileWarning};
use sway_types::{Ident, Span, Spanned};
use sway_utils::{constants, time_expr, PerformanceData, PerformanceMetric};
use sysinfo::{System, SystemExt};
use tracing::{info, warn};

type GraphIx = u32;
Expand Down
4 changes: 3 additions & 1 deletion sway-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ sway-ir = { version = "0.41.0", path = "../sway-ir" }
sway-parse = { version = "0.41.0", path = "../sway-parse" }
sway-types = { version = "0.41.0", path = "../sway-types" }
sway-utils = { version = "0.41.0", path = "../sway-utils" }
sysinfo = "0.29.0"
thiserror = "1.0"
tracing = "0.1"
uint = "0.9"
vec1 = "1.8.0"

[target.'cfg(not(target_os = "macos"))'.dependencies]
sysinfo = "0.29.0"
1 change: 0 additions & 1 deletion sway-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ pub mod fuel_prelude {
}

pub use engine_threading::Engines;
use sysinfo::{System, SystemExt};

/// Given an input `Arc<str>` and an optional [BuildConfig], parse the input into a [lexed::LexedProgram] and [parsed::ParseProgram].
///
Expand Down
16 changes: 12 additions & 4 deletions sway-utils/src/performance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serde::Serialize;
pub struct PerformanceMetric {
pub phase: String,
pub elapsed: f64,
pub memory_usage: u64,
pub memory_usage: Option<u64>,
}

#[derive(Debug, Default, Serialize)]
Expand All @@ -26,12 +26,20 @@ macro_rules! time_expr {
println!(" Time elapsed to {}: {:?}", $description, elapsed);
}
if cfg.metrics_outfile.is_some() {
let mut sys = System::new();
sys.refresh_system();
#[cfg(not(target_os = "macos"))]
let memory_usage = {
use sysinfo::{System, SystemExt};
let mut sys = System::new();
sys.refresh_system();
Some(sys.used_memory())
};
#[cfg(target_os = "macos")]
let memory_usage = None;

$data.metrics.push(PerformanceMetric {
phase: $key.to_string(),
elapsed: elapsed.as_secs_f64(),
memory_usage: sys.used_memory(),
memory_usage,
});
}
output
Expand Down

0 comments on commit 5dac20e

Please sign in to comment.