Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Turn that visualization hack into a feature #12

Open
simonw opened this issue Apr 18, 2022 · 4 comments
Open

Turn that visualization hack into a feature #12

simonw opened this issue Apr 18, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@simonw
Copy link
Owner

simonw commented Apr 18, 2022

Hack from:

@simonw simonw added the enhancement New feature or request label Apr 18, 2022
@simonw
Copy link
Owner Author

simonw commented Apr 18, 2022

def visualize_traces(traces, chars=80):
    start = min(t[1] for t in traces)
    end = max(t[2] for t in traces)
    width = end - start
    pos = lambda value1, value2: int((value1 - value2) * chars / width)
    for trace in traces:
        name, p1, p2 = trace[0], pos(trace[1], start), pos(trace[2], trace[1])
        print("{}: started {:5f}, took {:5f}".format(name, trace[1] - start, trace[2] - trace[1]))
        print(' ' * p1, '*' * p2)

Output looks like this:

a: started 0.000022, took 1.000659
 ****************************************
b: started 0.000000, took 2.000802
 *******************************************************************************
c: started 1.000875, took 1.000121
                                         ***************************************
d: started 2.001063, took 0.000000

@simonw
Copy link
Owner Author

simonw commented Apr 18, 2022

That's when run against data collected using this pattern:

registry = Registry(a, b, c, d)
collected = []
registry.timer = lambda name, start, end: collected.append((name, start, end))
await registry.resolve(d)
visualize_traces(collected)

@adriangb
Copy link
Contributor

This almost feels like a tracing API. I wonder if it could just be made compatible with OpenTelemetry so that existing tooling could be used for visualization?

@simonw
Copy link
Owner Author

simonw commented Apr 18, 2022

My hope is that the .timer hook itself is enough that people who use OpenTelemetry could easily plug it in.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants