在 /cgi-bin/ 中的 Python 脚本上使用 cProfile 或 line_profile?

发布于 2024-09-14 03:29:43 字数 213 浏览 3 评论 0原文

有没有办法在服务器上的脚本上运行 cProfile 或 line_profile?

即:我如何获得 http://www 上两种方法之一的结果.Example.com/cgi-bin/myScript.py

谢谢!

Is there a way to run cProfile or line_profile on a script on a server?

ie: how could I get the results for one of the two methods on http://www.Example.com/cgi-bin/myScript.py

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

玩物 2024-09-21 03:29:43

不确定 line_profile 是什么。对于cProfile,您只需将结果定向到稍后可以在服务器上读取的文件(取决于您对服务器的访问类型)。

引用文档中的示例,

import cProfile
cProfile.run('foo()', 'fooprof')

并将所有其余代码放入def foo(): -- 然后检索该 fooprof 文件并闲暇时分析它(当然,假设您的脚本运行时具有写入它的权限) 。

当然,您可以确保不同的运行被分析到不同的文件中,等等——这是否实用还取决于您从托管提供商处获得的访问和权限类型,即如何您是否可以保留数据,以便以后检索该数据?这不是 Python 的问题,而是您和托管提供商之间的合同问题;-)。

Not sure what line_profile is. For cProfile, you just need to direct the results to a file you can later read on the server (depending on what kind of access you have to the server).

To quote the example from the docs,

import cProfile
cProfile.run('foo()', 'fooprof')

and put all the rest of the code into a def foo(): -- then later retrieve that fooprof file and analyze it at leisure (assuming your script runs with permissions to write it in the first place, of course).

Of course you can ensure different runs get profiled into different files, etc, etc -- whether this is practical also depends on what kind of access and permissions you're getting from your hosting provider, i.e., how are you allowed to persist data, in a way that lets you retrieve that data later? That's not a question of Python, it's a question of contracts between you and your hosting provider;-).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文