MCPcopy
hub / github.com/grafana/k6 / Split

Method Split

lib/execution_segment.go:166–195  ·  view source on GitHub ↗

Split evenly divides the execution segment into the specified number of equal consecutive execution sub-segments.

(numParts int64)

Source from the content-addressed store, hash-verified

164// Split evenly divides the execution segment into the specified number of
165// equal consecutive execution sub-segments.
166func (es *ExecutionSegment) Split(numParts int64) ([]*ExecutionSegment, error) {
167 if numParts < 1 {
168 return nil, fmt.Errorf("the number of parts must be at least 1, %d received", numParts)
169 }
170
171 from, to := zeroRat, oneRat
172 if es != nil {
173 from, to = es.from, es.to
174 }
175
176 increment := new(big.Rat).Sub(to, from)
177 increment.Denom().Mul(increment.Denom(), big.NewInt(numParts))
178
179 results := make([]*ExecutionSegment, numParts)
180 for i := range numParts {
181 segmentTo := new(big.Rat).Add(from, increment)
182 segment, err := NewExecutionSegment(from, segmentTo)
183 if err != nil {
184 return nil, err
185 }
186 results[i] = segment
187 from = segmentTo
188 }
189
190 if from.Cmp(to) != 0 {
191 return nil, fmt.Errorf("expected %s and %s to be equal", from, to)
192 }
193
194 return results, nil
195}
196
197// Equal returns true only if the two execution segments have the same from and
198// to values.

Callers 15

TestSplitBadSegmentFunction · 0.95
UnmarshalTextMethod · 0.80
AddSubmetricMethod · 0.80
ParseMetricNameFunction · 0.80
parseRequestMethod · 0.80
TestRequestCompressionFunction · 0.80
splitAttrMethod · 0.80
buildGroupFunction · 0.80
UnmarshalTextMethod · 0.80
UnmarshalTextMethod · 0.80

Calls 3

NewExecutionSegmentFunction · 0.85
ErrorfMethod · 0.80
AddMethod · 0.65

Tested by 6

TestSplitBadSegmentFunction · 0.76
TestRequestCompressionFunction · 0.64
sortExtraTagsForTestFunction · 0.64
TestFeaturesSubCommandFunction · 0.64
getSampleValuesFunction · 0.64