Skip to content

Commit 962ea85

Browse files
committed
Refactorized rules targetting profiling-* & memory-profiling
Part of nicolargo#2906: * `profiling-*` share the same start banner * used `OUT_DIR` for static outputs * `TIMES` controls the number of iterations. Signed-off-by: Ariel Otilibili <otilibil@eurecom.fr>
1 parent d9fc2ca commit 962ea85

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

Makefile

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -126,23 +126,30 @@ codespell: ## Run codespell to fix common misspellings in text files
126126
semgrep: ## Run semgrep to find bugs and enforce code standards
127127
$(venv_dev)/semgrep scan --config=auto
128128

129+
profiling-%: SLEEP = 3
130+
profiling-%: TIMES = 30
131+
profiling-%: OUT_DIR = docs/_static
132+
133+
define DISPLAY-BANNER
134+
@echo "Start Glances for $(TIMES) iterations (more or less 1 mins, please do not exit !)"
135+
sleep $(SLEEP)
136+
endef
137+
138+
profiling-gprof: CPROF = glances.cprof
129139
profiling-gprof: ## Callgraph profiling (need "apt install graphviz")
130-
@echo "Start Glances for 30 iterations (more or less 1 mins, please do not exit !)"
131-
sleep 3
132-
$(PYTHON) -m cProfile -o ./glances.cprof ./run.py --stop-after 30
133-
$(venv_dev)/gprof2dot -f pstats ./glances.cprof | dot -Tsvg -o ./docs/_static/glances-cgraph.svg
134-
rm -f ./glances.cprof
140+
$(DISPLAY-BANNER)
141+
$(PYTHON) -m cProfile -o $(CPROF) run.py --stop-after $(TIMES)
142+
$(venv_dev)/gprof2dot -f pstats $(CPROF) | dot -Tsvg -o $(OUT_DIR)/glances-cgraph.svg
143+
rm -f $(CPROF)
135144

136145
profiling-pyinstrument: ## PyInstrument profiling
137-
@echo "Start Glances for 30 iterations (more or less 1 mins, please do not exit !)"
138-
sleep 3
146+
$(DISPLAY-BANNER)
139147
$(PIP) install pyinstrument
140-
$(PYTHON) -m pyinstrument -r html -o ./docs/_static/glances-pyinstrument.html -m glances --stop-after 30
148+
$(PYTHON) -m pyinstrument -r html -o $(OUT_DIR)/glances-pyinstrument.html -m glances --stop-after $(TIMES)
141149

142150
profiling-pyspy: ## Flame profiling (currently not compatible with Python 3.12)
143-
@echo "Start Glances for 30 iterations (more or less 1 mins, please do not exit !)"
144-
sleep 3
145-
$(venv_dev)/py-spy record -o ./docs/_static/glances-flame.svg -d 60 -s -- $(PYTHON) ./run.py --stop-after 30
151+
$(DISPLAY-BANNER)
152+
$(venv_dev)/py-spy record -o $(OUT_DIR)/glances-flame.svg -d 60 -s -- $(PYTHON) run.py --stop-after $(TIMES)
146153

147154
profiling: profiling-gprof profiling-pyinstrument profiling-pyspy ## Profiling of the Glances software
148155

@@ -153,17 +160,19 @@ trace-malloc: ## Trace the malloc() calls
153160
memory-leak: ## Profile memory leaks
154161
$(PYTHON) -m glances -C $(CONF) --memory-leak
155162

163+
memory-profiling: TIMES = 2400
164+
memory-profiling: PROFILE = mprofile_*.dat
156165
memory-profiling: ## Profile memory usage
157166
@echo "It's a very long test (~4 hours)..."
158-
rm -f mprofile_*.dat
167+
rm -f $(PROFILE)
159168
@echo "1/2 - Start memory profiling with the history option enable"
160-
$(venv_dev)/mprof run -T 1 -C run.py -C $(CONF) --stop-after 2400 --quiet
161-
$(venv_dev)/mprof plot --output ./docs/_static/glances-memory-profiling-with-history.png
162-
rm -f mprofile_*.dat
169+
$(venv_dev)/mprof run -T 1 -C run.py -C $(CONF) --stop-after $(TIMES) --quiet
170+
$(venv_dev)/mprof plot --output $(OUT_DIR)/glances-memory-profiling-with-history.png
171+
rm -f $(PROFILE)
163172
@echo "2/2 - Start memory profiling with the history option disable"
164-
$(venv_dev)/mprof run -T 1 -C run.py -C $(CONF) --disable-history --stop-after 2400 --quiet
165-
$(venv_dev)/mprof plot --output ./docs/_static/glances-memory-profiling-without-history.png
166-
rm -f mprofile_*.dat
173+
$(venv_dev)/mprof run -T 1 -C run.py -C $(CONF) --disable-history --stop-after $(TIMES) --quiet
174+
$(venv_dev)/mprof plot --output $(OUT_DIR)/glances-memory-profiling-without-history.png
175+
rm -f $(PROFILE)
167176

168177
# Trivy installation: https://aquasecurity.github.io/trivy/latest/getting-started/installation/
169178
trivy: ## Run Trivy to find vulnerabilities in container images

0 commit comments

Comments
 (0)