Pikos

Pikos is a profiling and investigation tool suite for python applications. The name is inspired by Pikos Apikos the main character in a mid 80s Greek puppet TV series. Pikos was an investigative journalist assigned to find out about a missing person case in the remote and strange land of “Froutopia”, a country populated by large fruits that can talk.

Key aims of Pikos are:

  • Help identify areas of the an application that need to improve.
  • Use, group and augment rather than replace commonly used tools like cProfile and line_profiler
  • Provide effective memory monitoring throughout python.
  • Be multi-platform.
  • Provide real-time access to profile data and allow live analysis while the application is running.

Repository

Pikos is hosted on github: https://github.com/enthought/pikos

Installation

The package requires a recent version of psutil (>=0.4.1):

python setup.py install

To build with the real-time fork of cProfile please provide the –with-real-time-lsprof before any setup command:

python setup.py --with-real-time-lsprof install

You will need a build of libzmq to compile and link against. If the needed files are not available at system default locations, they will need to be manually provided to the build_ext command:

python setup.py --with-real-time-lsprof build_ext -I <include directory for zmq> -L <libary directory for zmq>
python setup.py --with-real-time-lsprof install

or in one line as:

python setup.py --with-real-time-lsprof build_ext -I <include directory for zmq> -L <library directory for zmq> install

Finally to run the test suite please give:

python setup.py test

Optional packages of external profilers:

Optional packages for the live monitoring tools:

Usage

The main component in the pikos toolset is the Monitor. A monitor creates a number of records during the execution of the code which are passed on the recorder to be stored into memory or file.

In code

Monitors can be used programmatically in a number of ways.

  1. Enabled/Disabled using the corresponding functions:

    from pikos.api import screen
    from pikos.monitors.api import FunctionMonitor
    
    monitor = Monitor(recorder=screen())
    monitor.enable()
    
    # monitored code
    #
    
    monitor.disable()
    
  2. A monitor instance can be used as a context manager:

    from pikos.api import screen
    from pikos.monitors.api import FunctionMonitor
    
    monitor = Monitor(recorder=screen())
    
    with monitor:
        # monitored code
        #
        pass
    
  3. With the use of the attach method a monitor becomes a decorator:

    from pikos.api import screen
    from pikos.monitors.api import FunctionMonitor
    
    monitor = Monitor(recorder=screen())
    
    @monitor.attach
    def monitored_function():
        # monitored code
        #
        pass
    
  4. Finally the pikos.api module provides easy to use decorator factories for the standard monitors that are provided by pikos. The factories can optionally accept a recorder and dictate if a focused monitor should be used a:

    from pikos.api import function_monitor, csv_file
    
    @function_monitor(recorder=csv_file(), focused=True)
    def monitored_function():
        # monitored code
        #
        pass
    

Command line

Indices and tables