Comments (5)
You mean the thread stats retrieved by get_thread_stats() or per-thread function stats? pstats is a specific class designed for function profiling stats and thus have fields for those, our current thread statistics return information that is irrelevant(such as sched_cnt
...) to a pstats object.
from yappi.
I meant can we get per-thread function stats in pstats format(as we get by calling yappi.convert2pstats(yappi.get_func_stats())). Right now, per thread information is limited.
My code is something like this
def start_job():
yappi.start()
main_func() #main thread
func_pstats = yappi.convert2pstats(yappi.get_func_stats())
func_pstats.dump_stats(funcfile)
thstats = yappi.get_thread_stats()
def main_func():
# do some processing
# spawns n threads. Each thread processes items from queue pushed by main thread
# push items to main thread q.put()
# threads.join()
I am looking for detailed function stats per thread to identlify where most of the time is spent by them.
Updated subject to make it clearer
from yappi.
I believe this has been implemented while ago: after getting func_stats(), you can filter on a specific thread id. yappi.get_func_stats(filter={"ctx_id":<thread id>, })
from yappi.
The documentation is incomplete for this and there are other problems, too like no example is given on how to obtain context id of a thread and the reason why we don't use thread_id in the filter. We will look into those but in the mean time you can use set_context_id_callback() function to set/get thread id on the internal context object then use that id to filter on the threads.
from yappi.
I have updated the documentation. https://github.com/sumerc/yappi/blob/master/doc/api.md
You can especially look at the get_func_stats() implementation.
The answer to your question is you can do following:
func_pstats = yappi.convert2pstats(yappi.get_func_stats(filter={'ctx_id': }))
To get the context id of a thread:
threads = yappi.get_thread_stats()
Now in threads you can both look at the thread_id,name given by OS whatever you want(I do not know how you identify your thread), and get the associated context id.
from yappi.
Related Issues (20)
- Missing tag for 1.3.5 release HOT 3
- 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
- Matplotlib errors with TypeError: 'NoneType' object is not callable HOT 4
- Fastapi support HOT 3
- Not able to install yappi in ubuntu 18.04 using pip HOT 2
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.