We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
ProfilerMiddleware's default filename_format causes ValueError when ProfilerMiddleware is used with profile_dir
## Environment

```
$ sw_vers 
ProductName:	Mac OS X
ProductVersion:	10.13.6
BuildVersion:	17G3025

$ python --version
Python 3.7.2

$ pip freeze
Click==7.0
Flask==1.0.2
itsdangerous==1.1.0
Jinja2==2.10.1
MarkupSafe==1.1.1
Werkzeug==0.15.2
```

Basically, the only Python dependency I installed was Flask because that's what I'm most familiar with. However, the error I'm describing looks to be contained within werkzeug.


## Observed Behavior

When using `ProfilerMiddleware` with its `profile_dir` argument, the following error gets raised after a request is sent to the server:

```
Error on request:
Traceback (most recent call last):
  File "/dev/jlove-bazaarvoice/werkzeug-profiler-bug/.venv/lib/python3.7/site-packages/werkzeug/serving.py", line 302, in run_wsgi
    execute(self.server.app)
  File "/dev/jlove-bazaarvoice/werkzeug-profiler-bug/.venv/lib/python3.7/site-packages/werkzeug/serving.py", line 290, in execute
    application_iter = app(environ, start_response)
  File "/dev/jlove-bazaarvoice/werkzeug-profiler-bug/.venv/lib/python3.7/site-packages/flask/app.py", line 2309, in __call__
    return self.wsgi_app(environ, start_response)
  File "/dev/jlove-bazaarvoice/werkzeug-profiler-bug/.venv/lib/python3.7/site-packages/werkzeug/middleware/profiler.py", line 119, in __call__
    time=time.time(),
ValueError: Unknown format code 'd' for object of type 'float'
```

## Expected Behavior

No `ValueError`.

## Steps to Reproduce

