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