golang.org/toolchain@v0.0.1-go1.9rc2.windows-amd64/src/cmd/vendor/github.com/google/pprof/profile/prune_test.go (about) 1 // Copyright 2014 Google Inc. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package profile 16 17 import ( 18 "strings" 19 "testing" 20 ) 21 22 func TestPrune(t *testing.T) { 23 for _, test := range []struct { 24 in *Profile 25 want string 26 }{ 27 {in1, out1}, 28 } { 29 in := test.in.Copy() 30 in.RemoveUninteresting() 31 if err := in.CheckValid(); err != nil { 32 t.Error(err) 33 } 34 w := strings.Split(test.want, "\n") 35 for i, g := range strings.Split(in.String(), "\n") { 36 if i >= len(w) { 37 t.Fatalf("got trailing %s", g) 38 } 39 if strings.TrimSpace(g) != strings.TrimSpace(w[i]) { 40 t.Fatalf(`%d: got: "%s" want:"%s"`, i, g, w[i]) 41 } 42 } 43 } 44 } 45 46 var funs = []*Function{ 47 {ID: 1, Name: "main", SystemName: "main", Filename: "main.c"}, 48 {ID: 2, Name: "fun1", SystemName: "fun1", Filename: "fun.c"}, 49 {ID: 3, Name: "fun2", SystemName: "fun2", Filename: "fun.c"}, 50 {ID: 4, Name: "fun3", SystemName: "fun3", Filename: "fun.c"}, 51 {ID: 5, Name: "fun4", SystemName: "fun4", Filename: "fun.c"}, 52 {ID: 6, Name: "fun5", SystemName: "fun5", Filename: "fun.c"}, 53 } 54 55 var locs1 = []*Location{ 56 { 57 ID: 1, 58 Line: []Line{ 59 {Function: funs[0], Line: 1}, 60 }, 61 }, 62 { 63 ID: 2, 64 Line: []Line{ 65 {Function: funs[1], Line: 2}, 66 {Function: funs[2], Line: 1}, 67 }, 68 }, 69 { 70 ID: 3, 71 Line: []Line{ 72 {Function: funs[3], Line: 2}, 73 {Function: funs[1], Line: 1}, 74 }, 75 }, 76 { 77 ID: 4, 78 Line: []Line{ 79 {Function: funs[3], Line: 2}, 80 {Function: funs[1], Line: 2}, 81 {Function: funs[5], Line: 2}, 82 }, 83 }, 84 } 85 86 var in1 = &Profile{ 87 PeriodType: &ValueType{Type: "cpu", Unit: "milliseconds"}, 88 Period: 1, 89 DurationNanos: 10e9, 90 SampleType: []*ValueType{ 91 {Type: "samples", Unit: "count"}, 92 {Type: "cpu", Unit: "milliseconds"}, 93 }, 94 Sample: []*Sample{ 95 { 96 Location: []*Location{locs1[0]}, 97 Value: []int64{1, 1}, 98 }, 99 { 100 Location: []*Location{locs1[1], locs1[0]}, 101 Value: []int64{1, 1}, 102 }, 103 { 104 Location: []*Location{locs1[2], locs1[0]}, 105 Value: []int64{1, 1}, 106 }, 107 { 108 Location: []*Location{locs1[3], locs1[0]}, 109 Value: []int64{1, 1}, 110 }, 111 { 112 Location: []*Location{locs1[3], locs1[2], locs1[1], locs1[0]}, 113 Value: []int64{1, 1}, 114 }, 115 }, 116 Location: locs1, 117 Function: funs, 118 DropFrames: "fu.*[12]|banana", 119 KeepFrames: ".*[n2][n2]", 120 } 121 122 const out1 = `PeriodType: cpu milliseconds 123 Period: 1 124 Duration: 10s 125 Samples: 126 samples/count cpu/milliseconds 127 1 1: 1 128 1 1: 2 1 129 1 1: 1 130 1 1: 4 1 131 1 1: 2 1 132 Locations 133 1: 0x0 main main.c:1 s=0 134 2: 0x0 fun2 fun.c:1 s=0 135 3: 0x0 fun3 fun.c:2 s=0 136 fun1 fun.c:1 s=0 137 4: 0x0 fun5 fun.c:2 s=0 138 Mappings 139 `