如何统计 DBIx::Class 的查询数量?

发布于 2024-09-14 16:12:22 字数 168 浏览 3 评论 0原文

我在网络上下文中使用 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 技术交流群。

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

发布评论

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

评论(1

温柔少女心 2024-09-21 16:12:22

请参阅DBIx::Class 说明书“分析”部分中有关如何执行此操作的示例。

仅通过 DBIC_TRACE=1 环境变量启用分析不会满足您的要求,但您可以对 DBIx::Class::Storage::Statistics 进行子类化(根据链接的说明书示例)并以允许您计算已完成的 SQL 查询的方式覆盖 query_startquery_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-class DBIx::Class::Storage::Statistics (as per the linked cookbook example) and override query_start and query_end in a way that lets you count the SQL queries done.

The linked example is very close to what you want to achieve.

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