<commit_before>package main

import (
	"fmt"
	log "github.com/Sirupsen/logrus"
	"github.com/loadimpact/speedboat/sampler"
	stdlog "log"
	"time"
)

func printMetrics(l *stdlog.Logger) {
	for name, m := range sampler.DefaultSampler.Metrics {
		l.Printf("%s\n", name)
		switch m.Type {
		case sampler.GaugeType:
			l.Printf("  value=%s\n", applyIntent(m, m.Last()))
		case sampler.CounterType:
			l.Printf("  num=%s\n", applyIntent(m, m.Sum()))
		case sampler.StatsType:
			l.Printf("  min=%s\n", applyIntent(m, m.Min()))
			l.Printf("  max=%s\n", applyIntent(m, m.Max()))
			l.Printf("  avg=%s\n", applyIntent(m, m.Avg()))
			l.Printf("  med=%s\n", applyIntent(m, m.Med()))
		}
	}
}

func commitMetrics() {
	if err := sampler.DefaultSampler.Commit(); err != nil {
		log.WithError(err).Error("Couldn't write samples!")
	}
}

func applyIntent(m *sampler.Metric, v int64) interface{} {
	if m.Intent == sampler.TimeIntent {
		return time.Duration(v)
	}
	return fmt.Sprint(v)
}<commit_msg>[fix] Print metrics as single lines<commit_after>package main

import (
	"fmt"
	log "github.com/Sirupsen/logrus"
	"github.com/loadimpact/speedboat/sampler"
	stdlog "log"
	"time"
)

func printMetrics(l *stdlog.Logger) {
	for name, m := range sampler.DefaultSampler.Metrics {
		switch m.Type {
		case sampler.GaugeType:
			l.Printf("%s val=%v\n", name, applyIntent(m, m.Last()))
		case sampler.CounterType:
			l.Printf("%s num=%v\n", name, applyIntent(m, m.Sum()))
		case sampler.StatsType:
			l.Printf("%s min=%v max=%v avg=%v med=%v\n", name,
				applyIntent(m, m.Min()),
				applyIntent(m, m.Max()),
				applyIntent(m, m.Avg()),
				applyIntent(m, m.Med()),
			)
		}
	}
}

func commitMetrics() {
	if err := sampler.DefaultSampler.Commit(); err != nil {
		log.WithError(err).Error("Couldn't write samples!")
	}
}

func applyIntent(m *sampler.Metric, v int64) interface{} {
	if m.Intent == sampler.TimeIntent {
		return time.Duration(v)
	}
	return fmt.Sprint(v)
}
{'fraction_non_alphanumeric': 0.18467078189300412, 'fraction_numerical': 0.00205761316872428, 'mean_word_length': 4.0519480519480515, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '627864', 'n_tokens_mistral': 814, 'n_tokens_neox': 769, 'n_words': 153}