var ( // ErrDone is returned when the underlying file has ran out of lines. ErrDone = errors.New("no more values in the Simulator") // ErrBadLine is returned when the trace file line is unrecognizable to // the Parser. ErrBadLine = errors.New("bad line for trace format") )
func Collection(simulator Simulator, size uint64) []uint64
Collection evaluates the Simulator size times and saves each item to the returned slice.
func ParseARC(line string, err error) ([]uint64, error)
ParseARC takes a single line of input from an ARC trace file as described in "ARC: a self-tuning, low overhead replacement cache" 1 by Nimrod Megiddo and Dharmendra S. Modha 1 and returns a sequence of numbers generated from the line and any error. For use with NewReader.
func ParseLIRS(line string, err error) ([]uint64, error)
ParseLIRS takes a single line of input from a LIRS trace file as described in multiple papers 1 and returns a slice containing one number. A nice collection of LIRS trace files can be found in Ben Manes' repo 2.
func StringCollection(simulator Simulator, size uint64) []string
StringCollection evaluates the Simulator size times and saves each item to the returned slice, after converting it to a string.
Parser is used as a parameter to NewReader so we can create Simulators from varying trace file formats easily.
type Parser func(string, error) ([]uint64, error)
Simulator is the central type of the `sim` package. It is a function returning a key from some source (composed from the other functions in this package, either generated or parsed). You can use these Simulators to approximate access distributions.
type Simulator func() (uint64, error)
func NewReader(parser Parser, file io.Reader) Simulator
NewReader creates a Simulator from two components: the Parser, which is a filetype specific function for parsing lines, and the file itself, which will be read from.
When every line in the file has been read, ErrDone will be returned. For some trace formats (LIRS) there is one item per line. For others (ARC) there is a range of items on each line. Thus, the true number of items in each file is hard to determine, so it's up to the user to handle ErrDone accordingly.
func NewUniform(max uint64) Simulator
NewUniform creates a Simulator returning uniformly distributed 1 (random) numbers [0, max) infinitely.
func NewZipfian(s, v float64, n uint64) Simulator
NewZipfian creates a Simulator returning numbers following a Zipfian 1 distribution infinitely. Zipfian distributions are useful for simulating real workloads.