Skip to content

Commit 6a2b72d

Browse files
committed
Minor improvements intended to make profiling magma easier.
1 parent 81ef879 commit 6a2b72d

File tree

11 files changed

+161
-61
lines changed

11 files changed

+161
-61
lines changed

.cproject

Lines changed: 28 additions & 28 deletions
Large diffs are not rendered by default.

.gitignore

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,46 @@ res/sql/Hostname.sql
2222
/lib/objects/
2323
/lib/sources/
2424

25+
# Bundled Dependency Test Tool
26+
/lib/check/magma.open.check
27+
2528
# Compiled Binaries
2629
/magmad
27-
/stripped-magmad
2830
/magmad.so
29-
/stripped-magmad.so
3031
/magmad.check
32+
33+
# Stripped Binaries
34+
/magmad.stripped
35+
/magmad.so.stripped
36+
/magmad.check.stripped
37+
38+
# Crypto Tools
3139
/dime
3240
/signet
3341
/genrec
3442
/dime.check
35-
/lib/check/magma.open.check
3643

3744
# Tool Compiler Artifacts and Binaries
38-
dev/tools/pwtool/pwtool
39-
dev/tools/runner/runner
40-
dev/tools/testde/testde
41-
dev/tools/lockdown/lockdown
42-
dev/tools/shabench/shabench
43-
45+
/dev/tools/pwtool/pwtool
46+
/dev/tools/runner/runner
47+
/dev/tools/testde/testde
48+
/dev/tools/lockdown/lockdown
49+
/dev/tools/shabench/shabench
4450

4551
# Profiler Artifacts and Binaries
4652
/gmon.out
53+
/callgrind.out
54+
/massif.out.*
55+
/cachegrind.out.*
56+
/magmad.pprof.out
57+
/magmad.gprof.out.*
58+
/magmad.check.pprof.out
59+
/magmad.check.gprof.out.*
60+
4761
/magmad.gprof
4862
/magmad.gprof.so
4963
/magmad.check.gprof
5064

5165
/magmad.pprof
52-
/magmad.pprof.out
5366
/magmad.check.pprof
54-
/magmad.check.pprof.out
5567

Makefile

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ MAGMA_CHECK_PROGRAM_GPROF = $(addsuffix $(EXEEXT), magmad.check.gprof)
2727
MAGMA_PROGRAM_PPROF = $(addsuffix $(EXEEXT), magmad.pprof)
2828
MAGMA_CHECK_PROGRAM_PPROF = $(addsuffix $(EXEEXT), magmad.check.pprof)
2929

30+
MAGMA_PROGRAM_STRIPPED = $(addsuffix .stripped, $(MAGMA_PROGRAM))
31+
MAGMA_CHECK_PROGRAM_STRIPPED = $(addsuffix .stripped, $(MAGMA_CHECK_PROGRAM))
32+
MAGMA_SHARED_LIBRARY_STRIPPED = $(addsuffix .stripped, $(MAGMA_SHARED_LIBRARY))
33+
3034
DIME_PROGRAM = $(addsuffix $(EXEEXT), dime)
3135
SIGNET_PROGRAM = $(addsuffix $(EXEEXT), signet)
3236
GENREC_PROGRAM = $(addsuffix $(EXEEXT), genrec)
@@ -229,7 +233,9 @@ endif
229233

230234
all: config warning $(MAGMA_PROGRAM) $(DIME_PROGRAM) $(SIGNET_PROGRAM) $(GENREC_PROGRAM) $(MAGMA_CHECK_PROGRAM) $(DIME_CHECK_PROGRAM) finished
231235

232-
strip: config warning stripped-$(MAGMA_PROGRAM) stripped-$(MAGMA_SHARED_LIBRARY) finished
236+
strip: config warning $(MAGMA_SHARED_LIBRARY_STRIPPED) $(MAGMA_PROGRAM_STRIPPED) $(MAGMA_CHECK_PROGRAM_STRIPPED) finished
237+
238+
stripped: strip
233239

