ASE v15中的应用程序跟踪tracefile特性

Sybase 在ASE v15.0.2 中新增了“应用程序”跟踪这个特性。

您可以利用“应用程序”跟踪功能收集一个正在运行中的客户会话的有用诊断信息,包括:执行查询、IO 消耗等;并且ASE 会自动把收集到的跟踪信息写到一个文本文件中。可以很方便得用这个特性来诊断一些系统性能瓶颈。

您只需要知道想要跟踪的会话的SPID(Server Process ID) 就可以对那个会话进行跟踪监控。应用系统的用户只需要被授予“set tracing ”权限就可以利用“应用程序”跟踪对自己的会话信息进行跟踪。

执行“应用程序”跟踪需要具有 set tracing 的权限。主要有两类用户:第一:具有sa或者sso角色的用户(默认具有set tracing权限);第二:被赋予了set tracing 执行权限的用户。下面会分别予以介绍。

 

(1) 具有管理员特权的用户(属于 sa 或者 sso 角色)

对其他用户连接会话启用“应用程序”跟踪,执行:

set tracefile "<file-path>" for <spid>

 

关闭刚才打开的针对其他用户连接会话的跟踪,需要执行:

set tracefile off for <spid>

 

备注:
(1) 针对某个用户会话启用跟踪时,需要知道它的SPID 并填写跟踪结果文件保存的路径。如果没有指定跟踪结果文件保存的路径,那么ASE 会自动保存到$SYBASE 目录下。
(2) 在一个会话中,只能有一个set tracefile 为启用状态;并且,某一个SPID 不能被多个会话同时跟踪。
(3) 当被跟踪的会话自己退出,或者跟踪被手动关闭时,ASE 会生成跟踪结果文件。
(4) 在“应用程序”跟踪的过程中,如果跟踪结果文件所在的磁盘空间被耗尽,那么ASE 会自动保存跟踪文件并结束本次“应用程序”跟踪。
(5) 用sp_helpapptrace 存储过程来查看当前正在执行中的所有应用程序跟踪信息。


(2) 被赋予“set tracing” 权限的应用程序用户

对自己的会话启用跟踪,执行:

set tracefile "<file-path>"

 

结束对自己的会话上的跟踪,使用:

set tracefile off

 

备注: 不能使用sp_helpapptrace过程来查看正在被跟踪的会话。

(3 ) 哪些信息可被用来跟踪?

在“应用程序”跟踪中可以追踪以下的set option 命令。

set show_sqltext <on/off>
set showplan <on/off>
set statistics io <on/off>
set statistics time <on/off>
set statistics plancost <on/off>

set option 的子命令也可被用来跟踪。

set option show_lop <normal/brief/long/on/off>                        ---显示使用的逻辑操作数量
set option show_managers <normal/brief/long/on/off>               --- 显示使用的数据结构管理器的数量
set option show_log_props <normal/brief/long/on/off>               --- 显示所用的逻辑属性
set option show_parallel <normal/brief/long/on/off>                  --- 显示并行查询优化器信息
set option show_histograms <normal/brief/long/on/off>             --- 显示直方图统计信息处理过程
set option show_abstract_plan <normal/brief/long/on/off>         --- 显示虚拟查询计划具体信息
set option show_search_engine <normal/brief/long/on/off>        --- 显示搜索引擎的详细信息
set option show_counters <normal/brief/long/on/off>               ---  显示优化器找到的计划的数量
set option show_best_plan <normal/brief/long/on/off>              --- 显示最优计划信息
set option show_code_gen <normal/brief/long/on/off>              --- 显示代码产生器的信息
set option show_pio_costing <normal/brief/long/on/off>            --- 显示估计的物理IO数
set option show_lio_costing <normal/brief/long/on/off>             --- 显示估计的逻辑IO数
set option show_elimination <normal/brief/long/on/off>             --- 显示分区消除信息

 

(4) 例子 (使用具有sa 和sso 角色的用户)

在一个会话中执行如下的命令:

set tracefile "c:/tmp/trace-spid-16.txt" for 16
set show_sqltext on
set showplan on
go
sp_helpapptrace
go

traced_spid tracer_spid trace_file

----------- ----------- ----------------------------

16          19          c:/tmp/ase-trace-spid-16.txt

 
(1 row affected)

(return status = 0)

上面的输出结果表明该会话的spid为16。
在另外一个会话中,在被监控的用户会话spid=16中执行sp_helpdb过程。

