コード例 #1
0
ファイル: statistics.go プロジェクト: finklabs/GoGrinder
// function to process the incoming measurements and update the stats
// this is also the default-reporter. All other reporters are in reporter.go
func (test *TestStatistics) default_reporter(m Metric) {
	teststep := m.GetTeststep()
	elapsed := time.Duration(m.GetElapsed())
	timestamp := time.Time(m.GetTimestamp())
	err_count := int64(0)
	if len(m.GetError()) > 0 {
		err_count = 1
	}
	test.lock.RLock()
	val, exists := test.stats[teststep]
	test.lock.RUnlock()
	if exists {
		val.avg = (time.Duration(val.count)*val.avg +
			elapsed) / time.Duration(val.count+1)
		if elapsed > val.max {
			val.max = elapsed
		}
		if elapsed < val.min {
			val.min = elapsed
		}
		val.last = timestamp
		val.count++
		val.error += err_count
		test.lock.Lock()
		test.stats[teststep] = val
		test.lock.Unlock()
	} else {
		// create a new statistic for t
		test.lock.Lock()
		test.stats[teststep] = stats_value{elapsed, elapsed, elapsed, 1, err_count, timestamp}
		test.lock.Unlock()
	}
}
コード例 #2
0
ファイル: scenario.go プロジェクト: finklabs/GoGrinder
func (ts Timestamp) MarshalJSON() ([]byte, error) {
	t := time.Time(ts)
	if y := t.Year(); y < 0 || y >= 10000 {
		// RFC 3339 is clear that years are 4 digits exactly.
		// See golang.org/issue/4556#c15 for more discussion.
		return nil, errors.New("Time.MarshalJSON: year outside of range [0,9999]")
	}
	return []byte(t.Format(`"` + time.RFC3339Nano + `"`)), nil
}
コード例 #3
0
ファイル: scenario.go プロジェクト: finklabs/GoGrinder
func (ts Timestamp) UnixNano() int64 {
	return time.Time(ts).UnixNano()
}