@@ -20,14 +20,7 @@ type CompactionGrantHandle interface {
2020 // Started is called once and must precede calls to MeasureCPU and
2121 // CumulativeStats.
2222 Started ()
23- // MeasureCPU is used to measure the CPU consumption of a goroutine involved
24- // in a compaction. It must be called from each of the two goroutines that
25- // consume CPU during a compaction, and the first call must be before any
26- // significant work is done, since the first call is used to initialize the
27- // measurer for the goroutine. The parameter g must be 0 or 1, to
28- // differentiate between the goroutines. If a compaction is only using one
29- // goroutine, then it can skip calling MeasureCPU(1).
30- MeasureCPU (g int )
23+ CPUMeasurer
3124 // CumulativeStats reports the current cumulative stats. This method may
3225 // block if the scheduler wants to pace the compaction (say to moderate its
3326 // consumption of disk write bandwidth).
@@ -39,3 +32,36 @@ type CompactionGrantHandle interface {
3932 // been installed.
4033 Done ()
4134}
35+
36+ // CompactionGoroutineKind identifies the kind of compaction goroutine.
37+ type CompactionGoroutineKind uint8
38+
39+ const (
40+ // CompactionGoroutinePrimary is the primary compaction goroutine that
41+ // iterates over key-value pairs in the input and calls the current sstable
42+ // writer and blob file writer.
43+ CompactionGoroutinePrimary CompactionGoroutineKind = iota
44+ // CompactionGoroutineSSTableSecondary is the secondary goroutine in the
45+ // current sstable writer that writes blocks to the sstable.
46+ CompactionGoroutineSSTableSecondary
47+ // CompactionGoroutineBlobFileSecondary is the secondary goroutine in the
48+ // current blob file writer that writes blocks to the blob file.
49+ CompactionGoroutineBlobFileSecondary
50+ )
51+
52+ // CPUMeasurer is used to measure the CPU consumption of goroutines involved
53+ // in a compaction.
54+ type CPUMeasurer interface {
55+ // MeasureCPU allows the measurer to keep track of CPU usage while a
56+ // compaction is ongoing. It is to be called regularly from the compaction
57+ // goroutine corresponding to the argument. The first call from a goroutine
58+ // must be done before any significant CPU consumption, since it is used to
59+ // initialize the measurer for the goroutine making the call. If a
60+ // compaction is not using a certain kind of goroutine, it can skip calling
61+ // this method with the corresponding argument.
62+ MeasureCPU (CompactionGoroutineKind )
63+ }
64+
65+ type NoopCPUMeasurer struct {}
66+
67+ func (NoopCPUMeasurer ) MeasureCPU (CompactionGoroutineKind ) {}
0 commit comments