Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve tracing performances when f_trace is NULL #60876

Closed
xdegaye mannequin opened this issue Dec 12, 2012 · 15 comments
Closed

improve tracing performances when f_trace is NULL #60876

xdegaye mannequin opened this issue Dec 12, 2012 · 15 comments
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@xdegaye
Copy link
Mannequin

xdegaye mannequin commented Dec 12, 2012

BPO 16672
Nosy @birkenfeld, @jcea, @abalkin, @pitrou, @benjaminp, @asvetlov, @xdegaye
Files
  • f_trace_perfs.diff
  • foo.py
  • bar.py
  • f_trace_perfs-2.7.patch
  • revert_f_trace_perfs.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/benjaminp'
    closed_at = <Date 2013-01-23.15:09:44.806>
    created_at = <Date 2012-12-12.21:37:38.773>
    labels = ['interpreter-core', 'type-feature']
    title = 'improve tracing performances when f_trace is NULL'
    updated_at = <Date 2013-12-21.14:05:20.947>
    user = 'https://github.com/xdegaye'

    bugs.python.org fields:

    activity = <Date 2013-12-21.14:05:20.947>
    actor = 'xdegaye'
    assignee = 'benjamin.peterson'
    closed = True
    closed_date = <Date 2013-01-23.15:09:44.806>
    closer = 'benjamin.peterson'
    components = ['Interpreter Core']
    creation = <Date 2012-12-12.21:37:38.773>
    creator = 'xdegaye'
    dependencies = []
    files = ['28297', '28298', '28299', '28803', '28806']
    hgrepos = []
    issue_num = 16672
    keywords = ['patch']
    message_count = 15.0
    messages = ['177390', '177391', '178082', '180391', '180394', '180395', '180401', '180402', '180408', '180459', '180460', '180461', '180462', '180463', '206736']
    nosy_count = 8.0
    nosy_names = ['georg.brandl', 'jcea', 'belopolsky', 'pitrou', 'benjamin.peterson', 'asvetlov', 'xdegaye', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'rejected'
    stage = 'patch review'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue16672'
    versions = ['Python 3.4']

    @xdegaye
    Copy link
    Mannequin Author

    xdegaye mannequin commented Dec 12, 2012

    When f_trace is NULL, only PyTrace_CALL tracing events trigger the invocation of
    the trace function (see trace_trampoline).
    maybe_call_line_trace() does quite some work though _PyCode_CheckLineNumber to
    find out if the instruction should be traced, and all this work is useless when f_trace
    is NULL. The patch checks for f_trace on all tracing events that are not
    PyTrace_CALL.

    The performance gain with the following test is about 30%. The first test is
    with python on the default branch, the second one with the patch applied.
    Note: a breakpoint is set at line 1 to ensure that tracing is enabled, without
    any breakpoint, pdb sets the trace function to None after a continue.

    $ ./python -m pdb /tmp/foo.py
    > /tmp/foo.py(1)<module>()
    -> import timeit
    (Pdb) break 1
    Breakpoint 1 at /tmp/foo.py:1
    (Pdb) continue
    9.226385930000106
    The program finished and will be restarted
    > /tmp/foo.py(1)<module>()
    -> import timeit
    (Pdb) q
    [62276 refs]
    
    
    $ ./python -m pdb /tmp/foo.py 
    > /tmp/foo.py(1)<module>()
    -> import timeit
    (Pdb) break 1
    Breakpoint 1 at /tmp/foo.py:1
    (Pdb) continue
    7.199809867001022
    The program finished and will be restarted
    > /tmp/foo.py(1)<module>()
    -> import timeit
    (Pdb)

    @xdegaye xdegaye mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement labels Dec 12, 2012
    @xdegaye
    Copy link
    Mannequin Author

    xdegaye mannequin commented Dec 12, 2012

    When f_trace is NULL, only PyTrace_CALL tracing events trigger the invocation
    of the trace function (see trace_trampoline).

    This may be confusing. I meant that when f_trace is NULL, PyTrace_LINE,
    PyTrace_RETURN and PyTrace_EXCEPTION are not traced.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Dec 24, 2012

    New changeset 1fb26db7d719 by Benjamin Peterson in branch 'default':
    improve tracing performance when f_trace is NULL (closes bpo-16672)
    http://hg.python.org/cpython/rev/1fb26db7d719

    @python-dev python-dev mannequin closed this as completed Dec 24, 2012
    @xdegaye
    Copy link
    Mannequin Author

    xdegaye mannequin commented Jan 22, 2013

    Attached is a patch for the current head of 2.7.
    It would nice to have this patch on 2.7 too.

    With this patch, an implementation of pdb running on 2.7 with an
    extension module, runs at 1.2 times the speed of the interpreter when
    the trace function is active (see
    http://code.google.com/p/pdb-clone/wiki/Performances). The performance
    gain is 30%.

    @jcea jcea reopened this Jan 22, 2013
    @jcea
    Copy link
    Member

    jcea commented Jan 22, 2013

    Benjamin, ans the previous commiter, could you possibly check the 2.7 proposed patch?

    @benjaminp
    Copy link
    Contributor

    This patch causes test_hotshot to fail.

    @pitrou
    Copy link
    Member

    pitrou commented Jan 22, 2013

    I don't think performance patches should be committed to bugfix branches (especially 2.7 which is in slow maintenance mode). Recommend closing.

    @benjaminp
    Copy link
    Contributor

    That, too.

    @xdegaye
    Copy link
    Mannequin Author

    xdegaye mannequin commented Jan 22, 2013

    One may argue that this is not only a performances patch and that it
    fixes the wasting of cpu resources when tracing is on. Wasting cpu
    resources is a bug. Anyway, this is fine with me to close this minor
    issue on 2.7.

    The test_hotshot test is ok on my linux box and with the patch applied
    on 2.7 head. Just curious to know what the problem is.

    And thanks for applying the patch to 3.4.

    @xdegaye
    Copy link
    Mannequin Author

    xdegaye mannequin commented Jan 23, 2013

    The patch applied to the default branch should be reverted.

    The 2.7 _hotshot extension module follows the specifications of PyEval_SetTrace:

    """Set the tracing function to func. This is similar to PyEval_SetProfile(),
    except the tracing function does receive line-number events."""
    ^^^^^^^^^^^^

    The 2.7 patch breaks test_hotshot because PyTrace_LINE events are not sent
    anymore when f_trace is NULL.

    The first patch (already applied to the default branch), breaks also existing
    applications that expect to receive line events when they don't care to
    implement the following semantics defined by sys.settrace:

    """The trace function is invoked (with event set to 'call') whenever a new
    local scope is entered; it should return a reference to a local trace
    function to be used that scope, or None if the scope shouldn’t be
    traced."""

    Those applications want to receive unconditionally line debug events.

    Attached is a patch that reverts the patch on the default branch.

    @jcea
    Copy link
    Member

    jcea commented Jan 23, 2013

    So, Xavier, are you saying that you are reverting the patch?.

    Could be possible to provide a "good" patch, with a correct test of the situation you describe?

    Or are you suggesting just revert this and close this bugentry for good?.

    @jcea jcea reopened this Jan 23, 2013
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jan 23, 2013

    New changeset cd87afe18ff8 by Benjamin Peterson in branch 'default':
    revert bpo-16672 for incorrect semantics
    http://hg.python.org/cpython/rev/cd87afe18ff8

    @xdegaye
    Copy link
    Mannequin Author

    xdegaye mannequin commented Jan 23, 2013

    It is not possible to improve the performances of the trace function set with
    sys.settrace without breaking backward compatibility for PyEval_SetTrace or
    without introducing a new PyEval_xxx of some sort.

    Yes, I suggest to revert this patch.

    @xdegaye
    Copy link
    Mannequin Author

    xdegaye mannequin commented Jan 23, 2013

    status should be close, I guess.

    @xdegaye
    Copy link
    Mannequin Author

    xdegaye mannequin commented Dec 21, 2013

    A patch proposed in bpo-20041 provides a backward compatible solution to this performance enhancement.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants