Exemplo n.º 1
0
func BenchmarkLyticsPP(b *testing.B) {

	h := lytics.NewHll(14, 20)

	for i := 0; i < b.N; i++ {
		h.Add(uint64(i))
	}
}
Exemplo n.º 2
0
func main() {

	cpuprofile := flag.String("cpuprofile", "", "pprof output file")

	tzoffset := flag.Int64("tz", 0, "time zone offset between log and query")

	flag.Parse()

	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatalf("%v", err)
		}
		if err := pprof.StartCPUProfile(f); err != nil {
			log.Fatalf("%v", err)
		}
		defer pprof.StopCPUProfile()
	}

	scanner := bufio.NewScanner(os.Stdin)

	h := hll.NewHll(14, 20)

	var t0 int64
	var prevt []byte

	for scanner.Scan() {
		t, m, e1, _, err := parseLine(scanner.Bytes())
		if err != nil {
			continue
		}

		h.Add(siphash.Hash(0, 0, m))

		if !bytes.Equal(prevt, t) {
			prevt = append(prevt[:0], t...)
			tm, _ := time.Parse(logFormat, string(prevt))
			t0 = tm.Unix()
		}
		diff := t0 - e1 - *tzoffset

		var i int
		for i < len(seen) && seen[i].epoch < diff {
			i++
		}
		if i == len(seen) {
			i = len(seen) - 1
		}
		seen[i].count++
	}

	fmt.Printf("unique metrics %8d\n", h.Cardinality())

	var maxcount uint64
	var total uint64
	for i := range seen {
		if seen[i].count > maxcount {
			maxcount = seen[i].count
		}
		total += seen[i].count
	}

	const starcols = 70
	stars := dupRune('*', starcols)
	var cumulative uint64
	for i := range seen {
		d := time.Duration(seen[i].epoch) * time.Second
		s := stars[:int(float64(float64(starcols)*(float64(seen[i].count)/float64(maxcount))))]
		cumulative += seen[i].count
		fmt.Printf("%12s %10d (%0.2f, cum %0.2f) %s\n", d.String(), seen[i].count, float64(seen[i].count)/float64(total), float64(cumulative)/float64(total), s)
	}
}