Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reporter: use htlhash attribute for profiling specific hash #236

Merged
merged 3 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ devfiler spins up a local server that listens on `0.0.0.0:11000`.

To run it, simply download and unpack the archive from the following URL:

https://upload.elastic.co/d/87e7697991940ec37f0c6e39ac38d213f65e8dc1ef9dbedff6aab9cba0adfaba
https://upload.elastic.co/d/f8aa0c386baa808a616ca29f86b34c726edb5af36f8840a4cf28468ad534a4b5

Authentication token: `c74dfc4db2212015`
Authentication token: `2635c0750bf8ea69`


The archive contains a build for each of the following platforms:
Expand Down
37 changes: 18 additions & 19 deletions reporter/otlp_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ func (r *OTLPReporter) getProfile() (profile *profiles.Profile, startTS, endTS u
// semantic convention for build_id, replace these hard coded
// strings.
{key: "process.executable.build_id.gnu", value: execInfo.gnuBuildID},
{key: "process.executable.build_id.profiling",
{key: "process.executable.build_id.htlhash",
value: traceInfo.files[i].StringNoQuotes()},
}, attributeMap)

Expand Down Expand Up @@ -660,8 +660,8 @@ func (r *OTLPReporter) getProfile() (profile *profiles.Profile, startTS, endTS u
loc.Line = append(loc.Line, line)

// To be compliant with the protocol, generate a dummy mapping entry.
loc.MappingIndex = getDummyMappingIndex(fileIDtoMapping, stringMap,
profile, traceInfo.files[i])
loc.MappingIndex = getDummyMappingIndex(fileIDtoMapping,
stringMap, attributeMap, profile, traceInfo.files[i])
}
profile.Location = append(profile.Location, loc)
}
Expand Down Expand Up @@ -785,24 +785,23 @@ func addProfileAttributes[T string | int64](profile *profiles.Profile,

// getDummyMappingIndex inserts or looks up an entry for interpreted FileIDs.
func getDummyMappingIndex(fileIDtoMapping map[libpf.FileID]uint64,
stringMap map[string]uint32, profile *profiles.Profile,
fileID libpf.FileID) uint64 {
var locationMappingIndex uint64
stringMap map[string]uint32, attributeMap map[string]uint64,
profile *profiles.Profile, fileID libpf.FileID) uint64 {
if tmpMappingIndex, exists := fileIDtoMapping[fileID]; exists {
locationMappingIndex = tmpMappingIndex
} else {
idx := uint64(len(fileIDtoMapping))
fileIDtoMapping[fileID] = idx
locationMappingIndex = idx

profile.Mapping = append(profile.Mapping, &profiles.Mapping{
Filename: int64(getStringMapIndex(stringMap, "")),
BuildId: int64(getStringMapIndex(stringMap,
fileID.StringNoQuotes())),
BuildIdKind: *profiles.BuildIdKind_BUILD_ID_BINARY_HASH.Enum(),
})
return tmpMappingIndex
}
return locationMappingIndex
idx := uint64(len(fileIDtoMapping))
fileIDtoMapping[fileID] = idx

mappingAttributes := addProfileAttributes(profile, []attrKeyValue[string]{
{key: "process.executable.build_id.htlhash",
value: fileID.StringNoQuotes()}}, attributeMap)

profile.Mapping = append(profile.Mapping, &profiles.Mapping{
Filename: int64(getStringMapIndex(stringMap, "")),
Attributes: mappingAttributes,
})
return idx
}

// waitGrpcEndpoint waits until the gRPC connection is established.
Expand Down