Changes to set up the host python app with uv

This commit is contained in:
Atharva Sawant
2025-11-28 08:26:21 +05:30
parent 852957a7de
commit 3d4c3f7f04
10 changed files with 853 additions and 61 deletions

1
host/.python-version Normal file
View File

@@ -0,0 +1 @@
3.11

123
host/README.md Normal file
View File

@@ -0,0 +1,123 @@
# MiniProfiler Host Application
Python-based host application for real-time embedded profiling visualization.
## Quick Start with uv
### 1. Setup
```bash
# Create virtual environment
uv venv
# Activate it
source .venv/bin/activate # Linux/macOS
# or
.venv\Scripts\activate # Windows
# Install package
uv pip install -e .
```
### 2. Run
```bash
# Start the web server
miniprofiler
# Or with options
miniprofiler --host 0.0.0.0 --port 8080 --verbose
```
### 3. Test with Sample Data
```bash
cd tests
python sample_data_generator.py
```
Open http://localhost:5000 in your browser.
## Using the Makefile
From the project root:
```bash
make install # Install with uv
make run # Run the server
make sample # Generate sample data
make clean # Clean build artifacts
```
## Documentation
- [../README.md](../README.md) - Project overview
- [../docs/SETUP.md](../docs/SETUP.md) - Detailed setup guide
- [../docs/GETTING_STARTED.md](../docs/GETTING_STARTED.md) - Usage guide
- [../docs/PROTOCOL.md](../docs/PROTOCOL.md) - Protocol specification
## Development
Install with dev dependencies:
```bash
uv pip install -e ".[dev]"
# Run tests
pytest
# Format code
black miniprofiler tests
# Lint code
ruff check miniprofiler tests
```
## Project Structure
```
host/
├── miniprofiler/ # Main package
│ ├── __init__.py
│ ├── protocol.py # Binary protocol
│ ├── serial_reader.py # Serial communication
│ ├── symbolizer.py # ELF/DWARF parsing
│ ├── analyzer.py # Data analysis
│ ├── web_server.py # Flask + SocketIO server
│ └── cli.py # CLI entry point
├── web/ # Web interface
│ ├── templates/
│ │ └── index.html
│ └── static/
│ ├── css/style.css
│ └── js/app.js
├── tests/ # Tests and utilities
│ └── sample_data_generator.py
├── .venv/ # Virtual environment (created by uv venv)
├── pyproject.toml # Project configuration
└── run.py # Quick start script
```
## Requirements
- Python 3.8+
- uv (recommended) or pip
- Serial port access for real hardware
## Features
✅ Binary protocol with command-response structure
✅ Real-time serial communication
✅ ELF/DWARF symbol resolution
✅ Three visualization modes:
- Flame graph (d3-flame-graph)
- Timeline/flame chart (Plotly.js)
- Statistics table
✅ WebSocket-based real-time updates
✅ Sample data generator for testing
## Next Steps
1. Connect to STM32 device (Phase 2 - embedded module TBD)
2. Load .elf file for symbol resolution
3. Start profiling and view real-time visualizations

View File

@@ -183,7 +183,15 @@ class ResponsePacket:
@staticmethod
def calculate_crc16(data: bytes) -> int:
"""Calculate CRC16-CCITT for data validation."""
calculator = crc.Calculator(crc.Crc16.CCITT)
# CRC-16-CCITT: polynomial 0x1021, init 0xFFFF
calculator = crc.Calculator(crc.Configuration(
width=16,
polynomial=0x1021,
init_value=0xFFFF,
final_xor_value=0x0000,
reverse_input=False,
reverse_output=False
))
return calculator.checksum(data)
def to_bytes(self) -> bytes:

78
host/pyproject.toml Normal file
View File

@@ -0,0 +1,78 @@
[build-system]
requires = ["setuptools>=61.0", "wheel"]
build-backend = "setuptools.build_meta"
[project]
name = "miniprofiler"
version = "0.1.0"
description = "Host application for embedded STM32 profiling"
requires-python = ">=3.8"
license = "MIT"
authors = [
{name = "MiniProfiler Contributors"}
]
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"Topic :: Software Development :: Embedded Systems",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
dependencies = [
"Flask>=3.0.0",
"Flask-SocketIO>=5.3.0",
"pyserial>=3.5",
"pyelftools>=0.29",
"crc>=6.1.1",
"python-socketio>=5.10.0",
"eventlet>=0.33.3",
]
[project.optional-dependencies]
dev = [
"pytest>=7.0",
"pytest-cov>=4.0",
"black>=23.0",
"ruff>=0.1.0",
]
[project.scripts]
miniprofiler = "miniprofiler.cli:main"
[project.urls]
Homepage = "https://github.com/yourusername/miniprofiler"
Documentation = "https://github.com/yourusername/miniprofiler/tree/main/docs"
Repository = "https://github.com/yourusername/miniprofiler"
[tool.setuptools.packages.find]
where = ["."]
include = ["miniprofiler*"]
[tool.setuptools.package-data]
miniprofiler = [
"web/templates/*.html",
"web/static/css/*.css",
"web/static/js/*.js",
]
[tool.black]
line-length = 100
target-version = ['py38']
[tool.ruff]
line-length = 100
target-version = "py38"
select = ["E", "F", "I", "N", "W"]
ignore = []
[tool.pytest.ini_options]
testpaths = ["tests"]
python_files = ["test_*.py"]
python_classes = ["Test*"]
python_functions = ["test_*"]
addopts = "-v --cov=miniprofiler --cov-report=term-missing"

View File

@@ -1,51 +0,0 @@
"""Setup script for MiniProfiler host application."""
from setuptools import setup, find_packages
with open("../README.md", "r", encoding="utf-8") as fh:
long_description = fh.read()
setup(
name="miniprofiler",
version="0.1.0",
author="MiniProfiler Contributors",
description="Host application for embedded STM32 profiling",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/yourusername/miniprofiler",
packages=find_packages(),
classifiers=[
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"Topic :: Software Development :: Embedded Systems",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
],
python_requires=">=3.8",
install_requires=[
"Flask>=3.0.0",
"Flask-SocketIO>=5.3.0",
"pyserial>=3.5",
"pyelftools>=0.29",
"crc>=6.1.1",
"python-socketio>=5.10.0",
"eventlet>=0.33.3",
],
entry_points={
"console_scripts": [
"miniprofiler=miniprofiler.cli:main",
],
},
include_package_data=True,
package_data={
"miniprofiler": [
"../web/templates/*.html",
"../web/static/css/*.css",
"../web/static/js/*.js",
],
},
)