Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2881789
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/cli.rs b/src/cli.rs
index 4b3dd5c..abba16d 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -1,63 +1,73 @@
use crate::helpers;
use crate::process::Runner;
use crate::structs::Args;
use global_placeholders::global;
use macros_rs::string;
use psutil::process::{MemoryInfo, Process};
use std::env;
pub fn get_version(short: bool) -> String {
return match short {
true => format!("{} {}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION")),
false => format!("{} ({} {}) [{}]", env!("CARGO_PKG_VERSION"), env!("GIT_HASH"), env!("BUILD_DATE"), env!("PROFILE")),
};
}
pub fn start(name: &Option<String>, args: &Option<Args>) {
let mut runner = Runner::new(global!("pmc.logs"));
let name = match name {
Some(name) => string!(name),
None => string!(""),
};
match args {
Some(Args::Id(id)) => runner.restart(*id),
Some(Args::Script(script)) => runner.start(name, script),
None => {}
}
}
pub fn stop(id: &usize) {
let mut runner = Runner::new(global!("pmc.logs"));
runner.stop(*id);
println!("Stopped process");
}
pub fn remove(id: &usize) {
let mut runner = Runner::new(global!("pmc.logs"));
runner.remove(*id);
println!("Removed process");
}
pub fn list(format: &String) {
let runner = Runner::new(global!("pmc.logs"));
match format.as_str() {
"raw" => println!("{:?}", runner.list()),
"toml" => println!("{}", toml::to_string(runner.list()).unwrap()),
"json" => println!("{}", serde_json::to_string(runner.list()).unwrap()),
_ => {
for (id, item) in runner.list() {
+ let mut memory_usage: Option<MemoryInfo> = None;
+ let mut cpu_percent: Option<f32> = None;
+
+ if let Ok(mut process) = Process::new(item.pid as u32) {
+ memory_usage = process.memory_info().ok();
+ cpu_percent = process.cpu_percent().ok();
+ }
+
println!(
- "id: {id}\nname: {}\npid: {}\nstatus: {}\nuptime: {}",
+ "id: {id}, name: {}, pid: {}, status: {}, uptime: {}, memory: {:?}, cpu: {:?}",
item.name,
item.pid,
item.running,
- helpers::format_duration(item.started)
+ helpers::format_duration(item.started),
+ memory_usage,
+ cpu_percent
);
}
}
};
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Mar 19, 11:08 PM (11 h, 23 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
506944
Default Alt Text
(2 KB)
Attached To
Mode
rPMC Process Management Controller
Attached
Detach File
Event Timeline
Log In to Comment