New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tracer.depth = 0 but Cython Tracer.depth = 1 #45
Comments
Hmmm I thought I got it right. You're looking at the source code or do you have a test case? |
The source code clearly differs, and probably for a good reason. I discovered the difference while writing the following code. My goal is to have a way to measure things in production systems without having to rewrite (and rebuild/redeploy) the code being measured in any way. To accomplish this, I hope to mock.patch a method at runtime and read its local variables on return:
Feel free to use this for a cookbook entry or even steal it for hunter itself if you like. It's not very useful to package on its own since most of the work will be interfacing with logging//reporting tools and control interfaces. An earlier version of this used |
Hmmm ... looks like I didn't expect people would use the tracer classes directly. I'll try to capture this usecase in the test suite and maybe there's a way to fix the depth problem differently. Btw, what sort of codebase are you using this on? Another thing: this should work as well: p = FunctionProbe(
"module.path.to.my.function",
VarsPrinter("name_of_a_local_var.__len__()")
) ( |
Another idea worth mentioning: you could do without any monkeypatching, eg (didn't test): def FunctionProbe(target, action):
mod, func = target.rsplit(1)
predicate = hunter.When(
hunter.Query(
kind="return",
module=mod,
function=func,
), action
) |
It's true I don't need to eval a lambda, but I do still need to handle the case where the local variable hasn't been bound yet, or doesn't have a len, etc. The complexities are endless. However, because this will be used in production (and only for limited periods), it seems better to monkeypatch one function than set a tracer for the whole runtime and let it filter--even a nice fast Cython one (thanks for making it!) |
Thanks! |
@aminusfu I just noticed you had Also, another quirk is that the tracer doesn't do the filtering itself, thus it can't special-case the depth filter, thus the tracer will be active even in deeper function calls. |
Tracer depth starts from 0 since you fixed it in 3a22d5a :) Now I don't need that Hunter has been working really well for this project (with that change). Thanks again for making it! |
@aminusfu hehe thanks. Just curious, what sort of metrics are you pulling out of that function you trace? |
I've built a module which I use daily in production to measure dark code. Any Python function, any measurement, without waiting for a deployment phase (or a second one to take out the instrumentation when I'm done). Answers in minutes, not hours or days. For example, today I measured how long some of our API requests were blocked waiting on others, broken down by which "others" were most damaging, which I will then stick into a research paper and use to help guide our roadmap. |
Now open source! See https://github.com/Crunch-io/diagnose |
This causes a predicate with
depth=X
to fire differently depending on whether the Cython is compiled or not, or whetherPUREPYTHONHUNTER
is defined.The text was updated successfully, but these errors were encountered: