Exemple #1
0
func TestPrintDistribution(t *testing.T) {
	var (
		quantiles = []int{50, 90, 95, 99}
		h         = expvar.NewHistogram("test_print_distribution", 0, 100, 3, quantiles...)
		seed      = int64(555)
		mean      = int64(5)
		stdev     = int64(1)
	)
	teststat.PopulateNormalHistogram(t, h, seed, mean, stdev)

	var buf bytes.Buffer
	metrics.PrintDistribution(&buf, h)
	t.Logf("\n%s\n", buf.String())

	// Count the number of bar chart characters.
	// We should have ca. 100 in any distribution with a small-enough stdev.

	var n int
	for _, r := range buf.String() {
		if r == '#' {
			n++
		}
	}
	if want, have, tol := 100, n, 5; int(math.Abs(float64(want-have))) > tol {
		t.Errorf("want %d, have %d (tolerance %d)", want, have, tol)
	}
}
Exemple #2
0
// have to pass in name because metrics.Histogram blocks expvar.Histogram.Name()
func SaveHist(h metrics.Histogram, name, suffix string) {
	if archaius.Conf.Collect {
		file, err := os.Create("csv_metrics/" + names.Arch(name) + "_" + names.Instance(name) + suffix + ".csv")
		if err != nil {
			log.Printf("%v: %v\n", name, err)
		}
		metrics.PrintDistribution(file, h)
		file.Close()
	}
}
Exemple #3
0
// have to pass in name because metrics.Histogram blocks expvar.Historgram.Name()
func SaveHist(h metrics.Histogram, name, suffix string) {
	if archaius.Conf.Collect {
		file, err := os.Create("csv_metrics/" + names.Arch(name) + "_" + names.Machine(name) + suffix + ".csv")
		if err != nil {
			log.Printf("%v: %v\n", name, err)
		}
		metrics.PrintDistribution(file, h)
		file.Close()
		//Sample data is written out by SaveAllGuesses now
		//dfile, err := os.Create("csv_metrics/" + names.Arch(name) + "_" + names.Machine(name) + suffix + ".data")
		//if err != nil {
		//	log.Printf("%v: %v\n", name, err)
		//}
		//sj, _ := json.Marshal(sampleMap[h])
		//dfile.WriteString(fmt.Sprintf("%v", string(sj)))
		//dfile.Close()
	}
}