Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

127 lignes
3.5 KiB

  1. // Copyright 2018 Google LLC
  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 testdata provides some useful data sets for testing purposes.
  15. package testdata
  16. import (
  17. "github.com/google/pprof/profile"
  18. )
  19. var functions = []*profile.Function{
  20. {ID: 1, Name: "main", SystemName: "main", Filename: "main.go"},
  21. {ID: 2, Name: "foo", SystemName: "foo", Filename: "foo.go"},
  22. {ID: 3, Name: "foo_caller", SystemName: "foo_caller", Filename: "foo.go"},
  23. }
  24. const mainBinary = "/bin/main"
  25. var mappings = []*profile.Mapping{
  26. {
  27. ID: 1,
  28. Start: 0x10000,
  29. Limit: 0x40000,
  30. File: mainBinary,
  31. HasFunctions: true,
  32. HasFilenames: true,
  33. HasLineNumbers: true,
  34. HasInlineFrames: true,
  35. },
  36. {
  37. ID: 2,
  38. Start: 0x1000,
  39. Limit: 0x4000,
  40. File: "/lib/lib.so",
  41. HasFunctions: true,
  42. HasFilenames: true,
  43. HasLineNumbers: true,
  44. HasInlineFrames: true,
  45. },
  46. }
  47. var locations = []*profile.Location{
  48. {
  49. ID: 1,
  50. Mapping: mappings[1],
  51. Address: 0x1000,
  52. Line: []profile.Line{
  53. {Function: functions[0], Line: 1},
  54. },
  55. },
  56. {
  57. ID: 2,
  58. Mapping: mappings[0],
  59. Address: 0x2000,
  60. Line: []profile.Line{
  61. {Function: functions[1], Line: 2},
  62. {Function: functions[2], Line: 1},
  63. },
  64. },
  65. }
  66. // HeapProfileCollected1 represents a heap profile which could be collected using
  67. // pprof.WriteHeapProfile().
  68. var HeapProfileCollected1 = &profile.Profile{
  69. DurationNanos: 10e9,
  70. SampleType: []*profile.ValueType{
  71. {Type: "alloc_objects", Unit: "count"},
  72. {Type: "alloc_space", Unit: "bytes"},
  73. {Type: "inuse_objects", Unit: "count"},
  74. {Type: "inuse_space", Unit: "bytes"},
  75. },
  76. Sample: []*profile.Sample{{
  77. Location: []*profile.Location{locations[0], locations[1]},
  78. Value: []int64{10, 160, 10, 160},
  79. NumLabel: map[string][]int64{
  80. "bytes": {16},
  81. },
  82. NumUnit: map[string][]string{
  83. "bytes": {"bytes"},
  84. },
  85. }},
  86. Location: locations,
  87. Function: functions,
  88. Mapping: mappings,
  89. }
  90. // HeapProfileUploaded represents the heap profile bytes we would expect to
  91. // be uploaded if HeapProfileCollected1 were returned when profiling.
  92. var HeapProfileUploaded = func() *profile.Profile {
  93. p := HeapProfileCollected1.Copy()
  94. p.Sample[0].Value = []int64{0, 0, 10, 160}
  95. return p
  96. }()
  97. // HeapProfileCollected2 represents a heap profile which could be collected using
  98. // pprof.WriteHeapProfile().
  99. var HeapProfileCollected2 = func() *profile.Profile {
  100. p := HeapProfileCollected1.Copy()
  101. p.Sample[0].Value = []int64{11, 176, 11, 176}
  102. return p
  103. }()
  104. // AllocProfileUploaded represents the allocation profile bytes we would expect
  105. // to be uploaded if HeapProfileCollected1 was returned when first profiling
  106. // and HeapProfileCollect2 was return when profiling the second time.
  107. var AllocProfileUploaded = func() *profile.Profile {
  108. p := HeapProfileCollected1.Copy()
  109. p.DurationNanos = 5e9
  110. p.SampleType = []*profile.ValueType{
  111. {Type: "alloc_objects", Unit: "count"},
  112. {Type: "alloc_space", Unit: "bytes"},
  113. }
  114. p.Sample[0].Value = []int64{1, 16}
  115. return p
  116. }()