Skip to content

Tiny structural improvement of README. #199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,38 @@ Inspired heavily by [gperftools](https://code.google.com/p/gperftools/), and wri
In your Gemfile add:

```ruby
gem 'stackprof'
gem "stackprof"
```

Then run `$ bundle install`. Alternatively you can run `$ gem install stackprof`.


### Run

in ruby:
The `StackProf.run` method accepts a block with your code to be profiled.

``` ruby
StackProf.run(mode: :cpu, out: 'tmp/stackprof-cpu-myapp.dump') do
StackProf.run(mode: :cpu, out: "tmp/stackprof-cpu-myapp.dump") do
#...
end
```

via rack:
The `:out` option specifies where the sample data is written to.

#### Mode

When profiling a less complex code chunk it might be more helpful to switch from `:cpu` mode to `:object`. This is
advisable when your `:cpu` run doesn't produce any samples.

``` ruby
StackProf.run(mode: :object, out: "tmp/stackprof-cpu-myapp.dump") do
#...
end
```
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is accurate. You should only switch from :cpu to :object when you want to change from profiling time to profiling object allocations. If you run with :cpu doesn't produce any samples it means that your sampling frequency might not be high enough. Measuring :cpu vs :object are completely different things (some code could take lots of time but allocate no objects, some code could run fast but allocate many objects).


#### Rack

In a Rack application, `stackprof` provides a convenient middleware.

``` ruby
use StackProf::Middleware, enabled: true,
Expand All @@ -41,7 +56,9 @@ use StackProf::Middleware, enabled: true,
save_every: 5
```

reporting:
### Reporting

The file produced by the profiler can be visualized to a human-readable form by using the `stackprof` CLI command.

```
$ stackprof tmp/stackprof-cpu-*.dump --text --limit 1
Expand Down