Skip to content

Commit

Permalink
refact system module
Browse files Browse the repository at this point in the history
  • Loading branch information
dearfl committed Apr 11, 2024
1 parent e8ae3a9 commit 61fc2ab
Show file tree
Hide file tree
Showing 17 changed files with 435 additions and 201 deletions.
119 changes: 77 additions & 42 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/op/host-op-system/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ anyhow = "1.0.80"
wasmtime-wasi = "18.0.1"
uname = "0.1.1"
num_cpus = "1.16.0"
sysinfo = "0.30.7"
procfs = "0.16.0"
10 changes: 7 additions & 3 deletions crates/op/host-op-system/src/cpu/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//
// You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not,
// see <https://www.gnu.org/licenses/>.

use crate::{
profiling::system::cpu::{
self, AddressSizes as GuestAddressSizes, Arm64CpuInfo as GuestArm64CpuInfo,
Expand Down Expand Up @@ -115,8 +116,11 @@ impl From<&HostCpuInfo> for GuestCpuInfo {
}

impl cpu::Host for SysCtx {
fn get_cpu_info(&mut self) -> wasmtime::Result<Result<GuestCpuInfo, String>> {
let cpu_info = parse_cpuinfo!().unwrap();
Ok(Ok((&cpu_info).into()))
fn info(&mut self) -> wasmtime::Result<Result<GuestCpuInfo, String>> {
let cpu_info = match parse_cpuinfo!() {
Ok(ref info) => Ok(info.into()),
Err(err) => Err(err.to_string()),
};
Ok(cpu_info)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
//
// You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not,
// see <https://www.gnu.org/licenses/>.

use super::{InterruptDetails, InterruptType, IrqDetails};
use crate::interrupts::raw::{parse_interrupts, parse_irq};
use crate::profiling::system::interrupts;
use crate::interrupt::raw::{parse_interrupts, parse_irq};
use crate::profiling::system::interrupt;
use crate::SysCtx;

impl From<&IrqDetails> for interrupts::Irq {
impl From<&IrqDetails> for interrupt::InterruptInfo {
fn from(value: &IrqDetails) -> Self {
interrupts::Irq {
Self {
number: value.irq_number,
smp_affinity: value.smp_affinity.clone(),
smp_affinity_list: value.smp_affinity_list.clone(),
Expand All @@ -27,37 +28,41 @@ impl From<&IrqDetails> for interrupts::Irq {
}
}

impl From<&InterruptDetails> for interrupts::Stat {
impl From<&InterruptDetails> for interrupt::InterruptStat {
fn from(value: &InterruptDetails) -> Self {
interrupts::Stat {
Self {
interrupt_type: match &value.interrupt_type {
InterruptType::Common(irq) => interrupts::Kind::Common(*irq),
InterruptType::ArchSpecific(irq) => interrupts::Kind::ArchSpecific(irq.clone()),
InterruptType::Common(irq) => interrupt::InterruptType::Common(*irq),
InterruptType::ArchSpecific(irq) => {
interrupt::InterruptType::ArchSpecific(irq.clone())
}
},
description: value.description.clone(),
per_cpu_counts: value.cpu_counts.clone(),
}
}
}

impl interrupts::Host for SysCtx {
fn get_interrupts_info(&mut self) -> wasmtime::Result<Result<Vec<interrupts::Irq>, String>> {
match parse_irq!() {
Ok(irq) => Ok(Ok(irq
impl interrupt::Host for SysCtx {
fn info(&mut self) -> wasmtime::Result<Result<Vec<interrupt::InterruptInfo>, String>> {
let info = match parse_irq!() {
Ok(irq) => Ok(irq
.iter()
.map(interrupts::Irq::from)
.collect::<Vec<interrupts::Irq>>())),
Err(e) => Ok(Err(format!("{}: {}", "get interrupt info failed", e))),
}
.map(interrupt::InterruptInfo::from)
.collect::<Vec<interrupt::InterruptInfo>>()),
Err(e) => Err(format!("{}: {}", "get interrupt info failed", e)),
};
Ok(info)
}

fn get_interrupts_stat(&mut self) -> wasmtime::Result<Result<Vec<interrupts::Stat>, String>> {
match parse_interrupts!() {
Ok(bindings) => Ok(Ok(bindings
fn stat(&mut self) -> wasmtime::Result<Result<Vec<interrupt::InterruptStat>, String>> {
let stat = match parse_interrupts!() {
Ok(bindings) => Ok(bindings
.iter()
.map(interrupts::Stat::from)
.collect::<Vec<interrupts::Stat>>())),
Err(e) => Ok(Err(format!("{}: {}", "get interrupt statistics failed", e))),
}
.map(interrupt::InterruptStat::from)
.collect::<Vec<interrupt::InterruptStat>>()),
Err(e) => Err(format!("{}: {}", "get interrupt statistics failed", e)),
};
Ok(stat)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ pub fn do_parse_all_irq(path: &str) -> std::io::Result<Vec<IrqDetails>> {

macro_rules! parse_irq {
($path:expr) => {
crate::interrupts::irq::do_parse_all_irq($path)
crate::interrupt::irq::do_parse_all_irq($path)
};
() => {
crate::interrupts::irq::do_parse_all_irq("/proc/irq")
crate::interrupt::irq::do_parse_all_irq("/proc/irq")
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ pub fn do_parse_interrupts(path: &str) -> io::Result<Vec<InterruptDetails>> {

macro_rules! parse_interrupts {
($path:expr) => {
crate::interrupts::stat::do_parse_interrupts($path)
crate::interrupt::stat::do_parse_interrupts($path)
};
() => {
crate::interrupts::stat::do_parse_interrupts("/proc/interrupts")
crate::interrupt::stat::do_parse_interrupts("/proc/interrupts")
};
}

Expand Down
Loading

0 comments on commit 61fc2ab

Please sign in to comment.