Skip to content

Commit f001674

Browse files
committed
[BAEL-9370] Added script to start and profile the app
1 parent 1bc3f89 commit f001674

File tree

4 files changed

+102
-1
lines changed

4 files changed

+102
-1
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
APP_COMMAND=""
5+
6+
case "$1" in
7+
aot)
8+
APP_COMMAND="java -Dspring.aot.enabled=true \
9+
-Dspring.aot.repositories.enabled=false \
10+
-agentlib:native-image-agent=config-output-dir=target/native-image-hints \
11+
-jar spring-data-jpa-aot/target/spring-data-jpa-aot-0.0.1-SNAPSHOT.jar"
12+
;;
13+
aot-repo)
14+
APP_COMMAND="java -Dspring.aot.enabled=true \
15+
-Dspring.aot.repositories.enabled=true \
16+
-agentlib:native-image-agent=config-output-dir=target/native-image-hints \
17+
-jar spring-data-jpa-aot-repository/target/spring-data-jpa-aot-repository-0.0.1-SNAPSHOT.jar"
18+
;;
19+
non-aot)
20+
APP_COMMAND="java -jar spring-data-jpa-not-aot/target/spring-data-jpa-not-aot-0.0.1-SNAPSHOT.jar"
21+
;;
22+
*)
23+
echo "Error: Unknown mode '$1'. Use 'aot', 'aot-repo' or 'non-aot'."
24+
exit 1
25+
;;
26+
esac
27+
28+
# --- 1. Start your script in the background ---
29+
# Record start time in milliseconds
30+
start_ns=$(date +%s%N)
31+
$APP_COMMAND &
32+
APP_PID=$!
33+
echo "Started APP with PID $APP_PID"
34+
35+
# --- 2. Start sampling in the background ---
36+
sudo sample $APP_PID > sample_output.txt &
37+
SAMPLE_PID=$!
38+
echo "Sampling process started (PID $SAMPLE_PID)"
39+
echo "Waiting for service at http://localhost:8080/get-user ..."
40+
41+
# --- 3. Poll the endpoint until it returns HTTP 200 ---
42+
while [ "$(curl -s -o /dev/null -L -w ''%{http_code}'' http://localhost:8080/get-user)" != 200 ]
43+
do sleep 0.001;
44+
done
45+
46+
# Capture elapsed time (SECONDS has fractional part) and the memory info
47+
end_ns=$(date +%s%N)
48+
elapsed_ms=$(((end_ns - start_ns) / 1000000))
49+
MEMINFO=$(ps -o rss,vsz,pcpu,time -p $APP_PID | tail -1)
50+
51+
## --- 4. Stop sampling and show results ---
52+
#echo "Stopping sample..."
53+
#sudo kill -INT "$SAMPLE_PID"
54+
#wait "$SAMPLE_PID" 2>/dev/null || true
55+
#
56+
## Give sample a moment to flush output
57+
#sleep 2
58+
59+
# --- 5. Clean up ---
60+
echo "Stopping startup process..."
61+
kill "$APP_PID" 2>/dev/null || true
62+
63+
# Give app a moment to shutdown
64+
sleep 3
65+
66+
echo "Done."
67+
68+
THREADS=$(grep -E "Thread_[0-9]+" sample_output.txt | wc -l)
69+
echo "time elapsed $elapsed_ms millis"
70+
echo "Threads: $THREADS"
71+
echo "Memory/CPU (RSS KB / VSZ KB / %CPU / CPU Time): $MEMINFO"

persistence-modules/spring-data-jpa-repo-5/spring-data-jpa-aot-repository/README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ Startup times:
2929
`Root WebApplicationContext: initialization completed in 452 ms`
3030
`Started Application in 3.26 seconds`
3131

32+
## Performance
33+
34+
### Time startup
35+
from root `sudo ./scripts/startup.sh aot-repo`:
36+
```shell
37+
time elapsed 5296 millis
38+
Threads: 58
39+
Memory/CPU (RSS KB / VSZ KB / %CPU / CPU Time): 406992 523697872 167.5 0:10.91
40+
```
41+
3242
**NOTE**:
3343
AOT is a mandatory step to transform a Spring application to a native executable, so it is automatically enabled when running within a native image. However it is also possible to use AOT optimizations on the JVM by setting the spring.aot.enabled System
34-
property to true.
44+
property to true.

persistence-modules/spring-data-jpa-repo-5/spring-data-jpa-aot/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,13 @@ java -Dspring.aot.enabled=true \
2626
Startup times:
2727
`Root WebApplicationContext: initialization completed in 461 ms`
2828
`Started Application in 3.29 seconds`
29+
30+
## Performance
31+
32+
### Time startup
33+
from root `sudo ./scripts/startup.sh aot`:
34+
```shell
35+
time elapsed 5217 millis
36+
Threads: 56
37+
Memory/CPU (RSS KB / VSZ KB / %CPU / CPU Time): 448448 557256448 173.9 0:11.70
38+
```

persistence-modules/spring-data-jpa-repo-5/spring-data-jpa-not-aot/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,13 @@ java -jar target/spring-data-jpa-not-aot-0.0.1-SNAPSHOT.jar
1919
Startup times:
2020
`Root WebApplicationContext: initialization completed in 555 ms`
2121
`Started Application in 2.641 seconds`
22+
23+
## Performance
24+
25+
### Time startup
26+
from root `sudo ./scripts/startup.sh non-aot`:
27+
```shell
28+
time elapsed 4490 millis
29+
Threads: 57
30+
Memory/CPU (RSS KB / VSZ KB / %CPU / CPU Time): 407584 523866624 236.2 0:10.97
31+
```

0 commit comments

Comments
 (0)