Skip to content

Commit 4ca072b

Browse files
committed
chore: script to measure cpu and memory usage during startup
1 parent 275d229 commit 4ca072b

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
File renamed without changes.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
CMD="$@"
4+
URL="http://localhost:8080/info"
5+
6+
# Record start time
7+
START_TIME=$(date +%s.%N)
8+
9+
# Start app and get PID
10+
$CMD &
11+
PID=$!
12+
13+
# Wait for first successful HTTP 200 response
14+
until curl -sf "$URL" -w "%{http_code}" -o /dev/null | grep -q "200"; do sleep 0.001; done
15+
16+
# oha -n 1000 -c 10 "$URL"
17+
18+
# Calculate wall time
19+
END_TIME=$(date +%s.%N)
20+
WALL_TIME=$(echo "$END_TIME - $START_TIME" | bc)
21+
22+
# Wall Time: |------ 1.5s ------| (Real world elapsed time)
23+
# Core 1: |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| (100% busy = 1.5 seconds of work)
24+
# Core 2: |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ | ( 70% busy = 1.1 seconds of work)
25+
# Cores 3-10: | | ( 0% busy = idle)
26+
# ─────────────────────────────────────────────────────────────────────
27+
# Summary:
28+
# β€’ Total CPU Time = 1.5 + 1.1 = 2.6 seconds βœ“
29+
# β€’ Current CPU% = (100% + 70%) = 170% β‰ˆ 169% βœ“
30+
# β€’ Wall Time = 1.5 seconds (time that actually passed)
31+
#
32+
# Key Relationships:
33+
# β€’ Multi-threaded: CPU Time > Wall Time (more work than time passed)
34+
# β€’ CPU% Formula: (CPU Time Γ· Wall Time) Γ— 100%
35+
# β€’ Example: (2.6 Γ· 1.5) Γ— 100% = 173% β‰ˆ 169%
36+
# ======================================================================
37+
38+
ps -o rss,vsz,%cpu,cputime,time -p $PID | tail -1 | awk -v wt="$WALL_TIME" '{print "Memory: " $1 " KB, CPU%: " $3 "%, CPUTime: " $4 ", WallTime: " wt "s"}'
39+
40+
# Cleanup
41+
kill -9 $PID 2>/dev/null

0 commit comments

Comments
Β (0)