OpenSolaris2008.05環境でのPython Tracing

IPS(Image Packaging System)やxVMをはじめ多くのツールなどがPythonにて、提供されております。実は、xVMが入ってきた当時、USDTにて、PythonのDTrace Probesが入ってました。HotTopicsセミナーで何回か紹介したのですが、DTraceにて、Pythonの追跡ができるようになっております。ちなみに、libpython2.4.so.1に、USDTが定義されているようです。

OpenSolaris 2008.05もPythonの追跡ができるようになっております。本日は、IPSを追跡してみましょう。

とりあえず、システム->システム管理->Package ManagerのGUIをあげてみましょう。

そうすると、もちろん、GUIがあがります。
先日は、コマンドの追跡の仕方でしたが、今回は、Package Managerのソースを追跡します。

 

  kato@opensolaris:~$ pfexec dtrace -l | awk '{print $2}' | sort -u | grep py
 python702

 

 kato@opensolaris:~$ ps -ef | grep pyth
    root   702   701   2 20:58:55 ?           1:24 python /usr/bin/packagemanager

//Pythonが動いているpid 702で動いている。

//python 利用できるfunction 

 

 kato@opensolaris:~$ pfexec dtrace -l -P python702
   ID   PROVIDER            MODULE                          FUNCTION NAME
52266  python702 libpython2.4.so.1.0                  PyEval_EvalFrame function-entry
52267  python702 libpython2.4.so.1.0                      dtrace_entry function-entry
52268  python702 libpython2.4.so.1.0                  PyEval_EvalFrame function-return
52269  python702 libpython2.4.so.1.0                     dtrace_return function-return

//引数の確認

 

 kato@opensolaris:~$ pfexec dtrace -lvn 'python702:::{}'
   ID   PROVIDER            MODULE                          FUNCTION NAME
52266  python702 libpython2.4.so.1.0                  PyEval_EvalFrame function-entry

        Probe Description Attributes
                Identifier Names: Private
                Data Semantics:   Private
                Dependency Class: ISA

        Argument Attributes
                Identifier Names: Evolving
                Data Semantics:   Evolving
                Dependency Class: ISA

        Argument Types
                args[0]: char \*
                args[1]: char \*
                args[2]: int

52267  python702 libpython2.4.so.1.0                      dtrace_entry function-entry

        Probe Description Attributes
                Identifier Names: Private
                Data Semantics:   Private
                Dependency Class: ISA

        Argument Attributes
                Identifier Names: Evolving
                Data Semantics:   Evolving
                Dependency Class: ISA

        Argument Types
                args[0]: char \*
                args[1]: char \*
                args[2]: int
...

 kato@opensolaris:~$ pfexec dtrace -n 'python\*:::function-entry{@=count();}'
dtrace: description 'python\*:::function-entry' matched 2 probes
\^C

             9993

とても動いてpythonが激しくコールしていることがわかると思います。

kato@opensolaris:~$ pfexec dtrace -n 'python\*:::function-entry{@[copyinstr(arg0)]=count();}'
dtrace: description 'python\*:::function-entry' matched 2 probes
\^C

  /usr/lib/python2.4/cookielib.py                                   2
  /usr/lib/python2.4/vendor-packages/pkg/actions/license.py                2
  /usr/lib/python2.4/vendor-packages/pkg/client/retrieve.py                2
  /usr/lib/python2.4/vendor-packages/pkg/misc.py                    2
  /usr/lib/python2.4/vendor-packages/pkg/urlhelpers.py                2
  /usr/lib/python2.4/mimetools.py                                   3
  /usr/lib/python2.4/os.py                                          4
...


上記のファイルのスクリプトが呼ばれているようですね。

