[GE users] Retrieving details about finished jobs

Reuti reuti at staff.uni-marburg.de
Wed Mar 16 13:50:45 GMT 2005


Hi,

may I step in? To me it looks like a perfect task for awk. Please find 
attached a script, make it executable and test it to get the requested 
behavior.

I don't know the exact numerical precision of awk, but the sums are 
correct. Only thing is, that I see a difference between ./accounting -a 
and qacct (without any option).

Cheers - Reuti

Michal Ludvig wrote:
> Ron Chen wrote:
> 
>>Can you provide more detail? How exactly would you
>>like the output to be formated?
> 
> 
> Ideally it would be "qacct -o <user> -A" to get a list of
> per-account_string lines. Something like:
> 
> ACCT_STR    WALLCLOCK         UTIME         STIME           CPU   [...]
> ==================================================================[...]
> alloc_sh           50            45             0            46   [...]
> test1              16            15             0            15   [...]
> big_array         926             3             4             7   [...]
> ALL            254612          1007           123          1191   [...]
> 
> Michal Ludvig
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe at gridengine.sunsource.net
> For additional commands, e-mail: users-help at gridengine.sunsource.net


    [ Part 2: "Attached Text" ]

#!/bin/bash
#
# accounting will reformat the output of the qacct command by SGE.
#
# Version 1.0 - 2005-03-16 Initial release
#
# Copyright (C) 2005 Reuti, email: reuti at staff.uni-marburg.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

#
# If there is an unrecoverable error: display a message and exit.
#

function printExit
{
    case $1 in
        [iI]) echo INFO: "$2" >&2 ;;
        [wW]) echo WARNING: "$2" >&2 ;;
        [eE]) echo ERROR: "$2" ; exit 1 >&2 ;;
           *) echo $1 >&2 ;;
    esac
}

#
# System depended setups.
#

platform=`uname -s`
case $platform in

    SunOS) awk_command=/usr/xpg4/bin/awk ;;

        *) awk_command=awk ;;

esac
awk_path=`which $awk_command`
if [ ! -r "$awk_path" -o ! -x "$awk_path" ] ; then
    printExit W "No executable awk program found."
    printExit E "Please update the path to awk in \"status\" according to your installation."
fi 

#
# First define some functions.
#

function usage
{
    cat <<-EOF

	NAME
	    accounting - Display detailed accounting

	SYNTAX
	    accounting [ options ] [ <user> ]

	DESCRIPTION
	    Displays the accounting of your own by default. When a <user>
	    is specified, only the accounting belonging to this user will 
	    be displayed.

	OPTIONS

	    -a
	        Display the accounting of all users. May not be used, when there
	        is a dedicated user specified.

	    -h
	        Get this help page.

        Version 1.0              16 March 2005              accounting(1)
	EOF
    exit 0
}

#
# Analyze the given parameters to the command.
#

while getopts :ah options ; do
    case $options in

        a) CMDOPT_A="1" ;;

        h) usage ;;

       \?) printExit E "Invalid option: -$OPTARG." ;;

    esac
done

#
# Shift the arguments up to the input without the option prefix "-".
# This should be the user name.
#

shift $((OPTIND-1))

#
# Test, whether was a user specified.
#

if [ -n "$CMDOPT_A" ] ; then
    if [ -n "$1" ] ; then
        printExit E "You may only specify -a *or* an user, but not both."
    else
        myuser="*"
    fi
else
    if [ -n "$1" ] ; then
        myuser="$1"
    else
        myuser="$USER"
    fi
    selection="-o $myuser"
fi

#
# Now do it.
#

#
# Do the accounting.
#

qacct -j $selection | $awk_command '

        BEGIN { firstrun=1 }

        /^account/           { if (firstrun)
                               {
                                   firstrun=0
                               }
   
                               account=$2

                             }

        /^ru_wallclock/      { wallclock[account]+=$2 }

        /^ru_utime/          { utime[account]+=$2 }

        /^ru_stime/          { stime[account]+=$2 }

        /^cpu/               { cpu[account]+=$2 }

        /^mem/               { mem[account]+=$2 }

        /^iow/               { iow[account]+=$2
                               next }

        /^io/                { io[account]+=$2 }

        END { if (! firstrun)
              {
                  printf ("Accounting for user: %s\n", user)
                  printf ("\n")
                  printf ("ACCOUNT         WALLCLOCK         UTIME         STIME           CPU             MEMORY                 IO                IOW\n")
                  printf ("============================================================================================================================\n")
                  sort_command="sort"

                  for (account in utime)
                  {
                      total_wallclock+=wallclock[account]
                      total_utime+=utime[account]
                      total_stime+=stime[account]
                      total_cpu+=cpu[account]
                      total_mem+=mem[account]
                      total_io+=io[account]
                      total_iow+=iow[account]

                      printf("%-15s %9d %13d %13d %13d %18.3f %18.3f %18.3f\n",
                             account, wallclock[account], utime[account], stime[account], cpu[account], mem[account], io[account], iow[account]) | sort_command
                  }

                  close(sort_command)

                  printf ("============================================================================================================================\n")
                  printf("Total           %9d %13d %13d %13d %18.3f %18.3f %18.3f\n",
                         total_wallclock, total_utime, total_stime, total_cpu, total_mem, total_io, total_iow)

              }
            } ' user="$myuser" 

#
# So, that's all
#

exit 0



    [ Part 3: "Attached Text" ]

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe at gridengine.sunsource.net
For additional commands, e-mail: users-help at gridengine.sunsource.net



More information about the gridengine-users mailing list