-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added macOS support * typos * (Fix): source with string instead of variable
- Loading branch information
Showing
6 changed files
with
101 additions
and
15 deletions.
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
File renamed without changes.
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,32 @@ | ||
#!/usr/bin/env bash | ||
# By ChatGPT and masterfully adapted by Arne Tarara. No rights reserved :) | ||
|
||
iostat -w 1 | awk -v date_cmd="gdate +%s%N" ' | ||
NR > 3 { # skips first 3 rows, which contain header data and first average-only measurement | ||
# Extract user, system, and idle CPU percentages | ||
user = $3 | ||
sys = $4 | ||
idle = $6 | ||
# Calculate total CPU usage | ||
usage = 100 - idle | ||
# Get the current time in seconds with microseconds | ||
cmd = date_cmd | ||
cmd | getline current_time_ns | ||
close(cmd) | ||
# Calculate the time difference | ||
if (last_time_ns != "") { | ||
time_diff_ns = current_time_ns - last_time_ns | ||
} else { | ||
time_diff_ns = 1000000000 # No difference for the first line | ||
} | ||
# Print the time and CPU usage | ||
printf "%.10f %.2f\n", (time_diff_ns / 1000000000), usage | ||
# Store the current time as the last time for the next iteration | ||
last_time_ns = current_time_ns | ||
}' |
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
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
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