PyLoadL

Python Bindings for IBM LoadLeveler


 

Contents

Introduction

Example Code

API :

Download

Issues / ToDo

Miscellaneous

Links / Info

Example Code

Below is a PyLoadL example that generates output similar to the LoadLeveler llq command. This is the style I'm aiming the module to achieve, however issues and limitations in my coding my force this to change.

from pyloadl import *
from time import gmtime, strftime

stepstate = [
    "I", "P", "ST", "R",
    "CP", "XP", "RP",
    "VP", "C", "X", "RM",
    "V", "CA", "NR", "TX",
    "?", "SX", "H", "D",
    "NQ", "E", "EP",
    "MP" ]

HoldType = ["","H","S","HS"]

jobs_total = 0
jobs_run = 0
jobs_idle = 0
jobs_pending = 0
jobs_held = 0
jobs_preempt = 0

# Query Job information

query = ll_query(JOBS)
if not PyCObjValid(query):
   print "ll_query(): returns NULL\n"
   exit(-1)

retval = ll_set_request(query, QUERY_ALL, "", ALL_DATA)
job, num, err = ll_get_objs(query, LL_CM, "")

if num > 0:

   print "Id                        Owner      Submitted   ST PRI Class        Running On"
   print "------------------------- ---------- ----------- -- --- ------------ -------------"

   while PyCObjValid(job):

      cred  = ll_get_data(job,  LL_JobCredential)
      owner = ll_get_data(cred, LL_CredentialUserName)

      sdate = ll_get_data(job, LL_JobSubmitTime)
      date = ""
      if sdate != 0:
        sdate = gmtime(sdate)
        date  = strftime("%m/%d %H:%M", sdate)

      # Loop through all steps for this job

      step = ll_get_data(job, LL_JobGetFirstStep)
      while PyCObjValid(step):

        jobs_total = jobs_total + 1

        state  = ll_get_data(step, LL_StepState)
        status = stepstate[state]

        if status == "R":   jobs_run = jobs_run + 1
        if status == "I":   jobs_idle = jobs_idle + 1
        if status == "NQ":  jobs_pending = jobs_pending + 1
        if status == "E":   jobs_preempt = jobs_preempt + 1

        if machine = ""
        if ( state == STATE_RUNNING ):
           machine_obj = ll_get_data(step, LL_StepGetFirstMachine)
           if PyCObjValid(machine_obj):
              machine = ll_get_data(machine_obj, LL_MachineName)
        else:
           holdtype = ll_get_data(step, LL_StepHoldType)
           if ( holdtype > 0 ):
              status = HoldType[holdtype]
              jobs_held = jobs_held + 1

        id     = ll_get_data(step, LL_StepID)
        pri    = ll_get_data(step, LL_StepPriority)
        jclass = ll_get_data(step, LL_StepJobClass)

        print "%-25s %-10s %-11s %-2s %-3d %-12s %-13s" % 
                 (id, owner, date, status, pri, jclass, machine)

        step = ll_get_data(job, LL_JobGetNextStep)

      job = ll_next_obj(query)

# Free and deallocate objects used by LoadLeveler

ll_free_objs(job)
ll_deallocate(query)

if ( jobs_total > 0 ):
   print ""
   print "%d job step(s) in queue, %d waiting, %d pending, %d running, %d held, %d preempted" % 
             ( jobs_total, jobs_idle, jobs_pending, jobs_run, jobs_held, jobs_preempt)
else:
   print "llq: There is currently no job status to report."