Skip to content

Commit

Permalink
minor update
Browse files Browse the repository at this point in the history
  • Loading branch information
TakanoTaiga committed Mar 15, 2024
1 parent cd3bcb2 commit d588c83
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/target
/data
/optimized
*.csv
3 changes: 3 additions & 0 deletions ps_auto_start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
rm ./data/*.csv
rm ./p_list.csv
cargo run --bin auto_ps
20 changes: 7 additions & 13 deletions src/bin/auto_pmap.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::collections::HashMap;
use std::process::{Command, Stdio};
use std::thread;
use std::time::Duration;
Expand All @@ -9,31 +8,26 @@ use std::io::Write;
fn main() {
loop {
let output = Command::new("pmap")
.args(["-x", "54875"])
.args(["-x", "82768"])
.stdout(Stdio::piped())
.output()
.expect("Failed to execute command");

let output_str = String::from_utf8_lossy(&output.stdout);
let lines = output_str.lines().skip(1);

let mut rss_map: HashMap<String, u32> = HashMap::new();

for line in lines {
let columns: Vec<&str> = line.split_whitespace().collect();

let rss = columns.get(2).and_then(|&s| s.parse::<u32>().ok()).unwrap_or(0);
let name = columns.get(5).unwrap_or(&"");
let mapping = columns.get(5).unwrap_or(&"");
let address = columns.get(5).unwrap_or(&"");

if rss == 0 || !name.contains(".so") {
if rss == 0 {
continue;
}

*rss_map.entry(name.to_string()).or_insert(0) += rss;
}

for (name, total_rss) in rss_map {
let file_name = format!("./data/{}.csv",name);
let file_name = format!("./data/{}_{}.csv",address,mapping);
let path = Path::new(&file_name);
let mut file = OpenOptions::new()
.write(true)
Expand All @@ -42,8 +36,8 @@ fn main() {
.open(path)
.expect("Failed to open file");

writeln!(file, "{}",total_rss)
.expect("Failed to write to file");
writeln!(file, "{}",rss)
.expect("Failed to write to file");
}
thread::sleep(Duration::from_secs(1));
}
Expand Down
24 changes: 24 additions & 0 deletions src/bin/auto_ps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ fn main() {
let output_str = String::from_utf8_lossy(&output.stdout);

for line in output_str.lines().skip(1) {
if line.contains("ps aux"){ continue; }
if line.contains("vscode"){ continue; }
if line.contains("libexec"){ continue; }
if line.contains("sleep 1"){ continue; }
if line.contains("auto_ps"){ continue; }
if line.contains(".rustup/toolchains"){ continue; }
if line.contains("bash"){ continue; }
if line.contains("/bin/sh"){ continue; }
if line.contains("/usr/"){ continue; }
if line.contains("sshd: "){ continue; }
if line.contains("/snap/"){ continue; }

let columns: Vec<&str> = line.split_whitespace().collect();
let user = columns.get(0).unwrap_or(&"");
let pid = columns.get(1).unwrap_or(&"");
Expand All @@ -27,6 +39,18 @@ fn main() {

let file_name = format!("./data/{}.csv",pid);
let path = Path::new(&file_name);
if !path.is_file() {
let datafile_path = Path::new("./p_list.csv");
let mut file = OpenOptions::new()
.write(true)
.append(true)
.create(true)
.open(datafile_path)
.expect("Failed to open file");

writeln!(file, "{}", line)
.expect("Failed to write to file");
}
let mut file = OpenOptions::new()
.write(true)
.append(true)
Expand Down

0 comments on commit d588c83

Please sign in to comment.