{"id":14991240,"url":"https://github.com/procore-oss/rspec_profiling","last_synced_at":"2025-04-12T03:30:36.683Z","repository":{"id":221588900,"uuid":"754747727","full_name":"procore-oss/rspec_profiling","owner":"procore-oss","description":"Collects profiles of RSpec test suites","archived":false,"fork":false,"pushed_at":"2025-01-21T00:32:10.000Z","size":111,"stargazers_count":2,"open_issues_count":1,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-04-09T14:08:54.186Z","etag":null,"topics":["rspec","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"foraker/rspec_profiling","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/procore-oss.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-08T17:35:15.000Z","updated_at":"2024-07-16T01:09:18.000Z","dependencies_parsed_at":"2024-02-19T19:00:56.744Z","dependency_job_id":"5de93ba7-239b-4a79-9dfd-05fa13285e2c","html_url":"https://github.com/procore-oss/rspec_profiling","commit_stats":{"total_commits":57,"total_committers":15,"mean_commits":3.8,"dds":0.8070175438596492,"last_synced_commit":"02755b5ea92d06676e35e3d9e55ac75623d8165e"},"previous_names":["procore-oss/rspec_profiling"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/procore-oss%2Frspec_profiling","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/procore-oss%2Frspec_profiling/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/procore-oss%2Frspec_profiling/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/procore-oss%2Frspec_profiling/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/procore-oss","download_url":"https://codeload.github.com/procore-oss/rspec_profiling/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248512432,"owners_count":21116599,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rspec","ruby"],"created_at":"2024-09-24T14:21:57.292Z","updated_at":"2025-04-12T03:30:36.659Z","avatar_url":"https://github.com/procore-oss.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RspecProfiling\n\n[![Test](https://github.com/procore-oss/rspec_profiling/actions/workflows/test.yaml/badge.svg?branch=main)](https://github.com/procore-oss/rspec_profiling/actions/workflows/test.yaml)\n[![Gem Version](https://badge.fury.io/rb/rspec_profiling.svg)](https://badge.fury.io/rb/rspec_profiling)\n[![Discord](https://img.shields.io/badge/Chat-EDEDED?logo=discord)](https://discord.gg/PbntEMmWws) \n\n\nCollects profiles of RSpec test suites, enabling you to identify specs\nwith interesting attributes. For example, find the slowest specs, or the\nspec which issues the most queries.\n\nCollected attributes include:\n\n- git commit SHA (or SVN revision) and date\n- example file, line number and description\n- example status (i.e. passed or failed)\n- example exception (i.e. nil if passed, reason for failure otherwise)\n- example time\n- query count and time\n- request count and time\n\n## Compatibility\n\nRspecProfiling should work with Rails \u003e= 3.2 and RSpec \u003e= 2.14.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'rspec_profiling'\n```\n\nAnd then execute:\n\n```bash\nbundle\n```\n\nRequire the gem to your `spec_helper.rb`.\n\n```ruby\nrequire \"rspec_profiling/rspec\"\n```\n\nLastly, run the installation rake tasks to initialize an empty database in\nwhich results will be collected.\n\n```bash\nbundle exec rake rspec_profiling:install\n```\n\nIf you are planning on using `sqlite` or `pg` ensure to add the dependency to your gemfile\n\n```ruby\n  gem 'sqlite', require: false\n  gem 'pg', require: false\n```\n\n## Usage\n\n### Choose a version control system\n\nResults are collected based on the version control system employed e.g. revision or commit SHA for `svn` and `git` respectively.\n\n#### Git\n\nBy default, RspecProfiling expects Git as the version control system.\n\n#### Subversion\n\nRspecProfiling can be configured to use `svn` in `config/initializers/rspec_profiling.rb`:\n\n```Ruby\nRspecProfiling.configure do |config|\n  config.vcs = RspecProfiling::VCS::Svn\nend\n```\n\n#### Git / Subversion\n\nFor those with a mixed project, with some developers using `git svn` and others regular `svn`, use this configuration to detect which is being used locally and behave accordingly.\n\n```Ruby\nRspecProfiling.configure do |config|\n  config.vcs = RspecProfiling::VCS::GitSvn\nend\n```\n\n#### Custom Ownership Tracking\n\nIf the repo you are running the profiler on has many teams working on it, you can use the `magic_comment` option to specify a comment at the top of files to scan for ownership tracking.  In the example below,\nthe profiler will look for `#team: \u003cowner\u003e` comments at the top of each file and add \u003cowner\u003e to the results.\nThe default is `team` but can be configured to any comment you want.\n\n```Ruby\nRspecProfiling.configure do |config|\n  config.magic_comment = 'team'\nend\n```\n\n#### Custom Event Subscriptions\n\n```Ruby\nRspecProfiling.configure do |config|\n  config.events = %w[event1 event2]\nend\n```\n\nNote that custom events are only currently reported by the CSV collector.\n\n#### Custom Event Recording\n\nIt is possible to record the event metadata for a spec.\n\n```Ruby\n  describe 'Records all active record queries', record_events: %w[sql.active_record] do\n    it 'Records Rails deprecations', record_events: %w[deprecation.rails] do\n      ...\n    end\n    it 'Records nothing' do\n      ...\n    end\n  end\n```\n\n### Choose a results collector\n\nResults are collected just by running the specs.\n\n#### SQLite3\n\nMake sure you've run the installation rake task before attempting.\n\nYou can configure `RspecProfiling` to collect results in a SQL database in `config/initializers/rspec_profiling.rb`:\n\n```Ruby\nRspecProfiling.configure do |config|\n  config.collector = RspecProfiling::Collectors::SQL\nend\n```\n\nYou can review results by running the RspecProfiling console.\nThe console has a preloaded `results` variable.\n\n```bash\nbundle exec rake rspec_profiling:console\n\n\u003e results.count\n=\u003e 1970\n```\n\nYou can find the spec that runs the most queries:\n\n```ruby\n\u003e results.order(:query_count).last.to_s\n=\u003e \"Updating my account - ./spec/features/account_spec.rb:15\"\n```\n\nOr find the spec that takes the most time:\n\n```ruby\n\u003e results.order(:time).last.to_s\n=\u003e \"Updating my account - ./spec/features/account_spec.rb:15\"\n```\n\nThere are additional attributes available on the `Result` instances to enable\ndebugging, such as `exception` and `status`.\n\n#### CSV\n\nBy default, profiles are collected in an a CSV file. You can configure `RspecProfiling` to collect results in a CSV in `config/initializers/rspec_profiling.rb`:\n\n```Ruby\nRspecProfiling.configure do |config|\n  config.collector = RspecProfiling::Collectors::CSV\nend\n```\n\nBy default, the CSV is output to `cat tmp/spec_benchmarks.csv`.\nRerunning spec will overwrite the file. You can customize the CSV path\nto, for example, include the sample time.\n\n```Ruby\nRspecProfiling.configure do |config|\n  config.collector = RspecProfiling::Collectors::CSV\n  config.csv_path = -\u003e{ \"tmp/spec_benchmark_#{Time.now.to_i}\" }\nend\n```\n\n#### Postgresql\n\nYou can configure `RspecProfiling` to collect results in a Postgres database\nin your `spec_helper.rb` file.\n\n```Ruby\nRspecProfiling.configure do |config|\n  config.collector = RspecProfiling::Collectors::PSQL\n  config.db_path   = 'profiling'\nend\n```\n\n## Configuration Options\n\nConfiguration is performed like this:\n\n```Ruby\nRspecProfiling.configure do |config|\n  config.\u003coption\u003e = \u003csomething\u003e\nend\n```\n\n### Options\n\n- `db_path` - the location of the SQLite database file\n- `table_name` - the database table name in which results are stored\n- `csv_path` - the directory in which CSV files are dumped\n- `collector` - collector to use\n- `magic_comment` - comment to scan top of files to enable ownership tracking (EX: `#team: tooling`)\n\n### Usage in a script\n\nIf you want to access the results from a Ruby script instead of the `rake rspec_profiling:console` shell command:\n\n```ruby\nrequire 'rspec_profiling'\nrequire 'rspec_profiling/console'\n```\n\nThen `results` will be available as a variable to the script.\n\n## Uninstalling\n\nTo remove the results database, run `bundle exec rake rspec_profiling:uninstall`.\n\n## Contributing\n\nPlease read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.\n\n## Local Development\n\nLocal tools needed:\n\n- docker\n- docker-compose\n- ruby\n\nTo run the specs:\n\n```bash\nmake spec\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprocore-oss%2Frspec_profiling","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprocore-oss%2Frspec_profiling","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprocore-oss%2Frspec_profiling/lists"}