~john-koepi/ubuntu/trusty/golang/default

« back to all changes in this revision

Viewing changes to test/garbage/stats.go

  • Committer: Bazaar Package Importer
  • Author(s): Ondřej Surý
  • Date: 2011-04-20 17:36:48 UTC
  • Revision ID: james.westby@ubuntu.com-20110420173648-ifergoxyrm832trd
Tags: upstream-2011.03.07.1
Import upstream version 2011.03.07.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2010 The Go Authors.  All rights reserved.
 
2
// Use of this source code is governed by a BSD-style
 
3
// license that can be found in the LICENSE file.
 
4
 
 
5
package main
 
6
 
 
7
import (
 
8
        "fmt"
 
9
        "runtime"
 
10
        "sort"
 
11
)
 
12
 
 
13
func gcstats(name string, n int, t int64) {
 
14
        st := &runtime.MemStats
 
15
        fmt.Printf("garbage.%sMem Alloc=%d/%d Heap=%d NextGC=%d Mallocs=%d\n", name, st.Alloc, st.TotalAlloc, st.Sys, st.NextGC, st.Mallocs)
 
16
        fmt.Printf("garbage.%s %d %d ns/op\n", name, n, t/int64(n))
 
17
        fmt.Printf("garbage.%sLastPause 1 %d ns/op\n", name, st.PauseNs[(st.NumGC-1)%uint32(len(st.PauseNs))])
 
18
        fmt.Printf("garbage.%sPause %d %d ns/op\n", name, st.NumGC, int64(st.PauseTotalNs)/int64(st.NumGC))
 
19
        nn := int(st.NumGC)
 
20
        if nn >= len(st.PauseNs) {
 
21
                nn = len(st.PauseNs)
 
22
        }
 
23
        t1, t2, t3, t4, t5 := tukey5(st.PauseNs[0:nn])
 
24
        fmt.Printf("garbage.%sPause5: %d %d %d %d %d\n", name, t1, t2, t3, t4, t5)
 
25
        
 
26
//      fmt.Printf("garbage.%sScan: %v\n", name, st.ScanDist)
 
27
}
 
28
 
 
29
type T []uint64
 
30
func (t T) Len() int { return len(t) }
 
31
func (t T) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
 
32
func (t T) Less(i, j int) bool { return t[i] < t[j] }
 
33
 
 
34
func tukey5(raw []uint64) (lo, q1, q2, q3, hi uint64) {
 
35
        x := make(T, len(raw))
 
36
        copy(x, raw)
 
37
        sort.Sort(T(x))
 
38
        lo = x[0]
 
39
        q1 = x[len(x)/4]
 
40
        q2 = x[len(x)/2]
 
41
        q3 = x[len(x)*3/4]
 
42
        hi = x[len(x)-1]
 
43
        return
 
44
}