1. `pip install flask`
2. Save the following file as app.py.
```python
# app.py
from flask import Flask
from werkzeug.middleware.profiler import ProfilerMiddleware

app = Flask(__name__)
app.wsgi_app = ProfilerMiddleware(app.wsgi_app, profile_dir=".")


@app.route("/", methods=["GET"])
def get_index():
    return "Hello, world!"
```
3. Start the server with `FLASK_APP=app.py flask run`.
4. Send a request to the server (e.g. http://127.0.0.1:5000/).

## Workaround/Solution

Slightly modify `ProfilerMiddleware`'s `filename_format`, replacing the `d` with `f`. For example:
```python
app.wsgi_app = ProfilerMiddleware(
    app.wsgi_app, profile_dir=".", filename_format="{method}.{path}.{elapsed:06f}ms.{time:f}.prof"
)
```

Both instances of `d` need to be replaced because both `elapsed` and `time` are floating point numbers.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/werkzeug/middleware/profiler.py`
Content:
```
1 """
2 Application Profiler
3 ====================
4 
5 This module provides a middleware that profiles each request with the
6 :mod:`cProfile` module. This can help identify bottlenecks in your code
7 that may be slowing down your application.
8 
9 .. autoclass:: ProfilerMiddleware
10 
11 :copyright: 2007 Pallets
12 :license: BSD-3-Clause
13 """
14 from __future__ import print_function
15 
16 import os.path
17 import sys
18 import time
19 from pstats import Stats
20 
21 try:
22     from cProfile import Profile
23 except ImportError:
24     from profile import Profile
25 
26 
27 class ProfilerMiddleware(object):
28     """Wrap a WSGI application and profile the execution of each
29     request. Responses are buffered so that timings are more exact.
30 
31     If ``stream`` is given, :class:`pstats.Stats` are written to it
32     after each request. If ``profile_dir`` is given, :mod:`cProfile`
33     data files are saved to that directory, one file per request.
34 
35     The filename can be customized by passing ``filename_format``. If
36     it is a string, it will be formatted using :meth:`str.format` with
37     the following fields available:
38 
39     -   ``{method}`` - The request method; GET, POST, etc.
40     -   ``{path}`` - The request path or 'root' should one not exist.
41     -   ``{elapsed}`` - The elapsed time of the request.
42     -   ``{time}`` - The time of the request.
43 
44     If it is a callable, it will be called with the WSGI ``environ``
45     dict and should return a filename.
46 
47     :param app: The WSGI application to wrap.
48     :param stream: Write stats to this stream. Disable with ``None``.
49     :param sort_by: A tuple of columns to sort stats by. See
50         :meth:`pstats.Stats.sort_stats`.
51     :param restrictions: A tuple of restrictions to filter stats by. See
52         :meth:`pstats.Stats.print_stats`.
53     :param profile_dir: Save profile data files to this directory.
54     :param filename_format: Format string for profile data file names,
55         or a callable returning a name. See explanation above.
56 
57     .. code-block:: python
58 
59         from werkzeug.middleware.profiler import ProfilerMiddleware
60         app = ProfilerMiddleware(app)
61 
62     .. versionchanged:: 0.15
63         Stats are written even if ``profile_dir`` is given, and can be
64         disable by passing ``stream=None``.
65 
66     .. versionadded:: 0.15
67         Added ``filename_format``.
68 
69     .. versionadded:: 0.9
70         Added ``restrictions`` and ``profile_dir``.
71     """
72 
73     def __init__(
74         self,
75         app,
76         stream=sys.stdout,
77         sort_by=("time", "calls"),
78         restrictions=(),
79         profile_dir=None,
80         filename_format="{method}.{path}.{elapsed:06d}ms.{time:d}.prof",
81     ):
82         self._app = app
83         self._stream = stream
84         self._sort_by = sort_by
85         self._restrictions = restrictions
86         self._profile_dir = profile_dir
87         self._filename_format = filename_format
88 
89     def __call__(self, environ, start_response):
90         response_body = []
91 
92         def catching_start_response(status, headers, exc_info=None):
93             start_response(status, headers, exc_info)
94             return response_body.append
95 
96         def runapp():
97             app_iter = self._app(environ, catching_start_response)
98             response_body.extend(app_iter)
99 
100             if hasattr(app_iter, "close"):
101                 app_iter.close()
102 
103         profile = Profile()
104         start = time.time()
105         profile.runcall(runapp)
106         body = b"".join(response_body)
107         elapsed = time.time() - start
108 
109         if self._profile_dir is not None:
110             if callable(self._filename_format):
111                 filename = self._filename_format(environ)
112             else:
113                 filename = self._filename_format.format(
114                     method=environ["REQUEST_METHOD"],
115                     path=(
116                         environ.get("PATH_INFO").strip("/").replace("/", ".") or "root"
117                     ),
118                     elapsed=elapsed * 1000.0,
119                     time=time.time(),
120                 )
121             filename = os.path.join(self._profile_dir, filename)
122             profile.dump_stats(filename)
123 
124         if self._stream is not None:
125             stats = Stats(profile, stream=self._stream)
126             stats.sort_stats(*self._sort_by)
127             print("-" * 80, file=self._stream)
128             print("PATH: {!r}".format(environ.get("PATH_INFO", "")), file=self._stream)
129             stats.print_stats(*self._restrictions)
130             print("-" * 80 + "\n", file=self._stream)
131 
132         return [body]
133
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/werkzeug/middleware/profiler.py b/src/werkzeug/middleware/profiler.py
--- a/src/werkzeug/middleware/profiler.py
+++ b/src/werkzeug/middleware/profiler.py
@@ -77,7 +77,7 @@
         sort_by=("time", "calls"),
         restrictions=(),
         profile_dir=None,
-        filename_format="{method}.{path}.{elapsed:06d}ms.{time:d}.prof",
+        filename_format="{method}.{path}.{elapsed:.0f}ms.{time:.0f}.prof",
     ):
         self._app = app
         self._stream = stream

