Hisayoshi Kato's weblog at Sun Solution Center
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();}' |
上記のファイルのスクリプトが呼ばれているようですね。
|
kato@opensolaris:~$ pfexec dtrace -n 'python*:::function-entry{@[copyinstr(arg0),copyinstr(arg1)]=count();}' |
2つ目の引数は、どうやらオブジェクトのようです。
|
kato@opensolaris:~$ pfexec dtrace -n
'python*:::function-entry{@[copyinstr(arg0),copyinstr(arg1),arg2]=count();} ' /usr/lib/python2.4/inspect.py
isclass
42 10 |
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 ... |
スクリプト言語も簡単にモニタリングできるようになったもんですね。しかも、デバッグコードを入れずに。。
Posted at 02:09PM May 27, 2008 by katohisa in DTrace | Comments[0]
Tuesday May 27, 2008





