-
Notifications
You must be signed in to change notification settings - Fork 42
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
integrate perfetto - supported by android native #655
Comments
Interesting idea. An Android "system trace" is not exactly something that fits cleanly into the otel data model today. Curious if you have thoughts about specifics, @cforce ? |
It would consider potential solutions, such as:
Also consider that tools like strace or ftrace (used by Perfetto) are used since years and a lot of tools are around to provide data. A semantic model to map those is not isolated to android. Not to mention that eBPF similarly covers this areas even better and ther are solutions which might have some "mapping" already - see open-telemetry/community#2406 Android currently does not has any otel export - some kind of adapter is needed to collect data from native platform tooling which is backed into the kernel |
You can probably leverage https://developer.android.com/jetpack/androidx/releases/tracing |
It isn't particularly fancy, but I've found a basic span processor that starts & ends system traces to be quite effective in getting OTel spans represented in tools like Perfetto: @RequiresApi(29)
class AndroidTraceBridge : SpanProcessor {
override fun isStartRequired() = true
override fun isEndRequired() = true
override fun onStart(parentContext: Context, span: ReadWriteSpan) {
Trace.beginAsyncSection(span.name, span.spanContext.spanId.hashCode())
}
override fun onEnd(span: ReadableSpan) {
Trace.endAsyncSection(span.name, span.spanContext.spanId.hashCode())
}
} All you really get with that is the span name with a start & end on the timeline, but that's still quite useful in looking at what is happening within the application. I wouldn't generally expect folks to be looking at Android traces from any sort of production app use, and typically they represent only a short period of time so we don't need to capture a broad set of attributes to make them useful. Plus the currently available APIs don't really make it feasible to do a whole lot more than a named trace section. Here's an example of the output form that processor for a period of time that includes an OpenTelemetry span for a screenload alongside a few other Perfetto tracks capture from Android's tracing tools: |
The data captured in Perfetto traces (or even just the ones spit out by ATrace) is generally too verbose to be consumed and recorded in production (e.g. ~1MB for about a second of data). They are meant for local debugging and tracing to get a good handle on the "shape" of execution on a real device. Even using the data with forthcoming OTel profiling signal might be problematic given the impracticality of parsing and coming this data in production. @bherbst nailed in on the head - getting some OTel spans to show up inside a Perfetto trace might be interesting for local debugging, but I don't think it's practical to invert that relationship and get Perfetto data into OTel. That being said, I think some of the data exposed in there might be interesting the selectively capture as OTel signals, but a more promising API for that is ProfilingManager. Unfortunately, it is only available for Android 15+ - even the pending AndroidX library is only going to work for for 35+ since the underlying hooks are not available in older OS versions. If there are specific data from the API that looks interesting, it might be nice to add it, even if it's use in practice is quite limited until Android 15 is more widely adopted. |
"Unfortunately, it is only available for >Android 15+"
|
And I misspoke about it being pending - it's available already now as part of |
That’s why I initiated this discussion. Why do we have an until now an all-or-nothing and mostly bound to dedicated local tools approach in android , with data access being so restrictive? eBPF allows us to define trace points and “subscribe” to events with minimal overhead, offering a much more flexible method. If there’s an API for better security and compliance, that’s great, but it should also provide a way to hook into kernel space events (for minimal performance impact) and export data in a format compatible with open standards like OpenTelemetry. From what I understand, the OpenTelemetry profiling signal is currently the best option available, as seen in ProfilingManager and ATrace). By supporting an open, flexible framework like OpenTelemetry, Android profiling tools could align with widely adopted observability standards, making it easier to integrate performance data with other systems and maintain a low overhead, similar to eBPF’s approach. Using OpenTelemetry profiling signals would enable developers to “subscribe” to data sources with minimal performance impact, streamlining profiling efforts. Additionally, it would allow kernel-level data to be exported in a standardized format, facilitating interoperability with tools and platforms that already support OpenTelemetry. This could lead to a more modular and accessible profiling approach, with less reliance on proprietary or closed systems, benefiting both developers and users. |
A few things:
While I think there are some interesting data that can be collected by Perfetto (e.g. binder calls, GCs, etc.), and there are also concrete applications of the profiling signal in OTel that would benefit the Android community (e.g. to better model events like ANR), before I would recommend we take this enhancement request forward, I'd personally need to see a more precise proposal with what specifically you think we should collect and how we can feasibly do so. I'll leave it to the maintainers @breedx-splk and @LikeTheSalad to chime in. |
I think profiling tools are great for solving a lot of issues, especially during development, however, they do create a lot of data that I don't think everybody would like to have stored in the cloud, especially considering the amount of data it would mean for mobile apps where it can quickly get really big based on the number of devices an app runs on. If the intention of this issue is to provide the same data that can be seen when clicking on the That's not to say it's impossible though, I think it can be done right now for whoever needs that kind of info exported via OTel by doing something similar to what @bherbst mentioned. However, I don't see it happening in OTel Android, at least not anytime soon as we still have a lot of work to do regarding covering the basics in terms of Android/RUM telemetry. |
Perfetto allows you to collect system-wide performance traces from Android devices from a variety of data sources (kernel scheduler via ftrace, userspace instrumentation via atrace and all other data sources listed in this site).
Perfetto is based on platform services that are available since Android 9 (P) but are enabled by default only since Android 11 (R). On Android 9 (P) and 10 (Q) you need to do the following to ensure that the tracing services are enabled before getting started:
https://perfetto.dev/docs/quickstart/android-tracing
open-telemetry/opentelemetry-cpp#1483
The text was updated successfully, but these errors were encountered: