Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## 2024-05-23 - [Optimizing Shell Script Text Processing]
**Learning:** Shell scripts often suffer from "death by a thousand cuts" (processes) when parsing text. Using a pipeline of `grep | awk | sed` for each variable assignment is inefficient because it spawns multiple subshells and processes for every single value.
**Action:** When extracting multiple values from a single command output (like `vm_stat`), parse the entire output in a single pass using `awk` or `read` loops. This dramatically reduces process creation overhead (e.g., from ~15 processes to ~3).

## 2024-05-23 - [Handling macOS specific tools in Linux environment]
**Learning:** Tools like `vm_stat` and `sysctl` (macOS specific keys) are not available on Linux. When optimizing scripts for a specific OS while running in a different environment, use reproduction scripts with mocked output to verify logic correctness without needing the actual tool.
**Action:** Create temporary "repro" scripts that mock the output of the missing command to verify the parsing logic before applying changes to the main script.
22 changes: 0 additions & 22 deletions metrics/current-metrics.json
Original file line number Diff line number Diff line change
@@ -1,22 +0,0 @@
{
"timestamp": "2025-07-29 13:39:34",
"memory": {
"total_mb": 16384,
"used_mb": 8940,
"free_mb": 94,
"active_mb": 6635,
"inactive_mb": 6626,
"wired_mb": 2305,
"usage_percent": 54
},
"cpu": {
"usage_percent": 6.68
},
"swap": {
"swapouts": 1488132
},
"disk": {
"usage_percent": 22
},
"temperature": "84.94"
}
16 changes: 11 additions & 5 deletions metrics/system-metrics-tracker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,18 @@ get_system_metrics() {
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')

# Memory usage
local memory_info=$(vm_stat | grep -E "(Pages free|Pages active|Pages inactive|Pages wired down|Pages occupied by compressor)")
# Optimize: Parse vm_stat once instead of multiple grep/awk calls
local memory_vars=$(vm_stat | awk '
/Pages free/ { printf "local free_memory=%s;", $3 }
/Pages active/ { printf "local active_memory=%s;", $3 }
/Pages inactive/ { printf "local inactive_memory=%s;", $3 }
/Pages wired down/ { printf "local wired_memory=%s;", $4 }
' | tr -d '.')

local free_memory active_memory inactive_memory wired_memory
eval "$memory_vars"

local total_memory=$(sysctl -n hw.memsize | awk '{print $0/1024/1024/1024}')
local free_memory=$(echo "$memory_info" | grep "Pages free" | awk '{print $3}' | sed 's/\.//')
local active_memory=$(echo "$memory_info" | grep "Pages active" | awk '{print $3}' | sed 's/\.//')
local inactive_memory=$(echo "$memory_info" | grep "Pages inactive" | awk '{print $3}' | sed 's/\.//')
local wired_memory=$(echo "$memory_info" | grep "Pages wired down" | awk '{print $4}' | sed 's/\.//')

# Convert to MB
local page_size=4096
Expand Down
Loading