16926a676b
This makes it easier to query, simplifies the code, and makes it possible to figure out what transaction the data belongs to (simply because it's now stored _in_ the transaction). This new setup keeps track of both the real/wall time _and_ CPU time spent in a block, both measured using milliseconds (to keep all units the same).
924 B
924 B
Instrumenting Ruby Code
GitLab Performance Monitoring allows instrumenting of custom blocks of Ruby code. This can be used to measure the time spent in a specific part of a larger chunk of code. The resulting data is stored as a field in the transaction that executed the block.
To start measuring a block of Ruby code you should use Gitlab::Metrics.measure
and give it a name:
Gitlab::Metrics.measure(:foo) do
...
end
Two values are measured for a block:
- The real time elapsed, stored in NAME_real_time
- The CPU time elapsed, stored in NAME_cpu_time
Both the real and CPU timings are measured in milliseconds.
Multiple calls to the same block will result in the final values being the sum of all individual values. Take this code for example:
3.times do
Gitlab::Metrics.measure(:sleep) do
sleep 1
end
end
Here the final value of sleep_real_time
will be 3
, not 1
.