Skip to content

Commit

Permalink
Fix conditional features
Browse files Browse the repository at this point in the history
  • Loading branch information
TheElectronWill committed May 10, 2023
1 parent 13acf3a commit 01050fa
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ use scaphandre::{exporters, sensors::Sensor};
#[cfg(target_os = "linux")]
use scaphandre::sensors::powercap_rapl;

#[cfg(target_os = "windows")]
use scaphandre::sensors::msr_rapl;

// the struct below defines the main Scaphandre command-line interface
/// Extensible metrology agent for electricity consumption related metrics.
#[derive(Parser)]
Expand Down Expand Up @@ -53,6 +56,9 @@ struct Cli {
/// *not* in the third-person. That is, use "Do xyz" instead of "Does xyz".
#[derive(Subcommand)]
enum ExporterChoice {
/// Write the metrics to the terminal
Stdout(exporters::stdout::ExporterArgs),

/// Write the metrics in the JSON format to a file or to stdout
#[cfg(feature = "json")]
Json(exporters::json::ExporterArgs),
Expand All @@ -70,9 +76,6 @@ enum ExporterChoice {
#[cfg(feature = "riemann")]
Riemann(exporters::riemann::ExporterArgs),

/// Write the metrics to the terminal
Stdout(exporters::stdout::ExporterArgs),

/// Expose the metrics to a Warp10 host, through HTTP
#[cfg(feature = "warpten")]
Warpten(exporters::warpten::ExporterArgs),
Expand All @@ -93,21 +96,26 @@ fn main() {

fn build_exporter(choice: ExporterChoice, sensor: &dyn Sensor) -> Box<dyn exporters::Exporter> {
match choice {
ExporterChoice::Stdout(args) => {
Box::new(exporters::stdout::StdoutExporter::new(sensor, args))
}
#[cfg(feature = "json")]
ExporterChoice::Json(args) => {
Box::new(exporters::json::JsonExporter::new(sensor, args)) // keep this in braces
}
#[cfg(feature = "prometheus")]
ExporterChoice::Prometheus(args) => {
Box::new(exporters::prometheus::PrometheusExporter::new(sensor, args))
}
#[cfg(feature = "qemu")]
ExporterChoice::Qemu => {
Box::new(exporters::qemu::QemuExporter::new(sensor)) // keep this in braces
}
#[cfg(feature = "riemann")]
ExporterChoice::Riemann(args) => {
Box::new(exporters::riemann::RiemannExporter::new(sensor, args))
}
ExporterChoice::Stdout(args) => {
Box::new(exporters::stdout::StdoutExporter::new(sensor, args))
}
#[cfg(feature = "warpten")]
ExporterChoice::Warpten(args) => {
Box::new(exporters::warpten::Warp10Exporter::new(sensor, args))
}
Expand All @@ -130,7 +138,7 @@ fn build_sensor(cli: &Cli) -> impl Sensor {
};

#[cfg(target_os = "windows")]
let msr_sensor_win = || sensors::msr_rapl::MsrRAPLSensor::new();
let msr_sensor_win = || msr_rapl::MsrRAPLSensor::new();

match cli.sensor.as_deref() {
Some("powercap_rapl") => {
Expand All @@ -144,7 +152,7 @@ fn build_sensor(cli: &Cli) -> impl Sensor {
Some("msr") => {
#[cfg(target_os = "windows")]
{
msr_sensor()
msr_sensor_win()
}
#[cfg(not(target_os = "windows"))]
panic!("Invalid sensor: Scaphandre's msr only works on Windows")
Expand Down

0 comments on commit 01050fa

Please sign in to comment.