234240
warning:
235241
ifeq ($(VERBOSE),no)
@@ -278,30 +284,37 @@ endif
278284
clean:
279285
@$(RM) $(MAGMA_PROGRAM) $(DIME_PROGRAM) $(SIGNET_PROGRAM) $(GENREC_PROGRAM) $(MAGMA_CHECK_PROGRAM) $(DIME_CHECK_PROGRAM)
280286
@$(RM) $(MAGMA_PROGRAM_PPROF) $(MAGMA_CHECK_PROGRAM_PPROF) $(MAGMA_PROGRAM_GPROF) $(MAGMA_CHECK_PROGRAM_GPROF)
287+
@$(RM) $(MAGMA_PROGRAM_STRIPPED) $(MAGMA_CHECK_PROGRAM_STRIPPED) $(MAGMA_SHARED_LIBRARY_STRIPPED)
281288
@$(RM) $(MAGMA_OBJFILES) $(DIME_OBJFILES) $(SIGNET_OBJFILES) $(GENREC_OBJFILES) $(MAGMA_CHECK_OBJFILES) $(DIME_CHECK_OBJFILES) $(MAGMA_PROF_OBJFILES) $(MAGMA_CHECK_PROF_OBJFILES)
282289
@$(RM) $(MAGMA_DEPFILES) $(DIME_DEPFILES) $(SIGNET_DEPFILES) $(GENREC_DEPFILES) $(MAGMA_CHECK_DEPFILES) $(DIME_CHECK_DEPFILES)
283290
@for d in $(sort $(dir $(MAGMA_OBJFILES)) $(dir $(MAGMA_CHECK_OBJFILES)) $(dir $(DIME_OBJFILES)) $(dir $(SIGNET_OBJFILES)) $(dir $(GENREC_OBJFILES))); \
284291
do if test -d "$$d"; then $(RMDIR) "$$d"; fi; done
285292
@for d in $(sort $(dir $(MAGMA_DEPFILES)) $(dir $(MAGMA_CHECK_DEPFILES)) $(dir $(DIME_DEPFILES)) $(dir $(SIGNET_DEPFILES)) $(dir $(GENREC_DEPFILES))); \
286293
do if test -d "$$d"; then $(RMDIR) "$$d"; fi; done
294+
@$(RM) --force gmon.out callgrind.out callgraph.dot callgraph.dot.ps massif.out.* cachegrind.out.* \
295+
magmad.pprof.out magmad.check.pprof.out magmad.gprof.* magmad.check.gprof.*
287296
@echo 'Finished' $(BOLD)$(GREEN)$(TARGETGOAL)$(NORMAL)
288297

289298
distclean:
290299
@$(RM) $(MAGMA_PROGRAM) $(DIME_PROGRAM) $(SIGNET_PROGRAM) $(GENREC_PROGRAM) $(MAGMA_CHECK_PROGRAM) $(DIME_CHECK_PROGRAM)
291-
@$(RM) $(MAGMA_PROGRAM_PPROF) $(MAGMA_CHECK_PROGRAM_PPROF) $(MAGMA_PROGRAM_GPROF) $(MAGMA_CHECK_PROGRAM_GPROF) $(MAGMA_SHARED_LIBRARY)
300+
@$(RM) $(MAGMA_PROGRAM_STRIPPED) $(MAGMA_CHECK_PROGRAM_STRIPPED) $(MAGMA_SHARED_LIBRARY_STRIPPED)
301+
@$(RM) $(MAGMA_PROGRAM_PPROF) $(MAGMA_CHECK_PROGRAM_PPROF) $(MAGMA_PROGRAM_GPROF) $(MAGMA_CHECK_PROGRAM_GPROF)
292302
@$(RM) $(MAGMA_OBJFILES) $(DIME_OBJFILES) $(SIGNET_OBJFILES) $(GENREC_OBJFILES) $(MAGMA_CHECK_OBJFILES) $(DIME_CHECK_OBJFILES) $(MAGMA_PROF_OBJFILES) $(MAGMA_CHECK_PROF_OBJFILES)
293303
@$(RM) $(MAGMA_DEPFILES) $(DIME_DEPFILES) $(SIGNET_DEPFILES) $(GENREC_DEPFILES) $(MAGMA_CHECK_DEPFILES) $(DIME_CHECK_DEPFILES)
294-
@$(RM) --recursive --force $(DEPDIR) $(OBJDIR) lib/local lib/logs lib/objects lib/sources
304+
@$(RM) --force --recursive lib/local lib/logs lib/objects lib/sources $(DEPDIR) $(OBJDIR)
305+
@$(RM) --force gmon.out callgrind.out callgraph.dot callgraph.dot.ps massif.out.* cachegrind.out.* \
306+
magmad.pprof.out magmad.check.pprof.out magmad.gprof.* magmad.check.gprof.*
307+
@$(RM) $(MAGMA_SHARED_LIBRARY)
295308
@echo 'Finished' $(BOLD)$(GREEN)$(TARGETGOAL)$(NORMAL)
296309

