• Stars
    star
    1,624
  • Rank 28,812 (Top 0.6 %)
  • Language
    Python
  • License
    MIT License
  • Created over 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple real time visualisation of the execution of a Python program.

heartrate

This library offers a simple real time visualisation of the execution of a Python program:

demo

The numbers on the left are how many times each line has been hit. The bars show the lines that have been hit recently - longer bars mean more hits, lighter colours mean more recent.

Calls that are currently being executed are highlighted thanks to the executing library.

It also shows a live stacktrace:

stacktrace

Installation

pip install --user heartrate

Supports Python 3.5+.

Usage

import heartrate; heartrate.trace(browser=True)

This will:

  • Start tracing your program
  • Start a server in a thread
  • Open a browser window displaying the visualisation of the file where trace() was called.

In the file view, the stacktrace is at the bottom. In the stacktrace, you can click on stack entries for files that are being traced to open the visualisation for that file at that line.

trace only traces the thread where it is called. To trace multiple threads, you must call it in each thread, with a different port each time.

Options

  • files determines which files get traced in addition to the one where trace was called. It must be a callable which accepts one argument: the path to a file, and returns True if the file should be traced. For convenience, a few functions are supplied for use, e.g.:

    from heartrate import trace, files
    trace(files=files.path_contains('my_app', 'my_library'))

    The supplied functions are:

    • files.all: trace all files.
    • files.path_contains(*substrings) trace all files where the path contains any of the given substrings.
    • files.contains_regex(pattern) trace all files which contain the given regex in the file itself, so you can mark files to be traced in the source code, e.g. with a comment.

    The default is to trace files containing the comment "# heartrate" (spaces optional).

    If you're tracing multiple files, there are two ways to get to the pages with their visualisations:

    1. In the stacktrace, click on stack entries for files that are being traced. This will open the page and jump to the line in that stack entry.
    2. Go to the index page at http://localhost:9999/ (you can click on the logo in the top left corner) to see a list of traced files.
  • host: HTTP host for the server. To run a remote server accessible from anywhere, use '0.0.0.0'. Default '127.0.0.1'.

  • port: HTTP port for the server. Default 9999.

  • browser: if True, automatically opens a browser tab displaying the visualisation for the file where trace is called. False by default.

  • daemon: sets whether the thread containing the server is a daemon thread. Set this to true to shut down the server once the rest of the program completes.

Related libraries

  • pyheat: a heatmap showing which lines of a file consume the most time.
  • snoop: a feature-rich and convenient debugging library which records every line executed, the local variables at each point, and other information.
  • birdseye: a debugger which lets you easily view the value of every expression

More Repositories

1

birdseye

Graphical Python debugger which lets you easily view the values of all evaluated expressions
JavaScript
1,570
star
2

futurecoder

100% free and interactive Python course for beginners
Python
1,292
star
3

snoop

A powerful set of Python debugging tools, based on PySnooper
Python
927
star
4

sorcery

Dark magic delights in Python
Python
353
star
5

executing

Get information about what a Python frame is currently doing, particularly the AST node being executed
Python
324
star
6

s3-stream-upload

Manages streaming of data to AWS S3 without knowing the size beforehand and without keeping it all in memory or writing to disk.
Java
200
star
7

funcfinder

A tool for automatically solving problems of the form "I need a python function that does X."
Python
165
star
8

instant_api

Instantly create an HTTP API with automatic type conversions, JSON RPC, and a Swagger UI. Just add methods!
Python
126
star
9

stack_data

Python
32
star
10

birdseye-pycharm

IntelliJ IDE plugin for the Python debugger birdseye
Java
31
star
11

pure_eval

Safely evaluate AST nodes without side effects
Python
26
star
12

outdated

Check if a version of a PyPI package is outdated
Python
22
star
13

cheap_repr

Better version of repr/reprlib for short, cheap string representations in Python
Python
21
star
14

friendly_states

Declarative, explicit, tool-friendly finite state machines in Python
Python
19
star
15

nameof

Python function to get the name of a variable or attribute, as in C#
Python
13
star
16

boxes

A library that adds object oriented power to fields, letting you do better than traditional getters and setters.
Java
12
star
17

sunhours

Sketchup plugin for analysing the amount of sunlight hitting points on a surface over the year:
HTML
10
star
18

pyodide-worker-runner

TypeScript
9
star
19

instant_client

Type safe JSON RPC client with automatic (de)serialization. Best paired with instant_api.
Python
7
star
20

jsonfinder

Python library to easily handle JSON contained within strings.
Python
7
star
21

oeis-explorer

Explore related sequences in the OEIS
Python
6
star
22

sync-message

TypeScript
5
star
23

comsync

TypeScript
4
star
24

python_runner

Helper for running python code indirectly
Python
4
star
25

dryenv

Simple DRY configuration with environment variables and pydantic
Python
4
star
26

littleutils

Small personal collection of python utility functions, partly just for fun.
Python
3
star
27

askso

AskSO - StackOverflow Python Question Assistant
Python
2
star
28

datafunctions

Automatic (de)serialization of arguments and return values for Python functions
Python
2
star
29

quiggles

Android app for drawing symmetrical patterns
Kotlin
2
star
30

alexmojaki

2
star
31

dependent_types

Python
1
star
32

case-classes

A framework to refactor computing a result from an aggregate object
Java
1
star
33

trace_augmentation

Python
1
star