OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [runtime/] [pprof/] [pprof_test.go] - Blame information for rev 747

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// Copyright 2011 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 pprof_test
6
 
7
import (
8
        "bytes"
9
        "hash/crc32"
10
        "runtime"
11
        . "runtime/pprof"
12
        "strings"
13
        "testing"
14
        "unsafe"
15
)
16
 
17
func TestCPUProfile(t *testing.T) {
18
        switch runtime.GOOS {
19
        case "darwin":
20
                // see Apple Bug Report #9177434 (copied into change description)
21
                return
22
        case "plan9":
23
                // unimplemented
24
                return
25
        }
26
 
27
        buf := make([]byte, 100000)
28
        var prof bytes.Buffer
29
        if err := StartCPUProfile(&prof); err != nil {
30
                t.Fatal(err)
31
        }
32
        // This loop takes about a quarter second on a 2 GHz laptop.
33
        // We only need to get one 100 Hz clock tick, so we've got
34
        // a 25x safety buffer.
35
        for i := 0; i < 1000; i++ {
36
                crc32.ChecksumIEEE(buf)
37
        }
38
        StopCPUProfile()
39
 
40
        // Convert []byte to []uintptr.
41
        bytes := prof.Bytes()
42
        val := *(*[]uintptr)(unsafe.Pointer(&bytes))
43
        val = val[:len(bytes)/int(unsafe.Sizeof(uintptr(0)))]
44
 
45
        if len(val) < 10 {
46
                t.Fatalf("profile too short: %#x", val)
47
        }
48
        if val[0] != 0 || val[1] != 3 || val[2] != 0 || val[3] != 1e6/100 || val[4] != 0 {
49
                t.Fatalf("unexpected header %#x", val[:5])
50
        }
51
 
52
        // Check that profile is well formed and contains ChecksumIEEE.
53
        found := false
54
        val = val[5:]
55
        for len(val) > 0 {
56
                if len(val) < 2 || val[0] < 1 || val[1] < 1 || uintptr(len(val)) < 2+val[1] {
57
                        t.Fatalf("malformed profile.  leftover: %#x", val)
58
                }
59
                for _, pc := range val[2 : 2+val[1]] {
60
                        f := runtime.FuncForPC(pc)
61
                        if f == nil {
62
                                continue
63
                        }
64
                        if strings.Contains(f.Name(), "ChecksumIEEE") {
65
                                found = true
66
                        }
67
                }
68
                val = val[2+val[1]:]
69
        }
70
 
71
        if !found {
72
                t.Fatal("did not find ChecksumIEEE in the profile")
73
        }
74
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.