297-
stripped-%: $(MAGMA_PROGRAM) $(MAGMA_SHARED_LIBRARY)
310+
%.stripped $(addsuffix $(DYNLIBEXT), %.stripped): %
298311
ifeq ($(VERBOSE),no)
299312
@echo 'Creating' $(RED)$@$(NORMAL)
300313
else
301314
@echo
302315
endif
303-
$(RUN)$(STRIP) $(STRIPFLAGS) --output-format=$(shell objdump -p "$(subst stripped-,,$@)" | grep "file format" | head -1 | \
304-
awk -F'file format' '{print $$2}' | tr --delete [:space:]) -o "$@" "$(subst stripped-,,$@)"
316+
$(RUN)$(STRIP) $(STRIPFLAGS) --output-format=$(shell objdump -p "$(subst .stripped,,$@)" | grep "file format" | head -1 | \
317+
awk -F'file format' '{print $$2}' | tr --delete [:space:]) -o "$@" "$(subst .stripped,,$@)"
305318

306319
install: $(MAGMA_PROGRAM) $(MAGMA_SHARED_LIBRARY)
307320
ifeq ($(VERBOSE),no)
@@ -450,6 +463,6 @@ endif
450463
# Special Make Directives
451464
.SUFFIXES: .c .cc .cpp .o
452465
#.NOTPARALLEL: warning conifg $(PACKAGE_DEPENDENCIES)
453-
.PHONY: all strip warning config finished check setup clean distclean install pprof gprof
466+
.PHONY: all strip stripped warning config finished check setup clean distclean install pprof gprof
454467

455468
# vim:set softtabstop=4 shiftwidth=4 tabstop=4:

