[CRIU] [PATCH] perf: add ability to trace system calls with perf

Andrew Vagin avagin at parallels.com
Tue Oct 14 12:57:29 PDT 2014


On Tue, Oct 14, 2014 at 03:50:49PM +0400, Andrey Vagin wrote:
> First of all perf can trace parasite code. strace can't because ptrace
> doesn't allow to attach to one task twice
> 
> perf doesn't affect performance so significant as strace and
> it allows to trace parasite code. But perf isn't so verbose. For example
> it can't show arguments which are tranfered by pointers.
> 
> All processes are executed in a new perf_evets cgroup and
> "perf record" collects events only for processes from this group.
> 
> On dump perf is executed from a network-lock action script, it's a first
> point where processes are frozed.
> And perf is stopped from post-dump and post-restore, it's the last point
> where processes are frozed.
> 
> Example of output:
>     18.651 ( 0.001 ms): criu/9243 close(fd: 44                                                          ) = 0
>     18.655 ( 0.001 ms): criu/9243 gettimeofday(tv: 0x7fff32fdd7f0                                       ) = 0
>     18.670 ( 0.013 ms): criu/9243 write(fd: 1023, buf: 0x6b6a00, count: 53                              ) = 53
>     18.710 ( 1.078 ms): env00/9226 recvfrom(fd: 3, ubuf: 0x7f963bb95998, size: 12, flags: WAITALL        ) = 12
>     18.726 ( 0.014 ms): env00/9226 write(fd: 4, buf: 0x7f963bb95878, count: 26                           ) = 26
>     18.761 ( 0.034 ms): env00/9226 mprotect(start: 0x7f963b771000, len: 2093056, prot: READ              ) = 0
> 
> Signed-off-by: Andrey Vagin <avagin at openvz.org>
> ---
>  test/perf-script.sh | 16 ++++++++++++++++
>  test/zdtm.sh        | 26 +++++++++++++++++++++++++-
>  2 files changed, 41 insertions(+), 1 deletion(-)
>  create mode 100755 test/perf-script.sh
> 
> diff --git a/test/perf-script.sh b/test/perf-script.sh
> new file mode 100755
> index 0000000..ad56187
> --- /dev/null
> +++ b/test/perf-script.sh
> @@ -0,0 +1,16 @@
> +#!/bin/sh
> +
> +set -e
> +[ "$CRTOOLS_SCRIPT_ACTION" == network-lock ] && {

network-lock is executed only if netns is dumped.

> +	echo 0 > /sys/fs/cgroup/perf_event/tasks
> +	perf record -o perf.dump -e raw_syscalls:sys_exit,raw_syscalls:sys_enter --cgroup zdtm,zdtm -a &
> +	echo $! > perf.pid
> +	sleep 1
> +	exit 0
> +}
> +[ "$CRTOOLS_SCRIPT_ACTION" == post-dump -o "$CRTOOLS_SCRIPT_ACTION" == post-restore ] && {
> +	kill `cat perf.pid`
> +	exit 0
> +}
> +
> +exit 0
> diff --git a/test/zdtm.sh b/test/zdtm.sh
> index 9a2c188..1d0f6c3 100755
> --- a/test/zdtm.sh
> +++ b/test/zdtm.sh
> @@ -255,6 +255,7 @@ COMPILE_ONLY=0
>  START_ONLY=0
>  BATCH_TEST=0
>  SPECIFIED_NAME_USED=0
> +PERF=""
>  
>  zdtm_sep()
>  { (
> @@ -547,6 +548,8 @@ EOF
>  		gen_args="$gen_args --force-irmap"
>  	fi
>  
> +	[ -n "$PERF" ] && gen_args="$gen_args --action-script $SCRIPTDIR/perf-script.sh"
> +
>  	for i in `seq $ITERATIONS`; do
>  		local cpt_args=
>  		local dump_only=
> @@ -585,6 +588,12 @@ EOF
>  		setsid $CRIU_CPT $dump_cmd -D $ddump -o dump.log -v4 -t $PID $gen_args $cpt_args
>  		retcode=$?
>  
> +		[ -n "$PERF" ] && {
> +			echo Use the following command to analize perf data:
> +			echo perf trace report -i $ddump/perf.dump
> +			[ "$retcode" -ne 0 ] && kill `cat $ddump/perf.pid`
> +		}
> +
>  		#
>  		# Here we may have two cases: either checkpoint is failed
>  		# with some error code, or checkpoint is complete but return
> @@ -645,7 +654,16 @@ EOF
>  			rm -f $TPID || true
>  
>  			echo Restore
> -			setsid $CRIU restore -D $ddump -o restore.log -v4 -d $gen_args || return 2
> +			[ -n "$PERF" ] &&  (
> +				echo 0 > /sys/fs/cgroup/perf_event/tasks
> +				perf record -o $ddump/perf.restore -e raw_syscalls:sys_exit,raw_syscalls:sys_enter --cgroup zdtm,zdtm -a &
> +				echo $! > $ddump/perf.pid
> +				sleep 1
> +			)
> +			setsid $CRIU restore -D $ddump -o restore.log -v4 -d $gen_args || {
> +				[ -n "$PERF" ] && kill `cat $ddump/perf.pid`
> +				return 2
> +			}
>  
>  			[ -n "$PIDNS" ] && PID=`cat $TPID`
>  			for i in `seq 5`; do
> @@ -911,6 +929,12 @@ while :; do
>  		}
>  		shift
>  		;;
> +	  --perf)
> +		PERF=1
> +		test -d /sys/fs/cgroup/perf_event/zdtm || mkdir /sys/fs/cgroup/perf_event/zdtm || exit 1
> +		echo $$ > /sys/fs/cgroup/perf_event/zdtm/tasks
> +		shift
> +		;;
>  	  -*)
>  		echo "Unrecognized option $1, aborting!" 1>&2
>  		usage
> -- 
> 1.9.3
> 


More information about the CRIU mailing list