import cProfile import multiprocessing import time import requests from fasthtml.common import * from app import serve, weeks PORT = 7860 # Update this to match the port your app is using def run_server(): serve() # This should start your FastHTML app def make_requests(): base_url = f"http://127.0.0.1:{PORT}" # Test home page try: requests.get(f"{base_url}/") except requests.exceptions.RequestException as e: print(f"Error accessing home page: {e}") # Test 5 weeks (or fewer if less than 5 weeks available) for week in weeks[: min(5, len(weeks))]: try: requests.get(f"{base_url}/week/{week}") except requests.exceptions.RequestException as e: print(f"Error accessing week {week}: {e}") # Add more requests here to cover other parts of your application def profile_app(): server_process = multiprocessing.Process(target=run_server) server_process.start() # Wait for the server to start time.sleep(5) # Increased wait time try: make_requests() finally: server_process.terminate() server_process.join() if __name__ == "__main__": cProfile.run("profile_app()", "profile_output.prof") print("Profiling complete. Run 'snakeviz profile_output.prof' to view results.")