check/magma/magma_check.c

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void suite_check_testcase(Suite *s, const char *tags, const char *name, TFun fun
8585

8686
/***
8787
* @return Will return -1 if the code is unable to determine whether tracing is active, 0 if tracing is disabled and
88-
* 1 if tracing has been detected.
88+
* 1 if tracing has been detected. Tracing indicates the process is running atop a debugger.
8989
*/
9090
int_t running_on_debugger(void) {
9191

@@ -120,6 +120,21 @@ int_t running_on_debugger(void) {
120120
return -1;
121121
}
122122

123+
/***
124+
* @return Will return -1 if the code is unable to determine whether profiling is active, 0 if profiling is disabled and
125+
* 1 if profiling has been detected.
126+
*/
127+
int_t running_on_profiler(void) {
128+
129+
void *mcount = NULL;
130+
131+
if ((mcount = dlsym(NULL, "mcount"))) {
132+
return 1;
133+
}
134+
135+
return 0;
136+
}
137+
123138
/**
124139
* @brief Show the check program usage information.
125140
* @see display_usage()
@@ -230,7 +245,7 @@ int_t check_args_parse(int argc, char *argv[]) {
230245
int main(int argc, char *argv[]) {
231246

232247
SRunner *sr;
233-
int_t failed = 0, result;
248+
int_t failed = 0, debugger = 0, profiler = 0, result;
234249
pthread_t *net_listen_thread = NULL;
235250
time_t prog_start, test_start, test_end;
236251

@@ -287,17 +302,26 @@ int main(int argc, char *argv[]) {
287302
srunner_add_suite(sr, suite_check_regression());
288303
}
289304

290-
// If were being run under Valgrind, we need to disable forking and increase the default timeout.
291-
// Under Valgrind, forked checks appear to improperly timeout.
292-
if (RUNNING_ON_VALGRIND == 0 && (failed = running_on_debugger()) == 0) {
305+
306+
// Check whether valgrind, gdb, or gprof are active. Otherwise execute normally. The profiler check should be done
307+
// before the debugger check, as the latter involves forking, which will result in a spurious gprof output file if
308+
// if profiling is indeed active.
309+
if (RUNNING_ON_VALGRIND == 0 && (profiler = running_on_profiler()) == 0 && (debugger = running_on_debugger()) == 0) {
293310
log_unit("Not being traced or profiled...\n");
294311
srunner_set_fork_status (sr, CK_FORK);
295312
case_timeout = RUN_TEST_CASE_TIMEOUT;
296313
}
297314

298-
// Trace detection attempted was thwarted.
315+
// A profiler was detected.
316+
else if (profiler) {
317+
log_unit("A profiler has been detected...\n");
318+
srunner_set_fork_status (sr, CK_NOFORK);
319+
case_timeout = RUN_TEST_CASE_TIMEOUT;
320+
}
321+
322+
// If were being run under Valgrind, or atop a debugger like gdb, we disable forking and increase the default timeout.
299323
else {
300-
if (failed == -1) log_unit("Trace detection was thwarted.\n");
324+
if (debugger == -1) log_unit("Trace detection was thwarted.\n");
301325
else log_unit("Tracing or debugging is active...\n");
302326
srunner_set_fork_status (sr, CK_NOFORK);
303327
case_timeout = PROFILE_TEST_CASE_TIMEOUT;

dev/scripts/launch/check.cachegrind.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ valgrind --tool=cachegrind \
3030
--read-var-info=yes \
3131
--cache-sim=yes \
3232
--branch-sim=no \
33-
--cachegrind-out-file=$HOME/cachegrind.out.%p \
33+
--cachegrind-out-file=$MAGMA_DIST/cachegrind.out.%p \
3434
--suppressions=/usr/lib64/valgrind/default.supp \
3535
--suppressions=$MAGMA_DIST/sandbox/etc/magma.suppressions \
3636
$MAGMA_DIST/magmad.check $MAGMA_DIST/sandbox/etc/magma.sandbox.config

dev/scripts/launch/check.callgrind.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash -x
1+
#!/bin/bash
22

33
# Name: check.callgrind.sh
44
# Author: Ladar Levison
@@ -38,13 +38,13 @@ valgrind --tool=callgrind \
3838
--trace-jump=yes \
3939
--collect-atstart=yes \
4040
--instr-atstart=yes \
41-
--callgrind-out-file=$HOME/Desktop/callgrind.out \
41+
--callgrind-out-file=$MAGMA_DIST/callgrind.out \
4242
--suppressions=/usr/lib64/valgrind/default.supp \
4343
--suppressions=$MAGMA_DIST/sandbox/etc/magma.suppressions \
4444
$MAGMA_DIST/magmad.check $MAGMA_DIST/sandbox/etc/magma.sandbox.config
4545

4646
export VPID=$!
47-
export VLOG=$HOME/Desktop/callgrind.out
47+
export VLOG=$MAGMA_DIST/callgrind.out
4848

4949
wait $VPID
5050

dev/scripts/launch/check.gprof.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
# Name: check.gprof.sh
4+
# Author: Ladar Levison
5+
#
6+
# Description: Used for profiling the magmad unit tests. The tests are executed using the gprof profiler.
7+
8+
LINK=`readlink -f $0`
9+
BASE=`dirname $LINK`
10+
11+
cd $BASE/../../../
12+
13+
MAGMA_DIST=`pwd`
14+
15+
if [ ! -e "$MAGMA_DIST/magmad.check.gprof" ] || [ ! -f "$MAGMA_DIST/magmad.check.gprof" ]; then
16+
tput setaf 1; tput bold; echo "The magmad.check.gprof binary doesn't exist. Please compile it first."; tput sgr0
17+
exit 1
18+
fi
19+
GMON_OUT_PREFIX="$MAGMA_DIST/magmad.check.gprof.out" $MAGMA_DIST/magmad.check.gprof $MAGMA_DIST/sandbox/etc/magma.sandbox.config & MAGMA_PID=$!
20+
wait $MAGMA_PID
21+
22+
if [ -e "$MAGMA_DIST/magmad.check.gprof.out.$MAGMA_PID" ] && [ -f "$MAGMA_DIST/magmad.check.gprof.out.$MAGMA_PID" ]; then
23+
gprof $MAGMA_DIST/magmad.check.gprof $MAGMA_DIST/magmad.check.gprof.out.$MAGMA_PID
24+
fi

dev/scripts/launch/check.massif.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ valgrind --tool=massif \
3737
--time-unit=i \
3838
--detailed-freq=10 \
3939
--max-snapshots=100 \
40-
--massif-out-file=$HOME/massif.out.%p \
40+
--massif-out-file=$MAGMA_DIST/massif.out.%p \
4141
--suppressions=/usr/lib64/valgrind/default.supp \
4242
--suppressions=$MAGMA_DIST/sandbox/etc/magma.suppressions \
4343
$MAGMA_DIST/magmad.check $MAGMA_DIST/sandbox/etc/magma.sandbox.config

dev/scripts/launch/magma.callgrind.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash -x
1+
#!/bin/bash
22

33
# Name: check.callgrind.sh
44
# Author: Ladar Levison
@@ -38,13 +38,13 @@ valgrind --tool=callgrind \
3838
--trace-jump=yes \
3939
--collect-atstart=yes \
4040
--instr-atstart=yes \
41-
--callgrind-out-file=$HOME/Desktop/callgrind.out \
41+
--callgrind-out-file=$MAGMA_DIST/callgrind.out \
4242
--suppressions=/usr/lib64/valgrind/default.supp \
4343
--suppressions=$MAGMA_DIST/sandbox/etc/magma.suppressions \
4444
$MAGMA_DIST/magmad $MAGMA_DIST/sandbox/etc/magma.sandbox.config
4545

4646
export VPID=$!
47-
export VLOG=$HOME/Desktop/callgrind.out
47+
export VLOG=$MAGMA_DIST/callgrind.out
4848

4949
wait $VPID
5050

dev/scripts/launch/magma.gprof.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
# Name: check.gprof.sh
4+
# Author: Ladar Levison
5+
#
6+
# Description: Used for profiling the magma daemon. The daemon is executed using the gprof profiler.
7+
8+
LINK=`readlink -f $0`
9+
BASE=`dirname $LINK`
10+
11+
cd $BASE/../../../
12+
13+
MAGMA_DIST=`pwd`
14+
15+
if [ ! -e "$MAGMA_DIST/magmad.gprof" ] || [ ! -f "$MAGMA_DIST/magmad.gprof" ]; then
16+
tput setaf 1; tput bold; echo "The magmad.gprof binary doesn't exist. Please compile it first."; tput sgr0
17+
exit 1
18+
fi
19+
20+
GMON_OUT_PREFIX="$MAGMA_DIST/magmad.check.gprof.out" $MAGMA_DIST/magmad.check.gprof $MAGMA_DIST/sandbox/etc/magma.sandbox.config & MAGMA_PID=$!
21+
wait $MAGMA_PID
22+
23+
if [ -e "$MAGMA_DIST/magmad.check.gprof.out.$MAGMA_PID" ] && [ -f "$MAGMA_DIST/magmad.check.gprof.out.$MAGMA_PID" ]; then
24+
gprof $MAGMA_DIST/magmad.check.gprof $MAGMA_DIST/magmad.check.gprof.out.$MAGMA_PID
25+
fi

0 commit comments

Comments
 (0)