v$session_longops TIMESTAMP 字段和计时过程(以毫秒为单位)

发布于 2024-11-04 06:26:51 字数 572 浏览 5 评论 0原文

有谁知道v$session_longops中的TIMESTAMP字段是做什么的? 文档页面上的描述只是说“时间戳”。

我需要获取在 longops 中监控的某些操作的运行时间,对于测试,它们通常不到 1 秒,但我仍然想知道哪些操作运行时间更长。我希望使用这个 TIMESTAMP 字段来捕获毫秒时间,但我不知道 TIMESTAMP 字段是否可以用于此目的。

如果做不到这一点,是否有其他方法可以在 longops 中获取这些进程的毫秒持续时间?

更新:

进行了更多调查后,TIMESTAMP 字段似乎始终具有 NULL 值。另外,它的数据类型是 DATE,而不是 TIMESTAMP...

(使用 Oracle 10g)

Does anyone know what the TIMESTAMP field in v$session_longops does? The description on the documentation page just says "timestamp".

I need to get the elapsed time of some operations I monitor in longops and for short tests they are often less than 1 second, but I still want to know which ones run longer. I was hoping to use this TIMESTAMP field to capture millisecond time, but I can't find out if the TIMESTAMP field can even be used for that.

Failing that, is there any other way I could get the millisecond duration of these processes in longops?

UPDATE:

Having done some more investigation, the TIMESTAMP field appears to always have a value of NULL. Also, it's datatype is a DATE, not a TIMESTAMP...

(using Oracle 10g)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

悲凉≈ 2024-11-11 06:26:53

Oracle 维护 V$SESSION_LONGOPS - 您可以使用 DBMS_APPLICATION_INFO.SET_SESSION_LONGOPS 将条目放入其中并更新它们,但 Oracle 控制它们的清除方式。

有人想知道为什么您不创建自己的表来存储所有测试的计时,以便您可以在闲暇时分析所有数据?您似乎表明您已经获得了包含测试的软件包;与调用 DBMS_APPLICATION_INFO 相比,向这些包中添加 INSERTUPDATE 语句似乎是零和游戏。

V$SESSION_LONGOPS 早于 Oracle 对 TIMESTAMP 数据类型的支持,因此该列是 DATE 的原因。

Oracle maintains V$SESSION_LONGOPS - you can use DBMS_APPLICATION_INFO.SET_SESSION_LONGOPS to put entries in there and to update them, but Oracle controls how they get purged.

One wonders why you don't create your own table to store timings for all of your tests, so that you can analyze all the data at your leisure? You seem to indicate that you've got packages that contain your tests; throwing an INSERT or UPDATE statement into those packages seems pretty zero-sum compared to calls to DBMS_APPLICATION_INFO.

V$SESSION_LONGOPS predates Oracle's support of the TIMESTAMP datatype, so that's why the column is a DATE.

一个人的旅程 2024-11-11 06:26:53

你可以这样得到毫秒:

SYS@PRJ_SCOTTY1-VM> select to_char(SYSTIMESTAMP, 'hh24:mi:ss:ff3') from dual;

TO_CHAR(SYSTIMESTAMP,'HH24:MI:SS:FF3')
------------------------------------------------------
16:06:10:944

SYS@PRJ_SCOTTY1-VM> select to_char(SYSTIMESTAMP, 'hh24:mi:ss:ff3') from dual;

TO_CHAR(SYSTIMESTAMP,'HH24:MI:SS:FF3')
------------------------------------------------------
16:06:12:241

SYS@PRJ_SCOTTY1-VM>

如果你需要 INTERVAL 对象的数字表示,你可以使用这些函数:

  /*
  ** **************************************************************************
  */
  Function daysBetween
   (ts1 timestamp with time zone,
    ts2 timestamp with time zone,
    numDec number default 0
   )
  Return Number is
    i INTERVAL DAY(3) TO SECOND(3) := ts2 - ts1;
  Begin
    return round(
      +      extract( day    from i )
      +      extract( hour   from i )/60
      +      extract( minute from i )/60/60
      +      extract( second from i )/60/60/60
    , numDec);
  End;

  /*
  ** **************************************************************************
  */
  Function hoursBetween
   (ts1 timestamp with time zone,
    ts2 timestamp with time zone,
    numDec number default 0
   )
  Return Number is
    i INTERVAL DAY(3) TO SECOND(3) := ts2 - ts1;
  Begin
    return round(
      +      extract( day    from i )*24
      +      extract( hour   from i )
      +      extract( minute from i )/60
      +      extract( second from i )/60/60
    , numDec);
  End;

  /*
  ** **************************************************************************
  */
  Function minutesBetween
   (ts1 timestamp with time zone,
    ts2 timestamp with time zone,
    numDec number default 0
   )
  Return Number is
    i INTERVAL DAY(3) TO SECOND(3) := ts2 - ts1;
  Begin
    return round(
      +      extract( day    from i )*24*60
      +      extract( hour   from i )*60
      +      extract( minute from i )
      +      extract( second from i )/60
    , numDec);
  End;


  /*
  ** **************************************************************************
  */
  Function secondsBetween
   (ts1 timestamp with time zone,
    ts2 timestamp with time zone,
    numDec number default 0
   )
  Return Number is
    i INTERVAL DAY(3) TO SECOND(3) := ts2 - ts1;
  Begin
    return round(
      +     extract( day    from i )*24*60*60
      +     extract( hour   from i )*60*60
      +     extract( minute from i )*60
      +     extract( second from i )
    , numDec);
  End;


  /*
  ** **************************************************************************
  */
  Function msecBetween
   (ts1 timestamp with time zone,
    ts2 timestamp with time zone,
    numDec number default 0
   )
  Return Number is
    i INTERVAL DAY(3) TO SECOND(3) := ts2 - ts1;
  Begin
    return round (
      +     extract( day    from i )*24*60*60*1000
      +     extract( hour   from i )*60*60*1000
      +     extract( minute from i )*60*1000
      +     extract( second from i )*1000
    , numDec);
  End;

