Skip to content

Commit

Permalink
update(memory metrics): store in Mbs
Browse files Browse the repository at this point in the history
  • Loading branch information
bkatsevych committed Apr 16, 2024
1 parent b5d73c0 commit 1281ab0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
13 changes: 2 additions & 11 deletions myprogram.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
import sys

def cpu_heavy_task():
# Perform a computationally heavy task
result = 0
for i in range(10000000):
result += i * i

def memory_heavy_task():
# Allocate a large amount of memory
large_list = [0] * (1024**3 // 4) # Allocate approximately 1GB of memory

if __name__ == "__main__":
# Run CPU-heavy tasks
for _ in range(10):
cpu_heavy_task()

# Run Memory-heavy tasks
for _ in range(10):
memory_heavy_task()
large_list = [0] * (1024**3 // 4) # Allocate approximately 1GB of memory

1 change: 1 addition & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub fn find_child_processes_recursive(system: &System, pid: Pid) -> Vec<Pid> {
child_pids
}

// more info about /proc/PID/smaps file: https://shorturl.at/ituHO
fn get_metric(pid: u32, metrics: &[&str]) -> io::Result<u64> {
let path = format!("/proc/{}/smaps", pid);
let file = File::open(&Path::new(&path))?;
Expand Down
5 changes: 3 additions & 2 deletions src/workflow_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -801,8 +801,9 @@ Use the `--produce-script myscript.sh` option for this.";
.start_time
.map_or(0, |t| Instant::now().duration_since(t).as_millis() as i32);

total_uss = total_uss / 1024 / 1024;
total_pss = total_pss / 1024 / 1024;
// return uss and pss in Mbs (remember that uss is still in Kbs)
total_uss = total_uss / 1024;
total_pss = total_pss / 1024;

let nice_value = unsafe { 20 - getpriority(PRIO_PROCESS, pid) };
let mut task_resources: BTreeMap<&str, serde_json::Value> = BTreeMap::new();
Expand Down

0 comments on commit 1281ab0

Please sign in to comment.