Package: tracers
Table of contentsTable of contentsProject descriptionKey FeaturesQuick IntroductionInstallationExamplesProject descriptionTracersis an Open-SourceAPM(Application monitoring) project
that offers you minimal overhead wrappers for profiling your code execution flow🛈  Finished transaction: 3.81 seconds

     # Timestamp                Net              Total    Call Chain

     1     0.00s     0.00s [  0.0%]     3.81s [100.0%]    ✓ async function_a
     2     0.00s     0.10s [  2.6%]     0.10s [  2.6%]    ¦   ✓ async asyncio.tasks.sleep
     3     0.10s     0.50s [ 13.1%]     0.50s [ 13.1%]    ¦   ✓ time.sleep
     4     0.60s     0.00s [  0.0%]     3.21s [ 84.2%]    ¦   ✓ async function_b
     5     0.60s     0.10s [  2.6%]     0.10s [  2.6%]    ¦   ¦   ✓ async asyncio.tasks.sleep
     6     0.70s     0.00s [  0.0%]     0.70s [ 18.4%]    ¦   ¦   ✓ async function_c
     7     0.70s     0.10s [  2.6%]     0.10s [  2.6%]    ¦   ¦   ¦   ✓ async asyncio.tasks.sleep
     8     0.80s     0.50s [ 13.1%]     0.50s [ 13.1%]    ¦   ¦   ¦   ✓ time.sleep
     9     1.31s     0.00s [  0.0%]     0.10s [  2.7%]    ¦   ¦   ¦   ✓ async function_d
    10     1.31s     0.10s [  2.6%]     0.10s [  2.6%]    ¦   ¦   ¦   ¦   ✓ async asyncio.tasks.sleep
    11     1.41s     2.00s [ 52.5%]     2.00s [ 52.5%]    ¦   ¦   ✓ time.sleep
    12     3.41s     0.10s [  2.7%]     0.10s [  2.7%]    ¦   ¦   ✓ async asyncio.tasks.sleep
    13     3.51s     0.00s [  0.0%]     0.10s [  2.7%]    ¦   ¦   ✓ async function_d
    14     3.51s     0.10s [  2.7%]     0.10s [  2.7%]    ¦   ¦   ¦   ✓ async asyncio.tasks.sleep
    15     3.61s     0.10s [  2.7%]     0.10s [  2.7%]    ¦   ¦   ✓ async asyncio.tasks.sleep
    16     3.71s     0.00s [  0.0%]     0.10s [  2.7%]    ¦   ¦   ✓ async function_e
    17     3.71s     0.10s [  2.7%]     0.10s [  2.7%]    ¦   ¦   ¦   ✓ async asyncio.tasks.sleep

           Count                Net              Total    Function

               3     3.00s [ 78.7%]     3.00s [ 78.7%]    ✓ time.sleep
               8     0.81s [ 21.2%]     0.81s [ 21.2%]    ✓ async asyncio.tasks.sleep
               1     0.00s [  0.0%]     3.21s [ 84.2%]    ✓ async function_b
               1     0.00s [  0.0%]     0.70s [ 18.4%]    ✓ async function_c
               1     0.00s [  0.0%]     3.81s [100.0%]    ✓ async function_a
               2     0.00s [  0.0%]     0.20s [  5.3%]    ✓ async function_d
               1     0.00s [  0.0%]     0.10s [  2.7%]    ✓ async function_e

  Some blocks (skews) occurred in the event loop ¹

  #    Timestamp     Delay

     0     1.40s     2.00s
     1     0.09s     0.50s
     2     0.80s     0.50s

  ¹ Consider reviewing them carefully to improve the overall system throughputKey FeaturesAllows you to instrument anyfunctionorstatementonyour own codeor anythird party libraryHandlesasynchronouscodeout-of-the box, no config requiredExposes ahigh-level API:A decorator:@trace, to instrument functionsExample:@trace
def any_function(*args, **kwargs):
    pass

@trace
async def other_function(*args, **kwargs):
    passA function:callto instrument code in-lineExample:call(any_function, *args, **kwargs)
