summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDennis Kobert <dennis@kobert.dev>2025-04-02 16:47:34 +0200
committerDennis Kobert <dennis@kobert.dev>2025-04-02 16:49:43 +0200
commita56c2e8ab39d7247d2b4c8959c306ffa07520d01 (patch)
tree7564e8190174276e0ae78959e9512c0ee82055f3 /src
parenteb32f2c998e1efc55edcb78899df7967bd531cc3 (diff)
Implement etop
Diffstat (limited to 'src')
-rw-r--r--src/energy.rs6
-rw-r--r--src/socket.rs39
2 files changed, 28 insertions, 17 deletions
diff --git a/src/energy.rs b/src/energy.rs
index 9c90ab9..3f6931d 100644
--- a/src/energy.rs
+++ b/src/energy.rs
@@ -19,7 +19,7 @@ pub use budget::BudgetPolicy;
pub use trackers::{KernelDriver, PerfEstimator};
const IDLE_CONSUMPTION_W: f64 = 7.;
-const UPDATE_INTERVAL: Duration = Duration::from_millis(3);
+const UPDATE_INTERVAL: Duration = Duration::from_millis(10);
pub enum Request {
NewTask(Pid, Arc<TaskInfo>),
@@ -122,6 +122,7 @@ pub struct EnergyService {
}
impl EnergyService {
+ #[allow(clippy::too_many_arguments)]
pub fn new(
estimator: Box<dyn Estimator>,
budget_policy: Box<dyn BudgetPolicy>,
@@ -244,7 +245,7 @@ impl EnergyService {
.unwrap_or(0.);
for pid in &self.active_processes {
let mut process_info = self.process_info.write().unwrap();
- if let Some(info) = process_info.get_mut(&pid) {
+ if let Some(info) = process_info.get_mut(pid) {
if info
.task_info
.read_time_since_last_schedule()
@@ -255,6 +256,7 @@ impl EnergyService {
}
if let Some(energy) = self.estimator.read_consumption(*pid as u64) {
info.energy += energy * self.bias;
+ info.tree_energy += energy * self.bias;
self.estimator.update_information(
*pid as u64,
info.task_info.read_cpu(),
diff --git a/src/socket.rs b/src/socket.rs
index 316c662..e2ecdbf 100644
--- a/src/socket.rs
+++ b/src/socket.rs
@@ -35,21 +35,9 @@ impl LoggingSocketService {
break;
}
if let Ok(pid) = line.trim().parse::<Pid>() {
- if let Some(info) = self.process_info.read().unwrap().get(&pid).clone() {
- socket
- .write_all(
- format!(
- "pid: {pid} process: {}J process tree: {}J\n",
- info.energy, info.tree_energy
- )
- .as_bytes(),
- )
- .unwrap();
- } else {
- socket
- .write_all(format!("Unknown pid: {pid}\n").as_bytes())
- .unwrap();
- }
+ socket
+ .write_all(self.handle_request(pid).as_bytes())
+ .unwrap();
} else {
socket
.write_all(
@@ -63,6 +51,27 @@ impl LoggingSocketService {
}
});
}
+
+ fn handle_request(&self, pid: i32) -> String {
+ let mut output = String::new();
+ use std::fmt::Write;
+ if pid == -1 {
+ for (pid, info) in self.process_info.read().unwrap().iter() {
+ writeln!(&mut output, "{pid},{},{}", info.energy, info.tree_energy).unwrap();
+ }
+ writeln!(&mut output, "#",).unwrap();
+ return output;
+ }
+
+ if let Some(info) = self.process_info.read().unwrap().get(&pid) {
+ format!(
+ "pid: {pid} process: {}J process tree: {}J\n",
+ info.energy, info.tree_energy
+ )
+ } else {
+ format!("Unknown pid: {pid}\n")
+ }
+ }
}
pub fn start_logging_socket_service(