- Contains the host code with a protocol implementation, data analyser and web-based visualiser
91 lines
2.3 KiB
Python
91 lines
2.3 KiB
Python
"""Command-line interface for MiniProfiler."""
|
|
|
|
import argparse
|
|
import logging
|
|
import sys
|
|
|
|
from .web_server import create_app
|
|
|
|
|
|
def setup_logging(verbose: bool = False):
|
|
"""Configure logging.
|
|
|
|
Args:
|
|
verbose: Enable verbose (DEBUG) logging
|
|
"""
|
|
level = logging.DEBUG if verbose else logging.INFO
|
|
logging.basicConfig(
|
|
level=level,
|
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
|
datefmt='%Y-%m-%d %H:%M:%S'
|
|
)
|
|
|
|
|
|
def main():
|
|
"""Main entry point for the CLI."""
|
|
parser = argparse.ArgumentParser(
|
|
description='MiniProfiler - Real-time Embedded Profiling Visualization'
|
|
)
|
|
|
|
parser.add_argument(
|
|
'--host',
|
|
type=str,
|
|
default='0.0.0.0',
|
|
help='Host address to bind to (default: 0.0.0.0)'
|
|
)
|
|
|
|
parser.add_argument(
|
|
'--port',
|
|
type=int,
|
|
default=5000,
|
|
help='Port number to listen on (default: 5000)'
|
|
)
|
|
|
|
parser.add_argument(
|
|
'--debug',
|
|
action='store_true',
|
|
help='Enable debug mode'
|
|
)
|
|
|
|
parser.add_argument(
|
|
'--verbose', '-v',
|
|
action='store_true',
|
|
help='Enable verbose logging'
|
|
)
|
|
|
|
args = parser.parse_args()
|
|
|
|
# Setup logging
|
|
setup_logging(args.verbose)
|
|
|
|
# Create and run the web server
|
|
print(f"""
|
|
╔═══════════════════════════════════════════════════════════╗
|
|
║ MiniProfiler ║
|
|
║ Real-time Embedded Profiling Tool ║
|
|
╚═══════════════════════════════════════════════════════════╝
|
|
|
|
Starting web server...
|
|
Host: {args.host}
|
|
Port: {args.port}
|
|
|
|
Open your browser and navigate to:
|
|
http://localhost:{args.port}
|
|
|
|
Press Ctrl+C to stop the server.
|
|
""")
|
|
|
|
try:
|
|
server = create_app(args.host, args.port)
|
|
server.run(debug=args.debug)
|
|
except KeyboardInterrupt:
|
|
print("\n\nShutting down gracefully...")
|
|
sys.exit(0)
|
|
except Exception as e:
|
|
print(f"\nError: {e}", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|