Wednesday, April 15, 2015

Display the true average response time, CPU time, db time ...

REPORT ZTRUERSP NO STANDARD PAGE HEADING.
*********************************************************************
* Display the true average response time.
* The result of this report contains the same data the ST03-workload
* overview screen has with one major difference: the values belonging
* to a defined set of abaps usually running online and taking a very
* long time to complete are ignored during the calculation. These
* abap's response time is not a real dialog response time (even if 
* they run in dialog mode) and it can completely offset the actual
* response time of ST03 as well as all the other values (cpu time,
* sequential read ...)
*********************************************************************
TABLES: TRDIR.
DATA: R TYPE P DECIMALS 1, K TYPE P DECIMALS 1, I TYPE I, X TYPE I,
      Y TYPE I, ELEM_PER_ROW TYPE I VALUE 8, LASTREC(8), ELAPSTIM(8).
*
DATA: BEGIN OF LIST OCCURS 10.
        INCLUDE STRUCTURE MSXXLIST.
DATA: END OF LIST.
DATA: BEGIN OF SUMMARY OCCURS 50.
        INCLUDE STRUCTURE SAPWLSUMRY.
DATA: END OF SUMMARY.
DATA: BEGIN OF  HI OCCURS 50.
        INCLUDE STRUCTURE SAPWLHITL.
DATA: END OF HI.
DATA: BEGIN OF STAB.
        INCLUDE STRUCTURE SAPWLSUMRY.
DATA: END OF STAB.
*
PARAMETERS: DATE LIKE SY-DATUM MODIF ID SC1 OBLIGATORY.
PARAMETERS: SERVER(8) MODIF ID SC1 OBLIGATORY LOWER CASE.
PARAMETERS: TRUE_RSP AS CHECKBOX.
SELECT-OPTIONS ABPAP FOR TRDIR-NAME  NO INTERVALS.
*
PERFORM CALCULATE.
FORMAT INTENSIFIED OFF.
* box1
PERFORM BOX USING 1 4 'Instance'.
SKIP TO LINE 2. POSITION 2.
* line1
WRITE: /2 'SAP System',
       18 SY-SYSID,
       29 'First record',
       45 '00:00:00',
       56 'Date',
       72 DATE.
* line2
IF DATE = SY-DATUM.
  LASTREC = SY-UZEIT.
ELSE.
  LASTREC = '235959'.
ENDIF.

WRITE: / 'Server' UNDER 'SAP System',
       SY-HOST UNDER SY-SYSID,
       'Last record' UNDER 'First record',
       LASTREC USING EDIT MASK '__:__:__' UNDER '00:00:00'.
* line3
READ TABLE LIST INDEX 1.
TRANSLATE LIST-SERV USING 's a p d '.
CONDENSE LIST-SERV NO-GAPS.
WRITE: / 'Instance no.' UNDER 'SAP System',
       LIST-SERV UNDER SY-SYSID,
       'Elapsed time' UNDER 'First record',
       LASTREC USING EDIT MASK '__:__:__' UNDER '00:00:00'.
* box2
PERFORM BOX USING 7 14 'Workload'.
SKIP TO LINE 8. POSITION 2.
* line1
WRITE: /2 'CPU time',
       26 STAB-CPUTI LEFT-JUSTIFIED,
       38 'Database calls',
       62 STAB-PHYCALLS LEFT-JUSTIFIED.
* line2
R = STAB-READDIRCNT + STAB-READSEQCNT + STAB-CHNGCNT.
WRITE: / 'Elapsed time' UNDER 'CPU time',
         STAB-ELAPSEDTI UNDER STAB-CPUTI LEFT-JUSTIFIED,
         'Database requests' UNDER 'Database calls',
         R UNDER STAB-PHYCALLS LEFT-JUSTIFIED.
* line3
WRITE: / ' Direct reads' UNDER 'Database calls',
         STAB-READDIRCNT UNDER STAB-PHYCALLS LEFT-JUSTIFIED.
* line4
WRITE: / 'Dialog steps' UNDER 'CPU time',
         STAB-COUNT UNDER STAB-CPUTI LEFT-JUSTIFIED,
         'Sequential reads' UNDER 'Database calls',
         STAB-READSEQCNT UNDER STAB-PHYCALLS LEFT-JUSTIFIED.
