@@ -39,6 +39,7 @@ type profileBuilder struct {
39
39
unsymbolziedFuncNameMap map [string ]uint64
40
40
locationMap map [* otelProfile.Location ]uint64
41
41
mappingMap map [* otelProfile.Mapping ]uint64
42
+ cpuConversion bool
42
43
}
43
44
44
45
func newProfileBuilder (src * otelProfile.Profile ) * profileBuilder {
@@ -68,7 +69,22 @@ func newProfileBuilder(src *otelProfile.Profile) *profileBuilder {
68
69
Unit : res .addstr ("ms" ),
69
70
}}
70
71
res .dst .DefaultSampleType = res .addstr ("samples" )
72
+ } else if len (res .dst .SampleType ) == 1 && res .dst .PeriodType != nil && res .dst .Period != 0 {
73
+ profileType := fmt .Sprintf ("%s:%s:%s:%s" ,
74
+ res .dst .StringTable [res .dst .SampleType [0 ].Type ],
75
+ res .dst .StringTable [res .dst .SampleType [0 ].Unit ],
76
+ res .dst .StringTable [res .dst .PeriodType .Type ],
77
+ res .dst .StringTable [res .dst .PeriodType .Unit ],
78
+ )
79
+ if profileType == "samples:count:cpu:nanoseconds" {
80
+ res .dst .SampleType = []* googleProfile.ValueType {{
81
+ Type : res .addstr ("cpu" ),
82
+ Unit : res .addstr ("nanoseconds" ),
83
+ }}
84
+ res .cpuConversion = true
85
+ }
71
86
}
87
+
72
88
if res .dst .TimeNanos == 0 {
73
89
res .dst .TimeNanos = time .Now ().UnixNano ()
74
90
}
@@ -191,6 +207,8 @@ func (p *profileBuilder) convertSampleBack(os *otelProfile.Sample) *googleProfil
191
207
192
208
if len (gs .Value ) == 0 {
193
209
gs .Value = []int64 {int64 (len (os .TimestampsUnixNano ))}
210
+ } else if len (gs .Value ) == 1 && p .cpuConversion {
211
+ gs .Value [0 ] *= p .src .Period
194
212
}
195
213
p .convertSampleAttributesToLabelsBack (os , gs )
196
214
0 commit comments