如何统计 DBIx::Class 的查询数量?
我在网络上下文中使用 DBIx::Class
并且我想要显示执行的 SQL 查询的数量以及它们呈现页面所花费的时间。
关于如何实施有什么想法吗?
I'm using DBIx::Class
in a web context and I'd like to display the number of SQL queries performed and the time they took for the rendering of a page.
Any idea about how to implement that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅DBIx::Class 说明书“分析”部分中有关如何执行此操作的示例。
仅通过
DBIC_TRACE=1
环境变量启用分析不会满足您的要求,但您可以对DBIx::Class::Storage::Statistics
进行子类化(根据链接的说明书示例)并以允许您计算已完成的 SQL 查询的方式覆盖query_start
和query_end
。链接的示例非常接近您想要实现的目标。
See the DBIx::Class cookbook on the "Profiling" section for examples on how to do that.
Simply enabling profiling via the
DBIC_TRACE=1
environment variable will not do what you want, but you can sub-classDBIx::Class::Storage::Statistics
(as per the linked cookbook example) and overridequery_start
andquery_end
in a way that lets you count the SQL queries done.The linked example is very close to what you want to achieve.