wfork-streamlit-profiler 0.2.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,84 @@
|
|
1
|
+
import streamlit.components.v1 as components
|
2
|
+
from pyinstrument import Profiler as OriginalProfiler
|
3
|
+
|
4
|
+
|
5
|
+
class Profiler(OriginalProfiler):
|
6
|
+
def stop(self):
|
7
|
+
session = super().stop()
|
8
|
+
|
9
|
+
# Create HTML report of profiling results.
|
10
|
+
html = self.output_html()
|
11
|
+
|
12
|
+
# Adapt style of html report to match Streamlit's design.
|
13
|
+
|
14
|
+
# Default colors for Streamlit's white theme.
|
15
|
+
# TODO: Use streamlit's theme colors instead of hardcoding colors. Doesn't work
|
16
|
+
# currently, see https://github.com/streamlit/streamlit/issues/4198.
|
17
|
+
text_color = "#31333f"
|
18
|
+
background_color = "#ffffff"
|
19
|
+
secondary_background_color = "#f0f2f6"
|
20
|
+
caption_color = "#84858c"
|
21
|
+
|
22
|
+
# Default font color
|
23
|
+
html = html.replace("#fff", text_color)
|
24
|
+
# Background color
|
25
|
+
html = html.replace("#303538", background_color)
|
26
|
+
# Line background when hovered
|
27
|
+
html = html.replace(
|
28
|
+
"background-color:#354759;opacity:.5",
|
29
|
+
f"background-color:{secondary_background_color}",
|
30
|
+
)
|
31
|
+
# Header background
|
32
|
+
html = html.replace("#292f32", secondary_background_color)
|
33
|
+
# Expander background
|
34
|
+
html = html.replace("#3b4043", secondary_background_color)
|
35
|
+
# Expander background when hovered
|
36
|
+
html = html.replace("#4a4f54", "#c1c1c5")
|
37
|
+
# Expander text + triangle
|
38
|
+
html = html.replace("hsla(0,0%,100%,.58)", caption_color)
|
39
|
+
html = html.replace('fill:"#FFF"', f'fill:"{caption_color}"')
|
40
|
+
html = html.replace('"fill-opacity":".582"', f'"fill-opacity":"1"')
|
41
|
+
# Vertical guiding lines
|
42
|
+
html = html.replace("opacity:.08", "opacity:.4")
|
43
|
+
# File name and line (right side)
|
44
|
+
html = html.replace("hsla(0,0%,100%,.5)", caption_color)
|
45
|
+
# Metrics top right
|
46
|
+
html = html.replace("#737779", text_color)
|
47
|
+
# Metrics top right labels
|
48
|
+
html = html.replace("#a9abad", caption_color)
|
49
|
+
|
50
|
+
# Blue -> blue 80
|
51
|
+
html = html.replace("#5db3ff", "#1c83e1")
|
52
|
+
# Red -> red 80
|
53
|
+
html = html.replace("#FF4159", "#ff2b2b")
|
54
|
+
# Yellow -> yellow 80
|
55
|
+
# html = html.replace("#D8CB2A", "#faca2b")
|
56
|
+
# Green -> green 70
|
57
|
+
html = html.replace("#7ED321", "#21c354")
|
58
|
+
# Font weight of green color from 500 to 600 (to match other colors).
|
59
|
+
# html = html.replace("e=500", "e=600")
|
60
|
+
|
61
|
+
# Add border around body. Make it stick to the component iframe.
|
62
|
+
html = html.replace(
|
63
|
+
"body,html{",
|
64
|
+
"body{position:absolute;top:0;right:0;bottom:0;left:0;border:1px solid #d6d6d8;border-radius:0.25rem}body,html{", # padding-bottom: 20px !important
|
65
|
+
)
|
66
|
+
|
67
|
+
# Make header top corners rounded to match border.
|
68
|
+
html = html.replace(
|
69
|
+
".header[data-v-0183f483]{",
|
70
|
+
".header[data-v-0183f483]{border-radius:0.25rem 0.25rem 0 0;",
|
71
|
+
)
|
72
|
+
|
73
|
+
# Make timeline content scrollable, but keep header fixed. Adapt padding.
|
74
|
+
html = html.replace("#app{", "#app{display:flex;flex-flow:column;height:100%;")
|
75
|
+
html = html.replace(
|
76
|
+
"#app{", "#app > div:nth-child(3){padding: 20px 30px;overflow:scroll}#app{"
|
77
|
+
)
|
78
|
+
html = html.replace('height:"20px"', 'height:"0"') # remove spacer
|
79
|
+
# html = html.replace(".margins{", ".margins{overflow:scroll;")
|
80
|
+
|
81
|
+
# Display modified HTML report in iframe.
|
82
|
+
components.html(html, height=600)
|
83
|
+
|
84
|
+
return session
|
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2021 Johannes Rieke
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,76 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: wfork-streamlit-profiler
|
3
|
+
Version: 0.2.5
|
4
|
+
Summary: (fork of) Runtime profiler for Streamlit, powered by pyinstrument
|
5
|
+
Home-page: https://github.com/wyattscarpenter/streamlit-profiler
|
6
|
+
License: MIT
|
7
|
+
Author: Johannes Rieke
|
8
|
+
Author-email: johannes.rieke@gmail.com
|
9
|
+
Requires-Python: >=3.7,<4.0
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
12
|
+
Classifier: Programming Language :: Python :: 3.7
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
18
|
+
Requires-Dist: pyinstrument (==4.2.0)
|
19
|
+
Requires-Dist: streamlit (>=1.0.0,<2.0.0)
|
20
|
+
Description-Content-Type: text/markdown
|
21
|
+
|
22
|
+
# wfork-streamlit-profiler 🏄🏼
|
23
|
+
|
24
|
+
[](https://pypi.org/project/wfork-streamlit-profiler/)
|
25
|
+
|
26
|
+
**Runtime profiler for Streamlit, powered by [pyinstrument](https://github.com/joerick/pyinstrument).**
|
27
|
+
|
28
|
+
* wfork-streamlit-profiler is a fork of streamlit-profiler 0.2.4. If there are any newer versions of the original streamlit-profiler, you should probably use those instead. See the original project's github for more: https://github.com/jrieke/streamlit-profiler *
|
29
|
+
|
30
|
+
streamlit-profiler is a [Streamlit component](https://streamlit.io/components) that
|
31
|
+
helps you find out which parts of your app are slow. It profiles the code via
|
32
|
+
[pyinstrument](https://github.com/joerick/pyinstrument) and shows the results right
|
33
|
+
within your Streamlit app.
|
34
|
+
|
35
|
+
<sup>Alpha version, use with care.</sup>
|
36
|
+
|
37
|
+
---
|
38
|
+
|
39
|
+
<h3 align="center">
|
40
|
+
⏱️ <a href="https://share.streamlit.io/jrieke/streamlit-profiler/main/examples/basic.py">Live demo</a> ⏱️
|
41
|
+
</h3>
|
42
|
+
|
43
|
+
---
|
44
|
+
|
45
|
+
<p align="center">
|
46
|
+
<a href="https://share.streamlit.io/jrieke/streamlit-profiler/main/examples/basic.py"><img src="images/demo.png" width=600></a>
|
47
|
+
</p>
|
48
|
+
|
49
|
+
## Installation
|
50
|
+
|
51
|
+
```bash
|
52
|
+
pip install wfork-streamlit-profiler
|
53
|
+
```
|
54
|
+
|
55
|
+
## Usage
|
56
|
+
|
57
|
+
```python
|
58
|
+
import streamlit as st
|
59
|
+
from streamlit_profiler import Profiler
|
60
|
+
|
61
|
+
with Profiler():
|
62
|
+
st.title("My app")
|
63
|
+
# ... other code
|
64
|
+
|
65
|
+
# Or:
|
66
|
+
# p = Profiler()
|
67
|
+
# p.start()
|
68
|
+
# ...
|
69
|
+
# p.stop()
|
70
|
+
```
|
71
|
+
|
72
|
+
Then start your app as usual: `streamlit run my_app.py`
|
73
|
+
|
74
|
+
The `Profiler` class is an extension of `pyinstrument.Profiler`, so you can use
|
75
|
+
[all of its functions](https://pyinstrument.readthedocs.io/en/latest/reference.html#pyinstrument.Profiler).
|
76
|
+
|
@@ -0,0 +1,5 @@
|
|
1
|
+
wfork_streamlit_profiler/__init__.py,sha256=LVSu6yccrR7AYARUDZmk2R9gQlvEnOR_zbgq_jH6iKQ,3503
|
2
|
+
wfork_streamlit_profiler-0.2.5.dist-info/LICENSE,sha256=Y9ej8y1BLFQZSAREXkrHmDgA0M35msgF8d6D9KoFf5c,1071
|
3
|
+
wfork_streamlit_profiler-0.2.5.dist-info/METADATA,sha256=-dmMS0LfoTdjZw2Vv7J3pUl-ceat4yaBOd2m6yxm2e8,2508
|
4
|
+
wfork_streamlit_profiler-0.2.5.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
5
|
+
wfork_streamlit_profiler-0.2.5.dist-info/RECORD,,
|