我想知道正在运行的程序正在访问多少条记录。 我找到了VST _TableStat,但它没有按程序对记录数进行分组。
FOR EACH _TableStat NO-LOCK
WHERE _TableStat._TableStat-Create > 0
OR _TableStat._TableStat-Delete > 0
OR _TableStat._TableStat-Read > 0
OR _TableStat._TableStat-Update > 0,
FIRST _File NO-LOCK
WHERE _File._File-Number = _TableStat._TableStat-Id:
DISPLAY
/*_File._File-Name*/
_TableStat-Create
_TableStat._TableStat-Delete
_TableStat._TableStat-Read
_TableStat._TableStat-Update
WITH SIDE-LABELS 1 COLUMN 1 DOWN.
END.
此代码向我显示了表以及正在访问的记录数,但我想知道正在访问该表的程序。
有办法知道吗? 或者是否有像 _TableStat 这样带有 PID 或类似内容的表?
PS:我使用的是Progress 10.2B。
提前致谢, 鲁比尼奥·桑托斯
Progress 是什么版本?
大约 10.1C _UserTableStat 被引入。它有用户的表格统计数据。
_connect VST 中还有“客户端语句缓存”字段。如果为会话启用了正确的位,则会保存堆栈跟踪,以便您可以确定会话正在执行哪一行以及它是如何到达那里的。
在它们之间,它们可以让你得到你需要的东西。
顺便说一句:ProTop 向您展示了大部分此类数据 - https://protop.com/
如果您需要按程序统计数据进行细粒度的程序,您可能还想查看一些“日志条目类型”功能,例如 4gltrace 和 QryInfo。
它与表 _UserTableStat 一起使用,正如我所期望的:
FOR EACH _UserTableStat NO-LOCK
WHERE _UserTableStat._UserTableStat-Read > 0
OR _UserTableStat._UserTableStat-Create > 0
OR _UserTableStat._UserTableStat-Update > 0
OR _UserTableStat._UserTableStat-Delete > 0,
FIRST _File NO-LOCK
WHERE _File._File-Number = _UserTableStat._UserTableStat-Num,
FIRST _Connect NO-LOCK
WHERE _Connect._Connect-Id = _UserTableStat._UserTableStat-Conn:
DISPLAY
_Connect._Connect-IPAddress
_Connect._Connect-Name
_Connect._Connect-Pid
_File._File-Name
_UserTableStat._UserTableStat-Read
_UserTableStat._UserTableStat-Create
_UserTableStat._UserTableStat-Update
_UserTableStat._UserTableStat-Delete
WITH SIDE-LABELS THREE-D 1 COLUMN 1 DOWN.
END.
感谢汤姆巴斯科姆的帮助!
上面的代码在 _connect 和 _UserTableStat 之间的连接上存在问题:
WHERE _Connect._Connect-Id = _UserTableStat._UserTableStat-Conn
你必须使用这个:
WHERE _Connect._Connect-Usr = _UserTableStat._UserTableStat-Conn
hint: _Connect-Usr = _Connect-Id + 1
接下来,下面的代码给出了一个按 _UserTableStat-read 降序排序的列表:
DEFAULT-WINDOW:WIDTH-CHARS = 240.
DEFINE VARIABLE dmon AS DATETIME NO-UNDO.
DEFINE VARIABLE dstart AS DATETIME NO-UNDO.
DEFINE VARIABLE iusertablestat AS INTEGER NO-UNDO.
DEFINE VARIABLE lfirstview AS LOGICAL INITIAL TRUE NO-UNDO.
DEFINE TEMP-TABLE ttuts LIKE _UserTableStat
FIELD _Connect-Type AS CHARACTER INITIAL ?
FIELD _Connect-Name AS CHARACTER INITIAL ? FORMAT "X(15)"
FIELD _Connect-Time AS CHARACTER INITIAL ? FORMAT "X(25)"
FIELD _Connect-ClientType AS CHARACTER INITIAL ?
INDEX _UserTableStat-read _UserTableStat-read
INDEX _UserTableStat-update _UserTableStat-update
INDEX _UserTableStat-create _UserTableStat-create
INDEX _UserTableStat-delete _UserTableStat-delete.
dstart = NOW.
dmon = NOW.
DEFAULT-WINDOW:TITLE = SUBSTITUTE("starting scan of _UserTableStat at &1", dstart).
FOR EACH _UserTableStat NO-LOCK:
iusertablestat = iusertablestat + 1.
IF iusertablestat MODULO 10000 = 0
OR INTERVAL(NOW, dmon, "milliseconds") > 1000 THEN
DO:
dmon = NOW.
IF lfirstview THEN
DO:
DISPLAY "scanning in process" WITH FRAME fviewit.
lfirstview = FALSE.
END.
DEFAULT-WINDOW:TITLE = SUBSTITUTE("&1 - Scanning since &2 ms - &3 _UserTableStat records (started at &4)"
, NOW, INTERVAL(NOW, dstart, "milliseconds"), iusertablestat, dstart).
DEFAULT-WINDOW:TITLE = SUBSTITUTE("starting scan of _UserTableStat at &1 scanned &2 records", dstart, iusertablestat).
PROCESS EVENTS.
END.
/* if you are interested in updates or delte, then adapath this next line */
IF _UserTableStat._UserTableStat-read = 0
THEN NEXT.
IF _UserTableStat._UserTableStat-Conn <> ?
THEN FIND _Connect NO-LOCK WHERE _Connect._Connect-Usr = _UserTableStat._UserTableStat-Conn NO-ERROR. /* beware: you may use _UserTableStat-id + 1 too but do not miss the + 1*/
ELSE RELEASE _Connect.
CREATE ttuts.
BUFFER-COPY _UserTableStat TO ttuts.
IF AVAIL _Connect
THEN BUFFER-COPY _Connect TO ttuts.
END.
DEFAULT-WINDOW:TITLE = SUBSTITUTE("&1 - Scan completed in &2 ms through &3 _UserTableStat records (started at &4)"
, NOW, INTERVAL(NOW, dstart, "milliseconds"), iusertablestat, dstart).
FOR EACH ttuts
, FIRST _File NO-LOCK WHERE _File._File-Number = ttuts._UserTableStat-Num
BY ttuts._UserTableStat-read DESCENDING:
DISPLAY
ttuts._UserTableStat-Num
_File._File-Name
ttuts._Connect-Name
ttuts._UserTableStat-Conn /* = _Connect._Connect-Usr */
ttuts._Connect-Type
ttuts._Connect-Time
ttuts._Connect-ClientType
ttuts._UserTableStat-read FORMAT ">>>,>>>,>>>,>>>,>>9"
ttuts._UserTableStat-update FORMAT ">>>,>>>,>>>,>>>,>>9"
ttuts._UserTableStat-create FORMAT ">>>,>>>,>>>,>>>,>>9"
ttuts._UserTableStat-delete FORMAT ">>>,>>>,>>>,>>>,>>9"
WITH WIDTH 240 FRAME fttuts 17 DOWN.
END.