Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions .github/workflows/build-dev-auto-feature.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ on:
- '*'
pull_request_target:
types:
- edited
- opened
- reopened
- synchronize
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -93,4 +96,4 @@ jobs:
target: ${{ matrix.target.triple }}
feature: auto

# TODO: Some tests will fail in GitHub Actions environment
# TODO: Some tests will fail in GitHub Actions environment
21 changes: 12 additions & 9 deletions .github/workflows/build-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ on:
- '*'
pull_request_target:
types:
- edited
- opened
- reopened
- synchronize
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -105,4 +108,4 @@ jobs:
env:
LINUX_HEADERS_PATH: ${{ github.workspace }}/linux-headers

# TODO: Some tests will fail in GitHub Actions environment
# TODO: Some tests will fail in GitHub Actions environment
3 changes: 2 additions & 1 deletion build/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://www.gnu.org/licenses/>.

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)
Expand Down
10 changes: 6 additions & 4 deletions build/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[toolchain]
channel = "1.85"
components = ["rustfmt", "clippy"]
profile = "minimal"
8 changes: 5 additions & 3 deletions src/infra/box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://www.gnu.org/licenses/>.

use std::alloc::{alloc, Layout};
use std::ptr;
use std::{
alloc::{alloc, Layout},
ptr,
};

pub trait WrapBox<T> {
#[inline]
Expand All @@ -36,6 +38,6 @@ impl<T> BoxSliceExt for Box<[T]> {
let layout = Layout::array::<u8>(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)) }
}
}
7 changes: 3 additions & 4 deletions src/infra/vla.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://www.gnu.org/licenses/>.

use std::marker::PhantomData;
use std::slice;
use std::{marker::PhantomData, slice};

#[repr(C)]
pub struct Vla<L, T> {
Expand Down Expand Up @@ -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<u8, u8> = unsafe { &*Vla::from_ptr(len_ptr) };
let vla: &Vla<u8, u8> = unsafe { Vla::from_ptr(len_ptr) };

assert_eq!(vla.as_slice(), &buf[1..3])
}
Expand All @@ -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<u32, u8> = unsafe { &*Vla::from_ptr(len_ptr) };
let vla: &Vla<u32, u8> = unsafe { Vla::from_ptr(len_ptr) };

assert_eq!(vla.as_slice(), &buf.0[4..6])
}
Expand Down
6 changes: 2 additions & 4 deletions src/infra/zt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://www.gnu.org/licenses/>.

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<T> {
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
// see <https://www.gnu.org/licenses/>.

#![cfg(target_os = "linux")]
#![deny(warnings)]
#![warn(clippy::all, clippy::nursery, clippy::cargo_common_metadata)]

mod infra;
mod perf_event;
Expand Down
1 change: 1 addition & 0 deletions src/perf_event/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// see <https://www.gnu.org/licenses/>.

use std::{io, result};

use thiserror::Error;

#[derive(Error, Debug)]
Expand Down
8 changes: 3 additions & 5 deletions src/perf_event/counting/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 8 additions & 5 deletions src/perf_event/counting/config/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://www.gnu.org/licenses/>.

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>(
Expand Down
10 changes: 6 additions & 4 deletions src/perf_event/counting/group/fixed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://www.gnu.org/licenses/>.

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<RwLock<Inner>>,
Expand Down
16 changes: 10 additions & 6 deletions src/perf_event/counting/group/guard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,23 @@
// 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::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,
inner: Arc<RwLock<Inner>>,
}

impl CounterGuard {
pub(crate) fn new(event_id: u64, inner: Arc<RwLock<Inner>>) -> Self {
pub(crate) const fn new(event_id: u64, inner: Arc<RwLock<Inner>>) -> Self {
Self { event_id, inner }
}

Expand Down
21 changes: 13 additions & 8 deletions src/perf_event/counting/group/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://www.gnu.org/licenses/>.

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<Counter>, // members[0] is the group leader, if it exists.
Expand Down
24 changes: 14 additions & 10 deletions src/perf_event/counting/group/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading
Loading