Last active
February 20, 2025 12:06
-
-
Save niradler/0fb5714108e784e12de7f776f2092617 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
cd /usr/app | |
# Function to monitor resource usage | |
monitor_resources() { | |
local pid=$1 | |
local log_file=$2 | |
echo "Monitoring PID: $pid" | |
while kill -0 $pid 2>/dev/null; do | |
ps -p $pid -o %cpu,%mem,cmd >> $log_file | |
free -m >> $log_file | |
sleep 1 | |
done | |
} | |
# Function to print directory size in MB | |
print_directory_size() { | |
local directory=$1 | |
local size=$(du -shm $directory | cut -f1) | |
echo "Directory size: ${size}MB" | |
echo "Directory size: ${size}MB" >> $2 | |
} | |
# Function to clone repository and monitor resources | |
clone_and_monitor() { | |
local clone_cmd=$1 | |
local log_file=$2 | |
local start_time=$(date +%s) | |
local repo_dir=$(basename $REPO_URL .git) | |
echo "Executing [$start_time]: $clone_cmd" | |
GIT_SSL_NO_VERIFY=true $clone_cmd & | |
local pid=$! | |
monitor_resources $pid $log_file | |
wait $pid | |
local end_time=$(date +%s) | |
local duration=$((end_time - start_time)) | |
echo -e "\nResults" | |
echo "Clone duration: $duration seconds" >> $log_file | |
echo "Resource usage:" | |
tail -n 5 $log_file | |
echo "Duration: $duration seconds" | |
du -h --max-depth=1 | |
if [ -d $repo_dir ]; then | |
print_directory_size $repo_dir $log_file | |
else | |
echo "Clone failed or directory not found." >> $log_file | |
fi | |
} | |
# Check if required tools are installed | |
if ! command -v git &> /dev/null || ! command -v ps &> /dev/null || ! command -v free &> /dev/null || ! command -v du &> /dev/null; then | |
echo "Required tools are not installed. Exiting." | |
exit 1 | |
fi | |
# Print repository size | |
echo "Fetching repository size..." | |
repo_size=$(git ls-remote $REPO_URL | wc -l) | |
echo "Repository size (number of objects): $repo_size" | |
# Ensure clean-up of global configurations | |
cleanup_git_config() { | |
git config --global --unset pack.windowMemory | |
git config --global --unset core.packedGitLimit | |
git config --global --unset pack.threads | |
} | |
# git config --global pack.windowMemory 1g | |
# git config --global core.packedGitLimit 3g | |
# git config --global pack.threads 3 | |
clone_and_monitor "git clone $REPO_URL --branch $BRANCH regular" "regular.log" | |
rm -rf regular | |
cleanup_git_config |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment