Nenhuma descrição

prune_test.go 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. package profile
  15. import (
  16. "strings"
  17. "testing"
  18. )
  19. func TestPrune(t *testing.T) {
  20. for _, test := range []struct {
  21. in *Profile
  22. want string
  23. }{
  24. {in1, out1},
  25. } {
  26. in := test.in.Copy()
  27. in.RemoveUninteresting()
  28. if err := in.CheckValid(); err != nil {
  29. t.Error(err)
  30. }
  31. w := strings.Split(test.want, "\n")
  32. for i, g := range strings.Split(in.String(), "\n") {
  33. if i >= len(w) {
  34. t.Fatalf("got trailing %s", g)
  35. }
  36. if strings.TrimSpace(g) != strings.TrimSpace(w[i]) {
  37. t.Fatalf(`%d: got: "%s" want:"%s"`, i, g, w[i])
  38. }
  39. }
  40. }
  41. }
  42. var funs = []*Function{
  43. {ID: 1, Name: "main", SystemName: "main", Filename: "main.c"},
  44. {ID: 2, Name: "fun1", SystemName: "fun1", Filename: "fun.c"},
  45. {ID: 3, Name: "fun2", SystemName: "fun2", Filename: "fun.c"},
  46. {ID: 4, Name: "fun3", SystemName: "fun3", Filename: "fun.c"},
  47. {ID: 5, Name: "fun4", SystemName: "fun4", Filename: "fun.c"},
  48. {ID: 6, Name: "fun5", SystemName: "fun5", Filename: "fun.c"},
  49. }
  50. var locs1 = []*Location{
  51. {
  52. ID: 1,
  53. Line: []Line{
  54. {Function: funs[0], Line: 1},
  55. },
  56. },
  57. {
  58. ID: 2,
  59. Line: []Line{
  60. {Function: funs[1], Line: 2},
  61. {Function: funs[2], Line: 1},
  62. },
  63. },
  64. {
  65. ID: 3,
  66. Line: []Line{
  67. {Function: funs[3], Line: 2},
  68. {Function: funs[1], Line: 1},
  69. },
  70. },
  71. {
  72. ID: 4,
  73. Line: []Line{
  74. {Function: funs[3], Line: 2},
  75. {Function: funs[1], Line: 2},
  76. {Function: funs[5], Line: 2},
  77. },
  78. },
  79. }
  80. var in1 = &Profile{
  81. PeriodType: &ValueType{Type: "cpu", Unit: "milliseconds"},
  82. Period: 1,
  83. DurationNanos: 10e9,
  84. SampleType: []*ValueType{
  85. {Type: "samples", Unit: "count"},
  86. {Type: "cpu", Unit: "milliseconds"},
  87. },
  88. Sample: []*Sample{
  89. {
  90. Location: []*Location{locs1[0]},
  91. Value: []int64{1, 1},
  92. },
  93. {
  94. Location: []*Location{locs1[1], locs1[0]},
  95. Value: []int64{1, 1},
  96. },
  97. {
  98. Location: []*Location{locs1[2], locs1[0]},
  99. Value: []int64{1, 1},
  100. },
  101. {
  102. Location: []*Location{locs1[3], locs1[0]},
  103. Value: []int64{1, 1},
  104. },
  105. {
  106. Location: []*Location{locs1[3], locs1[2], locs1[1], locs1[0]},
  107. Value: []int64{1, 1},
  108. },
  109. },
  110. Location: locs1,
  111. Function: funs,
  112. DropFrames: "fu.*[12]|banana",
  113. KeepFrames: ".*[n2][n2]",
  114. }
  115. const out1 = `PeriodType: cpu milliseconds
  116. Period: 1
  117. Duration: 10s
  118. Samples:
  119. samples/count cpu/milliseconds
  120. 1 1: 1
  121. 1 1: 2 1
  122. 1 1: 1
  123. 1 1: 4 1
  124. 1 1: 2 1
  125. Locations
  126. 1: 0x0 main main.c:1 s=0
  127. 2: 0x0 fun2 fun.c:1 s=0
  128. 3: 0x0 fun3 fun.c:2 s=0
  129. fun1 fun.c:1 s=0
  130. 4: 0x0 fun5 fun.c:2 s=0
  131. Mappings
  132. `