[Level 2] Solaris 10 Technical Conference ( 2009/10/25,11/13,12/4 ) -- Basic DTrace hands-on lab

The following is my lab file, please refer to it. 

Wish this helps.

regards,
Stanley Huang

****************************************************************************************************

The purpose of this lab is to let you have basic DTrace skill. And then you will have the following capabilities.
Lab 1:
* know dtrace probes.
* use dtrace tool kits to monitor your system.
* download dtrace tool kits.
* write your first D-script.

1. list dtrace probes.
# dtrace -l;

2. list demo dtrace tools
# cd /usr/demo/dtrace;
# ls -l *.d;
------------------------------------------------------------------
-rw-r--r--   1 root     bin         1677  5月 14 23:52 applicat.d
-rw-r--r--   1 root     bin         1699  5月 14 23:52 badopen.d
-rw-r--r--   1 root     bin         1732  5月 14 23:52 begin.d
-rw-r--r--   1 root     bin         1668  5月 14 23:52 callout.d
-rw-r--r--   1 root     bin         2220  5月 14 23:52 clause.d
-rw-r--r--   1 root     bin         1717  5月 14 23:52 clear.d
-rw-r--r--   1 root     bin         1640  5月 14 23:52 countdown.d
-rw-r--r--   1 root     bin         1664  5月 14 23:52 counter.d
-rw-r--r--   1 root     bin         2119  5月 14 23:52 dateprof.d
-rw-r--r--   1 root     bin         1694  5月 14 23:52 delay.d
-rw-r--r--   1 root     bin         1858  5月 14 23:52 denorm.d
------------------------------------------------------------------

3. run the dtrace script.
# /usr/sbin/dtrace -s ./iosnoop.d;
------------------------------------------------------------------------
    DEVICE                                                       FILE RW
       sd0                                                       W
       sd0                                                       W
       sd0                                                       W
       sd0                                                       W
       sd0                                                       W
       sd0                                                       W
       sd0                                                       W
       ...
------------------------------------------------------------------------
^C

# dtrace -s ./whoexec.d;
^C
-----------------------------------------------
WHO                  WHAT                 COUNT
bash                 dtrace               1
bash                 find                 1
bash                 ls                   1
bash                 passwd               1
dtrace               dtrace               1
-----------------------------------------------

4. down dtrace tool kits.
# firefox http://www.opensolaris.org/os/community/dtrace/dtracetoolkit/;
[After download the toolkit file.]
# gunzip -c ./DTraceToolkit-0.99.tar.gz | tar xvf -
# cd ./DTraceToolkit-0.99
# ./iosnoop
-------------------------------------------------
  UID   PID D    BLOCK   SIZE       COMM PATHNAME
  101  1264 R 182480384  65536       find
  101  1264 R 182480128  65536       find
  101  1264 R 229304832  65536       find
  101  1264 R 115049472  65536       find
  101  1264 R 91222144  65536       find
  101  1264 R 160868480  65536       find
  101  1264 R 27676544  65536       find
  101  1264 R 27649664  65536       find
  101  1264 R 193875712  65536       find
  101  1264 R 115076224  65536       find
  101  1264 R 167114112  65536       find
  101  1264 R 167346560  65536       find
-------------------------------------------------
^C

5. write your first D-script.
# cat ./myDscript.d;
-------------------------------------------------
#!/usr/sbin/dtrace -s
#pragma D option quiet
#pragma D option version=1.1
#pragma D option defaultargs
struct  myStruct {
  uint64_t nStartTimestamp;
  uint64_t nEndTimestamp;
  uint64_t nElapsed;
};
struct myStruct myTime;

BEGIN {
  myTime.nStartTimestamp=timestamp;
  trace("hello world\n");
}
END {
  printf("%s\n", "the end...");
  myTime.nEndTimestamp=timestamp;
  myTime.nElapsed=myTime.nEndTimestamp-myTime.nStartTimestamp;
  printf("The process spend time(sec) = %d sec\n",((myTime.nElapsed)/1000000000));
}
ERROR
{
  trace("Some syntax error!\n");
}
-------------------------------------------------
# chmod u+x ./myDscript.d;
# ./myDscript.d;
# ./h.d;
hello world
^C
the end...
The process spend time(sec) = 2 sec
#


Comments

Popular posts from this blog

[Level 2] Shell Interactive With Zenity Episode 5 -- list

[Level 2] iif in Python