* line5
R = STAB-RESPTI / STAB-COUNT.
WRITE: / ' AV. response time' UNDER 'CPU time',
         R UNDER STAB-CPUTI LEFT-JUSTIFIED,
         'Changes' UNDER 'Database calls',
         STAB-CHNGCNT UNDER STAB-PHYCALLS LEFT-JUSTIFIED.
* line6
R = STAB-CPUTI / STAB-COUNT.
WRITE: / ' AV. CPU time' UNDER 'CPU time',
         R UNDER STAB-CPUTI LEFT-JUSTIFIED.
* line7
R = STAB-QUEUETI / STAB-COUNT.
K = STAB-READDIRTI + STAB-READSEQTI + STAB-CHNGTI.
K = K / ( STAB-READDIRCNT + STAB-READSEQCNT + STAB-CHNGCNT ).
WRITE: / ' AV. wait time' UNDER 'CPU time',
         R UNDER STAB-CPUTI LEFT-JUSTIFIED,
         'Time per DB request' UNDER 'Database calls',
         K UNDER STAB-PHYCALLS LEFT-JUSTIFIED.
* line8
R = STAB-READDIRTI / STAB-READDIRCNT.
K = STAB-LOADGENTI / STAB-COUNT.
WRITE: / ' AV. load time' UNDER 'CPU time',
         K UNDER STAB-CPUTI LEFT-JUSTIFIED,
         ' Direct reads' UNDER 'Database calls',
         R UNDER STAB-PHYCALLS LEFT-JUSTIFIED.
* line9
R = STAB-READSEQTI / STAB-READSEQCNT.
K = ( STAB-READDIRTI + STAB-READSEQTI + STAB-CHNGTI ) / STAB-COUNT.
WRITE: / ' AV. DB req. time' UNDER 'CPU time',
         K UNDER STAB-CPUTI LEFT-JUSTIFIED,
         '  Sequential reads' UNDER 'Database calls',
         R UNDER STAB-PHYCALLS LEFT-JUSTIFIED.
* line10
R = ( STAB-BYTES / 1024 ) / STAB-COUNT.
K = STAB-CHNGTI / STAB-CHNGCNT.
IF TRUE_RSP = 'X'.
  WRITE: / ' AV. bytes req.' UNDER 'CPU time' COLOR 6,
           R UNDER STAB-CPUTI LEFT-JUSTIFIED COLOR 6,
           '  Changes and commis' UNDER 'Database calls',
           K UNDER STAB-PHYCALLS LEFT-JUSTIFIED.
ELSE.
  WRITE: / ' AV. bytes req.' UNDER 'CPU time',
           R UNDER STAB-CPUTI LEFT-JUSTIFIED,
           '  Changes and commis' UNDER 'Database calls',
           K UNDER STAB-PHYCALLS LEFT-JUSTIFIED.
ENDIF.
* line11
WRITE: / .
* line12
R = STAB-ROLLINTI / STAB-ROLLINCNT.
WRITE: / 'Roll-ins' UNDER 'CPU time',
         STAB-ROLLINCNT UNDER STAB-CPUTI LEFT-JUSTIFIED,
         'Av. time/roll in' UNDER 'Database calls',
         R UNDER STAB-PHYCALLS LEFT-JUSTIFIED.
* line13
R = STAB-ROLLOUTTI / STAB-ROLLOUTCNT.
WRITE: / 'Roll-outs' UNDER 'CPU time',
         STAB-ROLLOUTCNT UNDER STAB-CPUTI LEFT-JUSTIFIED,
         'Av. time/roll out' UNDER 'Database calls',
         R UNDER STAB-PHYCALLS LEFT-JUSTIFIED.
* box3
PERFORM BOX USING 23 6 'Task types'.
SKIP TO LINE 24. POSITION 2.
WRITE /2
'Only dialog times! The following long running reports are excluded:'.
FORMAT INTENSIFIED ON.
LOOP AT ABPAP.
  Y = 25 + ( ( SY-TABIX - 1 ) DIV ELEM_PER_ROW ).
  X = ( ( SY-TABIX - 1 ) MOD ELEM_PER_ROW ) * 9 + 2.
  SKIP TO LINE Y. POSITION X.
  WRITE ABPAP-LOW.
