You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# and then stop the flamegraph with e.g. rails runner 'Singed.stop'
61
+
flamegraph =Singed.stop
62
+
# The flamegraph is saved to the output directory
63
+
# Open it with your browser:
64
+
flamegraph.open
65
+
```
66
+
67
+
Note that `Singed.start` can't be run multiple times in parallel, instantiate multiple `Singed::Flamegraph` objects instead and call `start` on them.
68
+
50
69
### RSpec
51
70
52
71
If you are using RSpec, you can use the `flamegraph` metadata to capture it for you.
@@ -90,6 +109,38 @@ PROTIP: use Chrome Developer Tools to record network activity, and copy requests
90
109
91
110
This can also be enabled to always run by setting `SINGED_MIDDLEWARE_ALWAYS_CAPTURE=1` in the environment.
92
111
112
+
### Sidekiq
113
+
114
+
If you are using Sidekiq, you can use the `Singed::Sidekiq::ServerMiddleware` to capture flamegraphs for you.
115
+
116
+
```ruby
117
+
require"singed/sidekiq"
118
+
119
+
Sidekiq.configure_server do |config|
120
+
config.server_middleware do |chain|
121
+
chain.add Singed::Sidekiq::ServerMiddleware
122
+
end
123
+
end
124
+
```
125
+
126
+
To capture flamegraphs for all jobs, you can set the `SINGED_MIDDLEWARE_ALWAYS_CAPTURE` environment variable to `true` the same way as the Rack middleware.
127
+
128
+
To capture flamegraphs for a specific job, you can set the `x-singed` key in the job payload to `true`.
129
+
130
+
```ruby
131
+
MyJob.set("x-singed" => true).perform_async
132
+
```
133
+
134
+
Or define a `capture_flamegraph?` method on the job class:
135
+
136
+
```ruby
137
+
classMyJob
138
+
defself.capture_flamegraph?(payload)
139
+
payload["flamegraph"]
140
+
end
141
+
end
142
+
```
143
+
93
144
### Command Line
94
145
95
146
There is a `singed` command line you can use that will record a flamegraph from the entirety of a command run:
0 commit comments