Merged in feature/memory (pull request #155)
Memory Scripts * tests * cleanermemtest * files * tests
This commit is contained in:
@@ -32,6 +32,7 @@ tasks:
|
||||
deps:
|
||||
- task: test:functional
|
||||
- task: lint
|
||||
graph: psrecord "task fullsuite" --plot out/fullsuite.png --interval 0.1 --include-children
|
||||
precommit:
|
||||
- task: lint
|
||||
deps:tidy:
|
||||
|
||||
+94
-9
@@ -37,17 +37,102 @@ tasks:
|
||||
- rm -rf mocks/*
|
||||
- go tool mockery --log-level=""
|
||||
functional:
|
||||
- mkdir -p {{.OUT_DIR}}
|
||||
- task: wait
|
||||
- |
|
||||
GOMAXPROCS={{.TEST_PARALLEL}} go test -parallel {{.CPU_COUNT}} \
|
||||
-coverpkg={{.INTERNAL}},{{.API}},{{.PKG}} \
|
||||
-coverprofile={{.COVERAGE_FILE}} \
|
||||
./...
|
||||
- task: coverage
|
||||
race: GOMAXPROCS={{.TEST_PARALLEL}} go test -parallel {{.CPU_COUNT}} -race ./...
|
||||
graph: psrecord "task test:functional" --plot out/test.png --interval 0.1 --include-children
|
||||
wait: docker wait $(docker ps -q --filter "label=org.testcontainers.ryuk=true") 2>/dev/null || true
|
||||
mem:
|
||||
vars:
|
||||
NUM_RESULTS: 5
|
||||
RESULTS_FILE: "{{ .OUT_DIR }}/mem.out"
|
||||
cmds:
|
||||
- mkdir -p {{.OUT_DIR}}
|
||||
- |
|
||||
GOMAXPROCS={{.TEST_PARALLEL}} go test -parallel {{.CPU_COUNT}} \
|
||||
-coverpkg={{.INTERNAL}},{{.API}},{{.PKG}} \
|
||||
-coverprofile={{.COVERAGE_FILE}} \
|
||||
./...
|
||||
- task: coverage
|
||||
race:
|
||||
cmds:
|
||||
- GOMAXPROCS={{.TEST_PARALLEL}} go test -parallel {{.CPU_COUNT}} -race ./...
|
||||
YELLOW='\033[0;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
get_memory_usage() {
|
||||
local profile_file=$1
|
||||
if [ ! -f "$profile_file" ] || [ ! -s "$profile_file" ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
local mem_mb=$(go tool pprof -top "{{ .RESULTS_FILE }}" 2>/dev/null | \
|
||||
grep -E "^\s*[0-9]" | head -1 | \
|
||||
awk '{print $1}' | \
|
||||
sed 's/MB//g' | sed 's/KB//g' | sed 's/GB//g' | \
|
||||
sed 's/[^0-9.]//g')
|
||||
|
||||
if go tool pprof -top "{{ .RESULTS_FILE }}" 2>/dev/null | head -1 | grep -q "KB"; then
|
||||
mem_mb=$(echo "$mem_mb / 1024" | bc -l 2>/dev/null || echo "0")
|
||||
fi
|
||||
|
||||
if go tool pprof -top "{{ .RESULTS_FILE }}" 2>/dev/null | head -1 | grep -q "GB"; then
|
||||
mem_mb=$(echo "$mem_mb * 1024" | bc -l 2>/dev/null || echo "0")
|
||||
fi
|
||||
|
||||
echo "${mem_mb:-0}"
|
||||
}
|
||||
|
||||
test_package() {
|
||||
local pkg=$1
|
||||
local pkg_short=$(basename "$pkg")
|
||||
local profile="{{ .OUT_DIR }}/mem_${pkg_short}_$(date +%s).prof"
|
||||
|
||||
echo -e "${YELLOW}Testing:${NC} $pkg ... "
|
||||
|
||||
# Run test with memory profiling (with timeout)
|
||||
if timeout 120 go test -memprofile="$profile" "$pkg" >/dev/null 2>&1; then
|
||||
local mem_usage=$(get_memory_usage "$profile")
|
||||
echo -e "✅ ${mem_usage} MB"
|
||||
echo "$mem_usage|$pkg" >> "{{ .RESULTS_FILE }}"
|
||||
else
|
||||
echo -e "❌ FAILED/TIMEOUT"
|
||||
echo "0|$pkg" >> "{{ .RESULTS_FILE }}"
|
||||
fi
|
||||
}
|
||||
|
||||
echo -e "${BLUE}Go Test Memory Usage Analysis${NC}"
|
||||
echo -e "${BLUE}==============================${NC}"
|
||||
echo "Profile directory: out/"
|
||||
echo ""
|
||||
echo "Running tests with memory profiling..."
|
||||
echo ""
|
||||
|
||||
for pkg in $(go list ./... 2>/dev/null || echo "."); do
|
||||
task test:wait
|
||||
test_package "$pkg"
|
||||
done
|
||||
|
||||
if [ ! -f "{{ .RESULTS_FILE }}" ] || [ ! -s "{{ .RESULTS_FILE }}" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo -e "${BLUE}Memory Usage Rankings:${NC}"
|
||||
echo -e "${BLUE}=====================${NC}"
|
||||
|
||||
{
|
||||
echo "MEMORY(MB)|PACKAGE"
|
||||
echo "----------|--------"
|
||||
sort -t'|' -k1 -nr "{{ .RESULTS_FILE }}" | head -{{ .NUM_RESULTS }}
|
||||
} | column -t -s'|'
|
||||
|
||||
echo ""
|
||||
echo -e "${BLUE}Summary:${NC}"
|
||||
|
||||
total_mem=$(awk -F'|' '{sum+=$1} END {printf "%.2f", sum}' "{{ .RESULTS_FILE }}")
|
||||
total_packages=$(wc -l < "{{ .RESULTS_FILE }}")
|
||||
|
||||
echo "Total packages tested: $total_packages"
|
||||
echo "Total memory usage: ${total_mem} MB"
|
||||
perf:
|
||||
vars:
|
||||
NUM_RESULTS: 5
|
||||
|
||||
Reference in New Issue
Block a user