-
Notifications
You must be signed in to change notification settings - Fork 33
/
dist.go
61 lines (50 loc) · 2.04 KB
/
dist.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (C) 2015 Space Monkey, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package monkit
import (
"time"
)
const (
ReservoirSize = 64
)
var (
// If Window is > 0, the probability of replacing a datapoint will never
// fall below ReservoirSize/Window instead of continuing to fall over time.
// Window should be a multiple of ReservoirSize.
Window int64 = 1024
)
// ObservedQuantiles is the set of quantiles the internal distribution
// measurement logic will try to optimize for, if applicable.
var ObservedQuantiles = []float64{0, .1, .25, .5, .75, .9, .95, 1}
type float32Slice []float32
func (p float32Slice) Len() int { return len(p) }
func (p float32Slice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
func (p float32Slice) Less(i, j int) bool {
// N.B.: usually, float comparisons should check if either value is NaN, but
// in this package's usage, they never are here.
return p[i] < p[j]
}
//go:generate sh -c "m4 -D_IMPORT_='\"time\"' -D_NAME_=Duration -D_LOWER_NAME_=duration -D_TYPE_=time.Duration distgen.go.m4 > durdist.go"
//go:generate sh -c "m4 -D_IMPORT_= -D_NAME_=Float -D_LOWER_NAME_=float -D_TYPE_=float64 distgen.go.m4 > floatdist.go"
//go:generate sh -c "m4 -D_IMPORT_= -D_NAME_=Int -D_LOWER_NAME_=int -D_TYPE_=int64 distgen.go.m4 > intdist.go"
//go:generate gofmt -w -s durdist.go floatdist.go intdist.go
func (d *DurationDist) toFloat64(v time.Duration) float64 {
return v.Seconds()
}
func (d *IntDist) toFloat64(v int64) float64 {
return float64(v)
}
func (d *FloatDist) toFloat64(v float64) float64 {
return v
}