I see my original message was held up in moderation due to the large attachment.  I've uploaded the image to File:Screenshot of viztracer output.png



On Jan 13, 2023, at 6:38 PM, Roy Smith <roy@panix.com> wrote:



I've been trying to figure out why my pywikibot app is so slow.  It took me about 1 minute to instrument my code (see diff), I hit my URL in a browser, and loaded up the resulting json file into visviewer.  Now I'm scrolling around and drilling down into a total execution trace of my code, although it really only took a moment to see that most of the time is in 11 serialized API calls.  This is easily the coolest performance analysis tool I've ever used.

<Screen Shot 2023-01-13 at 6.32.31 PM.png>

diff --git a/dyk_web/core.py b/dyk_web/core.py
index 31758dc..1e58203 100644
--- a/dyk_web/core.py
+++ b/dyk_web/core.py
@@ -28,11 +28,16 @@ def get_pending_nominations():
     return titles
 
 
+from viztracer import VizTracer
+from pathlib import Path
+
+
 @bp.route("/display")
 def display():
     """template_name query arg is the DYK nomination template, including the Template: prefix."""
-    current_app.logger.info("Running on %s", os.uname().nodename)
-    page = Page(g.site, request.args["template_name"])
-    nomination = Nomination(page)
-    nomination_data = NominationData.from_nomination(nomination)
-    return render_template("display.html", nomination=nomination_data)
+    with VizTracer(output_file=str(Path.home() / "viztracer.json")):
+        current_app.logger.info("Running on %s", os.uname().nodename)
+        page = Page(g.site, request.args["template_name"])
+        nomination = Nomination(page)
+        nomination_data = NominationData.from_nomination(nomination)
+        return render_template("display.html", nomination=nomination_data)