Debian Codegraph @

exporter/debugexporter/internal/normal/profiles.go

raw symbols SCIP
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package normal // import "go.opentelemetry.io/collector/exporter/debugexporter/internal/normal"
5
6 import (
7 "bytes"
8 "fmt"
9 "strconv"
10 "strings"
11
12 "go.opentelemetry.io/collector/pdata/pprofile"
13 )
14
15 type normalProfilesMarshaler struct{}
16
17 // Ensure normalProfilesMarshaller implements interface pprofile.Marshaler
18 var _ pprofile.Marshaler = normalProfilesMarshaler{}
19
20 // NewNormalProfilesMarshaler returns a pprofile.Marshaler for normal verbosity. It writes one line of text per log record
21 func NewNormalProfilesMarshaler() pprofile.Marshaler {
22 return normalProfilesMarshaler{}
23 }
24
25 func (normalProfilesMarshaler) MarshalProfiles(pd pprofile.Profiles) ([]byte, error) {
26 var buffer bytes.Buffer
27 dic := pd.Dictionary()
28
29 for i := 0; i < pd.ResourceProfiles().Len(); i++ {
30 resourceProfiles := pd.ResourceProfiles().At(i)
31
32 buffer.WriteString(fmt.Sprintf("ResourceProfiles #%d%s%s\n", i, writeResourceDetails(resourceProfiles.SchemaUrl()), writeAttributesString(resourceProfiles.Resource().Attributes())))
33
34 for j := 0; j < resourceProfiles.ScopeProfiles().Len(); j++ {
35 scopeProfiles := resourceProfiles.ScopeProfiles().At(j)
36
37 buffer.WriteString(fmt.Sprintf("ScopeProfiles #%d%s%s\n", i, writeScopeDetails(scopeProfiles.Scope().Name(), scopeProfiles.Scope().Version(), scopeProfiles.SchemaUrl()), writeAttributesString(scopeProfiles.Scope().Attributes())))
38
39 for k := 0; k < scopeProfiles.Profiles().Len(); k++ {
40 profile := scopeProfiles.Profiles().At(k)
41
42 buffer.WriteString(profile.ProfileID().String())
43
44 buffer.WriteString(" samples=")
45 buffer.WriteString(strconv.Itoa(profile.Samples().Len()))
46
47 if profile.AttributeIndices().Len() > 0 {
48 attrs := []string{}
49 for _, i := range profile.AttributeIndices().AsRaw() {
50 a := dic.AttributeTable().At(int(i))
51 attrs = append(attrs, fmt.Sprintf("%s=%s", dic.StringTable().At(int(a.KeyStrindex())), a.Value().AsString()))
52 }
53
54 buffer.WriteString(" ")
55 buffer.WriteString(strings.Join(attrs, " "))
56 }
57
58 buffer.WriteString("\n")
59 }
60 }
61 }
62 return buffer.Bytes(), nil
63 }