Code Monkey home page Code Monkey logo

pyinstrument-py24-backport's Introduction

pyinstrument backport to Python 2.4

Pyinstrument is a Python profiler. A profiler is a tool to help you 'optimize' your code - make it faster. It sounds obvious, but to get the biggest speed increase you must focus on the slowest part of your program. Pyinstrument helps you find it!

This fork is a backport of Pyinstrument to Python 2.4. It was forked from version 2.1.1 of Pyinstrument. Please do not use it if you are running a version of Python that is natively supported by Pyinstrument (2.7 or 3.3+).

Installation

Copy the pyinstrument folder to your library folder (i.e. somewhere in your PYTHONPATH).

How to use it

The only use case that was completely backported is the API that allows profiling a specific chunk of code.

from pyinstrument import Profiler

profiler = Profiler()
profiler.start()

# code you want to profile

profiler.stop()

print(profiler.output_text(unicode=True, color=True))

(You can omit the unicode and color flags if your output/terminal does not support them.)

What is changed in this backport?

Breaking changes

  • dropped support for the pyinstrument C extension because this fork can not use pip nor wheels. In practice it means: this version of the profiler has a larger performance overhead.
  • dropped dynamic imports, which means that no custom renderers nor recorders can be used.

Non-breaking changes

  • added replacement code for methodcaller (part of the standard packages in 2.6+).
  • added replacement code for relpath (part of the standard packages in 2.6+), not as good as the real relpath but it does the job in pyinstrument's case.
  • enforced some path normalizations because there is no os.fspath to take care of it.
  • rewrote imports in old style (no relative path shortcuts, mostly).
  • rewrote string formats in old style (% instead of format).
  • removed six and thus compatibility with Python 3, obviously.
  • removed abc entirely, it was imported but not visibly used.
  • replaced with statements with straigtforward open-close calls.
  • replaced ternary if-else assignations with assignations behind multiple if statements.

Unsupported scenarios

Neither the Django middleware nor the command-line pyinstrument were backported. The files are still there, but they will not work if you try using them.

As a consequence, the HTML renderer was not tested. However, all the code in renderers.py was backported, so the renderer itself should work.

This version was only tested on Linux (a CentOS as old as Python 2.4), but chances it works on Windows are high.

Other

Items that will explicitly not be maintained as part of this backport have been removed from the repository. They are:

  • examples, because all but one were Django-based, and the last one would require the command-line pyinstrument
  • metrics, for many reasons: the c extension is not supported, cProfile is only for Python 2.5+, and Django is partially required
  • tests, because pytest no longer supports anything before Python 2.7 and it actually breaks
  • development, maintenance and setup files and documentation: this fork will never be published as a package

pyinstrument-py24-backport's People

Contributors

asmeurer avatar bursauxa avatar codelol avatar iddan avatar joerick avatar mrblaise avatar pmlandwehr avatar prashanthmadi avatar x1ah avatar z2kviswanathan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.