From: SK0001@ACAD.DRAKE.EDU (Sal Kabalani)
Newsgroups: comp.os.vms
Subject: CPU Time measurement on VMS.
Date: 23 Jan 93 00:52:45 GMT
Distribution: world
Organization: The Internet

LS> Hi: 
LS> 
LS>    I am a new user of OpenVMS running on Alpha. I have a problem and I am 
LS> asking for your help.  I have a FORTRAN program. I compile and link it and 
LS> use run command to run it.  My question is how I can measure the total CPU 
LS> used by the execution of the program.  In UNIX, I can easily use time to 
LS> do it.  But how do I do it in VMS?  Can some one help me?  Thanks a lot. 
LS> 
LS> 					Your Sincerely,
LS> 
LS> 					Lei Shi

Hello Lei

The following is a fragment of code from a program I wrote a few months ago.
The fragment reports CPU Time, Buffered I/O, Direct I/O and Page Faults used
during program execution. The way the code works is simple: you collect this 
information at the beginning of your program using sys$getjpi, then collect it 
again at the end, then report the difference.

The code is written in VAX basic, but it shouldn't be too difficult to convert
to FORTRAN. It was tested on a VAX 4600 running VMS 5.5-2. I do not have access
to an OpenVMS machine.

Hope this helps.

