Skip to content

Commit a1f04a4

Browse files
author
TheSnoozer
committed
add simple script to measure performance of the maven execution
1 parent d2d64d5 commit a1f04a4

File tree

1 file changed

+177
-0
lines changed

1 file changed

+177
-0
lines changed

misc/performance_measure.py

+177
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
# python3.6 -m pip install GitPython
2+
3+
import os
4+
import re
5+
import git
6+
import time
7+
import subprocess
8+
from git import RemoteProgress
9+
10+
TEST_DIR = '/tmp/testing'
11+
12+
GIT_URLS = [
13+
# [email protected]:torvalds/linux.git
14+
'[email protected]:pockethub/PocketHub.git',
15+
# '[email protected]:cstamas/nexus-core-ng.git',
16+
'[email protected]:apache/maven.git',
17+
'[email protected]:apache/wicket.git',
18+
'[email protected]:netty/netty.git',
19+
'[email protected]:tensorflow/tensorflow.git',
20+
'[email protected]:angular/angular.js.git',
21+
'[email protected]:twbs/bootstrap.git'
22+
]
23+
24+
25+
class CustomProgress(RemoteProgress):
26+
def update(self, op_code, cur_count, max_count=None, message=''):
27+
if message:
28+
percent = cur_count / max_count
29+
print("{0:50}\t{1:.2%}".format(message, percent), end='\r')
30+
if op_code & RemoteProgress.END == RemoteProgress.END:
31+
print('')
32+
33+
34+
def git_url_to_path(base_dir, git_url):
35+
repo_name = re.findall('/(.+?)\.git', git_url)[0]
36+
repo_path = os.path.join(base_dir, repo_name)
37+
return repo_path
38+
39+
40+
def setup_testing_repos():
41+
os.makedirs(TEST_DIR, exist_ok=True)
42+
for git_url in GIT_URLS:
43+
repo_path = git_url_to_path(TEST_DIR, git_url)
44+
45+
if not os.path.isdir(repo_path):
46+
print('Clone {0} into {1}'.format(git_url, repo_path))
47+
git.Repo.clone_from(git_url, repo_path, progress=CustomProgress())
48+
else:
49+
print('Nothing to-do for {0}'.format(git_url))
50+
51+
52+
def setup_maven_benchmark_pom(tmp_dir_name):
53+
with open(os.path.join(tmp_dir_name, "pom.xml"), 'w') as mvn_pom:
54+
mvn_pom.write('''<?xml version="1.0" encoding="UTF-8"?>
55+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
56+
<modelVersion>4.0.0</modelVersion>
57+
<parent>
58+
<groupId>org.sonatype.oss</groupId>
59+
<artifactId>oss-parent</artifactId>
60+
<version>9</version>
61+
</parent>
62+
63+
<artifactId>naive-performance-test</artifactId>
64+
<version>0.0.3-SNAPSHOT</version>
65+
66+
<properties>
67+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
68+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
69+
<git-commit-id-version>3.0.0-SNAPSHOT</git-commit-id-version>
70+
<git-use-native>false</git-use-native>
71+
</properties>
72+
73+
<build>
74+
<plugins>
75+
<plugin>
76+
<groupId>pl.project13.maven</groupId>
77+
<artifactId>git-commit-id-plugin</artifactId>
78+
<version>${git-commit-id-version}</version>
79+
<executions>
80+
<execution>
81+
<id>get-the-git-infos</id>
82+
<goals>
83+
<goal>revision</goal>
84+
</goals>
85+
<phase>initialize</phase>
86+
</execution>
87+
</executions>
88+
<configuration>
89+
<prefix>git</prefix>
90+
<verbose>true</verbose>
91+
<useNativeGit>${git-use-native}</useNativeGit>
92+
<skipPoms>false</skipPoms>
93+
<!-- <nativeGitTimeoutInMs>3000</nativeGitTimeoutInMs> -->
94+
<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
95+
<generateGitPropertiesFile>true</generateGitPropertiesFile>
96+
<evaluateOnCommit>HEAD</evaluateOnCommit>
97+
<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
98+
<!--
99+
<includeOnlyProperties>
100+
<includeOnlyProperty>^git.commit.id$</includeOnlyProperty>
101+
</includeOnlyProperties>
102+
-->
103+
<excludeProperties>
104+
<excludeProperty>^git.local.branch.*$</excludeProperty>
105+
</excludeProperties>
106+
</configuration>
107+
</plugin>
108+
<!--
109+
<plugin>
110+
<artifactId>maven-antrun-plugin</artifactId>
111+
<version>1.8</version>
112+
<executions>
113+
<execution>
114+
<id>echo-properties</id>
115+
<phase>initialize</phase>
116+
<goals>
117+
<goal>run</goal>
118+
</goals>
119+
<configuration>
120+
<target>
121+
<echo>git-evaluation-dir: ${git-evaluation-dir}</echo>
122+
<echo>git-use-native: ${git-use-native}</echo>
123+
</target>
124+
</configuration>
125+
</execution>
126+
</executions>
127+
</plugin>
128+
-->
129+
</plugins>
130+
</build>
131+
</project>''')
132+
133+
134+
def run_process(args, cwd):
135+
# print("start process: " + str(' '.join(args)))
136+
proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd)
137+
stdout, _ = proc.communicate()
138+
if proc.returncode != 0:
139+
raise ValueError('Process failed with exit-code {0}.\nOutput: {1}'.format(proc.returncode, stdout))
140+
141+
return stdout
142+
143+
144+
def mean(numbers):
145+
return float(sum(numbers)) / max(len(numbers), 1)
146+
147+
148+
setup_testing_repos()
149+
150+
for git_url in GIT_URLS:
151+
repo_path = git_url_to_path(TEST_DIR, git_url)
152+
actual_git_repo = os.path.join(repo_path, '.git')
153+
154+
commit_count = run_process(['git', 'rev-list', '--all', '--count'], cwd=repo_path)
155+
commit_count = re.search(r'\d+', str(commit_count)).group()
156+
157+
print(f"=== Run test for {repo_path} (commit count: {commit_count})")
158+
setup_maven_benchmark_pom(repo_path)
159+
160+
for use_native_git in [True, False]:
161+
for git_commit_id_plugin_version in ['2.2.6', '3.0.0-SNAPSHOT']:
162+
max_attempts = 10
163+
execution_times = []
164+
for attempt in range(1, max_attempts + 1):
165+
print(f"Launching {attempt} / {max_attempts} for {git_commit_id_plugin_version},{use_native_git}",
166+
end='\r', flush=True)
167+
start = time.time()
168+
run_process(
169+
['mvn',
170+
'pl.project13.maven:git-commit-id-plugin:' + str(git_commit_id_plugin_version) + ':revision',
171+
'-Dgit-use-native=' + str(use_native_git).lower()],
172+
cwd=repo_path)
173+
174+
total_time = time.time() - start
175+
execution_times.append(total_time)
176+
avg_execution_time = mean(execution_times)
177+
print(f"\"{git_commit_id_plugin_version}\",\"{use_native_git}\",\"{avg_execution_time:.2f}\"{100*' '}")

0 commit comments

Comments
 (0)