kato@opensolaris:~$ pfexec dtrace -n 'python\*:::function-entry{@[copyinstr(arg0),copyinstr(arg1)]=count();}'
dtrace: description 'python\*:::function-entry' matched 2 probes
\^C

  /usr/lib/python2.4/vendor-packages/pkg/manifest.py  set_content                                                       1
  /usr/lib/python2.4/vendor-packages/pkg/actions/link.py  __init__                                                          3
  /usr/lib/python2.4/socket.py                        __del__                                                           7
  /usr/lib/python2.4/socket.py                        close                                                             7
  /usr/lib/python2.4/socket.py                        flush                                                             7
  /usr/lib/python2.4/httplib.py                       read                                                             23
  /usr/lib/python2.4/socket.py                        read                                                             23
  /usr/lib/python2.4/vendor-packages/pkg/actions/directory.py  __init__                                                        176
  /usr/lib/python2.4/vendor-packages/pkg/actions/file.py  __init__                                                       4127
  /usr/lib/python2.4/vendor-packages/pkg/manifest.py  make_opener                                                    4127
  /usr/lib/python2.4/vendor-packages/pkg/actions/__init__.py  fromlist                                                       4306
  /usr/lib/python2.4/vendor-packages/pkg/actions/__init__.py  fromstr                                                        4306
  /usr/lib/python2.4/vendor-packages/pkg/actions/generic.py  __init__                                                       4306




2つ目の引数は、どうやらオブジェクトのようです。

 

 kato@opensolaris:~$ pfexec dtrace -n 'python\*:::function-entry{@[copyinstr(arg0),copyinstr(arg1),arg2]=count();} '
dtrace: description 'python\*:::function-entry' matched 2 probes   

/usr/lib/python2.4/inspect.py                       isclass                                                          42               10
  /usr/lib/python2.4/vendor-packages/pkg/version.py   __eq__                                                           70               10
  /usr/lib/python2.4/vendor-packages/pkg/version.py   __str__                                                          60               12
  /usr/lib/python2.4/rfc822.py                        getheader                                                       284               14
  /usr/lib/python2.4/posixpath.py                     exists                                                          168               15
  /usr/lib/python2.4/posixpath.py                     join                                                             56               17
  /usr/lib/python2.4/urllib2.py                       __lt__                                                          454               17
  /usr/lib/python2.4/vendor-packages/pkg/actions/file.py  __init__                                                         53               18
  /usr/lib/python2.4/vendor-packages/pkg/actions/file.py  generate_indices                                                280               18
  /usr/lib/python2.4/vendor-packages/pkg/manifest.py  make_opener                                                     228               19
  /usr/lib/python2.4/posixpath.py                     basename                                                        110               31
  /usr/lib/python2.4/posixpath.py                     split                                                            74               34
  /usr/lib/python2.4/vendor-packages/pkg/actions/__init__.py  fromlist                                                        120               35
  /usr/lib/python2.4/vendor-packages/pkg/actions/__init__.py  fromstr                                                          76               35
  /usr/lib/python2.4/vendor-packages/pkg/actions/generic.py  __init__                                                         92               36
  /usr/lib/python2.4/vendor-packages/pkg/actions/generic.py  __str__                                                         138               36
  /usr/lib/python2.4/vendor-packages/pkg/client/filter.py  apply_filters                                                   129               36
  /usr/lib/python2.4/vendor-packages/pkg/fmri.py      is_same_authority                                               351             2700
/usr/lib/python2.4/vendor-packages/pkg/fmri.py      __cmp__                                                         217         2701


3つ目の引数は、どうやら、行数のようです。

試しに、

/usr/lib/python2.4/vendor-packages/pkg/fmri.py をみてみましょう。

217         def __cmp__(self, other): <- got !!! (\^\^)
218                 if not other:
ということで、かなり細部までわかります。

もちろん、他のproviderとも組み合わせることが可能です。

 

 kato@opensolaris:~$ pfexec dtrace -n 'python\*:::function-entry{@[copyinstr(arg0),copyinstr(arg1),arg2]=count();} tick-1sec{printa(@);trunc(@);}'
dtrace: description 'python\*:::function-entry' matched 3 probes
CPU     ID                    FUNCTION:NAME
  0  52322                       :tick-1sec

  0  52322                       :tick-1sec

  0  52322                       :tick-1sec

  0  52322                       :tick-1sec

  0  52322                       :tick-1sec
  /usr/bin/packagemanager                             get_datetime                                                    573                1
  /usr/bin/packagemanager                             on_package_selection_changed                                    725                1
  /usr/bin/packagemanager                             show_package_info                                               754                1
...

スクリプト言語も簡単にモニタリングできるようになったもんですね。しかも、デバッグコードを入れずに。。 


Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

This blog is talked about OpenSolaris Community Activity and Bencmarking Test, which are my job.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today