+ Reply to Thread
Results 1 to 3 of 3

get time end of a process can capture(Stored Procedure)

  1. get time end of a process can capture(Stored Procedure)

    As I get time end of a process
    can capture? cpu time consumed (%)
    find time elapsed (Oracle 8i)
    I have this SP ,I catch the same time
    Thank you

    CREATE OR REPLACE PROCEDURE SPG_EXAMPLE
    ( p_fecha IN VARCHAR2,
    p_descripcion OUT VARCHAR2,
    p_estado OUT NUMBER,
    P_registros OUT NUMBER,
    p_message OUT VARCHAR2,
    p_inicio OUT DATE
    p_fin OUT DATE

    )
    IS
    TYPE T_numero IS TABLE OF AGENCIAS.NUMERO%type;
    TYPE T_indicador IS TABLE OF AGENCIAS.INDICADOR%type;
    v_numero T_numero;
    v_indicador T_indicador;
    ld_inicio DATE;
    ld_fin DATE;
    ld_diff DATE;
    lv_SQL2 VARCHAR2(2000);
    lv_Count NUMBER;
    v_errornumber CHAR(10);
    v_errortext CHAR(100);
    v_descripcin VARCHAR2(2000) :='CARGA AGENCIAS';
    BEGIN
    ld_inicio := sysdate;===> STARTTIME
    p_inicio := ld_inicio;
    p_estado:= 0;
    p_message:='';
    p_descripcion:=v_descripcin;
    lv_SQL2:='select count(ROWID) from agencias2 ' ;

    select numero,indicador

    BULK COLLECT INTO v_numero ,v_indicador
    FROM agencias;


    FORALL i IN v_numero.FIRST..v_numero.LAST
    INSERT INTO agencias2
    (numero, indicador,
    usuariocreacion, fechacreacion,
    usuarioactualizacion, fechaactualizacion)

    VALUES( v_numero(i) ,v_indicador(i),'PRUEBA',SYSDATE,'PRUEBA',SYSDATE);
    COMMIT;
    p_estado := 1;

    EXECUTE IMMEDIATE lv_SQL2 INTO lv_Count;
    P_registros:=lv_Count;
    p_message:=('Se Insertaron un Total de :'|| lv_Count||'
    Registros');
    ld_fin := sysdate; --- end time

    EXCEPTION
    WHEN others THEN
    ROLLBACK;
    v_errornumber := SQLCODE;
    v_errortext := substr(SQLERRM,1,100);
    Raise_application_error(-20002, 'Error al insertar:' ||
    v_errornumber || v_errortext);
    END SPGT147_CARGAAGENCIAS;

  2. Re: get time end of a process can capture(Stored Procedure)

    On Aug 19, 12:18*pm, EliasFigueroa wrote:
    > As I get time end of a process
    > can capture? cpu time consumed (%)
    > find time elapsed (Oracle 8i)
    > I have this SP ,I catch the same time
    > Thank you
    >
    > CREATE OR REPLACE PROCEDURE SPG_EXAMPLE
    > *( p_fecha * * * IN VARCHAR2,
    > * *p_descripcion OUT VARCHAR2,
    > * *p_estado * * *OUT NUMBER,
    > * *P_registros * OUT NUMBER,
    > * *p_message * * OUT VARCHAR2,
    > * *p_inicio * * *OUT DATE
    > * *p_fin * * * * OUT DATE
    >
    > *)
    > IS
    > * * TYPE T_numero *IS TABLE OF AGENCIAS.NUMERO%type;
    > * * TYPE T_indicador IS TABLE OF AGENCIAS.INDICADOR%type;
    > * * v_numero * * *T_numero;
    > * * v_indicador * T_indicador;
    > * * ld_inicio * * DATE;
    > * * ld_fin * * * *DATE;
    > * * ld_diff * * * DATE;
    > * * lv_SQL2 * * * VARCHAR2(2000);
    > * * lv_Count * * *NUMBER;
    > * * v_errornumber CHAR(10);
    > * * v_errortext * CHAR(100);
    > * * v_descripcin VARCHAR2(2000) :='CARGA AGENCIAS';
    > BEGIN
    > * * ld_inicio := sysdate;===> STARTTIME
    > * * p_inicio *:= ld_inicio;
    > * * p_estado:= 0;
    > * * p_message:='';
    > * * p_descripcion:=v_descripcin;
    > * * lv_SQL2:='select count(ROWID) from agencias2 ' ;
    >
    > select numero,indicador
    >
    > BULK COLLECT INTO v_numero ,v_indicador
    > FROM agencias;
    >
    > * * * * FORALL i IN v_numero.FIRST..v_numero.LAST
    > * * * * *INSERT *INTO *agencias2
    > * * * * * * * * * * (numero, indicador,
    > * * * * * * * * * * *usuariocreacion, fechacreacion,
    > * * * * * * * * * * *usuarioactualizacion, fechaactualizacion)
    >
    > VALUES( v_numero(i) ,v_indicador(i),'PRUEBA',SYSDATE,'PRUEBA',SYSDATE);
    > * * * * * * * * * COMMIT;
    > * * * * p_estado := 1;
    >
    > * * * * *EXECUTE IMMEDIATE lv_SQL2 INTO lv_Count;
    > * * * * *P_registros:=lv_Count;
    > * * * * * p_message:=('Se Insertaron un Total de :'|| lv_Count||'
    > Registros');
    > * * * * * ld_fin := sysdate; --- end time
    >
    > EXCEPTION
    > * WHEN others THEN
    > * * * * *ROLLBACK;
    > * * * * *v_errornumber := SQLCODE;
    > * * * * *v_errortext * := substr(SQLERRM,1,100);
    > * * * * *Raise_application_error(-20002, 'Error al insertar:' ||
    > v_errornumber || v_errortext);
    > END SPGT147_CARGAAGENCIAS;


    1 - if you can run the stored procedure from SQLPlus would the set
    timing on command be good enough?
    2 - Have you looked at the SQL trace facility?
    3 - You could modify the code to grap the timestamp at the start of
    the procedure and again at the end of the procedure where you could
    either display the information or store it to a table.

    HTH -- Mark D Powell --

  3. Re: get time end of a process can capture(Stored Procedure)

    On Aug 19, 11:18*am, EliasFigueroa wrote:
    > As I get time end of a process
    > can capture? cpu time consumed (%)
    > find time elapsed (Oracle 8i)
    > I have this SP ,I catch the same time
    > Thank you
    >
    > CREATE OR REPLACE PROCEDURE SPG_EXAMPLE
    > *( p_fecha * * * IN VARCHAR2,
    > * *p_descripcion OUT VARCHAR2,
    > * *p_estado * * *OUT NUMBER,
    > * *P_registros * OUT NUMBER,
    > * *p_message * * OUT VARCHAR2,
    > * *p_inicio * * *OUT DATE
    > * *p_fin * * * * OUT DATE
    >
    > *)
    > IS
    > * * TYPE T_numero *IS TABLE OF AGENCIAS.NUMERO%type;
    > * * TYPE T_indicador IS TABLE OF AGENCIAS.INDICADOR%type;
    > * * v_numero * * *T_numero;
    > * * v_indicador * T_indicador;
    > * * ld_inicio * * DATE;
    > * * ld_fin * * * *DATE;
    > * * ld_diff * * * DATE;
    > * * lv_SQL2 * * * VARCHAR2(2000);
    > * * lv_Count * * *NUMBER;
    > * * v_errornumber CHAR(10);
    > * * v_errortext * CHAR(100);
    > * * v_descripcin VARCHAR2(2000) :='CARGA AGENCIAS';
    > BEGIN
    > * * ld_inicio := sysdate;===> STARTTIME
    > * * p_inicio *:= ld_inicio;
    > * * p_estado:= 0;
    > * * p_message:='';
    > * * p_descripcion:=v_descripcin;
    > * * lv_SQL2:='select count(ROWID) from agencias2 ' ;
    >
    > select numero,indicador
    >
    > BULK COLLECT INTO v_numero ,v_indicador
    > FROM agencias;
    >
    > * * * * FORALL i IN v_numero.FIRST..v_numero.LAST
    > * * * * *INSERT *INTO *agencias2
    > * * * * * * * * * * (numero, indicador,
    > * * * * * * * * * * *usuariocreacion, fechacreacion,
    > * * * * * * * * * * *usuarioactualizacion, fechaactualizacion)
    >
    > VALUES( v_numero(i) ,v_indicador(i),'PRUEBA',SYSDATE,'PRUEBA',SYSDATE);
    > * * * * * * * * * COMMIT;
    > * * * * p_estado := 1;
    >
    > * * * * *EXECUTE IMMEDIATE lv_SQL2 INTO lv_Count;
    > * * * * *P_registros:=lv_Count;
    > * * * * * p_message:=('Se Insertaron un Total de :'|| lv_Count||'
    > Registros');
    > * * * * * ld_fin := sysdate; --- end time
    >
    > EXCEPTION
    > * WHEN others THEN
    > * * * * *ROLLBACK;
    > * * * * *v_errornumber := SQLCODE;
    > * * * * *v_errortext * := substr(SQLERRM,1,100);
    > * * * * *Raise_application_error(-20002, 'Error al insertar:' ||
    > v_errornumber || v_errortext);
    > END SPGT147_CARGAAGENCIAS;


    You're collecting elapsed time, not CPU time, for this procedure, and
    they can be, and most likely will be, different. Out of 100 seconds
    of elapsed time you may have spent 2 seconds actually using the CPU
    to do work. If you're licensed to use the Automatic Workload
    Repository you can query the AWR tables/views and possibly return the
    actual (or estimated) CPU time for a given session; taking 'readings'
    at the start and at the end of your procedure thenn computing the
    difference would give you a rough estimate of the actual CPU time
    consumed, which will probably be much less than the total elapsed time
    you're computing now.

    You could query V$SESSTAT for 'CPU used by this session' at the start
    and end of your processing, compute the difference and divide by 100
    to get seconds of CPU time consumed, but this will only give you a
    rough estimate as the value is updated for each interval of 10
    milliseconds. An example is shown below:

    SQL> declare
    2 usid number;
    3 cpu_elapsed number;
    4 cpu_start number;
    5 cpu_end number;
    6 start_time date;
    7 end_time date;
    8 x number;
    9 begin
    10 start_time := sysdate;
    11 select value*10
    12 into cpu_start
    13 from v$sesstat s, v$statname n
    14 where s.statistic# = n.statistic#
    15 and n.name = 'CPU used by this session'
    16 and sid = (select sid from v$session where
    sys_context('USERENV','SESSIONID') = audsid);
    17
    18 for i in 0..255 loop
    19 dbms_output.put_line('Code '||i||' = '||chr(i));
    20 for j in 1..50 loop
    21 x:=i*j*i*j;
    22 end loop;
    23 dbms_lock.sleep(1);
    24 end loop;
    25
    26 end_time := sysdate;
    27 select value*10
    28 into cpu_end
    29 from v$sesstat s, v$statname n
    30 where s.statistic# = n.statistic#
    31 and n.name = 'CPU used by this session'
    32 and sid = (select sid from v$session where
    sys_context('USERENV','SESSIONID') = audsid);
    33
    34 cpu_elapsed := (cpu_end - cpu_start)/1000.0000000;
    35
    36 dbms_output.put_line('Start CPU for this block: '||
    cpu_start||' milliseconds');
    37 dbms_output.put_line('End CPU for this block: '||
    cpu_end||' milliseconds');
    38 dbms_output.put_line('Elapsed CPU for this block: '||
    cpu_elapsed||' seconds');
    39 dbms_output.put_line('Elapsed time for this block: '||
    (end_time-start_time)*86400||' seconds');
    40 dbms_output.put_line('CPU percent for this block: '||
    (cpu_elapsed/((end_time-start_time)*86400))*100);
    41
    42 end;
    43 /
    Code 0 =
    Code 1 = 
    Code 2 = 
    Code 3 = 
    Code 4 = 
    Code 5 = 
    Code 6 = 
    Code 7 = 
    Code 8 = 
    Code 9 =
    Code 10 =

    Code 11 =
    Code 12 =
    Code 13 =

    Code 14 = 
    Code 15 = 
    Code 16 = 
    Code 17 = 
    Code 18 = 
    Code 19 = 
    Code 20 = 
    Code 21 = 
    Code 22 = 
    Code 23 = 
    Code 24 = 
    Code 25 = 
    Code 26 = 
    Code 27 = 
    Code 28 =
    Code 29 =
    Code 30 =
    Code 31 =
    Code 32 =
    Code 33 = !
    Code 34 = "
    Code 35 = #
    Code 36 = $
    Code 37 = %
    Code 38 = &
    Code 39 = '
    Code 40 = (
    Code 41 = )
    Code 42 = *
    Code 43 = +
    Code 44 = ,
    Code 45 = -
    Code 46 = .
    Code 47 = /
    Code 48 = 0
    Code 49 = 1
    Code 50 = 2
    Code 51 = 3
    Code 52 = 4
    Code 53 = 5
    Code 54 = 6
    Code 55 = 7
    Code 56 = 8
    Code 57 = 9
    Code 58 = :
    Code 59 = ;
    Code 60 = <
    Code 61 = =
    Code 62 = >
    Code 63 = ?
    Code 64 = @
    Code 65 = A
    Code 66 = B
    Code 67 = C
    Code 68 = D
    Code 69 = E
    Code 70 = F
    Code 71 = G
    Code 72 = H
    Code 73 = I
    Code 74 = J
    Code 75 = K
    Code 76 = L
    Code 77 = M
    Code 78 = N
    Code 79 = O
    Code 80 = P
    Code 81 = Q
    Code 82 = R
    Code 83 = S
    Code 84 = T
    Code 85 = U
    Code 86 = V
    Code 87 = W
    Code 88 = X
    Code 89 = Y
    Code 90 = Z
    Code 91 = [
    Code 92 = \
    Code 93 = ]
    Code 94 = ^
    Code 95 = _
    Code 96 = `
    Code 97 = a
    Code 98 = b
    Code 99 = c
    Code 100 = d
    Code 101 = e
    Code 102 = f
    Code 103 = g
    Code 104 = h
    Code 105 = i
    Code 106 = j
    Code 107 = k
    Code 108 = l
    Code 109 = m
    Code 110 = n
    Code 111 = o
    Code 112 = p
    Code 113 = q
    Code 114 = r
    Code 115 = s
    Code 116 = t
    Code 117 = u
    Code 118 = v
    Code 119 = w
    Code 120 = x
    Code 121 = y
    Code 122 = z
    Code 123 = {
    Code 124 = |
    Code 125 = }
    Code 126 = ~
    Code 127 = 
    Code 128 =
    Code 129 =
    Code 130 =
    Code 131 =
    Code 132 =
    Code 133 =
    Code 134 =
    Code 135 =
    Code 136 =
    Code 137 =
    Code 138 =
    Code 139 =
    Code 140 =
    Code 141 =
    Code 142 =
    Code 143 =
    Code 144 =
    Code 145 =
    Code 146 =
    Code 147 =
    Code 148 =
    Code 149 =
    Code 150 =
    Code 151 =
    Code 152 =
    Code 153 =
    Code 154 =
    Code 155 =
    Code 156 =
    Code 157 =
    Code 158 =
    Code 159 =
    Code 160 = *
    Code 161 =
    Code 162 =
    Code 163 =
    Code 164 =
    Code 165 =
    Code 166 =
    Code 167 =
    Code 168 =
    Code 169 =
    Code 170 =
    Code 171 =
    Code 172 =
    Code 173 = *
    Code 174 =
    Code 175 =
    Code 176 =
    Code 177 =
    Code 178 =
    Code 179 =
    Code 180 =
    Code 181 =
    Code 182 =
    Code 183 =
    Code 184 =
    Code 185 =
    Code 186 =
    Code 187 =
    Code 188 =
    Code 189 =
    Code 190 =
    Code 191 =
    Code 192 =
    Code 193 =
    Code 194 =
    Code 195 =
    Code 196 =
    Code 197 =
    Code 198 =
    Code 199 =
    Code 200 =
    Code 201 =
    Code 202 =
    Code 203 =
    Code 204 =
    Code 205 =
    Code 206 =
    Code 207 =
    Code 208 =
    Code 209 =
    Code 210 =
    Code 211 =
    Code 212 =
    Code 213 =
    Code 214 =
    Code 215 =
    Code 216 =
    Code 217 =
    Code 218 =
    Code 219 =
    Code 220 =
    Code 221 =
    Code 222 =
    Code 223 =
    Code 224 =
    Code 225 =
    Code 226 =
    Code 227 =
    Code 228 =
    Code 229 =
    Code 230 =
    Code 231 =
    Code 232 =
    Code 233 =
    Code 234 =
    Code 235 =
    Code 236 =
    Code 237 =
    Code 238 =
    Code 239 =
    Code 240 =
    Code 241 =
    Code 242 =
    Code 243 =
    Code 244 =
    Code 245 =
    Code 246 =
    Code 247 =
    Code 248 =
    Code 249 =
    Code 250 =
    Code 251 =
    Code 252 =
    Code 253 =
    Code 254 =
    Code 255 =
    Start CPU for this block: 90 milliseconds
    End CPU for this block: 130 milliseconds
    Elapsed CPU for this block: .04 seconds
    Elapsed time for this block: 256 seconds
    CPU percent for this block: .015625

    PL/SQL procedure successfully completed.

    SQL>



    David Fitzjarrell

+ Reply to Thread