Merge pull request #141 from jordalgo/rusty-logging

Add libbpf logging to rust schedulers
This commit is contained in:
Tejun Heo 2024-02-20 13:52:39 -10:00 committed by GitHub
commit 22d635c385
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 29 additions and 0 deletions

View File

@ -37,6 +37,9 @@ pub use bpf_builder::BpfBuilder;
pub mod ravg;
mod libbpf_logger;
pub use libbpf_logger::init_libbpf_logging;
mod user_exit_info;
pub use user_exit_info::UserExitInfo;
pub use user_exit_info::ScxExitKind;

View File

@ -0,0 +1,20 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.
//
// This software may be used and distributed according to the terms of the
// GNU General Public License version 2.
use libbpf_rs::{PrintLevel, set_print};
fn print_to_log(level: PrintLevel, msg: String) {
match level {
PrintLevel::Debug => log::debug!("{}", msg),
PrintLevel::Info => log::info!("{}", msg),
PrintLevel::Warn => log::warn!("{}", msg),
}
}
pub fn init_libbpf_logging(
level: Option<PrintLevel>,
) {
set_print(Some((level.unwrap_or(PrintLevel::Debug), print_to_log)));
}

View File

@ -38,6 +38,7 @@ use prometheus_client::encoding::text::encode;
use prometheus_client::metrics::family::Family;
use prometheus_client::metrics::gauge::Gauge;
use prometheus_client::registry::Registry;
use scx_utils::init_libbpf_logging;
use scx_utils::ravg::ravg_read;
use scx_utils::uei_exited;
use scx_utils::uei_report;
@ -1225,6 +1226,7 @@ impl<'a> Scheduler<'a> {
// Open the BPF prog first for verification.
let mut skel_builder = BpfSkelBuilder::default();
skel_builder.obj_builder.debug(opts.verbose > 1);
init_libbpf_logging(None);
let mut skel = skel_builder.open().context("Failed to open BPF program")?;
// Initialize skel according to @opts.

View File

@ -18,6 +18,7 @@ use libc::{sched_param, sched_setscheduler};
mod alloc;
use alloc::*;
use scx_utils::init_libbpf_logging;
use scx_utils::uei_exited;
use scx_utils::uei_report;
@ -232,6 +233,7 @@ impl<'cb> BpfScheduler<'cb> {
) -> Result<Self> {
// Open the BPF prog first for verification.
let skel_builder = BpfSkelBuilder::default();
init_libbpf_logging(None);
let mut skel = skel_builder.open().context("Failed to open BPF program")?;
// Lock all the memory to prevent page faults that could trigger potential deadlocks during

View File

@ -33,6 +33,7 @@ use log::info;
use log::trace;
use log::warn;
use ordered_float::OrderedFloat;
use scx_utils::init_libbpf_logging;
use scx_utils::ravg::ravg_read;
use scx_utils::uei_exited;
use scx_utils::uei_report;
@ -982,6 +983,7 @@ impl<'a> Scheduler<'a> {
// Open the BPF prog first for verification.
let mut skel_builder = BpfSkelBuilder::default();
skel_builder.obj_builder.debug(opts.verbose > 0);
init_libbpf_logging(None);
let mut skel = skel_builder.open().context("Failed to open BPF program")?;
// Initialize skel according to @opts.