DTrace Patch for Python 2.7.x and 3.x

Source: Internet
Author: User

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 is 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 have need to apply the matching patch O Ver 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 (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 "to --with-dtrace your" configure "command line and compile as usual. If you had previously compiled Python in the same directory, remember to do " make distclean " first.

When did, 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_dtracetest_function_entry_return (test.test_dtrace. Dtracetestsnormal) ... oktest_garbage_collection (test.test_dtrace. Dtracetestsnormal) ... oktest_instance_creation_destruction (test.test_dtrace. Dtracetestsnormal) ... oktest_line (test.test_dtrace. Dtracetestsnormal) ... oktest_stack (test.test_dtrace. Dtracetestsnormal) ... Oktest_unicode_function_entry_return (test.test_dtrace. Dtracetestsnormal) ... oktest_unicode_stack (test.test_dtrace. Dtracetestsnormal) ... oktest_verify_opcodes (test.test_dtrace. Dtracetestsnormal) ... ok----------------------------------------------------------------------Ran 8 tests in 5.335soktest_function_entry_return (Test.test_dtrace. Dtracetestsoptimize) ... oktest_garbage_collection (test.test_dtrace. Dtracetestsoptimize) ... oktest_instance_creation_destruction (test.test_dtrace. Dtracetestsoptimize) ... oktest_line (test.test_dtrace. Dtracetestsoptimize) ... oktest_stack (test.test_dtrace. Dtracetestsoptimize) ... Oktest_unicode_function_entry_returN (test.test_dtrace. Dtracetestsoptimize) ... oktest_unicode_stack (test.test_dtrace. Dtracetestsoptimize) ... oktest_verify_opcodes (test.test_dtrace. dtracetestsoptimize) ... ok----------------------------------------------------------------------Ran 8 tests in 5.455sok1 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: ' DTR Ace ' module indicates if the CPython executable currentlyrunning have been compiled with DTrace probes support ... Impl-deta   IL:: DTrace probes is implementation details of the CPython interpreter! No Garantees is 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 would be "True" if the current CPython interpreter is compiled with DTrace probe Suppo   Rt. ' False ' if not. DTrace probes-------------dtrace scripts is run externally to CPython. DTrace probes exportselected events inside CPython interpreter in order to make themaccessible to external scripts. The probes isExported through the "Python" provider. The availableprobes is 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 Co De enters a new function.   *arg0* is sourcecode file path, *arg1* is the name of the funcion called, and *arg2* are 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 is the same as in "Function-entry". The probe is not fired if the finishing function was written in c ... opcode:: Line (arg0, arg1, arg2) Fires when Python C Ode changes the execution line.   Parameters is the same as in "Function-entry". The probe isn't fired in C functions ... opcode:: Gc-start (arg0) Fires when the Python interpreter starts a garbage col   Lection 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 name of the class, *arg1* is the filename where the class is defined. The probe isn't fired for most C code object creations ... opcode:: Instance-new-done (arg0, arg1) Fires when an object Instanciation finishes.   Parameters is the same as in "Instance-new-done". The probe isn't fired for most C code object creations ... opcode:: Instance-delete-start (arg0, arg1) Fires when an obj ECT instance is going to be destroyed.   Parameters is the same as in "Instance-new-done". The probe isn't fired for most C code object destructions ... opcode:: Instance-delete-done (arg0, arg1) Fires when an O Bject instance has been destroyed.   Parameters is 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 a instance creates a deletion cascade. The probe is not a 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 would show cfunctions, with no direct relation to the Python Co De currently beingexecuted. Using the Special "Jstack ()" DTrace function, the user would be givenhints on the Python program stack, if possible. In particular, theaugmented stack would show Python function calls, filename, nameof the function or method, and the line n Umber. DTrace scripts Examples-----------------------DTrace python provider is suffixed by the PID of the process to monitor. In the examples, the PID would be 9876.Show of the time spent doing garbage collection (in nanoseconds):: Python9876:::gc-sta  RT {self->t = timestamp; } python9876:::gc-done/self->t/{printf ("%d", TIMESTAMP-SELF->T);  self->t = 0; }count How many instances is created of each class:: Python9876:::instance-new-start {@v[copyinstr (arg1), Copyins  TR (arg0)] = count (); }observe time spent in object destruction, useful if datastructures arecomplicated 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-sel      F->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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.