Skip to content

function metrics

function metrics #26

Workflow file for this run

on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Cache Maven dependencies
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/*.java') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Build with Maven
run: mvn clean install
- name: Run Checkstyle
run: mvn checkstyle:check
- name: Count Lines of Code
run: |
sudo apt-get update
sudo apt-get install -y cloc
cloc --exclude-dir=target --quiet .
# Measure execution time, throughput, error rate, memory usage, and call count
- name: Measure Java Application Metrics
run: |
# Install jq for parsing JSON results
sudo apt-get install jq
# Run tests with metrics (timing, error rate, throughput, etc.)
mvn test | tee result.log
# Extract test execution time
test_duration=$(grep "Total time" result.log | sed 's/[^0-9]*\([0-9]*\)[^0-9]*/\1/')
echo "Test Execution Time: $test_duration seconds"
# Extract error rate (failed tests)
failed_tests=$(grep -c 'FAILURE' result.log)
total_tests=$(grep -c 'Tests run' result.log)
error_rate=$(echo "scale=2; $failed_tests / $total_tests * 100" | bc)
echo "Error Rate: $error_rate%"
# Extract throughput (tests per second)
throughput=$(echo "scale=2; $total_tests / $test_duration" | bc)
echo "Throughput: $throughput tests per second"
# Measure memory usage with jvm options during test run
echo "Memory Usage (heap size):"
jps -v | grep 'java'
# Check method call count (assumes logging for call count)
call_count=$(grep -o 'methodCallCount' result.log | wc -l)
echo "Call Count: $call_count"
- name: Upload test results to GitHub
uses: actions/upload-artifact@v3
with:
name: test-results
path: result.log