#  Script name is awk_shorten.  It is called by /usr/contrib/bin/gp_list
#
#  This awk script takes the output from the profiler which has been
#  through the formatting script '/usr/contrib/bin/gp_list' and the re-formatting
#  script awk_percent.  The result of these is a format containing
#  the name of the routine, % of the total hits of COUNT1, the total numbers
#  for COUNT1 through COUNT4, and the total hits for the routine.
#  The script takes all the lines whose % is greater than 0 and prints
#  them.  The result is usually a MUCH shorter profiler output.
#
#  The general format for the data coming into the script is:
#
#   NAME   % (of COUNT1 total)   COUNT1   COUNT2   COUNT3   COUNT4  TOTAL
#
#  Set up variables at beginning of awk script; start will indicate whether
#  or not the actual profile data has been found (i.e. the lines for
#  total hits and idle have been scanned). 
#
BEGIN { 
  start = 0;
}
#  Now begin scanning the profile data.  Start has been initialized to
#  0, and as long as this is true and the first piece of data in the line
#  is not "NAME" then you have the header for the profile.  In this
#  case, all you want to do is print the lines and then go to the next
#  line (record).
{
#
  while ( ($1 != "NAME") && (start != 1) )
     {
       print $0;
       next;
     };

#  This next part occurs when the current record has "NAME" as the
#  first thing in the line.  This is the header line.  You just want
#  to print it out; but it indicates that the following lines contain
#  profiler data.
#
  if ( start != 1)
    {
       print $0;
       start = 1;
    }

#  Now the start variable is 1, and the second thing on the line is the
#  percentage of the total COUNT1 hits.  Basically, we will print the 
#  line as long as this percentage is greater than zero.  Otherwise it
#  will be skipped.
#
    else if ( (start == 1) && ($2 > 0.0) )
      {
        print $0;
        next;
      }

#  This loop prints blank lines.  If the line length is 0 and it's included
#  in the regular profile data we just print it out without trying to
#  interpret it.  Then we go to the next line.
#
      else if ( ((start == 1) && (length ($0) == 0)) || ($2 == "ERROR") )
        {
	  print $0;
	  next;
        };
}
