How can I measure shell latency when the time measuring commands also get stuck?

195 Views Asked by At
  • Some background and motivation

I'm working in a corporate that uses ClearCase for version control. In ClearCase, to work on a "branch" (stream) I have to enter a specific ClearCase shell for that stream. The issue I've been having is that sometime these ClearCase shells are slow.

  • Goal

I wanted to write a small script that would allow me to measure and print these performance hiccups. Once it's working I will use it to run other commands or send the information to the appropriate team.

  • My attempt

I use "time" command to measure how long it would take to run "sleep 0.1" 200 times, which should take exactly 20 seconds, and based on how long it actually took, I do some things.


while true;
do
  /usr/bin/time -f "%e" -o saved_timing bash -c "for ((i=1; i<=200; i++)) do sleep 0.1 ; echo hello > /dev/null ; done" 
  elapsed_time=$(cat saved_timing)
  elapsed_time=${elapsed_time%.*}
  [ "$elapsed_time" -lt 23 ] && echo -n $elapsed_time || echo -ne "\033[1;31m$elapsed_time\033[0m"
  echo -n " "
  if [ "$elapsed_time" -gt 35 ] 
  then
    notify-send "`echo $pwv`"
    exit 0
  fi
done

  • Example output

20 20 20 20 20 20 20 20 20 20 20 20 20 21 20 20 20 20 20 20 20 20 21 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 23 24 25 25 25 25 24 30 25 42

  • The question

As you can see, it sometimes works, but in fact there are many instances where there's very obvious latency, but when there's finally a print on the screen, it just shows a normal "20". I assume that this is because the "time" command itself got stuck, and not one of the "sleep" commands.

What can I do to solve this issue?

  • Note

When I'm outside of the ClearCase shell I do not have these gaps in performance, and maybe I can run two different scripts, one in each shell, and have them communicate somehow. They both have access to my homedir, for instance. However, I'm not quite sure how to leverage this idea and it it's the best approach.

Cheers.

0

There are 0 best solutions below