Skip to content

Commit cb642e8

Browse files
committed
Update README to mention CPU time tracking
1 parent 1987656 commit cb642e8

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Wrap a `use` block around the code's original behavior, and wrap `try` around th
2424

2525
* It decides whether or not to run the `try` block,
2626
* Randomizes the order in which `use` and `try` blocks are run,
27-
* Measures the durations of all behaviors in seconds,
27+
* Measures the wall time and cpu time of all behaviors in seconds,
2828
* Compares the result of `try` to the result of `use`,
2929
* Swallow and record exceptions raised in the `try` block when overriding `raised`, and
3030
* Publishes all this information.
@@ -334,11 +334,18 @@ class MyExperiment
334334

335335
def publish(result)
336336

337+
# Wall time
337338
# Store the timing for the control value,
338339
$statsd.timing "science.#{name}.control", result.control.duration
339340
# for the candidate (only the first, see "Breaking the rules" below,
340341
$statsd.timing "science.#{name}.candidate", result.candidates.first.duration
341342

343+
# CPU time
344+
# Store the timing for the control value,
345+
$statsd.timing "science.cpu.#{name}.control", result.control.cpu_time
346+
# for the candidate (only the first, see "Breaking the rules" below,
347+
$statsd.timing "science.cpu.#{name}.candidate", result.candidates.first.cpu_time
348+
342349
# and counts for match/ignore/mismatch:
343350
if result.matched?
344351
$statsd.increment "science.#{name}.matched"
@@ -543,17 +550,22 @@ end
543550

544551
#### Providing fake timing data
545552

546-
If you're writing tests that depend on specific timing values, you can provide canned durations using the `fabricate_durations_for_testing_purposes` method, and Scientist will report these in `Scientist::Observation#duration` instead of the actual execution times.
553+
If you're writing tests that depend on specific timing values, you can provide canned durations using the `fabricate_durations_for_testing_purposes` method, and Scientist will report these in `Scientist::Observation#duration` and `Scientist::Observation#cpu_time` instead of the actual execution times.
547554

548555
```ruby
549556
science "absolutely-nothing-suspicious-happening-here" do |e|
550557
e.use { ... } # "control"
551558
e.try { ... } # "candidate"
552-
e.fabricate_durations_for_testing_purposes( "control" => 1.0, "candidate" => 0.5 )
559+
e.fabricate_durations_for_testing_purposes({
560+
"control" => { "duration" => 1.0, "cpu_time" => 0.9 },
561+
"candidate" => { "duration" => 0.5, "cpu_time" => 0.4 }
562+
})
553563
end
554564
```
555565

556-
`fabricate_durations_for_testing_purposes` takes a Hash of duration values, keyed by behavior names. (By default, Scientist uses `"control"` and `"candidate"`, but if you override these as shown in [Trying more than one thing](#trying-more-than-one-thing) or [No control, just candidates](#no-control-just-candidates), use matching names here.) If a name is not provided, the actual execution time will be reported instead.
566+
`fabricate_durations_for_testing_purposes` takes a Hash of duration & cpu_time values, keyed by behavior names. (By default, Scientist uses `"control"` and `"candidate"`, but if you override these as shown in [Trying more than one thing](#trying-more-than-one-thing) or [No control, just candidates](#no-control-just-candidates), use matching names here.) If a name is not provided, the actual execution time will be reported instead.
567+
568+
We should mention these durations will be used both for the `duration` field and the `cpu_time` field.
557569

558570
_Like `Scientist::Experiment#cleaner`, this probably won't come up in normal usage. It's here to make it easier to test code that extends Scientist._
559571

0 commit comments

Comments
 (0)