All files / src/utils zcl_abapgit_timer.clas.abap

100% Statements 106/106
100% Branches 0/0
100% Functions 0/0
100% Lines 106/106

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 1071x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
CLASS zcl_abapgit_timer DEFINITION
  PUBLIC
  FINAL
  CREATE PRIVATE.
 
  PUBLIC SECTION.
 
    CLASS-METHODS create
      IMPORTING
        !iv_text        TYPE string OPTIONAL
        !iv_count       TYPE i OPTIONAL
          PREFERRED PARAMETER iv_text
      RETURNING
        VALUE(ro_timer) TYPE REF TO zcl_abapgit_timer.
 
    METHODS constructor
      IMPORTING
        !iv_text  TYPE string OPTIONAL
        !iv_count TYPE i OPTIONAL.
 
    METHODS start
      RETURNING
        VALUE(ro_timer) TYPE REF TO zcl_abapgit_timer.
 
    METHODS end
      IMPORTING
        !iv_output_as_status_message TYPE abap_bool DEFAULT abap_false
      RETURNING
        VALUE(rv_result)             TYPE string.
 
  PROTECTED SECTION.
  PRIVATE SECTION.
 
    DATA mv_text TYPE string.
    DATA mv_count TYPE i.
    DATA mv_timer TYPE timestampl.
 
ENDCLASS.
 
 
 
CLASS zcl_abapgit_timer IMPLEMENTATION.
 
 
  METHOD constructor.
    mv_text  = iv_text.
    mv_count = iv_count.
  ENDMETHOD.
 
 
  METHOD create.
    CREATE OBJECT ro_timer
      EXPORTING
        iv_text  = iv_text
        iv_count = iv_count.
  ENDMETHOD.
 
 
  METHOD end.
 
    DATA:
      lv_timestamp TYPE timestampl,
      lv_runtime   TYPE timestampl,
      lv_sec       TYPE p LENGTH 11 DECIMALS 2.
 
    IF mv_timer IS INITIAL.
      rv_result = 'Runtime measurement has not been started'.
    ELSE.
      GET TIME STAMP FIELD lv_timestamp.
 
      TRY.
          lv_runtime = cl_abap_tstmp=>subtract(
            tstmp1 = lv_timestamp
            tstmp2 = mv_timer ).
 
          lv_sec = lv_runtime. " round to 2 decimal places
 
          IF mv_count = 1.
            rv_result = |1 object, |.
          ELSEIF mv_count > 1.
            rv_result = |{ mv_count } objects, |.
          ENDIF.
 
          rv_result = rv_result && |{ lv_sec } seconds|.
 
        CATCH cx_parameter_invalid.
          rv_result = 'Error getting runtime measurement'.
      ENDTRY.
    ENDIF.
 
    IF iv_output_as_status_message = abap_true.
      MESSAGE s000(oo) WITH mv_text rv_result.
    ENDIF.
 
    IF mv_text IS NOT INITIAL.
      rv_result = |{ mv_text } { rv_result }|.
    ENDIF.
 
  ENDMETHOD.
 
 
  METHOD start.
    GET TIME STAMP FIELD mv_timer.
    ro_timer = me.
  ENDMETHOD.
ENDCLASS.