await call(other_function, *args, **kwargs)Sync/async cases are handled internallycalland@traceare equivalent, you can choose the one that fits you bestIt'sThread-safe,Async-safe,Process-safeandContext-safeYou'll get accurate results in any scenarioIntroducesminimal overheadand it'seasy to deploy!It's a pure python implementation based oncontextvarsanddecorators.
Your code runs as fast as if you were not profiling itIt's easy to pin-point performance problems:Gives you the total execution time in seconds and%Allows you to identify points in time where yourasyncevent loop got blockedMade with love by nerds, for humans :heart:Quick IntroductionLet's start with a very basic example:importtimefromdateutil.parserimportparsedefexample():time.sleep(2.0)your_business_logic('Sat Oct 11')defyour_business_logic(date:str):parse(date)time.sleep(1.0)example()Tracing its flow and gathering profiling information is a matter of
decorating your functions:--- a/examples/without_tracers.py+++ b/examples/with_tracers.py@@ -1,15 +1,18 @@import timefrom dateutil.parser import parse+from tracers.function import trace+@trace()def example():time.sleep(2.0)your_business_logic('Sat Oct 11')+@trace()def your_business_logic(date: str):parse(date)time.sleep(1.0)example()If you run it, all the functions you decorated will be traced
and you'll have metrics of the execution flow:🛈  Finished transaction: 3.00 seconds

     # Timestamp                Net              Total    Call Chain

     1     0.00s     2.00s [ 66.7%]     3.00s [100.0%]    ✓ example
     2     2.00s     1.00s [ 33.3%]     1.00s [ 33.3%]    ¦   ✓ your_business_logic

           Count                Net              Total    Function

               1     2.00s [ 66.7%]     3.00s [100.0%]    ✓ example
               1     1.00s [ 33.3%]     1.00s [ 33.3%]    ✓ your_business_logicFrom the output you can conclude:executing functionexampletook a total of3.0seconds to completefunctionexampletakes66.7%of the execution timefunction *example encloses100%of your code timefunctionexamplecalled function:your_business_logicfunctionyour_business_logictook1.0seconds out of the3.0seconds
the functionexampleneeded to completefunctionyour_business_logicrepresents33.3%of your execution timeTracing code is not limited to your own code.
You can trace anycallable objectincludingthird party packages,Python's standard library, and almost anythingThe level of detail is up to you!--- a/examples/with_tracers.py+++ b/examples/with_detailed_tracers.py@@ -1,18 +1,18 @@import timefrom dateutil.parser import parse-from tracers.function import trace+from tracers.function import call, trace@trace()def example():-    time.sleep(2.0)+    call(time.sleep, 2.0)your_business_logic('Sat Oct 11')@trace()def your_business_logic(date: str):-    parse(date)-    time.sleep(1.0)+    call(parse, date)+    call(time.sleep, 1.0)example()🛈  Finished transaction: 3.00 seconds

     # Timestamp                Net              Total    Call Chain

     1     0.00s     0.00s [  0.0%]     3.00s [100.0%]    ✓ example
     2     0.00s     2.00s [ 66.6%]     2.00s [ 66.6%]    ¦   ✓ time.sleep
     3     2.00s     0.00s [  0.0%]     1.00s [ 33.4%]    ¦   ✓ your_business_logic
     4     2.00s     0.00s [  0.0%]     0.00s [  0.0%]    ¦   ¦   ✓ dateutil.parser._parser.parse
     5     2.00s     1.00s [ 33.3%]     1.00s [ 33.3%]    ¦   ¦   ✓ time.sleep

           Count                Net              Total    Function

               2     3.00s [100.0%]     3.00s [100.0%]    ✓ time.sleep
               1     0.00s [  0.0%]     0.00s [  0.0%]    ✓ dateutil.parser._parser.parse
               1     0.00s [  0.0%]     1.00s [ 33.4%]    ✓ your_business_logic
               1     0.00s [  0.0%]     3.00s [100.0%]    ✓ exampleInstallationWe are hosted onPyPI:https://pypi.org/project/tracersJust run:pip install tracersor use the package manager you like the mostExamplesCheck them out in theexamplesfolder