Comments (9)
我把subprocess的fix已经check in了,但是django的这个架构让viztracer用起来会稍微有点点麻烦。
首先,你在用viztracer的时候需要额外pass进去一个--log_subprocess
,大概是
viztracer --log_subprocess --log_sparse manage.py runserver
然后你的代码部分,你需要给你的django一个save的entry,就是要想办法手动save。那比较直接的方法是给一个url,比如
from viztracer import get_tracer
@require_GET
def save(request):
tracer = get_tracer()
# 注意这里如果你不给output file,它会默认保存成json格式(因为是subprocess)
tracer.save(output_file="result.html")
return HttpResponse("done")
然后你添加一个url到这个save函数,就可以通过浏览/save
来保存report了。(你原来的@log_sparse
还要保留)
确实可能步骤多了一点,但是django的这个架构也没有特别好的办法。如果你和django的复杂度比一下,这个方式应该还是可以接受的。
from viztracer.
flask的部分确认了是viztracer的bug。bug比较复杂,涉及到viztracer在multithreading的hook机理。因为log_sparse直接bypass了所有的hook,导致thread-specific的一个值没有初始化。
我会调整一下threading机理的部分,尽快修复这个bug
from viztracer.
Flask的问题和Django不太一样。
Flask是viztracer的bug,在viztracer没有profile function的时候,新spawn的thread不会trigger thread specific initialization。我把这个问题在 #73 修复了,现在的thread initialization架构和原来不太一样了,正好 #66 可能也需要这个feature。现在log_sparse
应该可以在multithread的程序上正常工作了。
Django这个问题比较复杂。分为两个部分。
Django用了一个subprocess的模型去跑(至少manage.py是这样的),理论上viztracer是支持subprocess的,但是现在有两个问题:
- viztracer的subprocess hook现在判断的比较不科学,是直接判断
startswith("python")
,而Django用的绝对路径。这个事情是可以fix的。 - Django用的这个模型,在用户ctrl+c之后会直接给subprocess发一个
SIGKILL
。而SIGKILL
是不可以被catch的,所以在ctrl+c关闭服务器之后,是没有任何办法去保存subprocess的数据的。而viztracer的subprocess模型是需求main process去保证subprocess执行完毕的。所以这里是个死结。
我并没有修改任何Django的问题,但是现在有一个方案是或许可行的。就是你可以手动在你的Django文件里去输出report。
tracer = get_tracer()
tracer.save()
这样是可以拿到数据的(前提是我把subprocess的hook改掉)。所以我想知道你现在觉得这个方案会对你有帮助么?如果有帮助,我就再把subprocess的那个hook问题解决,然后你可以试一下在程序内输出。如果你觉得现在把flask修好就够了,那你可以把这个issue close了~
from viztracer.
另外,这个fix现在只commit到了master,还没有release,所以如果你要试验的话,你需要从git安装
pip install git+https://github.com/gaogaotiantian/viztracer
因为不是直接的wheels,所以你可能需要安装一下wheels
pip install twine setuptools wheel
另外就是因为用了C lib,所以你需要python3-dev
。
当然,如果你对Django这个事情没意见,我应该会这几天就把这个fix release了。
from viztracer.
嗯嗯, 感谢, flask的log_sparse已经可以抓到report了.
Django的方案我没意见, 我的使用场景是测试环境调试用的, 装饰器或者get_trace使用复杂度差不多.
by the way, 我发现flask没有抓到代码段, 当然这个对我使用没啥影响.
from viztracer.
还有django可以修复再关
from viztracer.
log_sparse目前是不支持source code的获取的,它的机制和正常的function hook不太一样,这个不是bug~
Django的部分我这几天修改一下,然后做个prototype,争取能尽快修复+release
from viztracer.
谢谢 O(∩_∩)O
from viztracer.
谢谢, 按您的方案操作, Django下产生了2个report文件, 我在result_72587.html中看到了被装饰的函数调用.
from viztracer.
Related Issues (20)
- 0.16.2: pytest fails in 8 units HOT 10
- 0.16.2: sphinx warnings `reference target not found` HOT 3
- VizTracer 能否可视化python 模块和类之间的调用关系,在分析不熟悉的项目时很有用? 类似于开源库pyan(已经停止维护了) HOT 2
- 可以为VS Code插件 在"设置"中提供 "默认运行参数" 的修改么? HOT 1
- AttributeError: Can't get attribute 'Bar' on <module '__main__' from 'miniconda3/envs/3.12.0/bin/viztracer'>
- Uncaught compile error when attempting to view traces using vizviewer HOT 3
- 请问,使用vizviewer时,如何指定监听的IP和port? HOT 1
- use `https://ui.perfetto.dev` instead of vendored html. HOT 4
- jupyter integration not working properly on remote jupyter lab HOT 2
- Test failed on Arch Linux against Python 3.12 HOT 6
- asyncio.create_subprocess_shell().communicate() hangs HOT 6
- 无法绑定ip及jupyter中无法更改端口号 HOT 1
- Gives warning: "Found and ignore invalid json file, you may lost some process data." HOT 3
- doesn't pick up existing threads at launch HOT 4
- VizTracer not tracing some functions HOT 1
- Build wheels for free-threading version HOT 3
- [optimize] always add quotes when printing file path HOT 2
- Is it possible to record the function in which tracer is stopped? HOT 3
- Viztracer/vizviewer displays only 1 of N threads with the same name HOT 1
- 关于c++编译的扩展模块中类成员函数没有记录的问题 HOT 6
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 viztracer.