DTrace patch for Python 2.7.x and 3.x
DTrace patch for Python 2.7.x and 3.x
Última Actualización: 21 de septiembre de 2015
https://www.jcea.es/artic/python_dtrace.htm
You can follow this work in the Python bugtracker on issue 13405 (original work on issue 4111).
How to get the patch
You can clone my mercurial repository. Interesting branches are dtrace-issue13405_2.7, dtrace-issue13405_3.4, dtrace-issue13405_3.5 and dtrace-issue13405 (future 3.6). This configuration is recommended if you plan to contribute.
If you just want to compile your Python interpreter with dtrace patch applied, you only need to apply the matching patch over a pristine copy of the canonical Python source tree:
- Python 3.5.1: 209b219a8b5b
- Python 3.5.0: a7da156226da
- Python 3.5.0b2: 20ac4207134f
- Python 3.5.0a1: 6a85b8f9fe18
- Python 3.4.4: c450f9cba38a
- Python 3.4.3: d406e844623e
- Python 3.4.2: 55be19e94859
- Python 3.4.1: a1b9322b6d8c
- Python 3.4.0: 0de6441eedb7
- Python 3.4.0rc1: 1c6ba78665ce
- Python 3.4.0b1: 654264da62f2
- Python 2.7.11: 8c5948409bbe (fully compatible with computed gotos)
- Python 2.7.11: 733833f7789d (You must configure with --without-computed-gotos)
- Python 2.7.10: b5158e9b7e17
- Python 2.7.9: 05d8fd4c57a1
- Python 2.7.8: 0b37c3647b82
- Python 2.7.7: af8ecf2352e1
- Python 2.7.6: 0b375fd8628e
- Python 2.7.5: f96ea83cd766
- Python 2.7.3: 1a89922027e1
- Python 3.3.5: b8da4a55237d
- Python 3.3.4: 1c7158230a62
- Python 3.3.3: 93eb37b54d6f
- Python 3.3.2: 23dafaf73d29
- Python 3.3.0: 3f5aab499e15
How to compile and test
Do "autoconf".
Add "--with-dtrace" to your "configure" command line and compile as usual. If you have previously compiled Python in the same directory, remember to do "make distclean" first.
When done, you should run the complete testsuite. If you just want to run dtrace tests, do
# LD_LIBRARY_PATH=`pwd` ./python Lib/test/regrtest.py -v test_dtrace.py
You should get something like
[1/1] test_dtrace
test_function_entry_return (test.test_dtrace.DTraceTestsNormal) ... ok
test_garbage_collection (test.test_dtrace.DTraceTestsNormal) ... ok
test_instance_creation_destruction (test.test_dtrace.DTraceTestsNormal) ... ok
test_line (test.test_dtrace.DTraceTestsNormal) ... ok
test_stack (test.test_dtrace.DTraceTestsNormal) ... ok
test_unicode_function_entry_return (test.test_dtrace.DTraceTestsNormal) ... ok
test_unicode_stack (test.test_dtrace.DTraceTestsNormal) ... ok
test_verify_opcodes (test.test_dtrace.DTraceTestsNormal) ... ok ----------------------------------------------------------------------
Ran 8 tests in 5.335s OK
test_function_entry_return (test.test_dtrace.DTraceTestsOptimize) ... ok
test_garbage_collection (test.test_dtrace.DTraceTestsOptimize) ... ok
test_instance_creation_destruction (test.test_dtrace.DTraceTestsOptimize) ... ok
test_line (test.test_dtrace.DTraceTestsOptimize) ... ok
test_stack (test.test_dtrace.DTraceTestsOptimize) ... ok
test_unicode_function_entry_return (test.test_dtrace.DTraceTestsOptimize) ... ok
test_unicode_stack (test.test_dtrace.DTraceTestsOptimize) ... ok
test_verify_opcodes (test.test_dtrace.DTraceTestsOptimize) ... ok ----------------------------------------------------------------------
Ran 8 tests in 5.455s OK
1 test OK.
The first set of tests run under non-optimizing Python, while the second set run under optimizing Python (-O).
Documentation
:mod:`dtrace` --- DTrace probes for Python
=============================================== .. module:: dtrace
:synopsis: DTrace probes for Python. **Source code:** :source:`Lib/dtrace.py` -------------- The :mod:`dtrace` module indicates if the CPython executable currently
running has been compiled with DTrace probes support. .. impl-detail:: DTrace probes are implementation details of the CPython interpreter!
No garantees are made about probe compatibility between versions of
CPython. DTrace scripts can stop working or work incorrectly without
warning when changing CPython versions. The :mod:`dtrace` module defines the following variable: .. data:: available The variable will be ``True`` if the current CPython interpreter was
compiled with DTrace probe support. ``False`` if not. DTrace probes
------------- DTrace scripts are run externally to CPython. DTrace probes export
selected events inside CPython interpreter in order to make them
accessible to external scripts. The probes are exported through the "python" provider. The available
probes are defined in the file :file:`Include/pydtrace.d`. To learn how to use DTrace, read `DTrace User Guide
`_. .. opcode:: function-entry (arg0, arg1, arg2) Fires when python code enters a new function. *arg0* is sourcecode
file path, *arg1* is the name of the funcion called, and *arg2* is
line number. The probe is not fired if Python code calls C functions. .. opcode:: function-return (arg0, arg1, arg2) Fires when Python code finishes execution of a function. Parameters
are the same as in ``function-entry``. The probe is not fired if the finishing function is written in C. .. opcode:: line (arg0, arg1, arg2) Fires when Python code changes the execution line. Parameters are the
same as in ``function-entry``. The probe is not fired in C functions. .. opcode:: gc-start (arg0) Fires when the Python interpreter starts a garbage collection cycle.
*arg0* is the generation to scan, like :func:`gc.collect()`. .. opcode:: gc-done (arg0) Fires when the Python interpreter finishes a garbage collection
cycle. *arg0* is the number of collected objects. .. opcode:: instance-new-start (arg0, arg1) Fires when an object instanciation starts. *arg0* is the class name,
*arg1* is the filename where the class is defined. The probe is not fired for most C code object creations. .. opcode:: instance-new-done (arg0, arg1) Fires when an object instanciation finishes. Parameters are the same
as in ``instance-new-done``. The probe is not fired for most C code object creations. .. opcode:: instance-delete-start (arg0, arg1) Fires when an object instance is going to be destroyed. Parameters
are the same as in ``instance-new-done``. The probe is not fired for most C code object destructions. .. opcode:: instance-delete-done (arg0, arg1) Fires when an object instance has been destroyed. parameters are the
same as in ``instance-new-done``. Between an ``instance-delete-start`` and corresponding
``instance-delete-done`` others probes can fire if, for instance,
deletion of an instance creates a deletion cascade. The probe is not fired for most C code object destructions. Python stack
------------ When a DTrace probe is fired, the DTrace script can examine the stack.
Since CPython is a Python interpreter coded in C, the stack will show C
functions, with no direct relation to the Python code currently being
executed. Using the special "jstack()" DTrace function, the user will be given
hints about the python program stack, if possible. In particular, the
augmented stack will show python function calls, filename, name
of the function or method, and the line number. DTrace scripts examples
----------------------- DTrace python provider is suffixed by the pid of the process to monitor.
In the examples, the pid will be 9876. Show the time spent doing garbage collection (in nanoseconds):: python9876:::gc-start
{
self->t = timestamp;
} python9876:::gc-done
/self->t/
{
printf("%d", timestamp-self->t);
self->t = 0;
} Count how many instances are created of each class:: python9876:::instance-new-start
{
@v[copyinstr(arg1), copyinstr(arg0)] = count();
} Observe time spent in object destruction, useful if datastructures are
complicated and deletion of an object can create a cascade effect:: python9876:::instance-delete-start
/self->t==0/
{
self->t = timestamp;
self->level = 0;
} python9876:::instance-delete-start
/self->t/
{
self->level += 1;
} python9876:::instance-delete-done
/(self->level) && (self->t)/
{
self->level -= 1;
} python9876:::instance-delete-done
/(self->level==0) && (self->t)/
{
@time = quantize(timestamp-self->t);
self->t = 0;
} To know which python source code lines create new TCP/IP connections:: pid9876::sock_connect:entry
{
@conn[jstack()] = count();
}
DTrace patch for Python 2.7.x and 3.x的更多相关文章
- 偷梁换柱:使用mock.patch辅助python单元测试
最近在搞软工项目的后端测试,重新复习了一下python的mock.patch,并用它简化了对一些复杂逻辑的测试,在此记录 问题描述 本组的项目比较特殊,设计对教务网站的模拟登陆与信息爬取,同时不少接口 ...
- python 2016 大会 pyconsk ppt ---python dtrace
https://github.com/pyconsk/2016-slides PyCon SK 2016 - March 2016 1DTrace and PythonJesús Cea Aviónj ...
- json-patch 了解
What is JSON Patch? JSON Patch is a format for describing changes to a JSON document. It can be used ...
- Linux下编译安装源码包软件 configure ,make, make install, make test/check, make clean
http://www.360doc7.net/wxarticlenew/541275971.html 一.什么是源码包软件? 顾名思义,源码包就是源代码的可见的软件包,基于Linux和BSD系统的软件 ...
- __sizeof__()
https://bugs.python.org/issue2898 https://bugs.python.org/file10353/footprint.patch Index: Python/sy ...
- 应用安全 - 编程语言 | 框架 - PHP - Djiango - 漏洞 -汇总
CVE-2007-0404 Date , 类型Filename validation issue in translation framework. Full description 影响范围 CVE ...
- Linux下编译安装源码包软件 configure ,make, make install, make test/check, make clean 假目标
http://www.360doc7.net/wxarticlenew/541275971.html 一.程序的组成部分 Linux下程序大都是由以下几部分组成: 二进制文件:也就是可以运行的程序文件 ...
- UltraSoft - Beta - Postmortem事后分析
UltraSoft - Beta - PostMORTEM 设想和目标 我们的软件要解决什么问题?是否定义得很清楚?是否对典型用户和典型场景有清晰的描述? 解决的问题和定义都在[软软软]功能规格说明书 ...
- UltraSoft Scrum Meeting 博客汇总
一.Alpha阶段 UltraSoft - Alpha - Scrum Meeting 1 UltraSoft - Alpha - Scrum Meeting 2 UltraSoft - Alpha ...
随机推荐
- JMP软件中的晶圆图( Wafer Map)分析
关键词:芯片 良率分析 晶圆图 质量管理 JMP Minitab 半导体芯片的生产,简单来讲,是将电路通过各种复杂的物理化学方法制作到晶圆上,在生产的最后阶段会进行不同电性功能的测试以确保产品的功能性 ...
- Android 图片处理方法
//压缩图片大小 public static Bitmap compressImage(Bitmap image) { ByteArrayOutputStream baos = new ByteArr ...
- Android fragment 回调函数改进
由于fragment的onResume()等回调的调用时机与Activity不一样,导致用起来比较麻烦,所以我重新封装了一下回调函数,十分简单. 使用时只需要继承此基类,使用onFragmentXXX ...
- 应付分配集 Distribution Sets
(N) AP > Setup > Invoice > Distribution Sets (定义分配集) You can use a Distribution Set to auto ...
- BZOJ_1821_[JSOI2010]_部落划分_(贪心,并查集)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1821 给出n个点的坐标,将n个点划分成k个部分,使得每个部分之间最小的距离最大. 分析 每两个 ...
- puppy 制作linux
经过一段时间的使用以后,我们每个人电脑里的Puppy Linux都是独一无二的,我们可以通过简单的方法将自己电脑上的Puppy制作成iso或Live-CD,成为自己玩的“Only You”Puppy ...
- Master Nginx(3) - Using the Mail Module
Basic proxy service Authentication service Combining with memcached Interpreting log files Operating ...
- 如何判断 Android 应用的 Apk 签名是否一致?
可以比对apk签名的fingerprint. 假定安装了JDK,如果想查HelloWorld.apk所使用的签名的fingerprint,可以这样做: 1. 查找apk里的rsa文件 (Windows ...
- Android与PHP服务器交互
转自:http://blog.csdn.net/ab_ba/article/details/7912424 服务器端:server.php 1 <?php 2 include(' ...
- 数据结构:二级指针与Stack的数组实现
[简介] Stack,栈结构,即传统的LIFO,后进先出,常用的实现方法有数组法和链表法两种.如果看过我上一篇文章<数据结构:二级指针与不含表头的单链表>,一定会看到其中的关键在于,利用v ...