百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
A

active_record_tracer

> 后端框架
开源

用于 Active Record 查询的跟踪器

200 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

用于 Active Record 查询的跟踪器

ActiveRecordTracer

A tracer for Active Record queries You identified (or suspect) that the reason for the slowness of some code is Active Record, specifically lots of queries and/or loaded records. How do you easily detect which queries, which records are loaded the most, and the sources of those? This tool to the rescue!

Requirements

  • ruby 3.1+
  • activerecord 7.1+

Installation

Add this line to your application's Gemfile:

ruby
gem "active_record_tracer", group: [:development, :test]

And then execute:

bash
$ bundle

Or install it yourself as:

bash
$ gem install active_record_tracer

Usage

ruby
require "active_record_tracer"
report = ActiveRecordTracer.report do
  # run your code here
end

report.pretty_print

Or, you can use the .start/.stop API as well:

ruby
require "active_record_tracer"

ActiveRecordTracer.start

# run your code

report = ActiveRecordTracer.stop
report.pretty_print

NOTE: .start/.stop can only be run once per report, and .stop will be the only time you can retrieve the report using this API.

Tracing tests

To trace tests, use the following in test_helper.rb for Minitest:

ruby
ActiveRecordTracer.start
Minitest.after_run do
  report = ActiveRecordTracer.stop
  report.pretty_print(to_file: "tmp/active_record_tracer-tests.txt")
end

Options

report

The report method can take a few options:

  • top: maximum number of entries to display in a report (default is 50)
  • backtrace_lines: maximum number of backtrace lines to include in the report (default is 5)
  • ignore_cached_queries: whether to ignore cached queries (default is false)
  • ignore_schema_queries: whether to ignore schema queries (default is true)

Check out Reporter#new for more details.

pretty_print

The pretty_print method can take a few options:

  • to_file: a path to your log file - can be given a String
  • detailed_report: whether to include detailed information - can be given a Boolean

Check out Report#pretty_print for more details.

Example output

…

Development

After checking out the repo, run bundle install to install dependencies. Then, run bundle exec rake test to run the tests. This project uses multiple Gemfiles to test against multiple versions of Active Record; you can run the tests against the specific version with BUNDLE_GEMFILE=gemfiles/activerecord_70.gemfile bundle exec rake test.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/fatkodima/active_record_tracer.

License

The gem is available as open source under the terms of the MIT License.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rubyactiverecordgemrailsruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类后端框架
定价开源

> 相关工具

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架