?? colortrace.d
字號:
#!/usr/sbin/dtrace -s
/*
* colortrace.d - Trace function, syscall and kernel events, in color.
* Written for DTrace (Solaris 10 3/05).
*
* 26-Jan-2005, ver 1.00
*
* USAGE: colortrace.d -p PID
*
* This script demonstrates some key DTrace features: the capability
* to observe function calls across the entire software stack, and
* to measure timestamps for any event. colortrace.d shows the function
* flow of a process, along with delta times between lines of output.
*
* NOTES: Run this on something small, such as a shell. If you are on
* a multi-CPU server, pbind the process to a single CPU else the output
* may by shuffled.
*/
#pragma D option quiet
#pragma D option switchrate=10
/* see "man -s5 dtterm" for a color list */
inline string RED = "\033[31;1m";
inline string BLUE = "\033[34;1m";
inline string GREEN = "\033[32;1m";
inline string VIOLET = "\033[35;1m";
inline string OFF = "\033[0m";
dtrace:::BEGIN
{
last = timestamp;
printf("%-12s %16s %s\n", "DELTA(ns)", "TYPE", "FUNCTION");
}
syscall:::entry
/pid == $target/
{
depth++;
printf("%-12d %16s %s%*s -> %s%s\n", timestamp - last, probeprov,
VIOLET, depth, " ", probefunc, OFF);
self->insyscall = 1;
last = timestamp;
}
syscall:::return
/pid == $target/
{
printf("%-12d %16s %s%*s <- %s%s\n", timestamp - last, probeprov,
VIOLET, depth, " ", probefunc, OFF);
depth = depth > 0 ? --depth : 0;
self->insyscall = 0;
last = timestamp;
}
fbt:::entry
/self->insyscall/
{
depth++;
printf("%-12d %16s %s%*s -> %s%s\n", timestamp - last, "kernel",
RED, depth, " ", probefunc, OFF);
last = timestamp;
}
fbt:::return
/self->insyscall/
{
printf("%-12d %16s %s%*s <- %s%s\n", timestamp - last, "kernel",
RED, depth, " ", probefunc, OFF);
depth = depth > 0 ? --depth : 0;
last = timestamp;
}
pid$target:a.out::entry
{
depth++;
printf("%-12d %16s %s%*s -> %s%s\n", timestamp - last, probemod,
BLUE, depth, " ", probefunc, OFF);
last = timestamp;
}
pid$target:a.out::return
{
printf("%-12d %16s %s%*s <- %s%s\n", timestamp - last, probemod,
BLUE, depth, " ", probefunc, OFF);
depth = depth > 0 ? --depth : 0;
last = timestamp;
}
pid$target:lib*::entry
{
depth++;
printf("%-12d %16s %s%*s -> %s%s\n", timestamp - last, probemod,
GREEN, depth, " ", probefunc, OFF);
last = timestamp;
}
pid$target:lib*::return
{
printf("%-12d %16s %s%*s <- %s%s\n", timestamp - last, probemod,
GREEN, depth, " ", probefunc, OFF);
depth = depth > 0 ? --depth : 0;
last = timestamp;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -