Skip to content

Commit

Permalink
Merge pull request #2542 from camptocamp/backport/2539-to-master
Browse files Browse the repository at this point in the history
[Backport master] Add some explain in the c2c page
  • Loading branch information
sbrunner authored Nov 28, 2024
2 parents 23e6374 + 3af23e4 commit 555e880
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 15 deletions.
Binary file modified acceptance_tests/out/tests/c2c-auth-dark.expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified acceptance_tests/out/tests/c2c-auth.expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified acceptance_tests/out/tests/c2c.expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions acceptance_tests/out/tests/test_image_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
pytest.param(
"c2c-auth.expected.png",
650,
2000,
2500,
{"X-API-Key": "changeme"},
[{"name": "prefers-color-scheme", "value": "light"}],
),
pytest.param(
"c2c-auth-dark.expected.png",
650,
2000,
2500,
{"X-API-Key": "changeme"},
[
{"name": "prefers-color-scheme", "value": "dark"},
Expand Down
Binary file removed c2c-auth-dark.actual-masked.png
Binary file not shown.
Binary file removed c2c-auth.actual-masked.png
Binary file not shown.
Binary file removed c2c.actual-masked.png
Binary file not shown.
7 changes: 1 addition & 6 deletions c2cwsgiutils/debug/_listeners.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
4 changes: 2 additions & 2 deletions c2cwsgiutils/debug/_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,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},
Expand Down Expand Up @@ -77,7 +77,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
Expand Down
31 changes: 27 additions & 4 deletions c2cwsgiutils/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
<div class="form-check">
<input class="form-check-input" type="checkbox" name="{name}" value="true" id="{id_}"{checked}>
<label class="form-check-label" for="{id_}">
{label}
</label>
</div>"""

result = ""
if label is not None:
result += f'<div class="row mb-3"><label class="col-sm-2 col-form-label" for="{id_}">{label}</label>'
Expand Down Expand Up @@ -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 ""

Expand Down Expand Up @@ -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 <a href="https://graphviz.org/">dot diagram</a>, can be open with <a href="https://pypi.org/project/xdot/">xdot</a>'
return section(
" ".join(
[
Expand All @@ -289,32 +302,42 @@ def _debug(request: pyramid.request.Request) -> str:
link(_url(request, "c2c_debug_memory_maps"), "Mapped memory"),
]
),
'<h2>Memory usage<span style="font-size: 0.5em;">, with <a href="https://mg.pov.lt/objgraph/">objgraph</a></span></h2>',
"<p>Runs the garbage collector and dumps the memory usage as JSON.</p>",
form(
dump_memory_url,
input_("limit", value=30),
input_("analyze_type"),
input_("python_internals_map", type_="checkbox"),
button("Dump memory usage"),
),
f"<p>Runs the garbage collector and dumps the memory refs {as_dot}.</p>",
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"),
),
"<p>Runs the garbage collector, query the path, runs the garbage collector again, get the memory diff as JSON.</p>",
form(
_url(request, "c2c_debug_memory_diff"),
input_("path"),
input_("limit", value=30),
input_("no_warmup", type_="checkbox"),
button("Memory diff"),
),
"<h2>Sleep</h2>",
form(
_url(request, "c2c_debug_sleep"),
input_("time", value=1),
button("Sleep"),
),
form(_url(request, "c2c_debug_time"), button("Time")),
"<h2>Server times</h2>",
form(_url(request, "c2c_debug_time"), button("Get")),
"<h2>HTTP error</h2>",
form(
_url(request, "c2c_debug_error"),
input_("status", value=500),
Expand Down
5 changes: 4 additions & 1 deletion c2cwsgiutils/templates/index.html.mako
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@
crossorigin="anonymous"
referrerpolicy="no-referrer"
/>
<title>c2cwsgiutils tools</title>
<title>C2C WSGI Utils tools</title>
<style>
body {
margin-top: 0.5rem;
}
button, p {
margin-bottom: 0.5rem;
}
.row > h2 {
margin-top: 1rem;
}
</style>
</head>
<body>
Expand Down

0 comments on commit 555e880

Please sign in to comment.