Skip to content

Instantly share code, notes, and snippets.

@adrianlzt
Created January 21, 2025 08:19
Show Gist options
  • Save adrianlzt/a8784e402d6fdd8cff9296225fb911cf to your computer and use it in GitHub Desktop.
Save adrianlzt/a8784e402d6fdd8cff9296225fb911cf to your computer and use it in GitHub Desktop.
#!/bin/bash
# Check if two arguments (cgroup paths) are provided
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <cgroup1_path> <cgroup2_path>"
exit 1
fi
cgroup1_path="$1"
cgroup2_path="$2"
# Check if the cgroup paths are valid directories
if [ ! -d "$cgroup1_path" ]; then
echo "Error: Cgroup path '$cgroup1_path' is not a valid directory."
exit 1
fi
if [ ! -d "$cgroup2_path" ]; then
echo "Error: Cgroup path '$cgroup2_path' is not a valid directory."
exit 1
fi
# Array of files to compare (excluding specified files)
files=(
cgroup.controllers
cgroup.events
cgroup.freeze
cgroup.max.depth
cgroup.max.descendants
cgroup.pressure
cgroup.procs
cgroup.subtree_control
cgroup.threads
cgroup.type
cpu.idle
cpu.max
cpu.max.burst
cpu.pressure
cpu.uclamp.max
cpu.uclamp.min
cpu.weight
cpu.weight.nice
io.pressure
irq.pressure
memory.current
memory.events
memory.events.local
memory.high
memory.low
memory.max
memory.min
memory.oom.group
memory.peak
memory.pressure
memory.swap.current
memory.swap.events
memory.swap.high
memory.swap.max
memory.swap.peak
memory.zswap.current
memory.zswap.max
memory.zswap.writeback
pids.current
pids.events
pids.events.local
pids.max
pids.peak
)
# Function to read a file and return its contents, or "N/A" if not found/readable
read_file() {
local file_path="$1"
if [ -r "$file_path" ]; then
# cat the file, replacing new lines with spaces
cat "$file_path" | tr '\n' ' '
else
echo "N/A"
fi
}
echo "-------------------------------------------------------------"
echo "Comparing cgroups:"
echo " Cgroup 1: $cgroup1_path"
echo " Cgroup 2: $cgroup2_path"
echo "-------------------------------------------------------------"
found_diff=false
for file in "${files[@]}"; do
file1_path="$cgroup1_path/$file"
file2_path="$cgroup2_path/$file"
file1_content=$(read_file "$file1_path")
file2_content=$(read_file "$file2_path")
if [ "$file1_content" != "$file2_content" ]; then
found_diff=true
echo " File: $file"
echo " Cgroup 1: $file1_content"
echo " Cgroup 2: $file2_content"
echo " -----------------"
fi
done
if [ "$found_diff" = false ]; then
echo " No Differences Found"
fi
echo "-------------------------------------------------------------"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment