- 添加 Harbor 快速恢复脚本 (harbor-quick-restore.sh) - 添加完整恢复指南 (HARBOR-RESTORE-GUIDE.md) - 添加版本信息文件 (VERSION.md) - 更新 .gitignore 排除敏感数据 - 配置 harbor git remote - 修复 Cloudflare Tunnel 配置 系统重装后可通过以下命令快速恢复: git clone http://192.168.1.83:33000/gao/ljwx-harbor.git cd ljwx-harbor ./harbor-quick-restore.sh
472 lines
16 KiB
Bash
Executable File
472 lines
16 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
#############################################################################
|
|
# Mac Studio Ultra Performance Test Script
|
|
# Comprehensive benchmarking for CPU, GPU, Memory, Disk I/O, and Network
|
|
# Author: DevOps Team
|
|
# Date: 2025-12-27
|
|
#############################################################################
|
|
|
|
set -e
|
|
|
|
# Colors
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
PURPLE='\033[0;35m'
|
|
CYAN='\033[0;36m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Logging functions
|
|
log_info() {
|
|
echo -e "${BLUE}[INFO]${NC} $1"
|
|
}
|
|
|
|
log_success() {
|
|
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
|
}
|
|
|
|
log_warning() {
|
|
echo -e "${YELLOW}[WARNING]${NC} $1"
|
|
}
|
|
|
|
log_error() {
|
|
echo -e "${RED}[ERROR]${NC} $1"
|
|
}
|
|
|
|
log_header() {
|
|
echo -e "${CYAN}============================================${NC}"
|
|
echo -e "${CYAN}$1${NC}"
|
|
echo -e "${CYAN}============================================${NC}"
|
|
}
|
|
|
|
log_subheader() {
|
|
echo -e "${PURPLE}--- $1 ---${NC}"
|
|
}
|
|
|
|
# Global variables
|
|
RESULTS_DIR="$HOME/performance_results"
|
|
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
|
|
RESULT_FILE="$RESULTS_DIR/performance_test_$TIMESTAMP.txt"
|
|
|
|
# Create results directory
|
|
mkdir -p "$RESULTS_DIR"
|
|
|
|
# Function to run a command and capture output with timing
|
|
run_command() {
|
|
local cmd="$1"
|
|
local description="$2"
|
|
|
|
log_subheader "$description"
|
|
echo "Command: $cmd"
|
|
|
|
local start_time=$(date +%s.%N)
|
|
eval "$cmd" 2>&1 | tee -a "$RESULT_FILE"
|
|
local end_time=$(date +%s.%N)
|
|
local duration=$(echo "$end_time - $start_time" | bc -l)
|
|
|
|
echo "Duration: ${duration}s" | tee -a "$RESULT_FILE"
|
|
echo "" | tee -a "$RESULT_FILE"
|
|
}
|
|
|
|
# System Information
|
|
get_system_info() {
|
|
log_header "System Information"
|
|
|
|
echo "Timestamp: $(date)" | tee -a "$RESULT_FILE"
|
|
echo "Hostname: $(hostname)" | tee -a "$RESULT_FILE"
|
|
echo "System: $(uname -a)" | tee -a "$RESULT_FILE"
|
|
echo "OS: $(sw_vers -productVersion) ($(sw_vers -buildVersion))" | tee -a "$RESULT_FILE"
|
|
echo "Model: $(system_profiler SPHardwareDataType | grep 'Chip\|Processor' | head -1)" | tee -a "$RESULT_FILE"
|
|
echo "Memory: $(system_profiler SPHardwareDataType | grep 'Memory' | head -1)" | tee -a "$RESULT_FILE"
|
|
echo "Serial: $(system_profiler SPHardwareDataType | grep 'Serial Number' | head -1)" | tee -a "$RESULT_FILE"
|
|
echo "" | tee -a "$RESULT_FILE"
|
|
}
|
|
|
|
# CPU Performance Test
|
|
cpu_test() {
|
|
log_header "CPU Performance Test"
|
|
|
|
# CPU Info
|
|
log_subheader "CPU Information"
|
|
echo "CPU Model: $(sysctl -n machdep.cpu.brand_string)" | tee -a "$RESULT_FILE"
|
|
echo "CPU Cores: $(sysctl -n hw.ncpu)" | tee -a "$RESULT_FILE"
|
|
echo "Physical Cores: $(sysctl -n hw.physicalcpu)" | tee -a "$RESULT_FILE"
|
|
echo "Logical Cores: $(sysctl -n hw.logicalcpu)" | tee -a "$RESULT_FILE"
|
|
echo "CPU Frequency: $(sysctl -n hw.cpufrequency_max | awk '{print $1/1000000000 " GHz"}')" | tee -a "$RESULT_FILE"
|
|
echo "" | tee -a "$RESULT_FILE"
|
|
|
|
# Single-core performance test
|
|
log_subheader "Single-core Performance Test"
|
|
echo "Running single-core performance test..." | tee -a "$RESULT_FILE"
|
|
local start_time=$(date +%s.%N)
|
|
yes > /dev/null &
|
|
local pid=$!
|
|
sleep 10
|
|
kill $pid 2>/dev/null
|
|
local end_time=$(date +%s.%N)
|
|
local duration=$(echo "$end_time - $start_time" | bc -l)
|
|
echo "Single-core test completed in ${duration}s" | tee -a "$RESULT_FILE"
|
|
echo "" | tee -a "$RESULT_FILE"
|
|
|
|
# Multi-core performance test
|
|
log_subheader "Multi-core Performance Test"
|
|
echo "Running multi-core performance test..." | tee -a "$RESULT_FILE"
|
|
local cores=$(sysctl -n hw.ncpu)
|
|
local start_time=$(date +%s.%N)
|
|
for i in $(seq 1 $cores); do
|
|
yes > /dev/null &
|
|
done
|
|
local pids=$(jobs -p)
|
|
sleep 10
|
|
kill $pids 2>/dev/null
|
|
local end_time=$(date +%s.%N)
|
|
local duration=$(echo "$end_time - $start_time" | bc -l)
|
|
echo "Multi-core test completed in ${duration}s" | tee -a "$RESULT_FILE"
|
|
echo "" | tee -a "$RESULT_FILE"
|
|
|
|
# Prime number calculation test
|
|
log_subheader "Prime Number Calculation Test"
|
|
echo "Calculating prime numbers up to 1000000..." | tee -a "$RESULT_FILE"
|
|
local start_time=$(date +%s.%N)
|
|
python3 -c "
|
|
import time
|
|
def is_prime(n):
|
|
if n < 2:
|
|
return False
|
|
for i in range(2, int(n**0.5) + 1):
|
|
if n % i == 0:
|
|
return False
|
|
return True
|
|
|
|
count = 0
|
|
for i in range(2, 1000000):
|
|
if is_prime(i):
|
|
count += 1
|
|
print(f'Found {count} primes')
|
|
" 2>&1 | tee -a "$RESULT_FILE"
|
|
local end_time=$(date +%s.%N)
|
|
local duration=$(echo "$end_time - $start_time" | bc -l)
|
|
echo "Prime calculation completed in ${duration}s" | tee -a "$RESULT_FILE"
|
|
echo "" | tee -a "$RESULT_FILE"
|
|
}
|
|
|
|
# Memory Performance Test
|
|
memory_test() {
|
|
log_header "Memory Performance Test"
|
|
|
|
# Memory Info
|
|
log_subheader "Memory Information"
|
|
echo "Total Memory: $(sysctl -n hw.memsize | awk '{print $1/1024/1024/1024 " GB"}')" | tee -a "$RESULT_FILE"
|
|
echo "Memory Speed: $(system_profiler SPHardwareDataType | grep 'Speed' | grep -i memory | head -1)" | tee -a "$RESULT_FILE"
|
|
echo "" | tee -a "$RESULT_FILE"
|
|
|
|
# Memory bandwidth test using dd
|
|
log_subheader "Memory Bandwidth Test"
|
|
echo "Testing memory bandwidth..." | tee -a "$RESULT_FILE"
|
|
dd if=/dev/zero of=/tmp/test_memory bs=1M count=1024 2>&1 | tee -a "$RESULT_FILE"
|
|
rm -f /tmp/test_memory
|
|
echo "" | tee -a "$RESULT_FILE"
|
|
|
|
# Memory allocation test
|
|
log_subheader "Memory Allocation Test"
|
|
echo "Testing memory allocation speed..." | tee -a "$RESULT_FILE"
|
|
local start_time=$(date +%s.%N)
|
|
python3 -c "
|
|
import time
|
|
import gc
|
|
|
|
def test_memory_allocation():
|
|
start_time = time.time()
|
|
data = []
|
|
for i in range(1000):
|
|
data.append([0] * 100000)
|
|
end_time = time.time()
|
|
print(f'Allocated {(len(data) * 100000 * 8) / 1024 / 1024:.2f} MB in {end_time - start_time:.2f} seconds')
|
|
|
|
test_memory_allocation()
|
|
" 2>&1 | tee -a "$RESULT_FILE"
|
|
local end_time=$(date +%s.%N)
|
|
local duration=$(echo "$end_time - $start_time" | bc -l)
|
|
echo "Memory allocation test completed in ${duration}s" | tee -a "$RESULT_FILE"
|
|
echo "" | tee -a "$RESULT_FILE"
|
|
}
|
|
|
|
# Disk I/O Performance Test
|
|
disk_test() {
|
|
log_header "Disk I/O Performance Test"
|
|
|
|
# Disk Info
|
|
log_subheader "Disk Information"
|
|
df -h | grep -E '^/dev/' | tee -a "$RESULT_FILE"
|
|
echo "" | tee -a "$RESULT_FILE"
|
|
|
|
# Disk read/write test
|
|
log_subheader "Sequential Read/Write Test"
|
|
|
|
# Write test
|
|
echo "Testing sequential write performance..." | tee -a "$RESULT_FILE"
|
|
local start_time=$(date +%s.%N)
|
|
dd if=/dev/zero of=/tmp/test_disk_write bs=1M count=1024 oflag=dsync 2>&1 | tee -a "$RESULT_FILE"
|
|
local end_time=$(date +%s.%N)
|
|
local duration=$(echo "$end_time - $start_time" | bc -l)
|
|
echo "Sequential write completed in ${duration}s" | tee -a "$RESULT_FILE"
|
|
rm -f /tmp/test_disk_write
|
|
|
|
# Read test
|
|
echo "Testing sequential read performance..." | tee -a "$RESULT_FILE"
|
|
dd if=/dev/zero of=/tmp/test_disk_read bs=1M count=1024 2>/dev/null
|
|
local start_time=$(date +%s.%N)
|
|
dd if=/tmp/test_disk_read of=/dev/null bs=1M 2>&1 | tee -a "$RESULT_FILE"
|
|
local end_time=$(date +%s.%N)
|
|
local duration=$(echo "$end_time - $start_time" | bc -l)
|
|
echo "Sequential read completed in ${duration}s" | tee -a "$RESULT_FILE"
|
|
rm -f /tmp/test_disk_read
|
|
echo "" | tee -a "$RESULT_FILE"
|
|
|
|
# Random I/O test
|
|
log_subheader "Random I/O Test"
|
|
echo "Testing random I/O performance..." | tee -a "$RESULT_FILE"
|
|
if command -v sysbench &> /dev/null; then
|
|
sysbench fileio --file-total-size=1G --file-test-mode=rndrw prepare > /dev/null 2>&1
|
|
sysbench fileio --file-total-size=1G --file-test-mode=rndrw --time=30 run 2>&1 | tee -a "$RESULT_FILE"
|
|
sysbench fileio --file-total-size=1G cleanup > /dev/null 2>&1
|
|
else
|
|
log_warning "sysbench not found. Installing..."
|
|
if command -v brew &> /dev/null; then
|
|
brew install sysbench
|
|
sysbench fileio --file-total-size=1G --file-test-mode=rndrw prepare > /dev/null 2>&1
|
|
sysbench fileio --file-total-size=1G --file-test-mode=rndrw --time=30 run 2>&1 | tee -a "$RESULT_FILE"
|
|
sysbench fileio --file-total-size=1G cleanup > /dev/null 2>&1
|
|
else
|
|
log_warning "Homebrew not found. Skipping sysbench tests."
|
|
fi
|
|
fi
|
|
echo "" | tee -a "$RESULT_FILE"
|
|
}
|
|
|
|
# GPU Performance Test
|
|
gpu_test() {
|
|
log_header "GPU Performance Test"
|
|
|
|
# GPU Info
|
|
log_subheader "GPU Information"
|
|
system_profiler SPDisplaysDataType | grep -E 'Chip|Processor|VRAM|Memory' | tee -a "$RESULT_FILE"
|
|
echo "" | tee -a "$RESULT_FILE"
|
|
|
|
# Metal performance test using a simple compute shader
|
|
log_subheader "GPU Compute Performance Test"
|
|
echo "Testing GPU compute performance..." | tee -a "$RESULT_FILE"
|
|
|
|
# Check if metal-cmake is available or use basic GPU info
|
|
if command -v metal &> /dev/null; then
|
|
echo "Metal framework is available" | tee -a "$RESULT_FILE"
|
|
else
|
|
log_warning "Metal command line tools not found. Using system info only." | tee -a "$RESULT_FILE"
|
|
fi
|
|
|
|
# Run a simple GPU stress test using a Python script if available
|
|
if command -v python3 &> /dev/null; then
|
|
python3 -c "
|
|
import platform
|
|
if platform.system() == 'Darwin':
|
|
import subprocess
|
|
try:
|
|
result = subprocess.run(['system_profiler', 'SPDisplaysDataType'], capture_output=True, text=True)
|
|
gpu_info = [line for line in result.stdout.split('\\n') if 'Metal' in line or 'GPU' in line or 'Graphics' in line]
|
|
print('GPU Info:', gpu_info)
|
|
except Exception as e:
|
|
print('Could not retrieve GPU info:', e)
|
|
else:
|
|
print('Not running on macOS')
|
|
" 2>&1 | tee -a "$RESULT_FILE"
|
|
fi
|
|
echo "" | tee -a "$RESULT_FILE"
|
|
}
|
|
|
|
# Network Performance Test
|
|
network_test() {
|
|
log_header "Network Performance Test"
|
|
|
|
# Network Info
|
|
log_subheader "Network Information"
|
|
networksetup -listallhardwareports | grep -A 1 -E 'Ethernet|Wi-Fi' | tee -a "$RESULT_FILE"
|
|
echo "" | tee -a "$RESULT_FILE"
|
|
|
|
# DNS Performance Test
|
|
log_subheader "DNS Performance Test"
|
|
echo "Testing DNS resolution speed for various DNS servers..." | tee -a "$RESULT_FILE"
|
|
|
|
# Define DNS servers for testing (domestic and international)
|
|
declare -a dns_servers=(
|
|
"223.5.5.5" # Alibaba DNS (China)
|
|
"223.6.6.6" # Alibaba DNS Backup (China)
|
|
"114.114.114.114" # 114 DNS (China)
|
|
"114.114.115.115" # 114 DNS Backup (China)
|
|
"180.76.76.76" # Baidu DNS (China)
|
|
"119.29.29.29" # Tencent DNS (China)
|
|
"182.254.116.116" # Tencent DNS Backup (China)
|
|
"8.8.8.8" # Google DNS (International)
|
|
"1.1.1.1" # Cloudflare DNS (International)
|
|
"8.8.4.4" # Google DNS Backup (International)
|
|
)
|
|
|
|
# Test DNS resolution speed
|
|
for dns in "${dns_servers[@]}"; do
|
|
echo "Testing DNS resolution speed for $dns..." | tee -a "$RESULT_FILE"
|
|
local start_time=$(date +%s.%N)
|
|
dig @$dns google.com +short +time=3 2>/dev/null | head -5 | tee -a "$RESULT_FILE"
|
|
local end_time=$(date +%s.%N)
|
|
local duration=$(echo "$end_time - $start_time" | bc -l)
|
|
echo "DNS resolution for $dns completed in ${duration}s" | tee -a "$RESULT_FILE"
|
|
echo "" | tee -a "$RESULT_FILE"
|
|
done
|
|
|
|
# Local network connectivity test
|
|
log_subheader "Local Network Connectivity Test"
|
|
echo "Testing local network connectivity..." | tee -a "$RESULT_FILE"
|
|
|
|
# Test connectivity to common domestic IPs
|
|
declare -a test_ips=(
|
|
"114.114.114.114" # 114 DNS
|
|
"223.5.5.5" # Alibaba DNS
|
|
"119.29.29.29" # Tencent DNS
|
|
"180.76.76.76" # Baidu DNS
|
|
)
|
|
|
|
for ip in "${test_ips[@]}"; do
|
|
echo "Testing connectivity to $ip..." | tee -a "$RESULT_FILE"
|
|
ping -c 3 "$ip" 2>&1 | tee -a "$RESULT_FILE"
|
|
echo "" | tee -a "$RESULT_FILE"
|
|
done
|
|
|
|
# Speed test using curl to various endpoints
|
|
log_subheader "Download Speed Test"
|
|
echo "Testing download speed from various endpoints..." | tee -a "$RESULT_FILE"
|
|
|
|
# Test download from domestic and international locations
|
|
declare -a test_urls=(
|
|
"https://www.baidu.com" # Domestic
|
|
"https://www.taobao.com" # Domestic
|
|
"https://www.qq.com" # Domestic
|
|
"http://speedtest.tele2.net/1MB.zip" # International
|
|
"https://cachefly.cachefly.net/100mb.test" # International
|
|
)
|
|
|
|
for url in "${test_urls[@]}"; do
|
|
echo "Testing download from: $url" | tee -a "$RESULT_FILE"
|
|
curl -s -w "Time: %{time_total}s, Speed: %{speed_download} bytes/sec\\n" -o /dev/null "$url" 2>&1 | tee -a "$RESULT_FILE"
|
|
echo "" | tee -a "$RESULT_FILE"
|
|
done
|
|
|
|
# If speedtest-cli is available, run a comprehensive speed test
|
|
if command -v speedtest-cli &> /dev/null; then
|
|
log_subheader "Comprehensive Speed Test"
|
|
echo "Running comprehensive speed test..." | tee -a "$RESULT_FILE"
|
|
speedtest-cli --simple 2>&1 | tee -a "$RESULT_FILE"
|
|
elif command -v brew &> /dev/null; then
|
|
log_warning "speedtest-cli not found. Installing..." | tee -a "$RESULT_FILE"
|
|
brew install speedtest-cli
|
|
speedtest-cli --simple 2>&1 | tee -a "$RESULT_FILE"
|
|
else
|
|
log_warning "Could not install speedtest-cli. Skipping comprehensive speed test." | tee -a "$RESULT_FILE"
|
|
fi
|
|
echo "" | tee -a "$RESULT_FILE"
|
|
}
|
|
|
|
# Thermal Performance Test
|
|
thermal_test() {
|
|
log_header "Thermal Performance Test"
|
|
|
|
# Check thermal sensors if available
|
|
log_subheader "Thermal Sensors Check"
|
|
if command -v ioreg &> /dev/null; then
|
|
echo "Checking thermal sensors..." | tee -a "$RESULT_FILE"
|
|
ioreg -c "ThermalZone" | grep -i temperature | head -10 2>&1 | tee -a "$RESULT_FILE"
|
|
else
|
|
log_warning "Thermal sensors check not available" | tee -a "$RESULT_FILE"
|
|
fi
|
|
echo "" | tee -a "$RESULT_FILE"
|
|
|
|
# Monitor temperature during stress test
|
|
log_subheader "Temperature Monitoring During Stress Test"
|
|
echo "Monitoring temperature during CPU stress test..." | tee -a "$RESULT_FILE"
|
|
|
|
# Run a simple stress test and monitor
|
|
local start_time=$(date +%s.%N)
|
|
yes > /dev/null &
|
|
local pid=$!
|
|
sleep 30
|
|
kill $pid 2>/dev/null
|
|
|
|
# Check temperature again after stress
|
|
if command -v ioreg &> /dev/null; then
|
|
ioreg -c "ThermalZone" | grep -i temperature | head -10 2>&1 | tee -a "$RESULT_FILE"
|
|
fi
|
|
local end_time=$(date +%s.%N)
|
|
local duration=$(echo "$end_time - $start_time" | bc -l)
|
|
echo "Thermal monitoring completed in ${duration}s" | tee -a "$RESULT_FILE"
|
|
echo "" | tee -a "$RESULT_FILE"
|
|
}
|
|
|
|
# Summary and Results
|
|
summary() {
|
|
log_header "Performance Test Summary"
|
|
|
|
echo "Performance test completed!" | tee -a "$RESULT_FILE"
|
|
echo "Results saved to: $RESULT_FILE" | tee -a "$RESULT_FILE"
|
|
echo "" | tee -a "$RESULT_FILE"
|
|
|
|
# Quick summary of key metrics
|
|
log_subheader "Key Performance Metrics"
|
|
echo "CPU Cores: $(sysctl -n hw.ncpu)" | tee -a "$RESULT_FILE"
|
|
echo "Memory: $(sysctl -n hw.memsize | awk '{print $1/1024/1024/1024 " GB"}')" | tee -a "$RESULT_FILE"
|
|
echo "System: $(sw_vers -productVersion)" | tee -a "$RESULT_FILE"
|
|
echo "" | tee -a "$RESULT_FILE"
|
|
|
|
# File size of results
|
|
local file_size=$(du -h "$RESULT_FILE" | cut -f1)
|
|
echo "Result file size: $file_size" | tee -a "$RESULT_FILE"
|
|
|
|
log_success "All tests completed. Results saved to $RESULT_FILE"
|
|
}
|
|
|
|
# Main function
|
|
main() {
|
|
echo -e "${CYAN}Mac Studio Ultra Performance Test Suite${NC}"
|
|
echo -e "${CYAN}=====================================${NC}"
|
|
echo ""
|
|
|
|
# Check for required tools
|
|
log_info "Checking for required tools..."
|
|
if ! command -v bc &> /dev/null; then
|
|
log_warning "bc (calculator) not found. Installing..."
|
|
if command -v brew &> /dev/null; then
|
|
brew install bc
|
|
else
|
|
log_error "Homebrew not found. Please install bc manually."
|
|
fi
|
|
fi
|
|
|
|
# Run all tests
|
|
get_system_info
|
|
cpu_test
|
|
memory_test
|
|
disk_test
|
|
gpu_test
|
|
network_test
|
|
thermal_test
|
|
summary
|
|
|
|
echo ""
|
|
log_success "Performance test suite completed!"
|
|
log_info "Results saved to: $RESULT_FILE"
|
|
log_info "You can view the results with: cat $RESULT_FILE"
|
|
log_info "Or open with: open $RESULT_FILE"
|
|
}
|
|
|
|
# Run main function if script is executed directly
|
|
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
|
main "$@"
|
|
fi |