Skip to content
This repository has been archived by the owner on Jul 27, 2024. It is now read-only.

Commit

Permalink
Add --profile flag + solargraph
Browse files Browse the repository at this point in the history
  • Loading branch information
charlespwd committed Sep 7, 2021
1 parent 46db7b6 commit 425ca50
Show file tree
Hide file tree
Showing 6 changed files with 18,591 additions and 11 deletions.
58 changes: 58 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,61 @@ MyNewCheckName:
ignore: []
muffin_mode: true
```

## Debugging

A couple of things are turned on when the `THEME_CHECK_DEBUG` environment variable is set.

1. The check timeout is turned off. This means you can add `binding.pry` in tests and properly debug with `bundle exec rake tests:in_memory`
2. The `--profile` flag appears. You can now create Flamegraphs to inspect performance.

```
export THEME_CHECK_DEBUG=true

# The following will behave slightly differently
bin/theme-check ../dawn
bundle exec rake tests:in_memory

# The following becomes available
bin/theme-check --profile ../dawn

# The LanguageServer will log the JSONRPC calls to STDERR
bin/theme-check-language-server
```
### Profiling
`ruby-prof` and `ruby-prof-flamegraph` are both included as development dependencies.
#### Flamegraph
With the `--profile` flag, you can run theme-check on a theme and the `ruby-prof-flamegraph` printer will output profiling information in a format [Flamegraph](/brendangregg/FlameGraph) understands.
**Setup:**
```bash
# clone the FlameGraph repo somewhere
git clone https://github.com/brendangregg/FlameGraph.git
# the flamegraph.pl perl script is in that repo
alias flamegraph=/path/to/FlameGraph/flamegraph.pl
```

**Profiling:**

```
# run theme-check with --profile
# pass the output to flamegraph
# dump the output into an svg file
bin/theme-check --profile ../dawn \
| flamegraph --countname=ms --width=1750 \
> /tmp/fg.svg
# open the svg file in Chrome to look at the flamegraph
chrome /tmp/fg.svg
```

What you'll see is an interactive version of the following image:

![flamegraph](docs/flamegraph.svg)
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ end
group :development do
gem 'guard'
gem 'guard-minitest'
gem 'ruby-prof'
gem 'ruby-prof-flamegraph'
gem 'solargraph'
end

gem 'rubocop', '~> 1.12.0', require: false
Expand Down
Loading

0 comments on commit 425ca50

Please sign in to comment.