| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
package otlptext |
| 5 |
|
| 6 |
import ( |
| 7 |
"strconv" |
| 8 |
|
| 9 |
"go.opentelemetry.io/collector/pdata/pprofile" |
| 10 |
) |
| 11 |
|
| 12 |
|
| 13 |
func NewTextProfilesMarshaler() pprofile.Marshaler { |
| 14 |
return textProfilesMarshaler{} |
| 15 |
} |
| 16 |
|
| 17 |
type textProfilesMarshaler struct{} |
| 18 |
|
| 19 |
|
| 20 |
func (textProfilesMarshaler) MarshalProfiles(pd pprofile.Profiles) ([]byte, error) { |
| 21 |
buf := dataBuffer{} |
| 22 |
dic := pd.Dictionary() |
| 23 |
rps := pd.ResourceProfiles() |
| 24 |
|
| 25 |
buf.logProfileMappings(dic.MappingTable()) |
| 26 |
buf.logProfileLocations(dic.LocationTable()) |
| 27 |
buf.logProfileFunctions(dic.FunctionTable()) |
| 28 |
buf.logAttributesWithIndentation( |
| 29 |
"Attribute table", |
| 30 |
keyValueAndUnitsToMap(dic.AttributeTable()), |
| 31 |
0) |
| 32 |
|
| 33 |
buf.logAttributesWithIndentation( |
| 34 |
"Link table", |
| 35 |
linkTableToMap(dic.LinkTable()), |
| 36 |
0) |
| 37 |
|
| 38 |
buf.logStringTable(dic.StringTable()) |
| 39 |
|
| 40 |
for i := 0; i < rps.Len(); i++ { |
| 41 |
buf.logEntry("ResourceProfiles #%d", i) |
| 42 |
rp := rps.At(i) |
| 43 |
buf.logEntry("Resource SchemaURL: %s", rp.SchemaUrl()) |
| 44 |
buf.logAttributes("Resource attributes", rp.Resource().Attributes()) |
| 45 |
buf.logEntityRefs(rp.Resource()) |
| 46 |
ilps := rp.ScopeProfiles() |
| 47 |
for j := 0; j < ilps.Len(); j++ { |
| 48 |
buf.logEntry("ScopeProfiles #%d", j) |
| 49 |
ilp := ilps.At(j) |
| 50 |
buf.logEntry("ScopeProfiles SchemaURL: %s", ilp.SchemaUrl()) |
| 51 |
buf.logInstrumentationScope(ilp.Scope()) |
| 52 |
profiles := ilp.Profiles() |
| 53 |
for k := 0; k < profiles.Len(); k++ { |
| 54 |
buf.logEntry("Profile #%d", k) |
| 55 |
profile := profiles.At(k) |
| 56 |
buf.logAttr("Profile ID", profile.ProfileID()) |
| 57 |
buf.logAttr("Start time", profile.Time().String()) |
| 58 |
buf.logAttr("DurationNano", strconv.FormatUint(profile.DurationNano(), 10)) |
| 59 |
buf.logAttr("Dropped attributes count", strconv.FormatUint(uint64(profile.DroppedAttributesCount()), 10)) |
| 60 |
|
| 61 |
buf.logProfileSamples(profile.Samples(), dic) |
| 62 |
} |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
return buf.buf.Bytes(), nil |
| 67 |
} |