Wrapture Pinpoints Slow Code by Measuring Self Time, Not Just Wall-Clock Totals

Finding Slow Code with Wrapture

Wrapture Pinpoints Slow Code by Measuring Self Time, Not Just Wall-Clock Totals

Graham Dumpleton demonstrates how wrapture identifies slow code by computing self time—an operation's duration minus its children's time—using parent links. A Flask shop example shows the ledger taking 35.1ms of a 35.9ms service call, revealing it as the true bottleneck. The Aggregate collector ranks methods across many requests by self time, while annotate() tags requests with tenant data for slicing. A Counter collector offers a lightweight way to catch N+1 regressions in test suites.

Self time is an operation's duration minus the time its observed children account for, and wrapture computes it from the parent links as events close.
  1. themgt

    Every "experienced software developer with expertise across multiple programming languages and technologies" in 2025:

    Currently, I'm on sabbatical (micro retirement) and pondering full retirement. The IT industry has undergone significant upheavals in recent years ... the rapid advancement of AI technologies has created new challenges for experienced developers seeking meaningful work opportunities.

    In 2026:

    The cheaper cousin. Everything above retained a duration. Sometimes the answer is just a number, and the Counter collector counts operations as they begin and keeps nothing else, which makes it cheap enough to leave running under a whole test suite. Bind a database layer's execute once, register a counter, and give every test a query budget in a fixture, and the classic N+1 regression fails with a number attached rather than slipping through as a test that merely got slower.

  2. simonw

    I'm really excited about this library.

    Wrapture is a new project from Graham, who previously developed wrapt (a 20+ year old Python monkey patching library) and built the first version of the New Relic Python agent - the library that instruments your app so New Relic can show you watt its doing.

    Wrapture provides the ability to both mock and instrument code in the same toolset. You can use it in tests for "did this method fire" or "when this method fires return this dummy data instead", and you can also use it to instrument your code to measure what's called and how long things take.

    It can instrument existing Python code without you modifying that code - you can instead define a TOML file saying which methods you want to instrument and Wrapture will live patch the code for you. This means you can instrument any Python code that you need to run without changing it, and export the results to OpenTelemetry.

    The linked article is part of a series of posts Graham wrote about it. I suggest starting here: https://grahamdumpleton.me/posts/2026/08/introducing-wraptur...

    Then hit the index post he just published that links to his others: https://grahamdumpleton.me/posts/2026/09/trying-out-wrapture...

More from this day

2026-09-12