-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
01309a4
commit 18b6d62
Showing
5 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/target | ||
/data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.