• Stars
    star
    105
  • Rank 321,461 (Top 7 %)
  • Language
    Python
  • License
    MIT License
  • Created over 5 years ago
  • Updated 14 days ago

Reviews

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

Repository Details

Generate waterfalls from `-Ximporttime` tracing.

build status pre-commit.ci status

importtime-waterfall

Generate waterfalls from -Ximporttime tracing.

install

pip install importtime-waterfall

note: importtime-waterfall requires python3.7+

usage

importtime-waterfall provides a single executable by the same name.

importtime-waterfall takes a module name as a positional argument. This is the module that will be profiled.

--include-interpreter-startup

Include tracing information of modules that are always imported as part of interpreter startup. These are usually not interesting and so they are left out by default.

--har

Output as an HTTP Archive or "HAR" file. Yes these aren't actual HTTP requests but it's an easy way to get a visualization using a standardized data format.

HAR unfortunaly doesn't have microsecond resolution so all times in the HAR output are * 1000 (1 μs => 1ms).

The easiest way to use the output of this is to paste it into a har viewer.

I use the following:

$ importtime-waterfall importtime_waterfall --har | xclip -selection c

xclip takes the output and puts it onto the clipboard. Alternatively, you can redirect to a file (> foo.har) and upload it that way.

Once pasted into the viewer you can inspect the output.

The blocked import time is represented as "waiting" (purple) and the self time is represented as "receiving" (grey). Generally when looking for slow modules look for ones with large grey chunks.

--graph

(this is the default display). Display the output as a tree. This doesn't really add much on top of what python -Ximporttime already displays (but was useful for developing / debugging this tool). I guess it's in human order instead of reversed so that's something 🤷.

Times displayed next to the module names are self-times in μs.

$ importtime-waterfall importtime_waterfall
importtime_waterfall (419)
  argparse (864)
    re (599)
      enum (661)
      sre_compile (270)
        _sre (109)
        sre_parse (336)
          sre_constants (339)
      copyreg (161)
    gettext (1056)
      locale (820)
  datetime (768)
    time (234)
    math (57)
    _datetime (154)
  json (254)
    json.decoder (446)
      json.scanner (481)
        _json (193)
    json.encoder (443)
  subprocess (628)
    signal (1030)
    errno (101)
    _posixsubprocess (40)
    select (51)
    selectors (543)
      collections.abc (184)
    threading (578)
      traceback (394)
        linecache (162)
          tokenize (911)
            token (178)
      _weakrefset (217)
  typing (1469)

success stories

I used this to find a 24% speedup in flake8's startup.

nitty-gritty how it works

importtime-waterfall imports the profiled module in a subprocess while setting the -Ximporttime flag. importtime-waterfall picks the best-of-5 (by total time) and uses that result. It parses the "import time:" lines and then outputs.

More Repositories

1

pyupgrade

A tool (and pre-commit hook) to automatically upgrade syntax for newer versions of the language.
Python
3,385
star
2

reorder-python-imports

Rewrites source to reorder python imports
Python
719
star
3

git-code-debt

A dashboard for monitoring code debt in a git repository.
Python
564
star
4

all-repos

Clone all your repositories and apply sweeping changes.
Python
523
star
5

babi

a text editor
Python
380
star
6

add-trailing-comma

A tool (and pre-commit hook) to automatically add trailing commas to calls and literals.
Python
332
star
7

dead

dead simple python dead code detection
Python
322
star
8

yesqa

Automatically remove unnecessary `# noqa` comments
Python
259
star
9

astpretty

Pretty print the output of python stdlib `ast.parse`.
Python
189
star
10

detect-test-pollution

a tool to detect test pollution
Python
168
star
11

setup-cfg-fmt

apply a consistent format to `setup.cfg` files
Python
151
star
12

setup-py-upgrade

upgrade a setup.py to declarative metadata
Python
146
star
13

scratch

Haphazard things.
Python
117
star
14

setuptools-golang

A setuptools extension for building cpython extensions written in golang.
Python
98
star
15

dockerfile

Parse a dockerfile into a high-level representation using the official go parser
Go
95
star
16

re-assert

show where your regex match assertion failed!
Python
81
star
17

gh-perf-review

hackety tool to view github PRs for a period
Python
79
star
18

covdefaults

A coverage plugin to provide sensible default settings
Python
62
star
19

tokenize-rt

A wrapper around the stdlib `tokenize` which roundtrips.
Python
48
star
20

flake8-typing-imports

flake8 plugin which checks that typing imports are properly guarded
Python
48
star
21

cfgv

Validate configuration and produce human readable error messages
Python
44
star
22

recipes

One day IoT will catch up and then I can use CI
26
star
23

classify-imports

Utilities for refactoring imports in python-like syntax.
Python
23
star
24

awshelp

awshelp forwards arguments to `aws` unless `-h` or `--help` are present
Python
20
star
25

setuptools-golang-examples

Example extensions written for https://github.com/asottile/setuptools-golang
Go
19
star
26

nintendo-microcontrollers

control various nintendo consoles with arduino!
Python
18
star
27

watch-plz

Ensure all of your repositories are watched.
Python
17
star
28

workflows

reusable github workflows / actions
17
star
29

onigurumacffi

python cffi bindings for the oniguruma regex engine
Python
16
star
30

color-code

Encodes files as color
Python
16
star
31

ukkonen

Implementation of bounded Levenshtein distance (Ukkonen)
C++
15
star
32

wat

my brain is full of wat
Python
11
star
33

personal-puppet

serverless puppet to manage my machines
Puppet
11
star
34

shiny-pokemon-scraper

automatically detect tera raid events with guaranteed shiny pokemon
Python
10
star
35

set-delete-branch-on-merge

github does not provide a way to set the `delete_branch_on_merge` as a default
Python
8
star
36

babi-grammars

pip installable package to provide syntax grammars for babi
Python
8
star
37

rubyvenv

Create no-hassle ruby "virtualenvs". No .bashrc, no shims, no cd-magic.
Python
7
star
38

tessdata

pip installable versions of tesseract-ocr data
Python
6
star
39

pygments-pre-commit

A pygments lexer for pre-commit output.
Python
6
star
40

setuptools-download

setuptools plugin to download external files
Python
5
star
41

t

haphazard code snippets
Python
4
star
42

markdown-code-blocks

Generate html from markdown with code-block highlighting
Python
4
star
43

asottile.github.io

Python
4
star
44

hiera-eyaml-sshagent

A hiera-eyaml plugin which uses the ssh agent connected to `SSH_AUTH_SOCK` to encrypt / decrypt values.
Ruby
4
star
45

kensquared

Kotlin
2
star
46

.github

centralized github metadata for asottile
2
star
47

itl

Python
2
star
48

asottile

2
star
49

gnome-terminal-broken

rip
1
star