Skip to content

Commit

Permalink
add pmap checker
Browse files Browse the repository at this point in the history
  • Loading branch information
TakanoTaiga committed Mar 14, 2024
1 parent 01309a4 commit 18b6d62
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target
/data
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,23 @@
# mem_checker
# mem_checker

## How to use

### setup

```
git clone https://github.com/TakanoTaiga/mem_checker.git
cd mem_checker
mkdir ./data
```

### record

ps
```
cargo run --bin auto_ps
```

pmap
```
cargo run --bin auto_pmap
```
50 changes: 50 additions & 0 deletions src/bin/auto_pmap.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use std::collections::HashMap;
use std::process::{Command, Stdio};
use std::thread;
use std::time::Duration;
use std::path::Path;
use std::fs::OpenOptions;
use std::io::Write;

fn main() {
loop {
let output = Command::new("pmap")
.args(["-x", "54875"])
.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(&"");

if rss == 0 || !name.contains(".so") {
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 path = Path::new(&file_name);
let mut file = OpenOptions::new()
.write(true)
.append(true)
.create(true)
.open(path)
.expect("Failed to open file");

writeln!(file, "{}",total_rss)
.expect("Failed to write to file");
}
thread::sleep(Duration::from_secs(1));
}
}
File renamed without changes.
Empty file added src/lib.rs
Empty file.

0 comments on commit 18b6d62

Please sign in to comment.