From 0b57d6679f523485809d83734f2491b4114c9d5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Fri, 22 Nov 2024 08:59:09 +0100 Subject: [PATCH] Add some explain in the c2c page --- c2cwsgiutils/debug/_listeners.py | 7 +----- c2cwsgiutils/debug/_views.py | 4 ++-- c2cwsgiutils/index.py | 31 ++++++++++++++++++++++---- c2cwsgiutils/templates/index.html.mako | 5 ++++- 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/c2cwsgiutils/debug/_listeners.py b/c2cwsgiutils/debug/_listeners.py index 1696806ac..771e15d37 100644 --- a/c2cwsgiutils/debug/_listeners.py +++ b/c2cwsgiutils/debug/_listeners.py @@ -68,12 +68,7 @@ def _dump_memory_impl( and not (FILES_FIELDS - set(obj["globals"].keys())) ): python_internal = True - if ( - python_internal - and not python_internals_map - or not python_internal - and python_internals_map - ): + if python_internal != python_internals_map: continue size = get_size(obj) / 1024 if len(biggest_objects) < limit or size > biggest_objects[0][0]: diff --git a/c2cwsgiutils/debug/_views.py b/c2cwsgiutils/debug/_views.py index 649a60735..904d8b933 100644 --- a/c2cwsgiutils/debug/_views.py +++ b/c2cwsgiutils/debug/_views.py @@ -47,7 +47,7 @@ def _dump_memory(request: pyramid.request.Request) -> list[Mapping[str, Any]]: auth.auth_view(request) limit = int(request.params.get("limit", "30")) analyze_type = request.params.get("analyze_type") - python_internals_map = request.params.get("python_internals_map", "0").lower() in ("", "1", "true", "on") + python_internals_map = request.params.get("python_internals_map", "0").lower() in ("1", "true", "on") result = broadcast.broadcast( "c2c_dump_memory", params={"limit": limit, "analyze_type": analyze_type, "python_internals_map": python_internals_map}, @@ -75,7 +75,7 @@ def _dump_memory_diff(request: pyramid.request.Request) -> list[Any]: # warm-up run try: - if "no_warmup" not in request.params: + if request.params.get("no_warmup", "0").lower() in ("1", "true", "on"): request.invoke_subrequest(sub_request) except Exception: # nosec # pylint: disable=broad-except pass diff --git a/c2cwsgiutils/index.py b/c2cwsgiutils/index.py index e0016c236..688f46cdc 100644 --- a/c2cwsgiutils/index.py +++ b/c2cwsgiutils/index.py @@ -122,8 +122,20 @@ def input_( if type_ is None: if isinstance(value, int): type_ = "number" + elif isinstance(value, bool): + type_ = "checkbox" else: type_ = "text" + if type_ == "checkbox": + checked = " checked" if value else "" + return f""" +
+ + +
""" + result = "" if label is not None: result += f'
' @@ -201,7 +213,7 @@ def _index(request: pyramid.request.Request) -> dict[str, str]: def _versions(request: pyramid.request.Request) -> str: versions_url = _url(request, "c2c_versions") if versions_url: - return section("Versions", paragraph(link(versions_url, "Get")), sep=False) + return section("Versions " + link(versions_url, "Get"), sep=False) else: return "" @@ -280,6 +292,7 @@ def _logging(request: pyramid.request.Request) -> str: def _debug(request: pyramid.request.Request) -> str: dump_memory_url = _url(request, "c2c_debug_memory") if dump_memory_url: + as_dot = 'as dot diagram, can be open with xdot' return section( " ".join( [ @@ -289,32 +302,42 @@ def _debug(request: pyramid.request.Request) -> str: link(_url(request, "c2c_debug_memory_maps"), "Mapped memory"), ] ), + '

Memory usage, with objgraph

', + "

Runs the garbage collector and dumps the memory usage as JSON.

", form( dump_memory_url, input_("limit", value=30), input_("analyze_type"), + input_("python_internals_map", type_="checkbox"), button("Dump memory usage"), ), + f"

Runs the garbage collector and dumps the memory refs {as_dot}.

", form( _url(request, "c2c_debug_show_refs"), input_("analyze_type", value="gunicorn.app.wsgiapp.WSGIApplication"), - input_("max_depth", value=3), - input_("too_many", value=10), + input_("analyze_id", type_="number"), + input_("max_depth", type_="number", value=3), + input_("too_many", type_="number", value=10), input_("min_size_kb", type_="number"), button("Object refs"), ), + "

Runs the garbage collector, query the path, runs the garbage collector again, get the memory diff as JSON.

", form( _url(request, "c2c_debug_memory_diff"), input_("path"), input_("limit", value=30), + input_("no_warmup", type_="checkbox"), button("Memory diff"), ), + "

Sleep

", form( _url(request, "c2c_debug_sleep"), input_("time", value=1), button("Sleep"), ), - form(_url(request, "c2c_debug_time"), button("Time")), + "

Server times

", + form(_url(request, "c2c_debug_time"), button("Get")), + "

HTTP error

", form( _url(request, "c2c_debug_error"), input_("status", value=500), diff --git a/c2cwsgiutils/templates/index.html.mako b/c2cwsgiutils/templates/index.html.mako index 3f6a46e78..a1c966462 100644 --- a/c2cwsgiutils/templates/index.html.mako +++ b/c2cwsgiutils/templates/index.html.mako @@ -24,7 +24,7 @@ crossorigin="anonymous" referrerpolicy="no-referrer" /> - c2cwsgiutils tools + C2C WSGI Utils tools