-
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
deb09e3
commit 9bfd6d3
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,8 @@ | ||
[package] | ||
name = "mem_checker" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] |
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,45 @@ | ||
use std::process::{Command, Stdio}; | ||
use std::fs::OpenOptions; | ||
use std::io::Write; | ||
use std::thread; | ||
use std::time::Duration; | ||
use std::path::Path; | ||
|
||
|
||
fn main() { | ||
loop { | ||
let output = Command::new("ps") | ||
.args(["aux"]) | ||
.stdout(Stdio::piped()) | ||
.output() | ||
.expect("Failed to execute command"); | ||
|
||
let output_str = String::from_utf8_lossy(&output.stdout); | ||
|
||
for line in output_str.lines().skip(1) { | ||
let columns: Vec<&str> = line.split_whitespace().collect(); | ||
let user = columns.get(0).unwrap_or(&""); | ||
let pid = columns.get(1).unwrap_or(&""); | ||
|
||
if *user == "taiga" { | ||
let rss_str = columns.get(5).unwrap_or(&"0"); | ||
let rss_value: i32 = rss_str.parse().unwrap_or(0); | ||
let cpu = columns.get(2).unwrap_or(&""); | ||
|
||
let file_name = format!("./data/{}.csv",pid); | ||
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, "{},{}", cpu, rss_value) | ||
.expect("Failed to write to file"); | ||
} | ||
} | ||
|
||
thread::sleep(Duration::from_secs(1)); | ||
} | ||
} |