func (s *Stats) PrecisionTiming(stat string, delta time.Duration, tags ...Tag) {
	s.trans.bufLock.Lock()
	lastLen := len(s.trans.buf)
	s.trans.buf = append(s.trans.buf, []byte(s.metricPrefix)...)
	if s.trans.tagFormat.Placement == TagPlacementName {
		s.trans.buf = s.formatTags(s.trans.buf, tags)
	}
	s.trans.buf = append(s.trans.buf, ' ')
	s.trans.buf = append(s.trans.buf, []byte(stat)...)
	s.trans.buf = append(s.trans.buf, s.trans.tagFormat.KeyValueSeparator)
	s.trans.buf = strconv.AppendFloat(s.trans.buf, float64(delta), 'f', -1, 64)
	if s.trans.tagFormat.Placement == TagPlacementSuffix {
		s.trans.buf = s.formatTags(s.trans.buf, tags)
	}
	s.trans.buf = append(s.trans.buf, '\n')
	s.trans.checkBuf(lastLen)
	s.trans.bufLock.Unlock()
}
PrecisionTiming track a duration event, the time delta has to be a duration

Usually request processing time, time to run database query, etc. are used with
this metric type.
package stats
import (
	"log"
	"net"
	"os"
	"strconv"
	"sync"
	"sync/atomic"
	"time"
)
type Config struct {
	Size  int
	HBins int  
	Addr  string
}
type Stats struct {
	sync.Mutex
	trans        *transport
	Count        uint64
	metricPrefix string
	defaultTags  []Tag
}
type transport struct {
	maxPacketSize int
	tagFormat     *TagFormat
	bufPool   chan []byte
	buf       []byte
	bufSize   int
	bufLock   sync.Mutex
	sendQueue chan []byte
	shutdown     chan struct{}
	shutdownOnce sync.Once
	shutdownWg   sync.WaitGroup
	lostPacketsPeriod  int64
	lostPacketsOverall int64
}
func New(c *Config, options ...Option) *Stats {
	opts := ClientOptions{
		Addr:              c.Addr,
		MetricPrefix:      DefaultMetricPrefix,
		MaxPacketSize:     DefaultMaxPacketSize,
		FlushInterval:     DefaultFlushInterval,
		ReconnectInterval: DefaultReconnectInterval,
		ReportInterval:    DefaultReportInterval,
		RetryTimeout:      DefaultRetryTimeout,
		Logger:            log.New(os.Stderr, DefaultLogPrefix, log.LstdFlags),
		BufPoolCapacity:   DefaultBufPoolCapacity,
		SendQueueCapacity: DefaultSendQueueCapacity,
		SendLoopCount:     DefaultSendLoopCount,
		TagFormat:         TagFormatInfluxDB,
	}
	s := &Stats{
		trans: &transport{
			shutdown: make(chan struct{}),
		},
	}
	s.trans.bufSize = opts.MaxPacketSize + 1024
	for _, option := range options {
		option(&opts)
	}
	s.metricPrefix = opts.MetricPrefix
	s.defaultTags = opts.DefaultTags
	s.trans.tagFormat = opts.TagFormat
	s.trans.maxPacketSize = opts.MaxPacketSize
	s.trans.buf = make([]byte, 0, s.trans.bufSize)
	s.trans.bufPool = make(chan []byte, opts.BufPoolCapacity)
	s.trans.sendQueue = make(chan []byte, opts.SendQueueCapacity)
	go s.trans.flushLoop(opts.FlushInterval)
	for i := 0; i < opts.SendLoopCount; i++ {
		s.trans.shutdownWg.Add(1)
		go s.trans.sendLoop(opts.Addr, opts.ReconnectInterval, opts.RetryTimeout, opts.Logger)
	}
	if opts.ReportInterval > 0 {
		s.trans.shutdownWg.Add(1)
		go s.trans.reportLoop(opts.ReportInterval, opts.Logger)
	}
	return s
}
func (t *transport) flushLoop(flushInterval time.Duration) {
	var flushC <-chan time.Time
	if flushInterval > 0 {
		flushTicker := time.NewTicker(flushInterval)
		defer flushTicker.Stop()
		flushC = flushTicker.C
	}
	for {
		select {
		case <-t.shutdown:
			t.bufLock.Lock()
			if len(t.buf) > 0 {
				t.flushBuf(len(t.buf))
			}
			t.bufLock.Unlock()
			close(t.sendQueue)
			return
		case <-flushC:
			t.bufLock.Lock()
			if len(t.buf) > 0 {
				t.flushBuf(len(t.buf))
			}
			t.bufLock.Unlock()
		}
	}
}
func (t *transport) sendLoop(addr string, reconnectInterval, retryTimeout time.Duration, log SomeLogger) {
	var (
		sock       net.Conn
		err        error
		reconnectC <-chan time.Time
	)
	if reconnectInterval > 0 {
		reconnectTicker := time.NewTicker(reconnectInterval)
		defer reconnectTicker.Stop()
		reconnectC = reconnectTicker.C
	}
RECONNECT:
	sock, err = net.Dial("udp", addr)
	if err != nil {
		log.Printf("[STATSD] Error connecting to server: %s", err)
		goto WAIT
	}
	for {
		select {
		case buf, ok := <-t.sendQueue:
			if !ok {
				_ = sock.Close()  
				t.shutdownWg.Done()
				return
			}
			if len(buf) > 0 {
				_, err := sock.Write(buf[0 : len(buf)-1])
				if err != nil {
					log.Printf("[STATSD] Error writing to socket: %s", err)
					_ = sock.Close()  
					goto WAIT
				}
			}
			select {
			case t.bufPool <- buf:
			default:
			}
		case <-reconnectC:
			_ = sock.Close()  
			goto RECONNECT
		}
	}
WAIT:
	time.Sleep(retryTimeout)
	goto RECONNECT
}
func (t *transport) reportLoop(reportInterval time.Duration, log SomeLogger) {
	defer t.shutdownWg.Done()
	reportTicker := time.NewTicker(reportInterval)
	defer reportTicker.Stop()
	for {
		select {
		case <-t.shutdown:
			return
		case <-reportTicker.C:
			lostPeriod := atomic.SwapInt64(&t.lostPacketsPeriod, 0)
			if lostPeriod > 0 {
				log.Printf("[STATSD] %d packets lost (overflow)", lostPeriod)
			}
		}
	}
}
func (s *Stats) Unregister() {
	s.Lock()
	s.trans.close()
	s.Unlock()
}
func (t *transport) close() {
	t.shutdownOnce.Do(func() {
		close(t.shutdown)
	})
	t.shutdownWg.Wait()
}
func (s *Stats) Incr(stat string, count int64, tags ...Tag) {
	if 0 != count {
		s.trans.bufLock.Lock()
		lastLen := len(s.trans.buf)
		s.trans.buf = append(s.trans.buf, []byte(s.metricPrefix)...)
		s.trans.buf = append(s.trans.buf, []byte(stat)...)
		if s.trans.tagFormat.Placement == TagPlacementName {
			s.trans.buf = s.formatTags(s.trans.buf, tags)
		}
		s.trans.buf = append(s.trans.buf, ':')
		s.trans.buf = strconv.AppendInt(s.trans.buf, count, 10)
		s.trans.buf = append(s.trans.buf, []byte("|c")...)
		if s.trans.tagFormat.Placement == TagPlacementSuffix {
			s.trans.buf = s.formatTags(s.trans.buf, tags)
		}
		s.trans.buf = append(s.trans.buf, '\n')
		s.trans.checkBuf(lastLen)
		s.trans.bufLock.Unlock()
	}
}
func (s *Stats) Decr(stat string, count int64, tags ...Tag) {
	s.Incr(stat, -count, tags...)
}
func (s *Stats) Timing(stat string, delta int64, tags ...Tag) {
	s.trans.bufLock.Lock()
	lastLen := len(s.trans.buf)
	s.trans.buf = append(s.trans.buf, []byte(s.metricPrefix)...)
	s.trans.buf = append(s.trans.buf, []byte(stat)...)
	if s.trans.tagFormat.Placement == TagPlacementName {
		s.trans.buf = s.formatTags(s.trans.buf, tags)
	}
	s.trans.buf = append(s.trans.buf, ':')
	s.trans.buf = strconv.AppendInt(s.trans.buf, delta, 10)
	s.trans.buf = append(s.trans.buf, []byte("|ms")...)
	if s.trans.tagFormat.Placement == TagPlacementSuffix {
		s.trans.buf = s.formatTags(s.trans.buf, tags)
	}
	s.trans.buf = append(s.trans.buf, '\n')
	s.trans.checkBuf(lastLen)
	s.trans.bufLock.Unlock()
}