Recently I wanted to know what are the files read and written by each test in Spoon. Here is what I managed to do it by using strace.
Profiling a single test
Profiling one single test:
strace -f -s 500 -o trace.txt mvn surefire:test -D test=spoon.test.annotation.AnnotationTest
(the -f
tells strace to also trace forks, it is required because Maven surefire forks the JVM; the -s is required to get the actual file paths which are usually longer than the default 32 characters).
If you want to only focus on write operations:
strace -f -s 500 -o trace.txt mvn surefire:test -D test=spoon.test.annotation.AnnotationTest | egrep "O_RDWR|O_CREAT"
Profiling all tests at once
First run all tests to get a list of tests in target/surefire-reports
.
mvn clean test
Then you can iterate over each test in a separate mvn call as follows:
for test in target/surefire-reports/*txt;
do
strace -f -s 500 -o $test.trace mvn surefire:test -Dtest=$(basename $test .txt);
done
For each test, you obtain a trace file in target/surefire-reports/
, for instance target/surefire-reports/spoon.test.annotation.AnnotationTest.txt.trace
.
Afterwards you can write a script to analyze the content of trace
files.
–Martin
Lille, November 2016