Feature request: Filter stats by function descriptor
See original GitHub issueAs part of an application profiler plugin project for the ASGI protocol, where users can just pass a list of functions to profile, I was using a simple yappi.get_func_stats({"name": somefunction.__qualname__, "tag": ctx_tag})
filter, thinking it would be enough to unambigously select those functions. I later found out that __qualname__
is only unambiguous within the scope of a module, so I should in all likelyhood specify somefunction.__module__
as part of the filter as well, but that got me to look at the code yappi uses to identify the functions being called:
It uses ml_name
as the function name, which apparently corresponds to __name__
, not __qualname__
like I initially figured yappi would use, and has a few edge-cases for both function and module name that could make it difficult/unreliable to build the correct filter automatically.
Shouldn’t yappi have some kind of filter_from_function_descriptor
function to generate a detailled filter from a function descriptor automatically, instead of leaving users guessing as to whether they’re accidentally profiling other functions with the same name as the one they want?
Issue Analytics
- State:
- Created 4 years ago
- Comments:26 (14 by maintainers)
Top GitHub Comments
Hey @sm-Fifteen , I have released a new version for Yappi:
1.2.4
😃 . Keep an eye on any hotfixes(maybe?) following days. Other than that, thanks again! This versions fixes most of the issues we have discussed.That’s the plan 😉
Yeah, the solution I have right now is by no means ideal, but it does the job reasonably enough that it’s not a priority for me at the moment.
https://github.com/sm-Fifteen/asgi-server-timing-middleware/blob/eaa91f18cb537b0ad1a7986f2e9e11ae626f82bc/asgi_server_timing/middleware.py#L79-L80
With the current structure, I think it should work for any application using the ASGI protocol (though I’ve only specifically tested FastAPI). I’ll be changing the interface a bit before release (I definitely need to replace those
__qualname__
strings with arrays of callables/coroutines), but there shouldn’t be any need to adapt it to work with, say, Sanic or Quart since all the FastAPI/Starlette-specific things are actually in the configuration.