Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ __pycache__/
*.onnx
.DS_Store
hmm_model/
profiles/
3 changes: 2 additions & 1 deletion backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,5 @@ def analyze_sleep():
allow_headers='Content-Type')
app.config['CORS_HEADERS'] = 'Content-Type'

serve(app, host='0.0.0.0', port=8080)
if __name__ == '__main__':
serve(app, host='0.0.0.0', port=8080)
18 changes: 18 additions & 0 deletions backend/profiler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from waitress import serve
from werkzeug.middleware.profiler import ProfilerMiddleware
from pathlib import Path
from os import path, makedirs
import sys

from app import app

SCRIPT_PATH = Path(path.realpath(sys.argv[0])).parent
PROFILES_PATH = SCRIPT_PATH / "profiles"

if not path.exists(PROFILES_PATH):
makedirs(PROFILES_PATH)

app = ProfilerMiddleware(app, stream=None, profile_dir="profiles")

if __name__ == '__main__':
serve(app, host='0.0.0.0', port=8080)
10 changes: 9 additions & 1 deletion backend/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ source venv/bin/activate
Install the required dependencies.

```bash
pip install -r requirements.txt requirements-dev.txt
pip install -r requirements.txt -r requirements-dev.txt
```

If you are running on Linux or MacOS, you also have to install OpenMP with your package manager. It is a dependency of ONNX runtime, used to load our model and make predictions.
Expand All @@ -40,3 +40,11 @@ If you want to run the backend with hot reload enabled (you must have installed
```bash
hupper -m waitress app:app
```

## Profile application

- Run `python profiler.py`

- Send the request to the server

- Open the profiler result contained in `profiles` folder with `snakeviz`
2 changes: 2 additions & 0 deletions backend/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
hupper==1.10.2
pyinstaller==4.0
snakeviz==2.1.0
Werkzeug==1.0.1