Comments (6)
We have a new API param for this filter_callback
in get_func_stats()
.
Here is an example from the docs:
import package_a
import yappi
import sys
def a():
pass
def b():
pass
yappi.start()
a()
b()
package_a.a()
yappi.stop()
# filter by module object
current_module = sys.modules[__name__]
stats = yappi.get_func_stats(
filter_callback=lambda x: yappi.module_matches(x, [current_module])
) # x is a yappi.YFuncStat object
stats.sort("name", "desc").print_all()
'''
Clock type: CPU
Ordered by: name, desc
name ncall tsub ttot tavg
doc2.py:10 b 1 0.000001 0.000001 0.000001
doc2.py:6 a 1 0.000001 0.000001 0.000001
'''
# filter by function object
stats = yappi.get_func_stats(
filter_callback=lambda x: yappi.func_matches(x, [a, b])
).print_all()
'''
name ncall tsub ttot tavg
doc2.py:6 a 1 0.000001 0.000001 0.000001
doc2.py:10 b 1 0.000001 0.000001 0.000001
'''
# filter by module name
stats = yappi.get_func_stats(filter_callback=lambda x: 'package_a' in x.module
).print_all()
'''
name ncall tsub ttot tavg
package_a/__init__.py:1 a 1 0.000001 0.000001 0.000001
'''
# filter by function name
stats = yappi.get_func_stats(filter_callback=lambda x: 'a' in x.name
).print_all()
'''
name ncall tsub ttot tavg
doc2.py:6 a 1 0.000001 0.000001 0.000001
package_a/__init__.py:1 a 1 0.000001 0.000001 0.000001
'''
from yappi.
Hi,
Well. I know for sure that the current filtering implementation is too simple and does not cover too many cases. The reason behind this is: when I do not see the use cases for a specific feature entirely, I do a minimum implementation and let some time to decide.
In that sense: I am all into a better implementation of filtering API(like something in Django queries?) but your current cases seemed a bit too specific to modname. So, please correct me if I am wrong but if we somehow have a regex support in modname, your problem is already solved, or maybe I am missing something?
Examples:
yappi.get_func_stats(modname_istartswith='django.db').print_all()
yappi.get_func_stats(modname_icontains='django.db').print_all()
from yappi.
Well, modname, at least for me, is the full path to the .py file. I'm testing this under Windows (I'm writing about Python profiling and using Windows to force myself not to write POSIX-specific things) and I see filenames. If I could do package/module identifier like django.db that'd be a great step up, and starts with would be sufficient.
from yappi.
Nice to know.
Ok. After thinking through this again and again, it turns out that it would be better to add new functionality rather than modifying the current behavior as it probably will break code.
What I am thinking very roughly is something like a filter_func
param which will be called per stats and we will simply filter based on that.
Pros:
- Implementation/Testing will be very simple,
- Will not break existing code,
- Highly customizable as it is a custom filter function,
Cons:
- It is ugly to have two params for filtering? Or maybe not?
Example:
yappi.get_func_stats(filter={"name"}, filter_callback=my_filter_callback)
from yappi.
Closing this as the same behavior can be accomplished by following code(instead of filter_callback). I could not see any benefit in having another filter param when we can get a YFuncStat object and apply filtering on its properties.
stats = yappi.get_func_stats()
for stat in stats:
if stat.module == PackageModule("apd.aggregation"):
# do something
Here is a more detailed answer.
from yappi.
Thanks, I'll update the example code and docs I wrote.
from yappi.
Related Issues (20)
- Tests are broken on Python 3.11 due to @asyncio.coroutine use HOT 1
- yappi fails to build with python 3.11
- suggestion: add a column showing max execution time for a single call HOT 6
- `test_gevent` seems to depend on `3.10`
- Support more architectures in Github Actions
- Openssl related Error install Yappi with pip on pyton 3.11 OS:Windows HOT 1
- Python run `gevent` tests on CI for `3.11`
- New 3.11 compatible release? HOT 3
- base class names incorrect HOT 2
- Question: does yappi add "considerable runtime overhead"? Can it be used in production? HOT 2
- failing to capture FastAPI uvicorn threads, only seeing the _MainThread HOT 4
- sum(<genexpr>) not represented correctly in call graph
- Can't install on macOS HOT 2
- Uniqueness of the YFuncStat object
- Full path not printed HOT 2
- could you make the git tag name pattern consistent? HOT 1
- Irrelevant Thread Name for Gevent/Greenlet Profiling HOT 1
- Print only `N` lines of result HOT 1
- Yappi 3.12 `AttributeError: _mock_methods` when using MagicMock HOT 3
- Please add context-manager for easier of use HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yappi.