.-Sal A Kabalani----------+--Internet: SK0001 @ Acad.Drake.Edu----------------.
| Superv. of Operations   |     Phone: (515) 830-0436                         |
| Data Systems Department | VoiceMail: (515) 830-1086    II  I\  II  .IIII    |
| Iowa Network Services   |      Fax : (515) 830-0123    II  II\ II  III      |
| 4201 Corporate Drive    | Centralized Equal Access     II  II \II    III    |
| Des Moines, Iowa 50265  |         CIC 225              II  II  \I  IIII'    |
`----------------------- Programmers Do It With a Byte -----------------------'


!--------------------------------- Cut Here -----------------------------------!
Option type = explicit     ! All Variables must be explicitly declared

Record Item_List_3         ! Item List Record for SYS$GETJPI
    Variant
    Case
        Word Buff_Len
        Word Code       
        Long Buff_Add
        Long Len_Add
    case
        Long terminator
    end variant
end Record

Common (JPI_Vars)       Long    BUFIO         ,&
                                DIRIO         ,&             
                                PAGEFLTS      ,&            
                                CPUTIM        ,&           
                                BEG_BUFIO     ,&              
                                BEG_DIRIO     ,&              
                                BEG_PAGEFLTS  ,&              
                                BEG_CPUTIM                   

External Long function          sys$getjpiw

%include "$BASDEF" %from %library  "SYS$LIBRARY:basic$starlet.tlb"  
%Include "$JPIDEF" %from %Library  "Sys$LIbrary:BASIC$STARLET.TLB"   

External Long   Constant    SS$_Normal     ,&                  
                            JPI$_BUFIO     ,&                 
                            JPI$_CPUTIM    ,&                  
                            JPI$_DIRIO     ,&                  
                            JPI$_PAGEFLTS                    

Declare  Long               Sys_Status     
Declare  Word               Length
Declare  Real               Begin_CPUTIME


Def String Convert_Time (Long My_Time)
    !
    ! Function to convert time from 100ths of seconds to the format hh:mm:ss.hh
    !
    Declare Real this_time, Hours, Minutes, Seconds
    This_Time = My_Time
    This_Time = This_Time / '100'L
    Hours = Int (This_Time/'3600'L) 
    This_Time = This_Time - (Hours*'3600'L)
    Minutes = Int (This_Time/'60'L)
    Seconds = This_Time - (Minutes*'60'L)
    Convert_Time = Format$(Hours, "<0>#:") + Format$(Minutes,"<0>#:") + &
                   Format$(Seconds, "<0>#.##") 
End Def    

Get_Initial_Stats:
    Declare Item_list_3 Begin_JPI_Item_list(4)

    Begin_JPI_Item_List(0)::Buff_Len  = 4%                       
    Begin_JPI_Item_List(0)::Code      = Jpi$_BUFIO
    Begin_JPI_Item_List(0)::Buff_Add  = Loc(BEG_BUFIO)     
    Begin_JPI_Item_List(0)::Len_Add   = Loc(length)

    Begin_JPI_Item_List(1)::Buff_Len  = 4%                       
    Begin_JPI_Item_List(1)::Code      = Jpi$_CPUTIM
    Begin_JPI_Item_List(1)::Buff_Add  = Loc(BEG_CPUTIM)    
    Begin_JPI_Item_List(1)::Len_Add  = Loc(length)

    Begin_JPI_Item_List(2)::Buff_Len  = 4%                       
    Begin_JPI_Item_List(2)::Code      = Jpi$_DIRIO
    Begin_JPI_Item_List(2)::Buff_Add  = Loc(BEG_DIRIO)     
    Begin_JPI_Item_List(2)::Len_Add  = Loc(length)

    Begin_JPI_Item_List(3)::Buff_Len  = 4%                       
    Begin_JPI_Item_List(3)::Code      = Jpi$_PAGEFLTS
    Begin_JPI_Item_List(3)::Buff_Add  = Loc(BEG_PAGEFLTS)  
    Begin_JPI_Item_List(3)::Len_Add   = Loc(length)

    Begin_JPI_Item_List(4)::terminator   = 0                     
    
    Sys_status = Sys$getjpiw (,,,Begin_JPI_Item_list() by REF,,,) 
                     
    Print "Initial Process Statistics:"
    Print                                        
    Print "      Page Faults:          ";format$(beg_pageflts,"#,###,###")
    Print "      Cpu Time:           ";convert_Time(Beg_CPUTIM)
    Print "      Buffered I/O Count:     ";format$(beg_bufio,"###,###")
    Print "      Direct I/O Count:       ";format$(Beg_dirio,"###,###")


!
! Your program goes here
!


Get_Final_Stats:
    Declare Item_list_3 JPI_Item_list(4)

    JPI_Item_List(0)::Buff_Len  = 4%                         
    JPI_Item_List(0)::Code      = Jpi$_BUFIO
    JPI_Item_List(0)::Buff_Add  = Loc(BUFIO)     
    JPI_Item_List(0)::Len_Add   = Loc(length)

    JPI_Item_List(1)::Buff_Len  = 4%                         
    JPI_Item_List(1)::Code      = Jpi$_CPUTIM
    JPI_Item_List(1)::Buff_Add  = Loc(CPUTIM)    
    JPI_Item_List(1)::Len_Add  = Loc(length)

    JPI_Item_List(2)::Buff_Len  = 4%                         
    JPI_Item_List(2)::Code      = Jpi$_DIRIO
    JPI_Item_List(2)::Buff_Add  = Loc(DIRIO)     
    JPI_Item_List(2)::Len_Add  = Loc(length)

    JPI_Item_List(3)::Buff_Len  = 4%                         
    JPI_Item_List(3)::Code      = Jpi$_PAGEFLTS
    JPI_Item_List(3)::Buff_Add  = Loc(PAGEFLTS)  
    JPI_Item_List(3)::Len_Add   = Loc(length)

    JPI_Item_List(4)::terminator   = 0                           

    Sys_status = Sys$getjpiw (,,,JPI_Item_list() by REF,,,)      
                
Report_Final_Statistics:
    Print                                        
    Print "Program Execution Statistics:"
    Print                                        
    Print "      Page Faults:          ";format$(pageflts-beg_pageflts,"#,###,###")
    Print "      Cpu Time:           ";convert_Time(CPUTIM-Beg_CPUTIM)
    Print "      Buffered I/O Count:     ";format$(bufio-beg_bufio,"###,###")
    Print "      Direct I/O Count:       ";format$(dirio-Beg_dirio,"###,###")