AIX 从 1990 年就开始提供 Trace 功能
AIX 6 ProbeVue——包含在当前 AIX 6 Open Beta 版本中,但有功能限制
可以采用交互方式运行 probevue(对我而言,这工作似乎有点艰难,因为必须键入和重复键入细节!),也可以通过脚本运行 probevue。至少可以采用五种方法,可能开始会让人有些迷惑,那么接下来我们就对各个方法进行说明,以便您决定尝试哪种方法:
probevue myscript.e
probevue <myscript.e
|
脚本(在本例中称为 myscript)包括第一行: #!/usr/bin/probevue
将文件处理为可执行文件:chmod +x myscript
然后运行脚本:./myscript.e
|
查找进程 ID:# ps -ef | grep find
使用 PID 参数运行: probevue myscript 43561
|
probevue -X progname -A prog-arguments myscript |
probevuew 脚本的结构如下(<-- 是注释,即不属于脚本的一部分)
<- optional declaring function prot-type so probevue understands your functionarguments
@@BEGIN
{
... <- optional start up code, good for initialisation of variables
}
@@<probe-spec> <- Probe point specification Tuple (see below)
when <predicate> <- Optional predicate
{
statements here;<- Probe actions in C like code
...
}
@@END
{
... <- Optional ending code. Can print out final
results. Gets runs if you hit Control+C
}
|
首先请注意,Tuple 是有序列表的雅名——我在知道这一点后帮助非常大!
目前有三种类型的 Tuple:
以下是一个非常简单的脚本,此脚本实际上工作并执行一些有意义的工作。
#!/usr/bin/probevue <-- autorun
@@BEGIN
{
int count, total; <-- declare the variables (later probevue
versions will not need this)
}
@@syscall:*:read:entry <-- System call: any process ID, read() function,
at start of the function
{
count++; <-- increment the counters
total++;
}
@@interval:*:clock:1000 <-- once per second (1000 ticks per second)
{
printf("Number of reads = %d\n", count);
count=0;
}
@@END <-- After you type Control-C
{
printf("\nTotal reads = %d\n",total);
}
|
# ./count.e Number of reads = 0 Number of reads = 1 Number of reads = 0 Number of reads = 0 Number of reads = 2 Number of reads = 0 Number of reads = 5 Number of reads = 269 Number of reads = 0 Number of reads = 0 ^C Total reads = 277 |
#!/usr/bin/probevue
@@BEGIN
{
int read(int fd, void *buf, int n); <-- Declare function so ProbeVue understands it
int bad;
int good;
}
@@syscall:*:read:exit
when(__rv == -1) <-- __rv means the return value
{
bad++;
}
@@syscall:*:read:exit
when(__rv != -1)
{
good++;
}
@@interval:*:clock:1000 <-- Once a second output counter
{
printf("Reads good=%d bad=%d\n",good,bad);
good=0;
}
|
以下是上面脚本的一些示例输出,我专门运行了一个程序来生成一些磁盘 I/O。注意:当程序尝试从无效的文件描述符(即未使用 open() 函数初始化文件描述符)进行读取时,将生成不良 I/O:
# ./goodandbad.e Reads good=0 bad=0 Reads good=55 bad=0 Reads good=0 bad=0 Reads good=0 bad=0 Reads good=57 bad=1 Reads good=0 bad=1 Reads good=0 bad=1 Reads good=55 bad=1 Reads good=0 bad=1 Reads good=1 bad=1 Reads good=55 bad=1 Reads good=40 bad=1 Reads good=1 bad=2 Reads good=55 bad=3 Reads good=1 bad=3 Reads good=0 bad=3 Reads good=56 bad=4 |
我使用一个小程序生成了很多 CUP 工作。此程序调用了 ncpu,其中包含函数“engine()”,此函数耗尽了 CPU 上的 CPU 时钟周期。以下脚本用于研究此函数的使用情况。注意:此程序已经编译并在运行,并且它包括符号表,probevue 使用此符号表来查找函数入口和出口点(即未剥离)。probevue 脚本包括用于输出所能找到的程序和环境的详细信息的 probevue 函数:
#!/usr/bin/probevue
double engine(int p1, int p2);
@@uft:$1:*:engine:entry
{
printf("PID=%d TID=%d PPID=%d PGID=%d UID=%d GID=%d InKernel=%d\n", __pid,
__tid, __ppid, __pgid, __uid, __euid, __kernelmode);
printf("ProgName=%s errno=%d\n", __pname, __errno);
printf("---\n");
stktrace(GET_USER_TRACE,-1);
printf("+++\n");
stktrace(PRINT_SYMBOLS|GET_USER_TRACE,-1);
}
|
# ps -ef | grep ncpu
root 299106 307250 27 14:02:00 pts/0 15:16 ./ncpu -p1 -z 90
root 315596 307250 0 16:48:47 pts/0 0:00 grep ncpu
# ./engine 299106
PID=299106 TID=630919 PPID=307250 PGID=299106 UID=0 GID=0 InKernel=0
ProgName=ncpu errno=0
---
0x100001dc
0x10000964
0x100010e8
0xd02fd66c
0x20000c80
0x10001160
+++
.__start+0x8c
.main+0x60c
.work+0x1b4
.random+0x2c
|
接下来让我们研究一下名为 engine() 的函数。该函数接受两个参数,第一个是随机生成的 1 到 1,000,000 之间的数字——但我们不确定具体是不是在此范围内。我们将随机数放入四个“桶”中。我们要确定各个桶中的随机数的数量是否大体相等——不是完全相等,但至少相近:
#!/usr/bin/probevue
double engine(int p1, int p2);
int b1, b2, b3, b4;
@@uft:$1:*:engine:entry
{
tmp = __arg1;
if( tmp < 250000 ) b1++;
if( 250000 <= tmp && tmp < 500000 ) b2++;
if( 500000 <= tmp && tmp < 750000 ) b3++;
if( tmp >750000 ) b4++;
}
@@END
{
printf("\nFour bucket results are: %d %d %d %d\n",b1,b2,b3,b4);
}
|
ps -ef | grep ncpu
root 299106 307250 27 14:02:00 pts/0 15:16 ./ncpu -p1 -z 90
root 315596 307250 0 16:48:47 pts/0 0:00 grep ncpu
# # ./random 299106
[[[Wait 30 seconds here]]]
^C
Four bucket results are: 101524 101262 101454 120657
|
我并没有讨论更为高级的功能,如:
|
||||
| · NAC安全访问控制 · 网络布线测试仪器 · Windows Server 2008专.. · Windows远程桌面应用 · 网络故障排除宝典 · 运营商封堵ADSL共享 中.. · 解析35岁技术人的价值.. · 世纪枭雄比尔盖茨的王.. |
· 主流品牌防火墙配置 · ASP.NET开发教程 · 超级计算机TOP500专题 · Vista SP1对决XP SP3 · SQL Server 2008/2005.. · 程序员如何成长? · C#技术开发指南 · 虚拟化技术还有点“虚” |
|||
|
||||
| · SOA 面向服务架构 · SQL Server 2008/2005.. · Apache技术专题 · 三层交换技术专题 · SQL Server入门到精通 · Windows远程桌面应用 · C#技术开发指南 · Apache技术专题 |
· Windows集群服务应用 · C#技术开发指南 · 国际文档格式标准开战 · 路由器设置与口令恢复 · Linux 集群技术专题 · PHP开发应用手册 · SOA 面向服务架构 · 企业数据恢复指南 |
|||
|
||||
| · SQL Server入门到精通 · SQL Server 2008/2005.. · SOA 面向服务架构 · Apache技术专题 · C#技术开发指南 · 三层交换技术专题 · Apache技术专题 · C#技术开发指南 |
· Windows远程桌面应用 · 企业数据恢复指南 · Windows集群服务应用 · 路由器设置与口令恢复 · Linux 集群技术专题 · SOA 面向服务架构 · 了解统一威胁管理(UTM).. · 反垃圾邮件技术应用 |
|||