ext4 時延stap指令碼

jesselyu發表於2017-04-07

#!/bin/sh

STAP_FILE_PATH="/tmp/moderate-ext4.stp"

MODERATE_EXT4_FUNCTIONS=(

#ext4 direct io function

"ext4_direct_IO"

#ext4 page related functions

#"ext4_readpages"

#"ext4_writepage"

#ext4 aio related functions

"generic_file_aio_read"

"ext4_file_write"

#ext4 sync function

"ext4_sync_file"

)

function error()

{

echo $@

exit 1

}

function probe_functions()

{

local delay=${1:-"1"}

rm $STAP_FILE_PATH &>/dev/null

# header

cat <> $STAP_FILE_PATH

#!/usr/bin/stap -DSTP_NO_OVERLOAD

# Delay reads by 250 ms

# stap -v -g nfsd_delay_op.stp nfsd_read 250

%{

#undef STP_OVERLOAD

#include

%}

function udelay(ms:long) %{

/* guru */

udelay(THIS->ms);

%}

EOF

for func_name in ${MODERATE_EXT4_FUNCTIONS[@]}; do

if [[ $func_name =~ "ext4" ]]; then

# ext4 module probe body

cat <> $STAP_FILE_PATH

probe module("ext4").function("$func_name").return

{

udelay($delay);

}

EOF

else

# kernel probe body

cat <> $STAP_FILE_PATH

probe kernel.function("$func_name").return

{

udelay($delay);

}

EOF

fi

done

}

function usage()

{

local program=`basename $0`

echo "Usage: $program is a tool to moderate ext4's io based on systemtap"

echo "the only option is time, and the unit is milliseconds"

exit 1

}

function main() {

if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then

usage

fi

which stap &>/dev/null || yum -b current intall -y systemtap

probe_functions $1

stap -v -g $STAP_FILE_PATH

}

main $1

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30088583/viewspace-2136830/,如需轉載,請註明出處,否則將追究法律責任。

相關文章