ENDLOOP.
*
INITIALIZATION.
  DATE = SY-DATUM.
  SERVER = SY-HOST.
*
*---------------------------------------------------------------------*
* FORM BOX                                                            *
*---------------------------------------------------------------------*
FORM BOX USING VALUE(YPOS) HEIGHT TEXT.
*
  DATA: WIDTH TYPE I VALUE 84,
        R TYPE I, K TYPE I.
* Bottom horizontal line
  R = HEIGHT + YPOS.
  SKIP TO LINE R.
  DO WIDTH TIMES.
    WRITE '-' NO-GAP.
  ENDDO.
* Top horizontal line with text
  K = STRLEN( TEXT ).
  R = WIDTH - 2 - K.
  SKIP TO LINE YPOS.
  WRITE:  '--'.
  WRITE AT 3(K) TEXT NO-GAP.
  DO R TIMES.
    WRITE:  '-' NO-GAP.
  ENDDO.
* Vertical lines
  DO HEIGHT TIMES.
    SKIP TO LINE YPOS.
    WRITE: '|'. POSITION WIDTH. WRITE: '|'.
    YPOS = YPOS + 1.
  ENDDO.
ENDFORM.
*---------------------------------------------------------------------*
*       FORM CALCULATE                                                *
*---------------------------------------------------------------------*
FORM CALCULATE.
* Get the performance data
  CALL FUNCTION 'TH_SERVER_LIST'
       TABLES
            LIST = LIST.
  CALL FUNCTION 'SAPWL_GET_SUMMARY_STATISTIC'
       EXPORTING
            PERIODTYPE     = 'D'
            HOSTID         = SERVER
            STARTDATE      = SY-DATUM
       TABLES
            SUMMARY        = SUMMARY
            HITLIST_RESPTI = HI.
  LOOP AT SUMMARY.
    IF SUMMARY-TASKTYPE = 'DIALOG'.
      MOVE-CORRESPONDING SUMMARY TO STAB.
    ENDIF.
  ENDLOOP.
* Correction with the abaps
  IF TRUE_RSP = 'X'.
    LOOP AT HI.
      LOOP AT ABPAP.
        IF HI-REPORT = ABPAP-LOW.
          STAB-CHNGCNT = STAB-CHNGCNT - HI-UPDCNT -
                            HI-DELCNT - HI-INSCNT.
          STAB-CHNGTI = STAB-CHNGTI - HI-UPDTI - HI-DELTI -
                  HI-INSTI.
          STAB-COUNT = STAB-COUNT - 1.
          STAB-CPUTI = STAB-CPUTI - HI-CPUTI.
          STAB-LOADGENTI = STAB-LOADGENTI - HI-GENERATETI -
                  HI-REPLOADTI - HI-CUALOADTI - HI-DYNPLOADTI.
          STAB-PHYCALLS = STAB-PHYCALLS - HI-PHYDELCNT -
                  HI-PHYREADCNT - HI-PHYINSCNT - HI-PHYUPDCNT.
          STAB-QUEUETI = STAB-QUEUETI - HI-QUEUETI.
          STAB-READDIRCNT = STAB-READDIRCNT - HI-READDIRCNT.
          STAB-READDIRTI = STAB-READDIRTI - HI-READDIRTI.
          STAB-READSEQCNT = STAB-READSEQCNT - HI-READSEQCNT.
          STAB-READSEQTI = STAB-READSEQTI - HI-READSEQTI.
          STAB-RESPTI = STAB-RESPTI - HI-RESPTI.
          STAB-ROLLINCNT = STAB-ROLLINCNT - HI-ROLLINCNT.
          STAB-ROLLOUTCNT = STAB-ROLLOUTCNT - HI-ROLLOUTCNT.
          STAB-ROLLOUTTI = STAB-ROLLOUTTI - HI-ROLLOUTTI.
        ENDIF.
      ENDLOOP.
    ENDLOOP.
  ENDIF.
ENDFORM.

No comments:

Post a Comment