def METHOD_NAME(exception=None):
    if app.config.get("FLEXMEASURES_PROFILE_REQUESTS", False):
        diff = time.time() - g.start
        if all([kw not in request.url for kw in ["/static", "favicon.ico"]]):
            app.logger.info(
                f"[PROFILE] {str(round(diff, 2)).rjust(6)} seconds to serve {request.url}."
            )
            if not hasattr(g, "profiler"):
                return app
            g.profiler.stop()
            output_html = g.profiler.output_html(timeline=True)
            endpoint = request.endpoint
            if endpoint is None:
                endpoint = "unknown"
            today = date.today()
            profile_filename = f"pyinstrument_{endpoint}.html"
            profile_output_path = Path(
                "profile_reports", today.strftime("%Y-%m-%d")
            )
            profile_output_path.mkdir(parents=True, exist_ok=True)
            with open(
                os.path.join(profile_output_path, profile_filename), "w+"
            ) as f:
                f.write(output_html)