libcgroups/v1/
perf_event.rs1use std::path::Path;
2
3use super::controller::Controller;
4use crate::common::{ControllerOpt, WrappedIoError};
5
6pub struct PerfEvent {}
7
8impl Controller for PerfEvent {
9 type Error = WrappedIoError;
10 type Resource = ();
11
12 fn apply(_controller_opt: &ControllerOpt, _cgroup_root: &Path) -> Result<(), Self::Error> {
13 Ok(())
14 }
15 fn needs_to_handle<'a>(_controller_opt: &'a ControllerOpt) -> Option<&'a Self::Resource> {
17 None
18 }
19}
20
21#[cfg(test)]
22mod tests {
23 use std::fs;
24
25 use nix::unistd::Pid;
26
27 use super::*;
28 use crate::common::CGROUP_PROCS;
29 use crate::test::setup;
30
31 #[test]
32 fn test_add_task() {
33 let (tmp, procs) = setup(CGROUP_PROCS);
34 let pid = Pid::from_raw(1000);
35
36 PerfEvent::add_task(pid, tmp.path()).expect("apply perf_event");
37
38 let content = fs::read_to_string(procs)
39 .unwrap_or_else(|_| panic!("read {CGROUP_PROCS} file content"));
40 assert_eq!(content, "1000");
41 }
42}