{"golden_diff": "diff --git a/src/werkzeug/middleware/profiler.py b/src/werkzeug/middleware/profiler.py\n--- a/src/werkzeug/middleware/profiler.py\n+++ b/src/werkzeug/middleware/profiler.py\n@@ -77,7 +77,7 @@\n         sort_by=(\"time\", \"calls\"),\n         restrictions=(),\n         profile_dir=None,\n-        filename_format=\"{method}.{path}.{elapsed:06d}ms.{time:d}.prof\",\n+        filename_format=\"{method}.{path}.{elapsed:.0f}ms.{time:.0f}.prof\",\n     ):\n         self._app = app\n         self._stream = stream\n", "issue": "ProfilerMiddleware's default filename_format causes ValueError when ProfilerMiddleware is used with profile_dir\n## Environment\r\n\r\n```\r\n$ sw_vers \r\nProductName:\tMac OS X\r\nProductVersion:\t10.13.6\r\nBuildVersion:\t17G3025\r\n\r\n$ python --version\r\nPython 3.7.2\r\n\r\n$ pip freeze\r\nClick==7.0\r\nFlask==1.0.2\r\nitsdangerous==1.1.0\r\nJinja2==2.10.1\r\nMarkupSafe==1.1.1\r\nWerkzeug==0.15.2\r\n```\r\n\r\nBasically, the only Python dependency I installed was Flask because that's what I'm most familiar with. However, the error I'm describing looks to be contained within werkzeug.\r\n\r\n\r\n## Observed Behavior\r\n\r\nWhen using `ProfilerMiddleware` with its `profile_dir` argument, the following error gets raised after a request is sent to the server:\r\n\r\n```\r\nError on request:\r\nTraceback (most recent call last):\r\n  File \"/dev/jlove-bazaarvoice/werkzeug-profiler-bug/.venv/lib/python3.7/site-packages/werkzeug/serving.py\", line 302, in run_wsgi\r\n    execute(self.server.app)\r\n  File \"/dev/jlove-bazaarvoice/werkzeug-profiler-bug/.venv/lib/python3.7/site-packages/werkzeug/serving.py\", line 290, in execute\r\n    application_iter = app(environ, start_response)\r\n  File \"/dev/jlove-bazaarvoice/werkzeug-profiler-bug/.venv/lib/python3.7/site-packages/flask/app.py\", line 2309, in __call__\r\n    return self.wsgi_app(environ, start_response)\r\n  File \"/dev/jlove-bazaarvoice/werkzeug-profiler-bug/.venv/lib/python3.7/site-packages/werkzeug/middleware/profiler.py\", line 119, in __call__\r\n    time=time.time(),\r\nValueError: Unknown format code 'd' for object of type 'float'\r\n```\r\n\r\n## Expected Behavior\r\n\r\nNo `ValueError`.\r\n\r\n## Steps to Reproduce\r\n\r\n1. `pip install flask`\r\n2. Save the following file as app.py.\r\n```python\r\n# app.py\r\nfrom flask import Flask\r\nfrom werkzeug.middleware.profiler import ProfilerMiddleware\r\n\r\napp = Flask(__name__)\r\napp.wsgi_app = ProfilerMiddleware(app.wsgi_app, profile_dir=\".\")\r\n\r\n\r\n@app.route(\"/\", methods=[\"GET\"])\r\ndef get_index():\r\n    return \"Hello, world!\"\r\n```\r\n3. Start the server with `FLASK_APP=app.py flask run`.\r\n4. Send a request to the server (e.g. http://127.0.0.1:5000/).\r\n\r\n## Workaround/Solution\r\n\r\nSlightly modify `ProfilerMiddleware`'s `filename_format`, replacing the `d` with `f`. For example:\r\n```python\r\napp.wsgi_app = ProfilerMiddleware(\r\n    app.wsgi_app, profile_dir=\".\", filename_format=\"{method}.{path}.{elapsed:06f}ms.{time:f}.prof\"\r\n)\r\n```\r\n\r\nBoth instances of `d` need to be replaced because both `elapsed` and `time` are floating point numbers.\n", "before_files": [{"content": "\"\"\"\nApplication Profiler\n====================\n\nThis module provides a middleware that profiles each request with the\n:mod:`cProfile` module. This can help identify bottlenecks in your code\nthat may be slowing down your application.\n\n.. autoclass:: ProfilerMiddleware\n\n:copyright: 2007 Pallets\n:license: BSD-3-Clause\n\"\"\"\nfrom __future__ import print_function\n\nimport os.path\nimport sys\nimport time\nfrom pstats import Stats\n\ntry:\n    from cProfile import Profile\nexcept ImportError:\n    from profile import Profile\n\n\nclass ProfilerMiddleware(object):\n    \"\"\"Wrap a WSGI application and profile the execution of each\n    request. Responses are buffered so that timings are more exact.\n\n    If ``stream`` is given, :class:`pstats.Stats` are written to it\n    after each request. If ``profile_dir`` is given, :mod:`cProfile`\n    data files are saved to that directory, one file per request.\n\n    The filename can be customized by passing ``filename_format``. If\n    it is a string, it will be formatted using :meth:`str.format` with\n    the following fields available:\n\n    -   ``{method}`` - The request method; GET, POST, etc.\n    -   ``{path}`` - The request path or 'root' should one not exist.\n    -   ``{elapsed}`` - The elapsed time of the request.\n    -   ``{time}`` - The time of the request.\n\n    If it is a callable, it will be called with the WSGI ``environ``\n    dict and should return a filename.\n\n    :param app: The WSGI application to wrap.\n    :param stream: Write stats to this stream. Disable with ``None``.\n    :param sort_by: A tuple of columns to sort stats by. See\n        :meth:`pstats.Stats.sort_stats`.\n    :param restrictions: A tuple of restrictions to filter stats by. See\n        :meth:`pstats.Stats.print_stats`.\n    :param profile_dir: Save profile data files to this directory.\n    :param filename_format: Format string for profile data file names,\n        or a callable returning a name. See explanation above.\n\n    .. code-block:: python\n\n        from werkzeug.middleware.profiler import ProfilerMiddleware\n        app = ProfilerMiddleware(app)\n\n    .. versionchanged:: 0.15\n        Stats are written even if ``profile_dir`` is given, and can be\n        disable by passing ``stream=None``.\n\n    .. versionadded:: 0.15\n        Added ``filename_format``.\n\n    .. versionadded:: 0.9\n        Added ``restrictions`` and ``profile_dir``.\n    \"\"\"\n\n    def __init__(\n        self,\n        app,\n        stream=sys.stdout,\n        sort_by=(\"time\", \"calls\"),\n        restrictions=(),\n        profile_dir=None,\n        filename_format=\"{method}.{path}.{elapsed:06d}ms.{time:d}.prof\",\n    ):\n        self._app = app\n        self._stream = stream\n        self._sort_by = sort_by\n        self._restrictions = restrictions\n        self._profile_dir = profile_dir\n        self._filename_format = filename_format\n\n    def __call__(self, environ, start_response):\n        response_body = []\n\n        def catching_start_response(status, headers, exc_info=None):\n            start_response(status, headers, exc_info)\n            return response_body.append\n\n        def runapp():\n            app_iter = self._app(environ, catching_start_response)\n            response_body.extend(app_iter)\n\n            if hasattr(app_iter, \"close\"):\n                app_iter.close()\n\n        profile = Profile()\n        start = time.time()\n        profile.runcall(runapp)\n        body = b\"\".join(response_body)\n        elapsed = time.time() - start\n\n        if self._profile_dir is not None:\n            if callable(self._filename_format):\n                filename = self._filename_format(environ)\n            else:\n                filename = self._filename_format.format(\n                    method=environ[\"REQUEST_METHOD\"],\n                    path=(\n                        environ.get(\"PATH_INFO\").strip(\"/\").replace(\"/\", \".\") or \"root\"\n                    ),\n                    elapsed=elapsed * 1000.0,\n                    time=time.time(),\n                )\n            filename = os.path.join(self._profile_dir, filename)\n            profile.dump_stats(filename)\n\n        if self._stream is not None:\n            stats = Stats(profile, stream=self._stream)\n            stats.sort_stats(*self._sort_by)\n            print(\"-\" * 80, file=self._stream)\n            print(\"PATH: {!r}\".format(environ.get(\"PATH_INFO\", \"\")), file=self._stream)\n            stats.print_stats(*self._restrictions)\n            print(\"-\" * 80 + \"\\n\", file=self._stream)\n\n        return [body]\n", "path": "src/werkzeug/middleware/profiler.py"}], "after_files": [{"content": "\"\"\"\nApplication Profiler\n====================\n\nThis module provides a middleware that profiles each request with the\n:mod:`cProfile` module. This can help identify bottlenecks in your code\nthat may be slowing down your application.\n\n.. autoclass:: ProfilerMiddleware\n\n:copyright: 2007 Pallets\n:license: BSD-3-Clause\n\"\"\"\nfrom __future__ import print_function\n\nimport os.path\nimport sys\nimport time\nfrom pstats import Stats\n\ntry:\n    from cProfile import Profile\nexcept ImportError:\n    from profile import Profile\n\n\nclass ProfilerMiddleware(object):\n    \"\"\"Wrap a WSGI application and profile the execution of each\n    request. Responses are buffered so that timings are more exact.\n\n    If ``stream`` is given, :class:`pstats.Stats` are written to it\n    after each request. If ``profile_dir`` is given, :mod:`cProfile`\n    data files are saved to that directory, one file per request.\n\n    The filename can be customized by passing ``filename_format``. If\n    it is a string, it will be formatted using :meth:`str.format` with\n    the following fields available:\n\n    -   ``{method}`` - The request method; GET, POST, etc.\n    -   ``{path}`` - The request path or 'root' should one not exist.\n    -   ``{elapsed}`` - The elapsed time of the request.\n    -   ``{time}`` - The time of the request.\n\n    If it is a callable, it will be called with the WSGI ``environ``\n    dict and should return a filename.\n\n    :param app: The WSGI application to wrap.\n    :param stream: Write stats to this stream. Disable with ``None``.\n    :param sort_by: A tuple of columns to sort stats by. See\n        :meth:`pstats.Stats.sort_stats`.\n    :param restrictions: A tuple of restrictions to filter stats by. See\n        :meth:`pstats.Stats.print_stats`.\n    :param profile_dir: Save profile data files to this directory.\n    :param filename_format: Format string for profile data file names,\n        or a callable returning a name. See explanation above.\n\n    .. code-block:: python\n\n        from werkzeug.middleware.profiler import ProfilerMiddleware\n        app = ProfilerMiddleware(app)\n\n    .. versionchanged:: 0.15\n        Stats are written even if ``profile_dir`` is given, and can be\n        disable by passing ``stream=None``.\n\n    .. versionadded:: 0.15\n        Added ``filename_format``.\n\n    .. versionadded:: 0.9\n        Added ``restrictions`` and ``profile_dir``.\n    \"\"\"\n\n    def __init__(\n        self,\n        app,\n        stream=sys.stdout,\n        sort_by=(\"time\", \"calls\"),\n        restrictions=(),\n        profile_dir=None,\n        filename_format=\"{method}.{path}.{elapsed:.0f}ms.{time:.0f}.prof\",\n    ):\n        self._app = app\n        self._stream = stream\n        self._sort_by = sort_by\n        self._restrictions = restrictions\n        self._profile_dir = profile_dir\n        self._filename_format = filename_format\n\n    def __call__(self, environ, start_response):\n        response_body = []\n\n        def catching_start_response(status, headers, exc_info=None):\n            start_response(status, headers, exc_info)\n            return response_body.append\n\n        def runapp():\n            app_iter = self._app(environ, catching_start_response)\n            response_body.extend(app_iter)\n\n            if hasattr(app_iter, \"close\"):\n                app_iter.close()\n\n        profile = Profile()\n        start = time.time()\n        profile.runcall(runapp)\n        body = b\"\".join(response_body)\n        elapsed = time.time() - start\n\n        if self._profile_dir is not None:\n            if callable(self._filename_format):\n                filename = self._filename_format(environ)\n            else:\n                filename = self._filename_format.format(\n                    method=environ[\"REQUEST_METHOD\"],\n                    path=(\n                        environ.get(\"PATH_INFO\").strip(\"/\").replace(\"/\", \".\") or \"root\"\n                    ),\n                    elapsed=elapsed * 1000.0,\n                    time=time.time(),\n                )\n            filename = os.path.join(self._profile_dir, filename)\n            profile.dump_stats(filename)\n\n        if self._stream is not None:\n            stats = Stats(profile, stream=self._stream)\n            stats.sort_stats(*self._sort_by)\n            print(\"-\" * 80, file=self._stream)\n            print(\"PATH: {!r}\".format(environ.get(\"PATH_INFO\", \"\")), file=self._stream)\n            stats.print_stats(*self._restrictions)\n            print(\"-\" * 80 + \"\\n\", file=self._stream)\n\n        return [body]\n", "path": "src/werkzeug/middleware/profiler.py"}]}