Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
TakanoTaiga authored Mar 12, 2024
1 parent deb09e3 commit 9bfd6d3
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Cargo.toml
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]
45 changes: 45 additions & 0 deletions src/main.rs
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));
}
}

0 comments on commit 9bfd6d3

Please sign in to comment.