Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/venthur/litestats
Converts Python Profiling Stats into Sqllite3
https://github.com/venthur/litestats
profiling python sqlite
Last synced: 2 months ago
JSON representation
Converts Python Profiling Stats into Sqllite3
- Host: GitHub
- URL: https://github.com/venthur/litestats
- Owner: venthur
- License: mit
- Created: 2018-10-12T12:53:31.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-08-23T06:28:39.000Z (over 1 year ago)
- Last Synced: 2024-08-09T12:17:43.534Z (6 months ago)
- Topics: profiling, python, sqlite
- Language: Python
- Homepage:
- Size: 14.6 KB
- Stars: 7
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Litestats
Profiling in Python has always been easy, however, analyzing the
profiler's output not so much. After the profile has been created you
can use Python's `pstats` module but it feels quite clumsy and not
really empowering.Enter litestats! Litestats is a simple command line tool that takes the
output of the Python profiler and transforms the data into a sqlite3
database. You can now easily analyze the profiler output using `sqlite`
on the command line, the `sqlitebrowser` for a graphical interface or
use the data base as the foundation of your very own tooling around the
analysis.## How does it work?
Litestats reads the dump of the profiler and creates a normalized
data base with tree tables:* `functions`: contains each function (callers and callees) with
filename, line number and function name
* `stats` contains the statistics (primitive/total calls,
total/cumulative time) for all functions
* `calls` a caller-callee mappingWhile this provides an exact representation of the dump, those tables
would be cumbersome to use. So litestats additionally creates three
views resembling `pstats` `print_stats`, `print_callers` and
`print_callees` functionality:* `pstats`
* `callers`
* `callees`## Install
Litestats has **no requirements** other than Python itself:
```bash
$ pip install litestats
```## Usage
```bash
$ # run the profiler and dump the output
$ python3 -m cProfile -o example.prof example.py
$ # convert dump to sqlite3 db
$ litestats example.prof
$ # example.prof.sqlite created
```You can now use the sqlite3 data base to investigate the profiler dump:
```sql
sqlite> select *
...> from pstats
...> order by cumtime desc
...> limit 20;ncalls tottime ttpercall cumtime ctpercall filename:lineno(function)
---------- ---------- -------------------- ---------- ---------- ------------------------------------
18/1 0.000161 8.94444444444444e-06 0.067797 0.067797 ~:0()
1 1.0e-06 1.0e-06 0.067755 0.067755 :1()
1 4.0e-06 4.0e-06 0.067754 0.067754 /usr/lib/python3.7/runpy.py:195(run_
1 6.0e-06 6.0e-06 0.066135 0.066135 /usr/lib/python3.7/runpy.py:62(_run_
1 1.1e-05 1.1e-05 0.066113 0.066113 /home/venthur/Documents/projects/lit
1 6.6e-05 6.6e-05 0.055152 0.055152 /home/venthur/Documents/projects/lit
1 4.1e-05 4.1e-05 0.0549 0.0549 /home/venthur/Documents/projects/lit
1 0.050196 0.050196 0.050196 0.050196 ~:0(:978(_f
20/3 4.8e-05 2.4e-06 0.011005 0.00366833 :948(_f
20/3 7.5e-05 3.75e-06 0.01083 0.00361 :663(_l
15/3 3.5e-05 2.33333333333333e-06 0.01073 0.00357666 :211(_c
3 6.0e-06 2.0e-06 0.010087 0.00336233 ~:0(:1009(_
1 9.0e-06 9.0e-06 0.00841 0.00841 /home/venthur/Documents/projects/lit
16 0.000138 8.625e-06 0.004802 0.00030012