Skip to content

Commit

Permalink
feat: adding optional --prefix option
Browse files Browse the repository at this point in the history
to ask scaph to look in PREFIX/proc and PREFIX/sys/class/powercap
instead of the default paths. This enables to run scaph in docker with
only RO mountpoins. (see discussion
#57 for more details)
  • Loading branch information
bpetit committed Jan 29, 2021
1 parent ba61b6d commit 0af3b61
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ fn get_sensor(matches: &ArgMatches) -> Box<dyn Sensor> {
.parse()
.unwrap(),
matches.is_present("vm"),
get_argument(matches, "prefix")
),
_ => PowercapRAPLSensor::new(
get_argument(matches, "sensor-buffer-per-socket-max-kB")
Expand All @@ -40,6 +41,7 @@ fn get_sensor(matches: &ArgMatches) -> Box<dyn Sensor> {
.parse()
.unwrap(),
matches.is_present("vm"),
get_argument(matches, "prefix")
),
};
Box::new(sensor)
Expand Down
9 changes: 9 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,17 @@ fn main() {
.long("vm")
.required(false)
.takes_value(false)
).arg(
Arg::with_name("prefix")
.value_name("prefix")
.help("Ask scaphandre to look for data in a specific location instead of the default one (will look in $PREFIX/sys/class/powercap and $PREFIX/proc).")
.long("prefix")
.required(false)
.takes_value(false)
.default_value("")
);


for exp in res {
let mut subcmd = SubCommand::with_name(exp).about(
match exp {
Expand Down
6 changes: 3 additions & 3 deletions src/sensors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1090,14 +1090,14 @@ mod tests {

#[test]
fn read_topology_stats() {
let mut sensor = powercap_rapl::PowercapRAPLSensor::new(8, 8, false);
let mut sensor = powercap_rapl::PowercapRAPLSensor::new(8, 8, false, String::from(""));
let topo = (*sensor.get_topology()).unwrap();
println!("{:?}", topo.read_stats());
}

#[test]
fn read_core_stats() {
let mut sensor = powercap_rapl::PowercapRAPLSensor::new(8, 8, false);
let mut sensor = powercap_rapl::PowercapRAPLSensor::new(8, 8, false, String::from(""));
let mut topo = (*sensor.get_topology()).unwrap();
for s in topo.get_sockets() {
for c in s.get_cores() {
Expand All @@ -1108,7 +1108,7 @@ mod tests {

#[test]
fn read_socket_stats() {
let mut sensor = powercap_rapl::PowercapRAPLSensor::new(8, 8, false);
let mut sensor = powercap_rapl::PowercapRAPLSensor::new(8, 8, false, String::from(""));
let mut topo = (*sensor.get_topology()).unwrap();
for s in topo.get_sockets() {
println!("{:?}", s.read_stats());
Expand Down
5 changes: 3 additions & 2 deletions src/sensors/powercap_rapl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ impl PowercapRAPLSensor {
buffer_per_socket_max_kbytes: u16,
buffer_per_domain_max_kbytes: u16,
virtual_machine: bool,
prefix: String
) -> PowercapRAPLSensor {
let mut powercap_path = String::from("/sys/class/powercap");
let mut powercap_path = String::from(format!("{}/sys/class/powercap", prefix));
if virtual_machine {
powercap_path = String::from("/var/scaphandre");
if let Ok(val) = env::var("SCAPHANDRE_POWERCAP_PATH") {
Expand Down Expand Up @@ -127,7 +128,7 @@ mod tests {
}
#[test]
fn get_topology_returns_topology_type() {
let mut sensor = PowercapRAPLSensor::new(1, 1, false);
let mut sensor = PowercapRAPLSensor::new(1, 1, false, String::from(""));
let topology = sensor.get_topology();
assert_eq!(
"alloc::boxed::Box<core::option::Option<scaphandre::sensors::Topology>>",
Expand Down
2 changes: 1 addition & 1 deletion tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::fs::{create_dir, read_dir};

#[test]
fn exporter_qemu() {
let sensor = PowercapRAPLSensor::new(1, 1, false);
let sensor = PowercapRAPLSensor::new(1, 1, false, String::from(""));
let mut exporter = QemuExporter::new(Box::new(sensor));
// Create integration_tests directory if it does not exist
let curdir = current_dir().unwrap();
Expand Down

0 comments on commit 0af3b61

Please sign in to comment.