set tracefile off for 16
go
sp_helpapptrace
go

traced_spid tracer_spid trace_file

 ----------- ----------- ----------

 
(0 rows affected)

(return status = 0)

跟踪结果信息如下:

================================================================================
    Application Tracing report for spid -1 from application "isql"
    run by login "sa" on host "TEST"
     Tracing started on 2010/04/24 17:08:10.23
================================================================================
No useful sqltext available.
QUERY PLAN FOR STATEMENT 1 (at line 1).
    STEP 1
        The type of query is EXECUTE.
2010/04/24 17:08:10.23
No useful sqltext available.
Sproc: sp_helpdb, Line: 0
QUERY PLAN FOR STATEMENT 1 (at line 0).
    STEP 1
        The type of query is DECLARE.
Sproc: sp_helpdb, Line: 38
QUERY PLAN FOR STATEMENT 2 (at line 38).
    STEP 1
        The type of query is COND.
    1 operator(s) under root
       |ROOT:EMIT Operator (VA = 1)
       |
       |   |SCALAR Operator (VA = 0)
Sproc: sp_helpdb, Line: 40
QUERY PLAN FOR STATEMENT 3 (at line 40).
    STEP 1
        The type of query is SET OPTION OFF.
Sproc: sp_helpdb, Line: 43
QUERY PLAN FOR STATEMENT 4 (at line 43).
    STEP 1
        The type of query is SET OPTION ON.
Sproc: sp_helpdb, Line: 45
QUERY PLAN FOR STATEMENT 5 (at line 45).
    STEP 1
        The type of query is SELECT.
    1 operator(s) under root
       |ROOT:EMIT Operator (VA = 1)
       |
       |   |SCALAR Operator (VA = 0)
Sproc: sp_helpdb, Line: 47
QUERY PLAN FOR STATEMENT 6 (at line 47).
    STEP 1
        The type of query is COND.
    1 operator(s) under root
       |ROOT:EMIT Operator (VA = 1)
       |
       |   |SCALAR Operator (VA = 0)
Sproc: sp_helpdb, Line: 49
QUERY PLAN FOR STATEMENT 7 (at line 49).
    STEP 1
        The type of query is COND.
    3 operator(s) under root
       |ROOT:EMIT Operator (VA = 3)
       |
       |   |RESTRICT Operator (VA = 2)(0)(0)(0)(4)(0)
       |   |
       |   |   |SCALAR AGGREGATE Operator (VA = 1)
       |   |   |  Evaluate Ungrouped ANY AGGREGATE.
       |   |   |  Scanning only up to the first qualifying row.
       |   |   |
       |   |   |   |SCAN Operator (VA = 0)
       |   |   |   |  FROM TABLE
       |   |   |   |  master.dbo.sysmessages
       |   |   |   |  Index : ncsysmessages
       |   |   |   |  Forward Scan.
       |   |   |   |  Positioning by key.
       |   |   |   |  Index contains all needed columns. Base table will not be read.
       |   |   |   |  Keys are:
       |   |   |   |    error ASC
       |   |   |   |  Using I/O Size 2 Kbytes for index leaf pages.
       |   |   |   |  With LRU Buffer Replacement Strategy for index leaf pages.
Sproc: sp_helpdb, Line: 53
QUERY PLAN FOR STATEMENT 8 (at line 53).
    STEP 1
        The type of query is SELECT.
    1 operator(s) under root
       |ROOT:EMIT Operator (VA = 1)
       |
       |   |SCALAR Operator (VA = 0)
Sproc: sp_helpdb, Line: 55
QUERY PLAN FOR STATEMENT 9 (at line 55).
    STEP 1
        The type of query is COND.
    3 operator(s) under root
       |ROOT:EMIT Operator (VA = 3)
       |
       |   |RESTRICT Operator (VA = 2)(0)(0)(0)(4)(0)
       |   |
       |   |   |SCALAR AGGREGATE Operator (VA = 1)
       |   |   |  Evaluate Ungrouped ANY AGGREGATE.
       |   |   |  Scanning only up to the first qualifying row.
       |   |   |
       |   |   |   |SCAN Operator (VA = 0)
       |   |   |   |  FROM TABLE
       |   |   |   |  master.dbo.sysmessages
       |   |   |   |  Index : ncsysmessages
       |   |   |   |  Forward Scan.
       |   |   |   |  Positioning by key.
       |   |   |   |  Index contains all needed columns. Base table will not be read.
       |   |   |   |  Keys are:
       |   |   |   |    error ASC
       |   |   |   |  Using I/O Size 2 Kbytes for index leaf pages.
       |   |   |   |  With LRU Buffer Replacement Strategy for index leaf pages.
