github.com/grafana/pyroscope@v1.18.0/pkg/compactor/duration_list.go (about) 1 package compactor 2 3 import ( 4 "strings" 5 "time" 6 ) 7 8 // DurationList is the block ranges for a tsdb 9 type DurationList []time.Duration 10 11 // String implements the flag.Value interface 12 func (d *DurationList) String() string { 13 values := make([]string, 0, len(*d)) 14 for _, v := range *d { 15 values = append(values, v.String()) 16 } 17 18 return strings.Join(values, ",") 19 } 20 21 // Set implements the flag.Value interface 22 func (d *DurationList) Set(s string) error { 23 values := strings.Split(s, ",") 24 *d = make([]time.Duration, 0, len(values)) // flag.Parse may be called twice, so overwrite instead of append 25 for _, v := range values { 26 t, err := time.ParseDuration(v) 27 if err != nil { 28 return err 29 } 30 *d = append(*d, t) 31 } 32 return nil 33 } 34 35 // ToMilliseconds returns the duration list in milliseconds 36 func (d *DurationList) ToMilliseconds() []int64 { 37 values := make([]int64, 0, len(*d)) 38 for _, t := range *d { 39 values = append(values, t.Milliseconds()) 40 } 41 42 return values 43 }