Thursday, February 2, 2012

Vim Tips and Tricks

VIM ON MAC:

In Macbook, create  a file called $HOME/.vimrc and add the following:

 :syntax on  - To include syntax highlighting in vi as default
:map :w\|!python %  - To save and run python script with just pressing 
:set number - To display line numbers

SCAN AND RUN:


 I had to do performance test on a REST server via SoapUi. This is what I did, in SOAPUI(3.5.1) I created Test suite->Test steps->properties(added the txnId to be unique for subsequent calls)->Groovy script to increment the txnId->Test case which has the sample request->LoadTestcase where I set the delay between requests and total # of requests for n number of threads.

In the server, I added code on server's entry point to print the difference of start and end timestamp. So after the Load Test case is done, I had to extract those timestamps, send it to a script which would calculate the avg time for each request.

The tricky part was how to extract the timestamp difference from the server log. Here's the vi commands to achieve it. In my logs, I had the timestamp in milliseconds like "PERFORMANCE:: 120". So I copy the server log to temp log. Open it via vim editor. In command prompt,

cp server.log temp.log - do not modify the original server log
grep "PERFORMANCE::" temp.log - verify you the test ran successfully
grep -c "PERFORMANCE::" temp.log - count the total number of occurrences
vi temp.log - open the temp log in vi editor
:v/PERFORMANCE:: /d - in esc mode, delete all lines except our performance test line
:%s/^.*PERFORMANCE::\([^"]*\).*$/\1 - in the leftover lines, delete the words and leave the numbers alone
wc -l temp.log - verify the count is still the same, note it down as total#Requests
vi testscript.sh - open file to write script to add the numbers left in temp.log


The file content should be:

sum="0"
for i in `cat $1`;
do
sum=$[$sum + $i];
done
echo "sum = "$sum

chmod +x testscript.sh - to enable execution of the script
./testscript.sh temp.log - to print the sum
then in calculator sum/total#request = avg time taken by the server for each request.

ToNote:
:g/.*/d - to delete all the lines in a file in Vi.

No comments: