question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: Filter stats by function descriptor

See original GitHub issue

As 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:

https://github.com/sumerc/yappi/blob/6c97f55ae69a0979bdea8e557510a5d349da340c/yappi/_yappi.c#L546-L567

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:closed
  • Created 4 years ago
  • Comments:26 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
sumerccommented, Apr 13, 2020

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.

1reaction
sm-Fifteencommented, Apr 9, 2020

Fair enough. Once I release two #38 and #41 (which is currently on master) I think we are good to go.

That’s the plan 😉

Incremental stats clearing will come but I will focus my efforts on releasing these first.

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

The reason I want this is your middleware implementation will indeed might be a reference implementation for all other ASGI frameworks as well 😃

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.

app.add_middleware(ServerTimingMiddleware, calls_to_track={
    "db_exec": [sqlalchemy.engine.base.Engine.execute],
    "db_fetch": [
        sqlalchemy.engine.ResultProxy.fetchall,
        sqlalchemy.engine.ResultProxy.fetchone
    ],

    # All steps of the generated fastapi.routing.get_request_handler app
    "1deps": [fastapi.routing.solve_dependencies], # `Depends` execution
    "2endpoint": [fastapi.routing.run_endpoint_function], # Since FastAPI 0.49.2
    "3valid": [fastapi.routing.ModelField.validate], # Pydantic model validation
    "4encode": [fastapi.encoders.jsonable_encoder], # JSON encoding
    "5render": [starlette.responses.JSONResponse.render], # Respnse (JSON) rendering
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

tsflex.features API documentation
This component allows to create multiple feature descriptors for all the function - series_name(s) - window - stride combinations. As shown in the...
Read more >
Add Filter Logic - Salesforce Help
Filter logic governs how and when filters apply to your report.Required Editions and User Permissions Available in: both Salesforce Classic (not available.
Read more >
Python's filter(): Extract Values From Iterables
Python's filter() is a built-in function that allows you to process an iterable and extract those items that satisfy a given condition.
Read more >
Filter Feature Requests by Customer Attributes - Savio
With Savio, you can filter your feature requests by these attributes. This is an extremely powerful feature. Because you know that not all...
Read more >
Query (Feature Service/Layer)—ArcGIS REST APIs
The exceededTransferLimit property is now included in the JSON response when paging through a query result with the resultOffset and resultRecordCount ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found