diff --git a/reporter/internal/pdata/generate.go b/reporter/internal/pdata/generate.go index 6133eddc9..df147b9b5 100644 --- a/reporter/internal/pdata/generate.go +++ b/reporter/internal/pdata/generate.go @@ -27,6 +27,9 @@ const ( FrameMapLifetime = 1 * time.Hour ) +// DummyFileID is used as the FileID for a dummy mapping +var dummyFileID = libpf.NewFileID(0, 0) + // Generate generates a pdata request out of internal profiles data, to be // exported. func (p *Pdata) Generate(tree samples.TraceEventsTree, @@ -42,7 +45,8 @@ func (p *Pdata) Generate(tree samples.TraceEventsTree, // By specification, the first element should be empty. stringSet.Add("") - funcSet.Add(funcInfo{nameIdx: stringSet.Add(""), fileNameIdx: stringSet.Add("")}) + mappingSet.Add(dummyFileID) + dic.MappingTable().AppendEmpty() for containerID, originToEvents := range tree { if len(originToEvents) == 0 { @@ -216,17 +220,8 @@ func (p *Pdata) setProfile( } locInfo.functionIndex = funcSet.Add(fi) } - - idx, exists := mappingSet.AddWithCheck(traceInfo.Files[i]) - locInfo.mappingIndex = idx - if !exists { - // To be compliant with the protocol, generate a dummy mapping entry. - mapping := dic.MappingTable().AppendEmpty() - mapping.SetFilenameStrindex(stringSet.Add("")) - attrMgr.AppendOptionalString(mapping.AttributeIndices(), - semconv.ProcessExecutableBuildIDHtlhashKey, - traceInfo.Files[i].StringNoQuotes()) - } + // mapping_table[0] is always the dummy mapping + locInfo.mappingIndex = 0 } // End frame type switch idx, exists := locationSet.AddWithCheck(locInfo) diff --git a/reporter/internal/pdata/generate_test.go b/reporter/internal/pdata/generate_test.go index a990f2a7f..630a8fcf7 100644 --- a/reporter/internal/pdata/generate_test.go +++ b/reporter/internal/pdata/generate_test.go @@ -110,7 +110,7 @@ func TestFunctionTableOrder(t *testing.T) { executables: map[libpf.FileID]samples.ExecInfo{}, frames: map[libpf.FileID]map[libpf.AddressOrLineno]samples.SourceInfo{}, events: map[libpf.Origin]samples.KeyToEventMapping{}, - wantFunctionTable: []string{""}, + wantFunctionTable: []string{}, expectedResourceProfiles: 0, }, { name: "single executable", @@ -177,7 +177,7 @@ func TestFunctionTableOrder(t *testing.T) { }, }, wantFunctionTable: []string{ - "", "func1", "func2", "func3", "func4", "func5", + "func1", "func2", "func3", "func4", "func5", }, }, } {