Debian Codegraph @

pdata/testdata/profile.go

raw
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package testdata // import "go.opentelemetry.io/collector/pdata/testdata"
5
6 import (
7 "time"
8
9 "go.opentelemetry.io/collector/pdata/pcommon"
10 "go.opentelemetry.io/collector/pdata/pprofile"
11 )
12
13 var profileStartTimestamp = pcommon.NewTimestampFromTime(time.Date(2020, 2, 11, 20, 26, 12, 321, time.UTC))
14
15 // GenerateProfiles generates dummy profiling data for tests
16 func GenerateProfiles(profilesCount int) pprofile.Profiles {
17 td := pprofile.NewProfiles()
18 initResource(td.ResourceProfiles().AppendEmpty().Resource())
19 ss := td.ResourceProfiles().At(0).ScopeProfiles().AppendEmpty().Profiles()
20
21 dic := td.Dictionary()
22 dic.StringTable().Append("")
23 dic.StringTable().Append("key")
24
25 attr := dic.AttributeTable().AppendEmpty()
26 attr.SetKeyStrindex(1)
27 attr.Value().SetStr("value")
28 attr2 := dic.AttributeTable().AppendEmpty()
29 attr.SetKeyStrindex(1)
30 attr2.Value().SetStr("value")
31
32 ss.EnsureCapacity(profilesCount)
33 for i := range profilesCount {
34 switch i % 2 {
35 case 0:
36 fillProfileOne(dic, ss.AppendEmpty())
37 case 1:
38 fillProfileTwo(dic, ss.AppendEmpty())
39 }
40 }
41
42 return td
43 }
44
45 func fillProfileOne(dic pprofile.ProfilesDictionary, profile pprofile.Profile) {
46 profile.SetProfileID([16]byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10})
47 profile.SetTime(profileStartTimestamp)
48 profile.SetDurationNano(uint64(time.Second.Nanoseconds()))
49 profile.SetDroppedAttributesCount(1)
50
51 loc := pprofile.NewLocation()
52 loc.SetAddress(1)
53 id, _ := pprofile.SetLocation(dic.LocationTable(), loc)
54 stack := dic.StackTable().AppendEmpty()
55 stack.LocationIndices().Append(id)
56
57 sample := profile.Samples().AppendEmpty()
58 sample.SetStackIndex(1)
59 sample.Values().Append(4)
60 sample.AttributeIndices().Append(0)
61 }
62
63 func fillProfileTwo(dic pprofile.ProfilesDictionary, profile pprofile.Profile) {
64 profile.SetProfileID([16]byte{0x02, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10})
65 profile.SetTime(profileStartTimestamp)
66 profile.SetDurationNano(uint64(time.Second.Nanoseconds()))
67
68 loc := pprofile.NewLocation()
69 loc.SetAddress(2)
70 id, _ := pprofile.SetLocation(dic.LocationTable(), loc)
71 stack := dic.StackTable().AppendEmpty()
72 stack.LocationIndices().Append(id)
73
74 sample := profile.Samples().AppendEmpty()
75 sample.SetStackIndex(1)
76 sample.Values().Append(9)
77 sample.AttributeIndices().Append(0)
78 }