Sproc: sp_helpdb, Line: 59
QUERY PLAN FOR STATEMENT 10 (at line 59).
    STEP 1
        The type of query is SELECT.
    1 operator(s) under root
       |ROOT:EMIT Operator (VA = 1)
       |
       |   |SCALAR Operator (VA = 0)
Sproc: sp_helpdb, Line: 0
QUERY PLAN FOR STATEMENT 11 (at line 0).
    STEP 1
        The type of query is GOTO.
Sproc: sp_helpdb, Line: 0
QUERY PLAN FOR STATEMENT 12 (at line 0).
    STEP 1
        The type of query is GOTO.
Sproc: sp_helpdb, Line: 62
QUERY PLAN FOR STATEMENT 13 (at line 62).
    STEP 1
        The type of query is SET OPTION ON.
Sproc: sp_helpdb, Line: 69
QUERY PLAN FOR STATEMENT 14 (at line 69).
    STEP 1
        The type of query is COND.
    1 operator(s) under root
       |ROOT:EMIT Operator (VA = 1)
       |
       |   |SCALAR Operator (VA = 0)
Sproc: sp_helpdb, Line: 70
QUERY PLAN FOR STATEMENT 15 (at line 70).
    STEP 1
        The type of query is SELECT.
    2 operator(s) under root
       |ROOT:EMIT Operator (VA = 2)
       |
       |   |SCALAR AGGREGATE Operator (VA = 1)
       |   |  Evaluate Ungrouped COUNT AGGREGATE.
       |   |
       |   |   |SCAN Operator (VA = 0)
       |   |   |  FROM TABLE
       |   |   |  master.dbo.sysdatabases
       |   |   |  Index : ncsysdatabases
       |   |   |  Forward Scan.
       |   |   |  Positioning at index start.
       |   |   |  Index contains all needed columns. Base table will not be read.
       |   |   |  Using I/O Size 2 Kbytes for index leaf pages.
       |   |   |  With LRU Buffer Replacement Strategy for index leaf pages.
Sproc: sp_helpdb, Line: 73
QUERY PLAN FOR STATEMENT 16 (at line 73).
    STEP 1
        The type of query is SELECT.
    3 operator(s) under root
       |ROOT:EMIT Operator (VA = 3)
       |
       |   |SCALAR AGGREGATE Operator (VA = 2)
       |   |  Evaluate Ungrouped COUNT AGGREGATE.
       |   |
       |   |   |RESTRICT Operator (VA = 1)(0)(0)(0)(6)(0)
       |   |   |
       |   |   |   |SCAN Operator (VA = 0)
       |   |   |   |  FROM TABLE
       |   |   |   |  master.dbo.sysdatabases
       |   |   |   |  Using Clustered Index.
       |   |   |   |  Index : cdatabases
       |   |   |   |  Forward Scan.
       |   |   |   |  Positioning at index start.
       |   |   |   |  Index contains all needed columns. Base table will not be read.
       |   |   |   |  Using I/O Size 2 Kbytes for index leaf pages.
       |   |   |   |  With LRU Buffer Replacement Strategy for index leaf pages.
Sproc: sp_helpdb, Line: 80

————————————————————————————————-
—- 本文为andkylee个人原创,请在尊重作者劳动成果的前提下进行转载;
—- 转载务必注明原始出处 : http://www.dbainfo.net
—- 关键字:tracefile showplan statistics 跟踪 会话
————————————————————————————————-

  • 本文链接地址:https://www.dbainfo.net/ase15-new-feature-app-tracefile.htm
  • 本文为dbainfo个人原创,请在尊重作者劳动成果的前提下进行转载;
  • 转载务必注明原始出处 : Sybase数据库技术,数据库恢复专家
  • 对《ASE v15中的应用程序跟踪tracefile特性》有何疑问或见解,请在本文下方发表;
  • 对网站还有其他问题或建议,请提交在留言板,谢谢!
  • 目前还没有任何评论.
    :wink: :twisted: :roll: :oops: :mrgreen: :lol: :idea: :evil: :cry: :arrow: :?: :-| :-x :-o :-P :-D :-? :) :( :!: 8-O 8)