Skip to content

drop use of CGO in profiler core#628

Merged
fabled merged 4 commits intoopen-telemetry:mainfrom
fabled:tt-drop-cgo
Jul 19, 2025
Merged

drop use of CGO in profiler core#628
fabled merged 4 commits intoopen-telemetry:mainfrom
fabled:tt-drop-cgo

Conversation

@fabled
Copy link
Copy Markdown
Contributor

@fabled fabled commented Jul 16, 2025

This removes usage of CGO in the ebpf-profiler core by creating a cgo generated alias type for needed types with ebpf.

fixes #511

@fabled fabled force-pushed the tt-drop-cgo branch 2 times, most recently from dff06f9 to bb25a13 Compare July 16, 2025 20:36
@fabled fabled changed the title drop use of CGO drop use of CGO in profiler core Jul 16, 2025
@fabled fabled marked this pull request as ready for review July 16, 2025 20:55
@fabled fabled requested review from a team as code owners July 16, 2025 20:55
Comment thread support/types_def.go
V8LineDeltaMask = C.V8_LINE_DELTA_MASK
)

var MetricsTranslation = []metrics.MetricID{
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This brings the awkward dependency on metrics package, and has implications on metrics to not depend on libpf (which depends on support).

Comment thread metrics/metrics.go
var (
// prevTimestamp holds the timestamp of the buffered metrics
prevTimestamp libpf.UnixTime32
prevTimestamp uint32
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to avoid circular dependency of metrics -> libpf -> support -> metrics. This is because of moving the metrics mappings to the generated file in support (to avoid adding generated files).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also move UnixTime32 to times or util package but as we don't use the MarshalJSON method here so it's probably not worth it just for this case.

Comment thread support/ebpf/types.h
u64 ktime;
// The current COMM of the thread of this Trace.
char comm[COMM_LEN];
u8 comm[COMM_LEN];
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and the above CustomLabel change are due to arm64 and amd64 default char differing on signedness and would cause the generated code check to fail on one or the other flavor due to inconsistent type.

It also greatly simplifies things to have this unconditionall u8 which maps to uint8 (and for which byte is an alias). These are directly usable as []byte.

Comment thread tracer/tracer.go
enableSampling := false
var probProfilingStatus = probProfilingDisable

//nolint:gosec
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to suppress lint warning on using non-secure random generator. This is ok here as this just for probability and not security related.

Copy link
Copy Markdown
Member

@florianl florianl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

Copy link
Copy Markdown
Member

@christos68k christos68k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread metrics/metrics.go
var (
// prevTimestamp holds the timestamp of the buffered metrics
prevTimestamp libpf.UnixTime32
prevTimestamp uint32
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also move UnixTime32 to times or util package but as we don't use the MarshalJSON method here so it's probably not worth it just for this case.

Comment thread Makefile
@fabled fabled merged commit 24819cd into open-telemetry:main Jul 19, 2025
27 checks passed
gnurizen pushed a commit to parca-dev/opentelemetry-ebpf-profiler that referenced this pull request Sep 10, 2025
gnurizen pushed a commit to parca-dev/opentelemetry-ebpf-profiler that referenced this pull request Sep 10, 2025
gnurizen pushed a commit to parca-dev/opentelemetry-ebpf-profiler that referenced this pull request Sep 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Building OTEL collector requires CGO_ENABLED=1

4 participants