diff --git a/.github/workflows/build-dev-auto-feature.yml b/.github/workflows/build-dev-auto-feature.yml index f95de7c..da95549 100644 --- a/.github/workflows/build-dev-auto-feature.yml +++ b/.github/workflows/build-dev-auto-feature.yml @@ -6,7 +6,6 @@ on: - '*' pull_request_target: types: - - edited - opened - reopened - synchronize @@ -25,18 +24,22 @@ jobs: - { os: ubuntu-22.04, triple: x86_64-unknown-linux-gnu , alias: amd64-gnu-ubuntu-22.04 } - { os: ubuntu-22.04, triple: x86_64-unknown-linux-musl, alias: amd64-musl-ubuntu-22.04 } + env: + SCCACHE_GHA_ENABLED: "true" + RUSTC_WRAPPER: "sccache" + steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.head.sha }} - name: Setup Rust toolchain - uses: actions-rs/toolchain@v1 + uses: actions-rs/toolchain@v2 with: profile: minimal override: true - toolchain: 1.75.0 + toolchain: 1.85 components: rustfmt, clippy - name: Show environment information @@ -49,13 +52,13 @@ jobs: uname -a cat /usr/include/linux/version.h - - name: Setup Rust cache - uses: Swatinem/rust-cache@v2 + - name: Setup build cache + uses: mozilla-actions/sccache-action@v0.0.9 with: - prefix-key: ${{ matrix.target.alias }} + version: 'v0.10.0' - name: Cache APT packages - uses: awalsh128/cache-apt-pkgs-action@v1.3.1 + uses: awalsh128/cache-apt-pkgs-action@latest with: packages: musl-tools version: 1.0 @@ -93,4 +96,4 @@ jobs: target: ${{ matrix.target.triple }} feature: auto - # TODO: Some tests will fail in GitHub Actions environment \ No newline at end of file + # TODO: Some tests will fail in GitHub Actions environment diff --git a/.github/workflows/build-dev.yml b/.github/workflows/build-dev.yml index fd9b0e8..8941ff8 100644 --- a/.github/workflows/build-dev.yml +++ b/.github/workflows/build-dev.yml @@ -6,7 +6,6 @@ on: - '*' pull_request_target: types: - - edited - opened - reopened - synchronize @@ -28,18 +27,22 @@ jobs: - { pkg: linux-source-6.2.0 , alias: 6.2 , feature: linux-6.0 } - { pkg: linux-source-6.5.0 , alias: 6.5 , feature: linux-6.3 } + env: + SCCACHE_GHA_ENABLED: "true" + RUSTC_WRAPPER: "sccache" + steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.head.sha }} - name: Setup Rust toolchain - uses: actions-rs/toolchain@v1 + uses: actions-rs/toolchain@v2 with: profile: minimal override: true - toolchain: 1.75.0 + toolchain: 1.85 components: rustfmt, clippy - name: Show environment information @@ -51,13 +54,13 @@ jobs: rustc -V uname -a - - name: Setup Rust cache - uses: Swatinem/rust-cache@v2 + - name: Setup build cache + uses: mozilla-actions/sccache-action@v0.0.9 with: - prefix-key: ${{ matrix.target.alias }} + version: 'v0.10.0' - name: Cache APT packages - uses: awalsh128/cache-apt-pkgs-action@v1.3.1 + uses: awalsh128/cache-apt-pkgs-action@latest with: packages: musl-tools ${{ matrix.linux-source.pkg }} version: 1.0 @@ -105,4 +108,4 @@ jobs: env: LINUX_HEADERS_PATH: ${{ github.workspace }}/linux-headers - # TODO: Some tests will fail in GitHub Actions environment \ No newline at end of file + # TODO: Some tests will fail in GitHub Actions environment diff --git a/build/helpers.rs b/build/helpers.rs index db6ae0b..b7dd277 100644 --- a/build/helpers.rs +++ b/build/helpers.rs @@ -12,9 +12,10 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::consts::IOCTLS; use std::fs; +use crate::consts::IOCTLS; + /// Parse `LINUX_VERSION_CODE` of `linux/version.h` to (major, patch_level, sub_level) pub fn parse_linux_version_h(path: &str) -> (usize, usize, usize) { let first_line = fs::read_to_string(path) diff --git a/build/main.rs b/build/main.rs index 3fdb9b6..6e6e133 100644 --- a/build/main.rs +++ b/build/main.rs @@ -17,10 +17,12 @@ mod helpers; extern crate bindgen; -use crate::consts::LINUX_FEATURE_VERSIONS; -use crate::helpers::{bindgen, parse_linux_version_h}; -use std::env; -use std::path::Path; +use std::{env, path::Path}; + +use crate::{ + consts::LINUX_FEATURE_VERSIONS, + helpers::{bindgen, parse_linux_version_h}, +}; fn main() { // Check target OS diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..c4c6f7a --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "1.85" +components = ["rustfmt", "clippy"] +profile = "minimal" diff --git a/src/infra/box.rs b/src/infra/box.rs index c2bdff9..d84b0c9 100644 --- a/src/infra/box.rs +++ b/src/infra/box.rs @@ -12,8 +12,10 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use std::alloc::{alloc, Layout}; -use std::ptr; +use std::{ + alloc::{alloc, Layout}, + ptr, +}; pub trait WrapBox { #[inline] @@ -36,6 +38,6 @@ impl BoxSliceExt for Box<[T]> { let layout = Layout::array::(len).unwrap(); let ptr = unsafe { alloc(layout) }; let slice = ptr::slice_from_raw_parts(ptr, len); - unsafe { Self::from_raw(std::mem::transmute(slice)) } + unsafe { Self::from_raw(std::mem::transmute::<*const [u8], *mut [T]>(slice)) } } } diff --git a/src/infra/vla.rs b/src/infra/vla.rs index 610bd3f..cf5b587 100644 --- a/src/infra/vla.rs +++ b/src/infra/vla.rs @@ -12,8 +12,7 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use std::marker::PhantomData; -use std::slice; +use std::{marker::PhantomData, slice}; #[repr(C)] pub struct Vla { @@ -114,7 +113,7 @@ mod tests { fn test_vla_u8_u8() { let buf = [2, 1, 2, 3, 4, 5_u8]; let len_ptr = &buf[0] as *const u8; - let vla: &Vla = unsafe { &*Vla::from_ptr(len_ptr) }; + let vla: &Vla = unsafe { Vla::from_ptr(len_ptr) }; assert_eq!(vla.as_slice(), &buf[1..3]) } @@ -126,7 +125,7 @@ mod tests { let buf = Wrapper([2, 0, 0, 0, 1, 2, 3, 4, 5_u8]); let len_ptr = &buf.0[0] as *const _ as *const u32; - let vla: &Vla = unsafe { &*Vla::from_ptr(len_ptr) }; + let vla: &Vla = unsafe { Vla::from_ptr(len_ptr) }; assert_eq!(vla.as_slice(), &buf.0[4..6]) } diff --git a/src/infra/zt.rs b/src/infra/zt.rs index de76869..7d52816 100644 --- a/src/infra/zt.rs +++ b/src/infra/zt.rs @@ -12,11 +12,9 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . +use std::{marker::PhantomData, mem::size_of, ops::Not, slice}; + use crate::infra::SizedExt; -use std::marker::PhantomData; -use std::mem::size_of; -use std::ops::Not; -use std::slice; #[repr(C)] pub struct ZeroTerminated { diff --git a/src/lib.rs b/src/lib.rs index eb9296f..c426bec 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,8 +13,6 @@ // see . #![cfg(target_os = "linux")] -#![deny(warnings)] -#![warn(clippy::all, clippy::nursery, clippy::cargo_common_metadata)] mod infra; mod perf_event; diff --git a/src/perf_event/config.rs b/src/perf_event/config.rs index a1c0eeb..2a68b4c 100644 --- a/src/perf_event/config.rs +++ b/src/perf_event/config.rs @@ -13,6 +13,7 @@ // see . use std::{io, result}; + use thiserror::Error; #[derive(Error, Debug)] diff --git a/src/perf_event/counting/config/mod.rs b/src/perf_event/counting/config/mod.rs index c83f32c..0018b82 100644 --- a/src/perf_event/counting/config/mod.rs +++ b/src/perf_event/counting/config/mod.rs @@ -15,14 +15,12 @@ mod extra_config; mod new; -use crate::perf_event::PerfEventAttr; -use std::ffi::CString; -use std::fmt::Debug; -use std::rc::Rc; +use std::{ffi::CString, fmt::Debug, rc::Rc}; -use crate::{Event, EventScope}; pub use extra_config::*; +use crate::{perf_event::PerfEventAttr, Event, EventScope}; + #[derive(Debug, Clone)] pub struct Config { // This will keep the ptr of `kprobe_func` or `uprobe_path` valid if present. diff --git a/src/perf_event/counting/config/new.rs b/src/perf_event/counting/config/new.rs index 98e4bf3..dadbd97 100644 --- a/src/perf_event/counting/config/new.rs +++ b/src/perf_event/counting/config/new.rs @@ -12,13 +12,16 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::counting::{Config, ExtraConfig}; -use crate::perf_event::PerfEventAttr; -use crate::syscall::bindings::*; +use std::mem::size_of; + +use crate::{ + counting::{Config, ExtraConfig}, + perf_event::PerfEventAttr, + syscall::bindings::*, + Event, EventScope, RawPerfEventAttr, +}; #[cfg(feature = "linux-4.17")] use crate::{DynamicPmuEvent, KprobeConfig, UprobeConfig}; -use crate::{Event, EventScope, RawPerfEventAttr}; -use std::mem::size_of; #[inline] pub fn new<'t>( diff --git a/src/perf_event/counting/group/fixed.rs b/src/perf_event/counting/group/fixed.rs index 7331918..3910887 100644 --- a/src/perf_event/counting/group/fixed.rs +++ b/src/perf_event/counting/group/fixed.rs @@ -12,10 +12,12 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::counting::group::inner::Inner; -use crate::counting::CounterGroupStat; -use std::io; -use std::sync::{Arc, RwLock, RwLockReadGuard, RwLockWriteGuard}; +use std::{ + io, + sync::{Arc, RwLock, RwLockReadGuard, RwLockWriteGuard}, +}; + +use crate::counting::{group::inner::Inner, CounterGroupStat}; pub struct FixedCounterGroup { inner: Arc>, diff --git a/src/perf_event/counting/group/guard.rs b/src/perf_event/counting/group/guard.rs index b04c9ea..32fb7fc 100644 --- a/src/perf_event/counting/group/guard.rs +++ b/src/perf_event/counting/group/guard.rs @@ -12,11 +12,15 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::counting::group::inner::Inner; -use crate::counting::CounterStat; -use crate::infra::WrapResult; -use std::io; -use std::sync::{Arc, RwLock, RwLockReadGuard, RwLockWriteGuard}; +use std::{ + io, + sync::{Arc, RwLock, RwLockReadGuard, RwLockWriteGuard}, +}; + +use crate::{ + counting::{group::inner::Inner, CounterStat}, + infra::WrapResult, +}; pub struct CounterGuard { event_id: u64, @@ -24,7 +28,7 @@ pub struct CounterGuard { } impl CounterGuard { - pub(crate) fn new(event_id: u64, inner: Arc>) -> Self { + pub(crate) const fn new(event_id: u64, inner: Arc>) -> Self { Self { event_id, inner } } diff --git a/src/perf_event/counting/group/inner.rs b/src/perf_event/counting/group/inner.rs index 06c4bd0..68bdf28 100644 --- a/src/perf_event/counting/group/inner.rs +++ b/src/perf_event/counting/group/inner.rs @@ -12,15 +12,20 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::counting::{inner_stat, Counter, CounterGroupStat}; -use crate::perf_event::PerfEventAttr; -use crate::syscall::bindings::*; -use crate::syscall::{ioctl_wrapped, perf_event_open_wrapped}; +use std::{ + fs::File, + io, + io::ErrorKind, + os::fd::{AsRawFd, FromRawFd}, +}; + use libc::pid_t; -use std::fs::File; -use std::io; -use std::io::ErrorKind; -use std::os::fd::{AsRawFd, FromRawFd}; + +use crate::{ + counting::{inner_stat, Counter, CounterGroupStat}, + perf_event::PerfEventAttr, + syscall::{bindings::*, ioctl_wrapped, perf_event_open_wrapped}, +}; pub struct Inner { pub(crate) members: Vec, // members[0] is the group leader, if it exists. diff --git a/src/perf_event/counting/group/mod.rs b/src/perf_event/counting/group/mod.rs index c543cd5..6bbc001 100644 --- a/src/perf_event/counting/group/mod.rs +++ b/src/perf_event/counting/group/mod.rs @@ -19,22 +19,26 @@ mod stat; #[cfg(test)] mod tests; -use crate::counting::Config; -use crate::infra::WrapResult; -use libc::pid_t; -pub use stat::*; -use std::io; -use std::sync::{Arc, RwLock, RwLockReadGuard, RwLockWriteGuard}; +use std::{ + io, + sync::{Arc, RwLock, RwLockReadGuard, RwLockWriteGuard}, +}; -use crate::config; -use crate::config::{Cpu, Process}; -use crate::counting::group::inner::Inner; -use crate::syscall::bindings::*; pub use fixed::*; #[allow(unused_imports)] pub use guard::*; +use libc::pid_t; #[allow(unused_imports)] pub use stat::CounterGroupStat; +pub use stat::*; + +use crate::{ + config, + config::{Cpu, Process}, + counting::{group::inner::Inner, Config}, + infra::WrapResult, + syscall::bindings::*, +}; pub struct CounterGroup { pid: pid_t, diff --git a/src/perf_event/counting/group/stat.rs b/src/perf_event/counting/group/stat.rs index 483117b..9d0ff8a 100644 --- a/src/perf_event/counting/group/stat.rs +++ b/src/perf_event/counting/group/stat.rs @@ -12,12 +12,17 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::counting::group::guard::CounterGuard; -use crate::counting::group::inner::Inner; -use crate::infra::{BoxSliceExt, WrapResult}; -use std::collections::HashMap; -use std::io::{ErrorKind, Read}; -use std::{io, slice}; +use std::{ + collections::HashMap, + io, + io::{ErrorKind, Read}, + slice, +}; + +use crate::{ + counting::group::{guard::CounterGuard, inner::Inner}, + infra::{BoxSliceExt, WrapResult}, +}; #[repr(C)] #[derive(Debug, Clone)] diff --git a/src/perf_event/counting/group/tests/hardware.rs b/src/perf_event/counting/group/tests/hardware.rs index ccd4e34..1435816 100644 --- a/src/perf_event/counting/group/tests/hardware.rs +++ b/src/perf_event/counting/group/tests/hardware.rs @@ -12,9 +12,7 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::counting::group::tests::test_group; -use crate::test::cpu_workload; -use crate::{Event, HardwareEvent}; +use crate::{counting::group::tests::test_group, test::cpu_workload, Event, HardwareEvent}; #[test] fn test_ipc() { diff --git a/src/perf_event/counting/group/tests/mod.rs b/src/perf_event/counting/group/tests/mod.rs index 951a4b8..99819d2 100644 --- a/src/perf_event/counting/group/tests/mod.rs +++ b/src/perf_event/counting/group/tests/mod.rs @@ -15,9 +15,11 @@ mod hardware; mod software; -use crate::config::{Cpu, Process}; -use crate::counting::{Config, CounterGroup}; -use crate::{Event, EventScope}; +use crate::{ + config::{Cpu, Process}, + counting::{Config, CounterGroup}, + Event, EventScope, +}; /// rate = ev_1 / ev_2 pub fn test_group(ev_1: &Event, ev_2: &Event, workload: &mut F) diff --git a/src/perf_event/counting/group/tests/software.rs b/src/perf_event/counting/group/tests/software.rs index 792d56f..068f632 100644 --- a/src/perf_event/counting/group/tests/software.rs +++ b/src/perf_event/counting/group/tests/software.rs @@ -12,9 +12,7 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::counting::group::tests::test_group; -use crate::test::mem_workload; -use crate::{Event, SoftwareEvent}; +use crate::{counting::group::tests::test_group, test::mem_workload, Event, SoftwareEvent}; #[test] fn test_page_fault_per_clock() { diff --git a/src/perf_event/counting/single/mod.rs b/src/perf_event/counting/single/mod.rs index 94d9701..04d2c35 100644 --- a/src/perf_event/counting/single/mod.rs +++ b/src/perf_event/counting/single/mod.rs @@ -16,16 +16,20 @@ mod stat; #[cfg(test)] mod tests; -use crate::config; -use crate::config::{Cpu, Error, Process}; -use crate::counting::single::stat::counter_stat; -use crate::counting::Config; -use crate::syscall::bindings::*; -use crate::syscall::{ioctl_wrapped, perf_event_open_wrapped}; +use std::{ + fs::File, + io, + os::fd::{AsRawFd, FromRawFd}, +}; + pub use stat::CounterStat; -use std::fs::File; -use std::io; -use std::os::fd::{AsRawFd, FromRawFd}; + +use crate::{ + config, + config::{Cpu, Error, Process}, + counting::{single::stat::counter_stat, Config}, + syscall::{bindings::*, ioctl_wrapped, perf_event_open_wrapped}, +}; pub struct Counter { pub(crate) file: File, diff --git a/src/perf_event/counting/single/stat.rs b/src/perf_event/counting/single/stat.rs index 7287bcd..dbe003d 100644 --- a/src/perf_event/counting/single/stat.rs +++ b/src/perf_event/counting/single/stat.rs @@ -12,11 +12,12 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::counting::Counter; -use crate::infra::{SizedExt, WrapResult}; -use std::io; -use std::io::Read; -use std::mem::size_of; +use std::{io, io::Read, mem::size_of}; + +use crate::{ + counting::Counter, + infra::{SizedExt, WrapResult}, +}; #[derive(Debug, Clone)] pub struct CounterStat { diff --git a/src/perf_event/counting/single/tests/hardware.rs b/src/perf_event/counting/single/tests/hardware.rs index 22d9635..75a1f87 100644 --- a/src/perf_event/counting/single/tests/hardware.rs +++ b/src/perf_event/counting/single/tests/hardware.rs @@ -12,9 +12,7 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::counting::single::tests::test_single; -use crate::test::cpu_workload; -use crate::{Event, HardwareEvent}; +use crate::{counting::single::tests::test_single, test::cpu_workload, Event, HardwareEvent}; #[test] fn test_cpu_cycles() { diff --git a/src/perf_event/counting/single/tests/mod.rs b/src/perf_event/counting/single/tests/mod.rs index 713ab94..add5188 100644 --- a/src/perf_event/counting/single/tests/mod.rs +++ b/src/perf_event/counting/single/tests/mod.rs @@ -15,9 +15,11 @@ mod hardware; mod software; -use crate::config::{Cpu, Process}; -use crate::counting::{Config, Counter}; -use crate::{Event, EventScope}; +use crate::{ + config::{Cpu, Process}, + counting::{Config, Counter}, + Event, EventScope, +}; pub fn test_single(ev: &Event, workload: &mut F) where diff --git a/src/perf_event/counting/single/tests/software.rs b/src/perf_event/counting/single/tests/software.rs index 38023af..b51550a 100644 --- a/src/perf_event/counting/single/tests/software.rs +++ b/src/perf_event/counting/single/tests/software.rs @@ -12,9 +12,7 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::counting::single::tests::test_single; -use crate::test::cpu_workload; -use crate::{Event, SoftwareEvent}; +use crate::{counting::single::tests::test_single, test::cpu_workload, Event, SoftwareEvent}; #[test] fn test_cpu_clock() { diff --git a/src/perf_event/event/breakpoint.rs b/src/perf_event/event/breakpoint.rs index 1ed3f96..86d91f3 100644 --- a/src/perf_event/event/breakpoint.rs +++ b/src/perf_event/event/breakpoint.rs @@ -12,8 +12,7 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::perf_event::event::Event; -use crate::syscall::bindings::*; +use crate::{perf_event::event::Event, syscall::bindings::*}; #[derive(Clone, Debug)] pub struct BreakpointEvent { diff --git a/src/perf_event/event/dynamic_pmu.rs b/src/perf_event/event/dynamic_pmu.rs index 26b1ee2..c6102e2 100644 --- a/src/perf_event/event/dynamic_pmu.rs +++ b/src/perf_event/event/dynamic_pmu.rs @@ -12,10 +12,11 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::perf_event::event::Event; #[cfg(feature = "linux-4.17")] use std::{ffi::CString, rc::Rc}; +use crate::perf_event::event::Event; + #[cfg(feature = "linux-4.17")] #[derive(Clone, Debug)] pub enum KprobeConfig { diff --git a/src/perf_event/event/hardware.rs b/src/perf_event/event/hardware.rs index d0315ed..43621d5 100644 --- a/src/perf_event/event/hardware.rs +++ b/src/perf_event/event/hardware.rs @@ -12,8 +12,7 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::syscall::bindings::*; -use crate::Event; +use crate::{syscall::bindings::*, Event}; #[derive(PartialEq, Eq, Clone, Debug)] pub enum CacheOp { diff --git a/src/perf_event/event/mod.rs b/src/perf_event/event/mod.rs index b1f3cbe..b456396 100644 --- a/src/perf_event/event/mod.rs +++ b/src/perf_event/event/mod.rs @@ -20,19 +20,19 @@ mod scope; mod software; mod tracepoint; -use crate::perf_event::PerfEventAttr; -use crate::syscall::bindings::*; -use libc::c_long; use std::mem::size_of; pub use breakpoint::*; pub use dynamic_pmu::*; pub use hardware::*; +use libc::c_long; pub use raw::*; pub use scope::*; pub use software::*; pub use tracepoint::*; +use crate::{perf_event::PerfEventAttr, syscall::bindings::*}; + #[derive(Clone, Debug)] pub enum Event { Hardware(HardwareEvent), diff --git a/src/perf_event/event/scope.rs b/src/perf_event/event/scope.rs index 834d686..c0b3cbb 100644 --- a/src/perf_event/event/scope.rs +++ b/src/perf_event/event/scope.rs @@ -12,9 +12,10 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::perf_event::PerfEventAttr; use std::ops::Not; +use crate::perf_event::PerfEventAttr; + #[derive(PartialEq, Eq, Clone, Debug)] pub enum EventScope { User, diff --git a/src/perf_event/event/software.rs b/src/perf_event/event/software.rs index f308002..72256bf 100644 --- a/src/perf_event/event/software.rs +++ b/src/perf_event/event/software.rs @@ -12,8 +12,7 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::syscall::bindings::*; -use crate::Event; +use crate::{syscall::bindings::*, Event}; #[derive(PartialEq, Eq, Clone, Debug)] pub enum SoftwareEvent { diff --git a/src/perf_event/event/tracepoint.rs b/src/perf_event/event/tracepoint.rs index 6911ecb..8ccab80 100644 --- a/src/perf_event/event/tracepoint.rs +++ b/src/perf_event/event/tracepoint.rs @@ -12,13 +12,12 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::perf_event::event::Event; -use std::num::ParseIntError; -use std::ops::Not; -use std::path::PathBuf; -use std::{fs, io}; +use std::{fs, io, num::ParseIntError, ops::Not, path::PathBuf}; + use thiserror::Error; +use crate::perf_event::event::Event; + #[derive(Error, Debug)] pub enum Error { #[error("Event name is invalid")] @@ -92,7 +91,7 @@ fn tracefs_path() -> Result { .lines() .find(|line| line.starts_with("tracefs")) .and_then(|line| line.split(' ').nth(1)) - .ok_or_else(|| Error::FailedToFindTracefs) + .ok_or(Error::FailedToFindTracefs) .map(PathBuf::from) } @@ -114,5 +113,5 @@ fn test_available_event_names() { let ev_names = TracepointEvent::available_event_names(); dbg!(&ev_names); let ev_names = ev_names.unwrap(); - assert!(ev_names.len() > 0); + assert!(!ev_names.is_empty()); } diff --git a/src/perf_event/mod.rs b/src/perf_event/mod.rs index 18515cb..20c3723 100644 --- a/src/perf_event/mod.rs +++ b/src/perf_event/mod.rs @@ -18,9 +18,10 @@ pub mod event; pub mod sampling; pub mod tracing; -use crate::syscall::bindings::perf_event_attr; pub use event::*; +use crate::syscall::bindings::perf_event_attr; + pub type RawPerfEventAttr = perf_event_attr; #[derive(Debug, Clone)] @@ -274,7 +275,6 @@ impl PerfEventAttr { /// (since Linux 4.6[Ref: man perf_event_open], feature selection from `linux-4.7`) /// This causes the ring buffer to be written from the end to the beginning. /// This is to support reading from overwritable ring buffer. - /// // The `write_backward` was first added to the Linux kernel in 4.7 // the man documentation incorrectly says "since Linux 4.6" // See: https://github.com/torvalds/linux/commit/9ecda41acb971ebd07c8fb35faf24005c0baea12 diff --git a/src/perf_event/sampling/config/extra_config.rs b/src/perf_event/sampling/config/extra_config.rs index f789573..748d655 100644 --- a/src/perf_event/sampling/config/extra_config.rs +++ b/src/perf_event/sampling/config/extra_config.rs @@ -12,9 +12,9 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::sampling::config::sample_record_fields::SampleRecordFields; -use crate::sampling::ExtraRecord; -use crate::sampling::Wakeup::Events; +use crate::sampling::{ + config::sample_record_fields::SampleRecordFields, ExtraRecord, Wakeup::Events, +}; #[derive(Debug, Clone)] pub struct ExtraConfig { diff --git a/src/perf_event/sampling/config/extra_record.rs b/src/perf_event/sampling/config/extra_record.rs index f262d51..4607bed 100644 --- a/src/perf_event/sampling/config/extra_record.rs +++ b/src/perf_event/sampling/config/extra_record.rs @@ -12,9 +12,10 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::perf_event::PerfEventAttr; use std::ops::Not; +use crate::perf_event::PerfEventAttr; + #[derive(PartialEq, Eq, Clone, Debug)] pub enum ExtraRecord { Mmap, diff --git a/src/perf_event/sampling/config/mod.rs b/src/perf_event/sampling/config/mod.rs index 3d261e0..01e5bda 100644 --- a/src/perf_event/sampling/config/mod.rs +++ b/src/perf_event/sampling/config/mod.rs @@ -17,16 +17,14 @@ mod extra_record; mod new; mod sample_record_fields; -use crate::perf_event::PerfEventAttr; -use crate::{Event, EventScope}; -use std::ffi::CString; -use std::fmt::Debug; -use std::rc::Rc; +use std::{ffi::CString, fmt::Debug, rc::Rc}; pub use extra_config::*; pub use extra_record::*; pub use sample_record_fields::*; +use crate::{perf_event::PerfEventAttr, Event, EventScope}; + #[derive(PartialEq, Eq, Clone, Debug)] pub enum OverflowBy { Period(u64), diff --git a/src/perf_event/sampling/config/new.rs b/src/perf_event/sampling/config/new.rs index d9d7aa8..872f228 100644 --- a/src/perf_event/sampling/config/new.rs +++ b/src/perf_event/sampling/config/new.rs @@ -12,18 +12,21 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::perf_event::PerfEventAttr; +use std::{mem::size_of, ops::Not}; + +#[cfg(feature = "linux-4.1")] +use libc::{CLOCK_BOOTTIME, CLOCK_MONOTONIC, CLOCK_MONOTONIC_RAW, CLOCK_REALTIME, CLOCK_TAI}; + #[cfg(feature = "linux-4.1")] use crate::sampling::ClockId; -use crate::sampling::{Config, ExtraConfig, OverflowBy, SampleIpSkid, Wakeup}; -use crate::syscall::bindings::*; +use crate::{ + perf_event::PerfEventAttr, + sampling::{Config, ExtraConfig, OverflowBy, SampleIpSkid, Wakeup}, + syscall::bindings::*, + Event, EventScope, RawPerfEventAttr, +}; #[cfg(feature = "linux-4.17")] use crate::{DynamicPmuEvent, KprobeConfig, UprobeConfig}; -use crate::{Event, EventScope, RawPerfEventAttr}; -#[cfg(feature = "linux-4.1")] -use libc::{CLOCK_BOOTTIME, CLOCK_MONOTONIC, CLOCK_MONOTONIC_RAW, CLOCK_REALTIME, CLOCK_TAI}; -use std::mem::size_of; -use std::ops::Not; #[inline] pub fn new<'t>( diff --git a/src/perf_event/sampling/config/sample_record_fields.rs b/src/perf_event/sampling/config/sample_record_fields.rs index 9272d96..baddccf 100644 --- a/src/perf_event/sampling/config/sample_record_fields.rs +++ b/src/perf_event/sampling/config/sample_record_fields.rs @@ -12,8 +12,7 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::sampling::record::sample::WeightRepr; -use crate::syscall::bindings::*; +use crate::{sampling::record::sample::WeightRepr, syscall::bindings::*}; /// Select the fields contained in `sample::Body` #[derive(Debug, Clone, Default)] diff --git a/src/perf_event/sampling/group/fixed.rs b/src/perf_event/sampling/group/fixed.rs index cbb7f7a..e473254 100644 --- a/src/perf_event/sampling/group/fixed.rs +++ b/src/perf_event/sampling/group/fixed.rs @@ -12,12 +12,16 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::sampling::group::guard::SamplerGuard; -use crate::sampling::group::inner::Inner; -use crate::sampling::record::Record; -use crate::sampling::SamplerGroupStat; -use std::io; -use std::sync::{Arc, RwLock, RwLockReadGuard, RwLockWriteGuard}; +use std::{ + io, + sync::{Arc, RwLock, RwLockReadGuard, RwLockWriteGuard}, +}; + +use crate::sampling::{ + group::{guard::SamplerGuard, inner::Inner}, + record::Record, + SamplerGroupStat, +}; pub struct FixedSamplerGroup { inner: Arc>, diff --git a/src/perf_event/sampling/group/guard.rs b/src/perf_event/sampling/group/guard.rs index 3999b27..a355cd5 100644 --- a/src/perf_event/sampling/group/guard.rs +++ b/src/perf_event/sampling/group/guard.rs @@ -12,12 +12,15 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::infra::WrapResult; -use crate::sampling::group::inner::Inner; -use crate::sampling::record::Record; -use crate::sampling::SamplerStat; -use std::io; -use std::sync::{Arc, RwLock, RwLockReadGuard, RwLockWriteGuard}; +use std::{ + io, + sync::{Arc, RwLock, RwLockReadGuard, RwLockWriteGuard}, +}; + +use crate::{ + infra::WrapResult, + sampling::{group::inner::Inner, record::Record, SamplerStat}, +}; pub struct SamplerGuard { event_id: u64, @@ -25,7 +28,7 @@ pub struct SamplerGuard { } impl SamplerGuard { - pub(crate) fn new(event_id: u64, inner: Arc>) -> Self { + pub(crate) const fn new(event_id: u64, inner: Arc>) -> Self { Self { event_id, inner } } diff --git a/src/perf_event/sampling/group/inner.rs b/src/perf_event/sampling/group/inner.rs index 17af525..7850218 100644 --- a/src/perf_event/sampling/group/inner.rs +++ b/src/perf_event/sampling/group/inner.rs @@ -12,19 +12,22 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::perf_event::PerfEventAttr; -use crate::sampling::group::stat::inner_stat; -use crate::sampling::record::Record; -use crate::sampling::{Sampler, SamplerGroupStat}; -use crate::syscall::bindings::*; -use crate::syscall::{ioctl_wrapped, perf_event_open_wrapped}; +use std::{ + collections::HashMap, + fs::File, + io, + io::ErrorKind, + os::fd::{AsRawFd, FromRawFd}, +}; + use libc::pid_t; use memmap2::MmapOptions; -use std::collections::HashMap; -use std::fs::File; -use std::io; -use std::io::ErrorKind; -use std::os::fd::{AsRawFd, FromRawFd}; + +use crate::{ + perf_event::PerfEventAttr, + sampling::{group::stat::inner_stat, record::Record, Sampler, SamplerGroupStat}, + syscall::{bindings::*, ioctl_wrapped, perf_event_open_wrapped}, +}; pub struct Inner { leader_event_id: Option, diff --git a/src/perf_event/sampling/group/mod.rs b/src/perf_event/sampling/group/mod.rs index a58beeb..54a8ce2 100644 --- a/src/perf_event/sampling/group/mod.rs +++ b/src/perf_event/sampling/group/mod.rs @@ -19,20 +19,23 @@ mod stat; #[cfg(test)] mod tests; -use crate::infra::WrapResult; -use crate::sampling::group::inner::Inner; -use crate::sampling::record::Record; -use crate::sampling::Config; -use libc::pid_t; -use std::io; -use std::sync::{Arc, RwLock, RwLockReadGuard, RwLockWriteGuard}; +use std::{ + io, + sync::{Arc, RwLock, RwLockReadGuard, RwLockWriteGuard}, +}; -use crate::config; -use crate::config::{Cpu, Error, Process}; pub use fixed::*; pub use guard::*; +use libc::pid_t; pub use stat::{MemberCount, SamplerGroupStat}; +use crate::{ + config, + config::{Cpu, Error, Process}, + infra::WrapResult, + sampling::{group::inner::Inner, record::Record, Config}, +}; + pub struct SamplerGroup { pid: pid_t, cpu: i32, diff --git a/src/perf_event/sampling/group/stat.rs b/src/perf_event/sampling/group/stat.rs index 7c90272..f9ad8e2 100644 --- a/src/perf_event/sampling/group/stat.rs +++ b/src/perf_event/sampling/group/stat.rs @@ -12,12 +12,17 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::infra::{BoxSliceExt, WrapResult}; -use crate::sampling::group::inner::Inner; -use crate::sampling::{ReadFormatHead, ReadFormatValue, SamplerGuard}; -use std::collections::HashMap; -use std::io::{Error, ErrorKind, Read}; -use std::{io, slice}; +use std::{ + collections::HashMap, + io, + io::{Error, ErrorKind, Read}, + slice, +}; + +use crate::{ + infra::{BoxSliceExt, WrapResult}, + sampling::{group::inner::Inner, ReadFormatHead, ReadFormatValue, SamplerGuard}, +}; #[derive(Debug, Clone)] pub struct SamplerGroupStat { diff --git a/src/perf_event/sampling/group/tests/hardware.rs b/src/perf_event/sampling/group/tests/hardware.rs index 72548f2..0683cfe 100644 --- a/src/perf_event/sampling/group/tests/hardware.rs +++ b/src/perf_event/sampling/group/tests/hardware.rs @@ -12,9 +12,7 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::sampling::group::tests::test_group; -use crate::test::cpu_workload; -use crate::{Event, HardwareEvent}; +use crate::{sampling::group::tests::test_group, test::cpu_workload, Event, HardwareEvent}; #[test] fn test_ipc() { diff --git a/src/perf_event/sampling/group/tests/mod.rs b/src/perf_event/sampling/group/tests/mod.rs index 1af9e6f..f05c19d 100644 --- a/src/perf_event/sampling/group/tests/mod.rs +++ b/src/perf_event/sampling/group/tests/mod.rs @@ -15,10 +15,14 @@ mod hardware; mod software; -use crate::config::{Cpu, Process}; -use crate::sampling::record::{Record, RecordBody}; -use crate::sampling::{Config, FixedSamplerGroup, OverflowBy, SamplerGroup, SamplerGuard}; -use crate::{Event, EventScope}; +use crate::{ + config::{Cpu, Process}, + sampling::{ + record::{Record, RecordBody}, + Config, FixedSamplerGroup, OverflowBy, SamplerGroup, SamplerGuard, + }, + Event, EventScope, +}; pub fn test_group(ev_1: &Event, ev_2: &Event, workload: &mut F) where @@ -40,7 +44,7 @@ fn gen_group() -> SamplerGroup { fn gen_cfg(ev: &Event) -> Config { let scopes = EventScope::all(); let overflow_by = OverflowBy::Period(1000); - Config::new(&ev, &scopes, &overflow_by) + Config::new(ev, &scopes, &overflow_by) } fn test_next_record(ev_1: &Event, ev_2: &Event, workload: &mut F) @@ -96,9 +100,9 @@ where fn consume_records(group: &mut FixedSamplerGroup, guard: &SamplerGuard) { let mut count = 0; - let mut next = group.next_record(&guard); - while let Some(_) = next { - next = group.next_record(&guard); + let mut next = group.next_record(guard); + while next.is_some() { + next = group.next_record(guard); count += 1; } assert!(count > 0); diff --git a/src/perf_event/sampling/group/tests/software.rs b/src/perf_event/sampling/group/tests/software.rs index c51820c..1be96bd 100644 --- a/src/perf_event/sampling/group/tests/software.rs +++ b/src/perf_event/sampling/group/tests/software.rs @@ -12,9 +12,7 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::sampling::group::tests::test_group; -use crate::test::cpu_workload; -use crate::{Event, SoftwareEvent}; +use crate::{sampling::group::tests::test_group, test::cpu_workload, Event, SoftwareEvent}; #[test] fn test_cpu_clock_cpu_clock() { diff --git a/src/perf_event/sampling/record/body/bpf_event/mod.rs b/src/perf_event/sampling/record/body/bpf_event/mod.rs index 781fd60..0e1f2e7 100644 --- a/src/perf_event/sampling/record/body/bpf_event/mod.rs +++ b/src/perf_event/sampling/record/body/bpf_event/mod.rs @@ -12,8 +12,7 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::sampling::record::sample_id::SampleId; -use crate::syscall::bindings::BPF_TAG_SIZE; +use crate::{sampling::record::sample_id::SampleId, syscall::bindings::BPF_TAG_SIZE}; mod raw; diff --git a/src/perf_event/sampling/record/body/bpf_event/raw.rs b/src/perf_event/sampling/record/body/bpf_event/raw.rs index 2c70d3a..bdcb848 100644 --- a/src/perf_event/sampling/record/body/bpf_event/raw.rs +++ b/src/perf_event/sampling/record/body/bpf_event/raw.rs @@ -22,8 +22,7 @@ struct { }; */ -use crate::sampling::record::sample_id::SampleId; -use crate::syscall::bindings::BPF_TAG_SIZE; +use crate::{sampling::record::sample_id::SampleId, syscall::bindings::BPF_TAG_SIZE}; #[repr(C)] #[derive(Debug, Clone)] diff --git a/src/perf_event/sampling/record/body/cgroup/mod.rs b/src/perf_event/sampling/record/body/cgroup/mod.rs index 8daaa11..62873b6 100644 --- a/src/perf_event/sampling/record/body/cgroup/mod.rs +++ b/src/perf_event/sampling/record/body/cgroup/mod.rs @@ -12,9 +12,10 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::sampling::record::sample_id::SampleId; use std::ffi::CString; +use crate::sampling::record::sample_id::SampleId; + mod raw; #[derive(Debug, Clone)] diff --git a/src/perf_event/sampling/record/body/cgroup/raw.rs b/src/perf_event/sampling/record/body/cgroup/raw.rs index fd5cf2b..20d0398 100644 --- a/src/perf_event/sampling/record/body/cgroup/raw.rs +++ b/src/perf_event/sampling/record/body/cgroup/raw.rs @@ -20,8 +20,10 @@ struct { }; */ -use crate::infra::{ConstPtrExt, SliceExt, ZeroTerminated}; -use crate::sampling::record::sample_id::SampleId; +use crate::{ + infra::{ConstPtrExt, SliceExt, ZeroTerminated}, + sampling::record::sample_id::SampleId, +}; pub struct Raw { pub read_ptr: *const u8, diff --git a/src/perf_event/sampling/record/body/comm/mod.rs b/src/perf_event/sampling/record/body/comm/mod.rs index ef430b9..9182ba0 100644 --- a/src/perf_event/sampling/record/body/comm/mod.rs +++ b/src/perf_event/sampling/record/body/comm/mod.rs @@ -14,9 +14,10 @@ mod raw; -use crate::sampling::record::sample_id::SampleId; use std::ffi::CString; +use crate::sampling::record::sample_id::SampleId; + #[derive(Debug, Clone)] pub struct Body { pub pid: u32, diff --git a/src/perf_event/sampling/record/body/comm/raw.rs b/src/perf_event/sampling/record/body/comm/raw.rs index 88450ee..e6743f8 100644 --- a/src/perf_event/sampling/record/body/comm/raw.rs +++ b/src/perf_event/sampling/record/body/comm/raw.rs @@ -21,8 +21,10 @@ struct { }; */ -use crate::infra::{ConstPtrExt, SliceExt, ZeroTerminated}; -use crate::sampling::record::sample_id::SampleId; +use crate::{ + infra::{ConstPtrExt, SliceExt, ZeroTerminated}, + sampling::record::sample_id::SampleId, +}; #[repr(C)] pub struct Sized { diff --git a/src/perf_event/sampling/record/body/ksymbol/mod.rs b/src/perf_event/sampling/record/body/ksymbol/mod.rs index 46e3de3..4cea2ab 100644 --- a/src/perf_event/sampling/record/body/ksymbol/mod.rs +++ b/src/perf_event/sampling/record/body/ksymbol/mod.rs @@ -12,9 +12,10 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::sampling::record::sample_id::SampleId; use std::ffi::CString; +use crate::sampling::record::sample_id::SampleId; + mod raw; #[derive(Debug, Clone)] diff --git a/src/perf_event/sampling/record/body/ksymbol/raw.rs b/src/perf_event/sampling/record/body/ksymbol/raw.rs index 05333d3..bea09b0 100644 --- a/src/perf_event/sampling/record/body/ksymbol/raw.rs +++ b/src/perf_event/sampling/record/body/ksymbol/raw.rs @@ -23,8 +23,10 @@ struct { }; */ -use crate::infra::{ConstPtrExt, SliceExt, ZeroTerminated}; -use crate::sampling::record::sample_id::SampleId; +use crate::{ + infra::{ConstPtrExt, SliceExt, ZeroTerminated}, + sampling::record::sample_id::SampleId, +}; #[repr(C)] pub struct Sized { diff --git a/src/perf_event/sampling/record/body/mmap2/mod.rs b/src/perf_event/sampling/record/body/mmap2/mod.rs index 770e9b2..fbb96eb 100644 --- a/src/perf_event/sampling/record/body/mmap2/mod.rs +++ b/src/perf_event/sampling/record/body/mmap2/mod.rs @@ -12,10 +12,11 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . +use std::ffi::CString; + use crate::sampling::record::sample_id::SampleId; #[cfg(feature = "linux-5.12")] use crate::syscall::bindings::PERF_RECORD_MISC_MMAP_BUILD_ID; -use std::ffi::CString; mod raw; diff --git a/src/perf_event/sampling/record/body/mmap2/raw.rs b/src/perf_event/sampling/record/body/mmap2/raw.rs index 40909cc..e6d0d5e 100644 --- a/src/perf_event/sampling/record/body/mmap2/raw.rs +++ b/src/perf_event/sampling/record/body/mmap2/raw.rs @@ -40,8 +40,10 @@ struct { }; */ -use crate::infra::{ConstPtrExt, SliceExt, ZeroTerminated}; -use crate::sampling::record::sample_id::SampleId; +use crate::{ + infra::{ConstPtrExt, SliceExt, ZeroTerminated}, + sampling::record::sample_id::SampleId, +}; #[repr(C)] #[derive(Copy, Clone)] diff --git a/src/perf_event/sampling/record/body/namespaces/raw.rs b/src/perf_event/sampling/record/body/namespaces/raw.rs index a423233..18385d0 100644 --- a/src/perf_event/sampling/record/body/namespaces/raw.rs +++ b/src/perf_event/sampling/record/body/namespaces/raw.rs @@ -22,9 +22,10 @@ struct { }; */ -use crate::infra::{SliceExt, Vla}; -use crate::sampling::record::namespaces::Namespace; -use crate::sampling::record::sample_id::SampleId; +use crate::{ + infra::{SliceExt, Vla}, + sampling::record::{namespaces::Namespace, sample_id::SampleId}, +}; #[repr(C)] pub struct Sized { diff --git a/src/perf_event/sampling/record/body/read/mod.rs b/src/perf_event/sampling/record/body/read/mod.rs index 9d99d29..c3770ed 100644 --- a/src/perf_event/sampling/record/body/read/mod.rs +++ b/src/perf_event/sampling/record/body/read/mod.rs @@ -12,8 +12,7 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::sampling::record::sample_id::SampleId; -use crate::sampling::SamplerGroupStat; +use crate::sampling::{record::sample_id::SampleId, SamplerGroupStat}; mod raw; diff --git a/src/perf_event/sampling/record/body/read/raw.rs b/src/perf_event/sampling/record/body/read/raw.rs index d99240b..840ca35 100644 --- a/src/perf_event/sampling/record/body/read/raw.rs +++ b/src/perf_event/sampling/record/body/read/raw.rs @@ -20,11 +20,13 @@ struct { }; */ -use crate::infra::SliceExt; -use crate::sampling::record::sample_id::SampleId; -use crate::sampling::{ReadFormatHead, ReadFormatValue}; use std::slice; +use crate::{ + infra::SliceExt, + sampling::{record::sample_id::SampleId, ReadFormatHead, ReadFormatValue}, +}; + #[repr(C)] pub struct Sized { pub pid: u32, diff --git a/src/perf_event/sampling/record/body/sample/mod.rs b/src/perf_event/sampling/record/body/sample/mod.rs index a9f1f75..81a9bc1 100644 --- a/src/perf_event/sampling/record/body/sample/mod.rs +++ b/src/perf_event/sampling/record/body/sample/mod.rs @@ -17,12 +17,12 @@ mod data_src; mod raw; mod weight; -use crate::sampling::SamplerGroupStat; -use crate::syscall::bindings::*; pub use abi_and_regs::*; pub use data_src::*; pub use weight::*; +use crate::{sampling::SamplerGroupStat, syscall::bindings::*}; + #[derive(Debug, Clone)] pub struct Body { #[cfg(feature = "linux-3.12")] diff --git a/src/perf_event/sampling/record/body/sample/raw.rs b/src/perf_event/sampling/record/body/sample/raw.rs index 012b352..054fbbd 100644 --- a/src/perf_event/sampling/record/body/sample/raw.rs +++ b/src/perf_event/sampling/record/body/sample/raw.rs @@ -58,12 +58,13 @@ struct { }; */ -use crate::infra::{SliceExt, Vla, WrapOption}; -use crate::sampling::{ReadFormatHead, ReadFormatValue}; -use crate::syscall::bindings::*; -use std::mem::size_of; -use std::ops::Not; -use std::slice; +use std::{mem::size_of, ops::Not, slice}; + +use crate::{ + infra::{SliceExt, Vla, WrapOption}, + sampling::{ReadFormatHead, ReadFormatValue}, + syscall::bindings::*, +}; pub(super) struct Raw { pub read_ptr: *const u8, diff --git a/src/perf_event/sampling/record/body/text_poke/raw.rs b/src/perf_event/sampling/record/body/text_poke/raw.rs index 882f948..1fad3ce 100644 --- a/src/perf_event/sampling/record/body/text_poke/raw.rs +++ b/src/perf_event/sampling/record/body/text_poke/raw.rs @@ -22,8 +22,10 @@ struct { }; */ -use crate::infra::{ConstPtrExt, SliceExt, ZeroTerminated}; -use crate::sampling::record::sample_id::SampleId; +use crate::{ + infra::{ConstPtrExt, SliceExt, ZeroTerminated}, + sampling::record::sample_id::SampleId, +}; #[repr(C)] pub struct Sized { diff --git a/src/perf_event/sampling/record/sample_id/raw.rs b/src/perf_event/sampling/record/sample_id/raw.rs index 1e650ed..611b8d5 100644 --- a/src/perf_event/sampling/record/sample_id/raw.rs +++ b/src/perf_event/sampling/record/sample_id/raw.rs @@ -23,9 +23,9 @@ struct sample_id { }; */ +use std::{mem::size_of, ops::Not}; + use crate::syscall::bindings::*; -use std::mem::size_of; -use std::ops::Not; #[repr(C)] #[derive(Debug, Clone)] diff --git a/src/perf_event/sampling/single/into_iter.rs b/src/perf_event/sampling/single/into_iter.rs index 1cf8d5b..e18b5fd 100644 --- a/src/perf_event/sampling/single/into_iter.rs +++ b/src/perf_event/sampling/single/into_iter.rs @@ -12,8 +12,7 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::sampling::record::Record; -use crate::sampling::Sampler; +use crate::sampling::{record::Record, Sampler}; pub struct IntoIter { inner: Sampler, diff --git a/src/perf_event/sampling/single/iter.rs b/src/perf_event/sampling/single/iter.rs index 379c172..62c9fff 100644 --- a/src/perf_event/sampling/single/iter.rs +++ b/src/perf_event/sampling/single/iter.rs @@ -12,8 +12,7 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::sampling::record::Record; -use crate::sampling::Sampler; +use crate::sampling::{record::Record, Sampler}; impl Sampler { #[inline] diff --git a/src/perf_event/sampling/single/mod.rs b/src/perf_event/sampling/single/mod.rs index 658c930..c48cdaa 100644 --- a/src/perf_event/sampling/single/mod.rs +++ b/src/perf_event/sampling/single/mod.rs @@ -19,24 +19,29 @@ mod stat; #[cfg(test)] mod tests; -use crate::config; -use crate::infra::WrapResult; -use crate::sampling::record::*; -use crate::sampling::single::next_record::next_record; -use crate::sampling::Config; -use crate::syscall::bindings::*; -use crate::syscall::{ioctl_wrapped, perf_event_open_wrapped}; -use memmap2::{MmapMut, MmapOptions}; -use std::fs::File; -use std::io; -use std::os::fd::{AsRawFd, FromRawFd}; +use std::{ + fs::File, + io, + os::fd::{AsRawFd, FromRawFd}, +}; -use crate::config::{Cpu, Error, Process}; -use crate::sampling::single::stat::sampler_stat; pub use into_iter::*; pub use iter::*; +use memmap2::{MmapMut, MmapOptions}; pub use stat::SamplerStat; +use crate::{ + config, + config::{Cpu, Error, Process}, + infra::WrapResult, + sampling::{ + record::*, + single::{next_record::next_record, stat::sampler_stat}, + Config, + }, + syscall::{bindings::*, ioctl_wrapped, perf_event_open_wrapped}, +}; + pub struct Sampler { pub(crate) mmap: MmapMut, pub(crate) file: File, diff --git a/src/perf_event/sampling/single/next_record.rs b/src/perf_event/sampling/single/next_record.rs index e04518c..6f493a3 100644 --- a/src/perf_event/sampling/single/next_record.rs +++ b/src/perf_event/sampling/single/next_record.rs @@ -12,12 +12,16 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::infra::{SizedExt, WrapBox, WrapOption}; -use crate::sampling::record::*; -use crate::sampling::Sampler; -use crate::syscall::bindings::*; -use std::alloc::{alloc, dealloc, Layout}; -use std::slice; +use std::{ + alloc::{alloc, dealloc, Layout}, + slice, +}; + +use crate::{ + infra::{SizedExt, WrapBox, WrapOption}, + sampling::{record::*, Sampler}, + syscall::bindings::*, +}; #[inline] pub fn next_record(sampler: &mut Sampler) -> Option { @@ -43,7 +47,7 @@ pub fn next_record(sampler: &mut Sampler) -> Option { let mut buf = <[u8; 2]>::uninit(); buf[0] = *(data_ptr.add((data_size - 1) as _) as *const u8); buf[1] = *(data_ptr as *const u8); - std::mem::transmute(buf) + std::mem::transmute::<[u8; 2], u16>(buf) }, left => unsafe { let ptr = data_ptr.add((left - 2) as _) as *const u16; diff --git a/src/perf_event/sampling/single/stat.rs b/src/perf_event/sampling/single/stat.rs index b8c3cd2..e7bee22 100644 --- a/src/perf_event/sampling/single/stat.rs +++ b/src/perf_event/sampling/single/stat.rs @@ -12,11 +12,12 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::infra::{SizedExt, WrapResult}; -use crate::sampling::{ReadFormatHead, ReadFormatValue, Sampler}; -use std::io; -use std::io::Read; -use std::mem::size_of; +use std::{io, io::Read, mem::size_of}; + +use crate::{ + infra::{SizedExt, WrapResult}, + sampling::{ReadFormatHead, ReadFormatValue, Sampler}, +}; #[derive(Debug, Clone)] pub struct SamplerStat { diff --git a/src/perf_event/sampling/single/tests/hardware.rs b/src/perf_event/sampling/single/tests/hardware.rs index bb2bb15..9ddf00d 100644 --- a/src/perf_event/sampling/single/tests/hardware.rs +++ b/src/perf_event/sampling/single/tests/hardware.rs @@ -12,9 +12,7 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::sampling::single::tests::test_single; -use crate::test::cpu_workload; -use crate::{Event, HardwareEvent}; +use crate::{sampling::single::tests::test_single, test::cpu_workload, Event, HardwareEvent}; #[test] fn test_cpu_cycles() { diff --git a/src/perf_event/sampling/single/tests/mod.rs b/src/perf_event/sampling/single/tests/mod.rs index 51d847b..7528838 100644 --- a/src/perf_event/sampling/single/tests/mod.rs +++ b/src/perf_event/sampling/single/tests/mod.rs @@ -16,10 +16,14 @@ mod hardware; mod sample_record_fields; mod software; -use crate::config::{Cpu, Process}; -use crate::sampling::record::{Record, RecordBody}; -use crate::sampling::{Config, ExtraConfig, OverflowBy, Sampler}; -use crate::{Event, EventScope}; +use crate::{ + config::{Cpu, Process}, + sampling::{ + record::{Record, RecordBody}, + Config, ExtraConfig, OverflowBy, Sampler, + }, + Event, EventScope, +}; pub fn test_single(ev: &Event, workload: &mut F) where @@ -44,7 +48,7 @@ fn gen_cfg(ev: &Event) -> Config { let overflow_by = OverflowBy::Period(1000); let mut extra_config = ExtraConfig::default(); extra_config.sample_record_fields.time = true; - Config::extra_new(&ev, &scopes, &overflow_by, &extra_config) + Config::extra_new(ev, &scopes, &overflow_by, &extra_config) } fn test_next_record(ev: &Event, workload: &mut F) diff --git a/src/perf_event/sampling/single/tests/sample_record_fields/abi_and_regs_intr.rs b/src/perf_event/sampling/single/tests/sample_record_fields/abi_and_regs_intr.rs index aaea93e..1ad4d64 100644 --- a/src/perf_event/sampling/single/tests/sample_record_fields/abi_and_regs_intr.rs +++ b/src/perf_event/sampling/single/tests/sample_record_fields/abi_and_regs_intr.rs @@ -12,11 +12,15 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::config::{Cpu, Process}; -use crate::sampling::record::{Record, RecordBody}; -use crate::sampling::{Config, ExtraConfig, OverflowBy, Sampler}; -use crate::test::cpu_workload; -use crate::{Event, EventScope, HardwareEvent}; +use crate::{ + config::{Cpu, Process}, + sampling::{ + record::{Record, RecordBody}, + Config, ExtraConfig, OverflowBy, Sampler, + }, + test::cpu_workload, + Event, EventScope, HardwareEvent, +}; fn gen_sampler(cfg: &Config) -> Sampler { let mmap_pages = 1 + 512; diff --git a/src/perf_event/sampling/single/tests/sample_record_fields/abi_and_regs_user.rs b/src/perf_event/sampling/single/tests/sample_record_fields/abi_and_regs_user.rs index 1197b15..12c8a5c 100644 --- a/src/perf_event/sampling/single/tests/sample_record_fields/abi_and_regs_user.rs +++ b/src/perf_event/sampling/single/tests/sample_record_fields/abi_and_regs_user.rs @@ -12,11 +12,15 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::config::{Cpu, Process}; -use crate::sampling::record::{Record, RecordBody}; -use crate::sampling::{Config, ExtraConfig, OverflowBy, Sampler}; -use crate::test::cpu_workload; -use crate::{Event, EventScope, HardwareEvent}; +use crate::{ + config::{Cpu, Process}, + sampling::{ + record::{Record, RecordBody}, + Config, ExtraConfig, OverflowBy, Sampler, + }, + test::cpu_workload, + Event, EventScope, HardwareEvent, +}; fn gen_sampler(cfg: &Config) -> Sampler { let mmap_pages = 1 + 512; diff --git a/src/perf_event/sampling/single/tests/sample_record_fields/all.rs b/src/perf_event/sampling/single/tests/sample_record_fields/all.rs index 1d68036..dff64ec 100644 --- a/src/perf_event/sampling/single/tests/sample_record_fields/all.rs +++ b/src/perf_event/sampling/single/tests/sample_record_fields/all.rs @@ -12,12 +12,15 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::config::{Cpu, Process}; -use crate::sampling::record::sample::WeightRepr; -use crate::sampling::record::{Record, RecordBody}; -use crate::sampling::{Config, ExtraConfig, OverflowBy, SampleRecordFields, Sampler}; -use crate::test::cpu_workload; -use crate::{Event, EventScope, HardwareEvent}; +use crate::{ + config::{Cpu, Process}, + sampling::{ + record::{sample::WeightRepr, Record, RecordBody}, + Config, ExtraConfig, OverflowBy, SampleRecordFields, Sampler, + }, + test::cpu_workload, + Event, EventScope, HardwareEvent, +}; fn gen_sampler(cfg: &Config) -> Sampler { let mmap_pages = 1 + 512; @@ -33,37 +36,39 @@ fn gen_cfg(extra_config: ExtraConfig) -> Config { #[test] fn test() { - let mut extra_config = ExtraConfig::default(); - extra_config.sample_record_fields = SampleRecordFields { - #[cfg(feature = "linux-3.12")] - sample_id: true, - ip: true, - pid_and_tid: true, - time: true, - addr: true, - id: true, - stream_id: true, - cpu: true, - period: true, - v: true, - ips: Some(1), - data_raw: true, - abi_and_regs_user: Some(1), - data_stack_user: Some(2_u16.pow(3)), - weight: Some(WeightRepr::Full), - data_src: true, - #[cfg(feature = "linux-3.13")] - transaction: true, - #[cfg(feature = "linux-3.19")] - abi_and_regs_intr: Some(1), - #[cfg(feature = "linux-4.14")] - phys_addr: true, - #[cfg(feature = "linux-5.7")] - cgroup: true, - #[cfg(feature = "linux-5.11")] - data_page_size: true, - #[cfg(feature = "linux-5.11")] - code_page_size: true, + let extra_config = ExtraConfig { + sample_record_fields: SampleRecordFields { + #[cfg(feature = "linux-3.12")] + sample_id: true, + ip: true, + pid_and_tid: true, + time: true, + addr: true, + id: true, + stream_id: true, + cpu: true, + period: true, + v: true, + ips: Some(1), + data_raw: true, + abi_and_regs_user: Some(1), + data_stack_user: Some(2_u16.pow(3)), + weight: Some(WeightRepr::Full), + data_src: true, + #[cfg(feature = "linux-3.13")] + transaction: true, + #[cfg(feature = "linux-3.19")] + abi_and_regs_intr: Some(1), + #[cfg(feature = "linux-4.14")] + phys_addr: true, + #[cfg(feature = "linux-5.7")] + cgroup: true, + #[cfg(feature = "linux-5.11")] + data_page_size: true, + #[cfg(feature = "linux-5.11")] + code_page_size: true, + }, + ..Default::default() }; let cfg = gen_cfg(extra_config); let mut sampler = gen_sampler(&cfg); diff --git a/src/perf_event/sampling/single/tests/sample_record_fields/data_stack_user.rs b/src/perf_event/sampling/single/tests/sample_record_fields/data_stack_user.rs index 226b734..48265b3 100644 --- a/src/perf_event/sampling/single/tests/sample_record_fields/data_stack_user.rs +++ b/src/perf_event/sampling/single/tests/sample_record_fields/data_stack_user.rs @@ -12,11 +12,15 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::config::{Cpu, Process}; -use crate::sampling::record::{Record, RecordBody}; -use crate::sampling::{Config, ExtraConfig, OverflowBy, Sampler}; -use crate::test::cpu_workload; -use crate::{Event, EventScope, HardwareEvent}; +use crate::{ + config::{Cpu, Process}, + sampling::{ + record::{Record, RecordBody}, + Config, ExtraConfig, OverflowBy, Sampler, + }, + test::cpu_workload, + Event, EventScope, HardwareEvent, +}; fn gen_sampler(cfg: &Config) -> Sampler { let mmap_pages = 1 + 512; diff --git a/src/perf_event/sampling/single/tests/sample_record_fields/ips.rs b/src/perf_event/sampling/single/tests/sample_record_fields/ips.rs index bc804f4..449a840 100644 --- a/src/perf_event/sampling/single/tests/sample_record_fields/ips.rs +++ b/src/perf_event/sampling/single/tests/sample_record_fields/ips.rs @@ -12,11 +12,15 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::config::{Cpu, Process}; -use crate::sampling::record::{Record, RecordBody}; -use crate::sampling::{Config, ExtraConfig, OverflowBy, Sampler}; -use crate::test::cpu_workload; -use crate::{Event, EventScope, HardwareEvent}; +use crate::{ + config::{Cpu, Process}, + sampling::{ + record::{Record, RecordBody}, + Config, ExtraConfig, OverflowBy, Sampler, + }, + test::cpu_workload, + Event, EventScope, HardwareEvent, +}; fn gen_sampler(cfg: &Config) -> Sampler { let mmap_pages = 1 + 512; diff --git a/src/perf_event/sampling/single/tests/sample_record_fields/mod.rs b/src/perf_event/sampling/single/tests/sample_record_fields/mod.rs index 5181455..3ce0288 100644 --- a/src/perf_event/sampling/single/tests/sample_record_fields/mod.rs +++ b/src/perf_event/sampling/single/tests/sample_record_fields/mod.rs @@ -20,11 +20,15 @@ mod data_stack_user; mod ips; mod weight; -use crate::config::{Cpu, Process}; -use crate::sampling::record::{Record, RecordBody}; -use crate::sampling::{Config, ExtraConfig, OverflowBy, Sampler}; -use crate::test::cpu_workload; -use crate::{Event, EventScope, HardwareEvent}; +use crate::{ + config::{Cpu, Process}, + sampling::{ + record::{Record, RecordBody}, + Config, ExtraConfig, OverflowBy, Sampler, + }, + test::cpu_workload, + Event, EventScope, HardwareEvent, +}; fn gen_sampler(cfg: &Config) -> Sampler { let mmap_pages = 1 + 512; diff --git a/src/perf_event/sampling/single/tests/sample_record_fields/weight.rs b/src/perf_event/sampling/single/tests/sample_record_fields/weight.rs index 15c877d..c622628 100644 --- a/src/perf_event/sampling/single/tests/sample_record_fields/weight.rs +++ b/src/perf_event/sampling/single/tests/sample_record_fields/weight.rs @@ -12,12 +12,18 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::config::{Cpu, Process}; -use crate::sampling::record::sample::{Weight, WeightRepr}; -use crate::sampling::record::{Record, RecordBody}; -use crate::sampling::{Config, ExtraConfig, OverflowBy, Sampler}; -use crate::test::cpu_workload; -use crate::{Event, EventScope, HardwareEvent}; +use crate::{ + config::{Cpu, Process}, + sampling::{ + record::{ + sample::{Weight, WeightRepr}, + Record, RecordBody, + }, + Config, ExtraConfig, OverflowBy, Sampler, + }, + test::cpu_workload, + Event, EventScope, HardwareEvent, +}; fn gen_sampler(cfg: &Config) -> Sampler { let mmap_pages = 1 + 512; diff --git a/src/perf_event/sampling/single/tests/software.rs b/src/perf_event/sampling/single/tests/software.rs index 24ccfb8..407f06c 100644 --- a/src/perf_event/sampling/single/tests/software.rs +++ b/src/perf_event/sampling/single/tests/software.rs @@ -12,9 +12,7 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::sampling::single::tests::test_single; -use crate::test::cpu_workload; -use crate::{Event, SoftwareEvent}; +use crate::{sampling::single::tests::test_single, test::cpu_workload, Event, SoftwareEvent}; #[test] fn test_cpu_clock() { diff --git a/src/perf_event/tracing/config/mod.rs b/src/perf_event/tracing/config/mod.rs index 180b4e8..8d8f106 100644 --- a/src/perf_event/tracing/config/mod.rs +++ b/src/perf_event/tracing/config/mod.rs @@ -14,10 +14,9 @@ mod new; -use crate::perf_event::PerfEventAttr; -use crate::{Event, EventScope}; -use std::ffi::CString; -use std::rc::Rc; +use std::{ffi::CString, rc::Rc}; + +use crate::{perf_event::PerfEventAttr, Event, EventScope}; pub type ExtraConfig = crate::sampling::ExtraConfig; diff --git a/src/perf_event/tracing/config/new.rs b/src/perf_event/tracing/config/new.rs index 246757f..606937e 100644 --- a/src/perf_event/tracing/config/new.rs +++ b/src/perf_event/tracing/config/new.rs @@ -12,19 +12,22 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::perf_event::PerfEventAttr; +use std::{mem::size_of, ops::Not}; + +#[cfg(feature = "linux-4.1")] +use libc::{CLOCK_BOOTTIME, CLOCK_MONOTONIC, CLOCK_MONOTONIC_RAW, CLOCK_REALTIME, CLOCK_TAI}; + #[cfg(feature = "linux-4.1")] use crate::sampling::ClockId; -use crate::sampling::{ExtraConfig, SampleIpSkid, Wakeup}; -use crate::syscall::bindings::*; -use crate::tracing::config::Config; +use crate::{ + perf_event::PerfEventAttr, + sampling::{ExtraConfig, SampleIpSkid, Wakeup}, + syscall::bindings::*, + tracing::config::Config, + Event, EventScope, RawPerfEventAttr, +}; #[cfg(feature = "linux-4.17")] use crate::{DynamicPmuEvent, KprobeConfig, UprobeConfig}; -use crate::{Event, EventScope, RawPerfEventAttr}; -#[cfg(feature = "linux-4.1")] -use libc::{CLOCK_BOOTTIME, CLOCK_MONOTONIC, CLOCK_MONOTONIC_RAW, CLOCK_REALTIME, CLOCK_TAI}; -use std::mem::size_of; -use std::ops::Not; #[inline] pub fn new<'t>( diff --git a/src/perf_event/tracing/tests/breakpoint.rs b/src/perf_event/tracing/tests/breakpoint.rs index aedf67d..aedaa7d 100644 --- a/src/perf_event/tracing/tests/breakpoint.rs +++ b/src/perf_event/tracing/tests/breakpoint.rs @@ -12,9 +12,11 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::sampling::record::{Record, RecordBody}; -use crate::tracing::tests::{gen_cfg, gen_tracer}; -use crate::{BreakpointEvent, BreakpointLen, BreakpointType, Event}; +use crate::{ + sampling::record::{Record, RecordBody}, + tracing::tests::{gen_cfg, gen_tracer}, + BreakpointEvent, BreakpointLen, BreakpointType, Event, +}; fn test(ev: &Event, workload: &mut F, addr: u64) where diff --git a/src/perf_event/tracing/tests/mod.rs b/src/perf_event/tracing/tests/mod.rs index 6c1ebe8..8d52d37 100644 --- a/src/perf_event/tracing/tests/mod.rs +++ b/src/perf_event/tracing/tests/mod.rs @@ -15,9 +15,11 @@ mod breakpoint; mod tracepoint; -use crate::config::{Cpu, Process}; -use crate::tracing::{Config, ExtraConfig, Tracer}; -use crate::{Event, EventScope}; +use crate::{ + config::{Cpu, Process}, + tracing::{Config, ExtraConfig, Tracer}, + Event, EventScope, +}; fn gen_tracer(cfg: &Config) -> Tracer { let mmap_pages = 1 + 512; diff --git a/src/perf_event/tracing/tests/tracepoint.rs b/src/perf_event/tracing/tests/tracepoint.rs index a0bb7f6..4b2eeb0 100644 --- a/src/perf_event/tracing/tests/tracepoint.rs +++ b/src/perf_event/tracing/tests/tracepoint.rs @@ -12,12 +12,15 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::sampling::record::{Record, RecordBody}; -use crate::test::{cpu_workload, read_file}; -use crate::tracing::tests::{gen_cfg, gen_tracer}; -use crate::{Event, TracepointEvent}; use std::str::FromStr; +use crate::{ + sampling::record::{Record, RecordBody}, + test::{cpu_workload, read_file}, + tracing::tests::{gen_cfg, gen_tracer}, + Event, TracepointEvent, +}; + fn test(ev: &Event, workload: &mut F) where F: FnMut(), diff --git a/src/perf_event/tracing/tracer/into_iter.rs b/src/perf_event/tracing/tracer/into_iter.rs index 0a8292a..afcb66f 100644 --- a/src/perf_event/tracing/tracer/into_iter.rs +++ b/src/perf_event/tracing/tracer/into_iter.rs @@ -12,8 +12,7 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::sampling::record::Record; -use crate::tracing::tracer::Tracer; +use crate::{sampling::record::Record, tracing::tracer::Tracer}; pub struct IntoIter { inner: Tracer, diff --git a/src/perf_event/tracing/tracer/iter.rs b/src/perf_event/tracing/tracer/iter.rs index dfa1f90..eacc275 100644 --- a/src/perf_event/tracing/tracer/iter.rs +++ b/src/perf_event/tracing/tracer/iter.rs @@ -12,8 +12,7 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::sampling::record::Record; -use crate::tracing::tracer::Tracer; +use crate::{sampling::record::Record, tracing::tracer::Tracer}; impl Tracer { #[inline] diff --git a/src/perf_event/tracing/tracer/mod.rs b/src/perf_event/tracing/tracer/mod.rs index 4a7e1ec..22e4f52 100644 --- a/src/perf_event/tracing/tracer/mod.rs +++ b/src/perf_event/tracing/tracer/mod.rs @@ -15,28 +15,26 @@ mod into_iter; mod iter; -use crate::config::Error; -#[cfg(feature = "linux-4.17")] -use crate::infra::Vla; -#[cfg(feature = "linux-4.17")] -use crate::infra::WrapResult; -use crate::sampling::record::Record; -use crate::sampling::{Sampler, SamplerStat}; -use crate::syscall::bindings::*; -use crate::syscall::{ioctl_wrapped, perf_event_open_wrapped}; -use memmap2::MmapOptions; #[cfg(feature = "linux-4.17")] use std::alloc::{alloc, Layout}; -use std::fs::File; -use std::io; -use std::os::fd::FromRawFd; +use std::{fs::File, io, os::fd::FromRawFd}; -use crate::config::{Cpu, Process}; -use crate::tracing::Config; #[allow(unused_imports)] pub use into_iter::*; #[allow(unused_imports)] pub use iter::*; +use memmap2::MmapOptions; + +#[cfg(feature = "linux-4.17")] +use crate::infra::Vla; +#[cfg(feature = "linux-4.17")] +use crate::infra::WrapResult; +use crate::{ + config::{Cpu, Error, Process}, + sampling::{record::Record, Sampler, SamplerStat}, + syscall::{bindings::*, ioctl_wrapped, perf_event_open_wrapped}, + tracing::Config, +}; pub struct Tracer { pub(crate) sampler: Sampler, diff --git a/src/syscall/bindings/impl/perf_event_attr.rs b/src/syscall/bindings/impl/perf_event_attr.rs index f27858e..e66794e 100644 --- a/src/syscall/bindings/impl/perf_event_attr.rs +++ b/src/syscall/bindings/impl/perf_event_attr.rs @@ -12,10 +12,10 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::syscall::bindings::perf_event_attr; -use crate::{debug_struct, debug_struct_fn}; use std::fmt::{Debug, Formatter}; +use crate::{debug_struct, debug_struct_fn, syscall::bindings::perf_event_attr}; + impl Debug for perf_event_attr { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { debug_struct! { diff --git a/src/syscall/bindings/impl/perf_event_attr__bindgen_ty_1.rs b/src/syscall/bindings/impl/perf_event_attr__bindgen_ty_1.rs index 6dd83b7..66a35a4 100644 --- a/src/syscall/bindings/impl/perf_event_attr__bindgen_ty_1.rs +++ b/src/syscall/bindings/impl/perf_event_attr__bindgen_ty_1.rs @@ -12,10 +12,10 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::debug_union; -use crate::syscall::bindings::perf_event_attr__bindgen_ty_1; use std::fmt::{Debug, Formatter}; +use crate::{debug_union, syscall::bindings::perf_event_attr__bindgen_ty_1}; + impl Debug for perf_event_attr__bindgen_ty_1 { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { debug_union! { diff --git a/src/syscall/bindings/impl/perf_event_attr__bindgen_ty_2.rs b/src/syscall/bindings/impl/perf_event_attr__bindgen_ty_2.rs index a4edcb4..59a23ad 100644 --- a/src/syscall/bindings/impl/perf_event_attr__bindgen_ty_2.rs +++ b/src/syscall/bindings/impl/perf_event_attr__bindgen_ty_2.rs @@ -12,10 +12,10 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::debug_union; -use crate::syscall::bindings::perf_event_attr__bindgen_ty_2; use std::fmt::{Debug, Formatter}; +use crate::{debug_union, syscall::bindings::perf_event_attr__bindgen_ty_2}; + impl Debug for perf_event_attr__bindgen_ty_2 { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { debug_union! { diff --git a/src/syscall/bindings/impl/perf_event_attr__bindgen_ty_3.rs b/src/syscall/bindings/impl/perf_event_attr__bindgen_ty_3.rs index e4e55c2..450e25f 100644 --- a/src/syscall/bindings/impl/perf_event_attr__bindgen_ty_3.rs +++ b/src/syscall/bindings/impl/perf_event_attr__bindgen_ty_3.rs @@ -12,10 +12,10 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::debug_union; -use crate::syscall::bindings::perf_event_attr__bindgen_ty_3; use std::fmt::{Debug, Formatter}; +use crate::{debug_union, syscall::bindings::perf_event_attr__bindgen_ty_3}; + impl Debug for perf_event_attr__bindgen_ty_3 { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { debug_union! { diff --git a/src/syscall/bindings/impl/perf_event_attr__bindgen_ty_4.rs b/src/syscall/bindings/impl/perf_event_attr__bindgen_ty_4.rs index 20d5cbc..eb8e05c 100644 --- a/src/syscall/bindings/impl/perf_event_attr__bindgen_ty_4.rs +++ b/src/syscall/bindings/impl/perf_event_attr__bindgen_ty_4.rs @@ -12,10 +12,10 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::debug_union; -use crate::syscall::bindings::perf_event_attr__bindgen_ty_4; use std::fmt::{Debug, Formatter}; +use crate::{debug_union, syscall::bindings::perf_event_attr__bindgen_ty_4}; + impl Debug for perf_event_attr__bindgen_ty_4 { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { debug_union! { diff --git a/src/syscall/bindings/impl/perf_event_mmap_page.rs b/src/syscall/bindings/impl/perf_event_mmap_page.rs index 708281e..593e8e2 100644 --- a/src/syscall/bindings/impl/perf_event_mmap_page.rs +++ b/src/syscall/bindings/impl/perf_event_mmap_page.rs @@ -12,10 +12,10 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::debug_struct; -use crate::syscall::bindings::perf_event_mmap_page; use std::fmt::{Debug, Formatter}; +use crate::{debug_struct, syscall::bindings::perf_event_mmap_page}; + impl Debug for perf_event_mmap_page { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { debug_struct! { diff --git a/src/syscall/bindings/impl/perf_event_mmap_page__bindgen_ty_1.rs b/src/syscall/bindings/impl/perf_event_mmap_page__bindgen_ty_1.rs index fe3e088..e837dc5 100644 --- a/src/syscall/bindings/impl/perf_event_mmap_page__bindgen_ty_1.rs +++ b/src/syscall/bindings/impl/perf_event_mmap_page__bindgen_ty_1.rs @@ -12,10 +12,10 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::debug_union; -use crate::syscall::bindings::perf_event_mmap_page__bindgen_ty_1; use std::fmt::{Debug, Formatter}; +use crate::{debug_union, syscall::bindings::perf_event_mmap_page__bindgen_ty_1}; + impl Debug for perf_event_mmap_page__bindgen_ty_1 { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { debug_union! { diff --git a/src/syscall/bindings/impl/perf_sample_weight.rs b/src/syscall/bindings/impl/perf_sample_weight.rs index 5621d26..05eab3f 100644 --- a/src/syscall/bindings/impl/perf_sample_weight.rs +++ b/src/syscall/bindings/impl/perf_sample_weight.rs @@ -12,10 +12,10 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::debug_union; -use crate::syscall::bindings::perf_sample_weight; use std::fmt::{Debug, Formatter}; +use crate::{debug_union, syscall::bindings::perf_sample_weight}; + impl Debug for perf_sample_weight { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { debug_union! { diff --git a/src/syscall/wrapped.rs b/src/syscall/wrapped.rs index 4e8b315..5cb55df 100644 --- a/src/syscall/wrapped.rs +++ b/src/syscall/wrapped.rs @@ -12,12 +12,9 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use crate::syscall::bindings::perf_event_attr; -use crate::syscall::{ioctl, perf_event_open}; -use std::ffi::c_int; -use std::fs::File; -use std::io; -use std::os::fd::AsRawFd; +use std::{ffi::c_int, fs::File, io, os::fd::AsRawFd}; + +use crate::syscall::{bindings::perf_event_attr, ioctl, perf_event_open}; pub fn ioctl_wrapped(file: &File, request: impl Into, arg: Option) -> io::Result<()> { let i32 = match arg { diff --git a/src/test/mod.rs b/src/test/mod.rs index 39e3175..10e0fc8 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -12,8 +12,7 @@ // You should have received a copy of the GNU Lesser General Public License along with Perf-event-rs. If not, // see . -use std::time::Duration; -use std::{fs, thread}; +use std::{fs, thread, time::Duration}; pub fn cpu_workload() { for _ in 0..1000000 {