Skip to content

Commit

Permalink
Merge pull request #76 from Halleck45/optimize_performance
Browse files Browse the repository at this point in the history
Optimize performances
  • Loading branch information
Halleck45 authored Dec 1, 2024
2 parents 9fb50ea + 38374a4 commit dc555ce
Show file tree
Hide file tree
Showing 32 changed files with 1,471 additions and 1,127 deletions.
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: install build
.PHONY: install build monkey-test

PROTOC_VERSION=24.4
ARCHITECTURE=linux-x86_64
Expand Down Expand Up @@ -41,4 +41,10 @@ test:
go clean -testcache
find . -type d -iname ".ast-metrics-cache" -exec rm -rf "{}" \; || true
go test ./...
@echo "\e[34m\033[1mDONE \033[0m\e[39m\n"
@echo "\e[34m\033[1mDONE \033[0m\e[39m\n"

# monkey test: download random PHP and Go packages from top 100 and analyze them
monkey-test:
@echo "\e[34m\033[1m-> Monkey testing\033[0m\e[39m\n"
bash scripts/monkey-test.sh
@echo "\e[34m\033[1mDONE \033[0m\e[39m\n"
20 changes: 10 additions & 10 deletions proto/NodeType.proto
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,16 @@ message Volume {
optional int32 cloc = 3;
optional int32 halsteadVocabulary = 4;
optional int32 halsteadLength = 5;
optional float halsteadVolume = 6;
optional float halsteadDifficulty = 7;
optional float halsteadEffort = 8;
optional float halsteadTime = 9;
optional float halsteadEstimatedLength = 10;
optional double halsteadVolume = 6;
optional double halsteadDifficulty = 7;
optional double halsteadEffort = 8;
optional double halsteadTime = 9;
optional double halsteadEstimatedLength = 10;
}
message Maintainability {
optional float maintainabilityIndex = 1;
optional float maintainabilityIndexWithoutComments = 2;
optional float commentWeight = 3;
optional double maintainabilityIndex = 1;
optional double maintainabilityIndexWithoutComments = 2;
optional double commentWeight = 3;
}

// ------------------------------------
Expand All @@ -239,7 +239,7 @@ message Commit {
// -- Risk
// ------------------------------------
message Risk {
float score = 1; // score of risk. Lower is better
double score = 1; // score of risk. Lower is better
}

// ------------------------------------
Expand All @@ -248,5 +248,5 @@ message Risk {
message Coupling {
int32 afferent = 1; // number of classes that depends on this class
int32 efferent = 2; // number of classes that this class depends on
float instability = 3; // instability of the class
double instability = 3; // instability of the class
}
72 changes: 72 additions & 0 deletions scripts/monkey-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
set -e

# number of packages to download
PACKAGES_COUNT=100

workdir=$(mktemp -d)
echo "Working in $workdir"
if [ -z "$workdir" ]; then
echo "Workdir not found"
exit 1
fi

# cleanup reports
rm -f ast-metrics-report.json


# sort TOP packages randomly
url="https://packagist.org/explore/popular.json?per_page=100"
# shuffle 100 packages
packages=$(curl -s $url | jq -r '.packages[].name' | shuf)
# take only $PACKAGES_COUNT packages
packages=$(echo "$packages" | head -n $PACKAGES_COUNT)

echo "Downloading $PACKAGES_COUNT packages"
for package in $packages;
do
echo " Downloading $package"
repository=$(curl -s https://packagist.org/packages/$package.json | jq -r '.package.repository')
zipUrl="$repository/archive/refs/heads/master.zip"
# generate random name for destination
name=$(uuidgen)
destination="$workdir/$name"
echo " Downloading $zipUrl to $destination"
curl -s -L -o $destination.zip $zipUrl

# if zip contains HTML, like "Just a moment...", then skip
if grep -q "<html" $destination.zip; then
echo " Skipping $package because it contains HTML (probably rate limited)"
continue
fi

# if contains 404, then skip
if grep -q "404" $destination.zip; then
echo " Skipping $package because it contains 404"
continue
fi

unzip $destination.zip -d $destination > /dev/null
rm $destination.zip
done

echo "Analyzing $workdir"
time go run . analyze --ci $workdir

# Ensure that report is generated
if [ ! -f ast-metrics-report.json ]; then
echo "Report not generated"
exit 1
else
echo "Report generated"
fi


# Count number of analyzed files
# | **PHP** | 122.0 K | 🟢 112 | 1.21 | 12 |
line=$(cat build/report.md |grep '**PHP**'|head -n 1)
separator="|"
linesOfCode=$(echo $line | awk -F "$separator" '{print $3}')
echo "Analyzed $linesOfCode lines of code"


echo "Done"
Loading

0 comments on commit dc555ce

Please sign in to comment.