you can get the milliseconds like that:

SYS@PRJ_SCOTTY1-VM> select to_char(SYSTIMESTAMP, 'hh24:mi:ss:ff3') from dual;

TO_CHAR(SYSTIMESTAMP,'HH24:MI:SS:FF3')
------------------------------------------------------
16:06:10:944

SYS@PRJ_SCOTTY1-VM> select to_char(SYSTIMESTAMP, 'hh24:mi:ss:ff3') from dual;

TO_CHAR(SYSTIMESTAMP,'HH24:MI:SS:FF3')
------------------------------------------------------
16:06:12:241

SYS@PRJ_SCOTTY1-VM>

in case you need a numeric representation of the INTERVAL object you could use these functions:

  /*
  ** **************************************************************************
  */
  Function daysBetween
   (ts1 timestamp with time zone,
    ts2 timestamp with time zone,
    numDec number default 0
   )
  Return Number is
    i INTERVAL DAY(3) TO SECOND(3) := ts2 - ts1;
  Begin
    return round(
      +      extract( day    from i )
      +      extract( hour   from i )/60
      +      extract( minute from i )/60/60
      +      extract( second from i )/60/60/60
    , numDec);
  End;

  /*
  ** **************************************************************************
  */
  Function hoursBetween
   (ts1 timestamp with time zone,
    ts2 timestamp with time zone,
    numDec number default 0
   )
  Return Number is
    i INTERVAL DAY(3) TO SECOND(3) := ts2 - ts1;
  Begin
    return round(
      +      extract( day    from i )*24
      +      extract( hour   from i )
      +      extract( minute from i )/60
      +      extract( second from i )/60/60
    , numDec);
  End;

  /*
  ** **************************************************************************
  */
  Function minutesBetween
   (ts1 timestamp with time zone,
    ts2 timestamp with time zone,
    numDec number default 0
   )
  Return Number is
    i INTERVAL DAY(3) TO SECOND(3) := ts2 - ts1;
  Begin
    return round(
      +      extract( day    from i )*24*60
      +      extract( hour   from i )*60
      +      extract( minute from i )
      +      extract( second from i )/60
    , numDec);
  End;


  /*
  ** **************************************************************************
  */
  Function secondsBetween
   (ts1 timestamp with time zone,
    ts2 timestamp with time zone,
    numDec number default 0
   )
  Return Number is
    i INTERVAL DAY(3) TO SECOND(3) := ts2 - ts1;
  Begin
    return round(
      +     extract( day    from i )*24*60*60
      +     extract( hour   from i )*60*60
      +     extract( minute from i )*60
      +     extract( second from i )
    , numDec);
  End;


  /*
  ** **************************************************************************
  */
  Function msecBetween
   (ts1 timestamp with time zone,
    ts2 timestamp with time zone,
    numDec number default 0
   )
  Return Number is
    i INTERVAL DAY(3) TO SECOND(3) := ts2 - ts1;
  Begin
    return round (
      +     extract( day    from i )*24*60*60*1000
      +     extract( hour   from i )*60*60*1000
      +     extract( minute from i )*60*1000
      +     extract( second from i )*1000
    , numDec);
  End;
等待圉鍢 2024-11-11 06:26:53

也许您可以使用 SELECT dbms_utility.get_time FROM Dual; ?
它以数百秒为单位返回时间,并且只需通过简单的减法即可计算经过的时间。

Maybe you can use SELECT dbms_utility.get_time FROM dual; ?
It returns the time in hundreds of a second and computing an elapsed time is just by a simple subtraction.

無心 2024-11-11 06:26:53

实际的解决方案最终看起来像这样:

io_start := systimestamp;
/*do some work*/
io_end := systimestamp;
dbms_application_info.set_session_longops(rindex => io_rindex, slno => io_slno, target => 0,
                      context => extract(second from (io_end-io_start)), --for very short jobs, store the millisecond time difference in the Context field.
                      op_name => in_op_name, sofar => 1, totalwork => 1,
                      units => 'blocks', target_desc => 'block job');

是的,我将毫秒持续时间存储在上下文字段中,因为它似乎可用于开发人员需要的任何目的。

Actual solution ended up looking like this:

io_start := systimestamp;
/*do some work*/
io_end := systimestamp;
dbms_application_info.set_session_longops(rindex => io_rindex, slno => io_slno, target => 0,
                      context => extract(second from (io_end-io_start)), --for very short jobs, store the millisecond time difference in the Context field.
                      op_name => in_op_name, sofar => 1, totalwork => 1,
                      units => 'blocks', target_desc => 'block job');

Yes, I stored the millisecond duration in the context field since it seems to be available for whatever purpose the developer needs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文