Performance problems in Android applications are not always easy to reproduce. An application may run smoothly during development but experience slow startup, unexpected memory consumption, application freezes, or crashes on users' devices.
Traditional profiling tools such as Android Studio Profiler and Perfetto help developers investigate these problems locally. However, collecting performance information from real users is more difficult, especially when an issue occurs only occasionally or under specific device conditions.
Android provides ProfilingManager to help developers capture performance information directly from applications. It allows an application to request profiling sessions or register system triggers that automatically capture diagnostic information when specific events occur.
Android 17 expands this capability with additional triggers for cold starts, OutOfMemoryError events, excessive CPU usage, and application anomalies.
In this article, you will learn how ProfilingManager works, how to capture system traces and memory profiles, how to register automatic profiling triggers, and how to collect profiling results for performance analysis.
What Is Android ProfilingManager?
ProfilingManager is an Android system API that allows applications to request performance profiling and receive the resulting files.
It was introduced in Android 15 (API level 35) and supports several profiling types:
System traces for investigating CPU activity, scheduling, and application performance.
Java heap dumps for investigating memory usage and object retention.
Heap profiles for understanding memory allocation behavior.
Stack sampling for examining frequently executing call stacks.
Applications can use ProfilingManager in two ways.
App-Driven Profiling
App-driven profiling allows developers to start and stop profiling sessions directly from application code.
For example, an application may start a profiling session before a large database operation and stop it after the operation finishes.
This approach is useful when developers know which user journey or operation they want to investigate.
Trigger-Based Profiling
Trigger-based profiling allows Android to capture performance information automatically when specific system events occur.
For example, developers can register a trigger for an OutOfMemoryError or an application cold start.
When the event occurs and the system's profiling conditions are satisfied, Android captures the relevant information and delivers the resulting file to the application.
This approach is especially useful for investigating problems that cannot easily be reproduced during development.
What's New in Android 17 ProfilingManager?
Android 17 introduces additional profiling triggers that help developers investigate application performance problems.
The important additions include:
Trigger | Purpose |
|---|
TRIGGER_TYPE_COLD_START | Captures performance information during application cold startup |
TRIGGER_TYPE_OOM | Captures a Java heap dump when an uncaught OutOfMemoryError occurs |
TRIGGER_TYPE_KILL_EXCESSIVE_CPU_USAGE | Captures a background trace when the system terminates an application because of excessive CPU usage |
TRIGGER_TYPE_ANOMALY | Provides profiling information for detected runtime performance anomalies |
TRIGGER_TYPE_APP_COMPAT | Captures information related to application compatibility anomalies |
Android 17 also supports capturing sampled call stacks alongside a system trace in a single profiling session.
This makes it easier to investigate application execution and system activity together.
An important distinction is that ProfilingManager itself is not new in Android 17. It was introduced earlier, while Android 17 expands its trigger capabilities and profiling options.
Understanding the Profiling Architecture
ProfilingManager works with Android's system profiling infrastructure.
The application requests a profile or registers a trigger. Android manages the capture and returns a ProfilingResult when the result is ready.
The general process looks like this:
Android Application
|
v
ProfilingManager
|
v
Profiling Request or System Trigger
|
v
Android Profiling Service
|
v
Profile Collection
|
v
Result File Generation
|
v
ProfilingResult Callback
|
v
Application Analysis or Upload
The application does not directly control every part of the profiling process.
Android manages the recording, applies system policies, and delivers the resulting file through the registered callback.
Profiling results are redacted and contain information about the requesting application's process rather than exposing unrestricted information about other applications running on the device.
Adding Dependencies for ProfilingManager
Android provides the platform ProfilingManager API. Developers can also use AndroidX wrappers to simplify profiling requests.
For the recommended AndroidX integration, add the following dependencies to the module-level build.gradle.kts file:
dependencies {
implementation("androidx.tracing:tracing-ktx:2.0.5")
implementation("androidx.core:core:1.19.1")
}
The AndroidX libraries provide higher-level request builders and compatibility support.
You can use ProfilingManager directly without these libraries, but the AndroidX approach is generally easier to maintain because it simplifies request configuration.
For the examples in this article, direct platform APIs are used for trigger registration, while AndroidX is used for app-driven system trace capture.
Accessing ProfilingManager in Kotlin
First, obtain the ProfilingManager system service.
import android.content.Context
import android.os.ProfilingManager
fun getProfilingManager(
context: Context
): ProfilingManager? {
return context.applicationContext.getSystemService(
ProfilingManager::class.java
)
}
Using the application context avoids keeping a reference to a short-lived Activity.
Profiling operations can take time, and their callbacks may arrive after the screen that initiated the operation has been destroyed.
For that reason, profiling management is better handled by an application-level component.
Capturing a System Trace
A system trace provides information about application execution, thread scheduling, CPU activity, and other system events.
It is useful when investigating:
Slow screen rendering.
UI freezes.
Expensive background operations.
CPU-intensive functions.
Application startup delays.
Unexpected thread activity.
AndroidX provides SystemTraceRequestBuilder to configure a system trace request.
The following example demonstrates how to capture a trace around a performance-sensitive operation.
Step 1: Import the Required Classes
import android.content.Context
import android.os.CancellationSignal
import android.util.Log
import androidx.core.os.Profiling
import androidx.tracing.BufferFillPolicy
import androidx.tracing.SystemTraceRequestBuilder
import java.util.concurrent.Executor
import java.util.concurrent.Executors
Step 2: Create the Profiling Request
fun captureSystemTrace(context: Context) {
val appContext = context.applicationContext
val callbackExecutor: Executor =
Executors.newSingleThreadExecutor()
val stopSignal = CancellationSignal()
val resultCallback = ProfilingResultConsumer()
val request = SystemTraceRequestBuilder().apply {
setCancellationSignal(stopSignal)
setTag("DatabaseOperation")
setDurationMs(60000)
setBufferFillPolicy(BufferFillPolicy.RING_BUFFER)
setBufferSizeKb(32768)
}.build()
Profiling.requestProfiling(
appContext,
request,
callbackExecutor,
resultCallback
)
}
The request includes several important settings.
Setting | Purpose |
|---|
setCancellationSignal() | Allows the application to stop profiling |
setTag() | Identifies the profiling session |
setDurationMs() | Sets the maximum recording duration |
setBufferFillPolicy() | Controls how the trace buffer behaves |
setBufferSizeKb() | Configures the trace buffer size |
The RING_BUFFER policy retains recent trace data by overwriting older data when the buffer becomes full.
This is useful when investigating an operation because the most recent activity remains available.
Step 3: Handle Profiling Results
The application receives a ProfilingResult through its callback.
import android.util.Log
import android.os.ProfilingResult
import java.util.function.Consumer
class ProfilingResultConsumer :
Consumer<ProfilingResult> {
override fun accept(
result: ProfilingResult
) {
if (result.errorCode == ProfilingResult.ERROR_NONE) {
Log.d(
"Profiling",
"Profile saved: ${result.resultFilePath}"
)
} else {
Log.e(
"Profiling",
"Profiling failed: ${result.errorCode}, " +
result.errorMessage
)
}
}
}
The result contains information about whether profiling succeeded and where the generated file was saved.
The file path can be used for local analysis or transferred to an approved diagnostic pipeline.
Profiling requests are rate-limited and are not guaranteed to be fulfilled. Therefore, applications should always handle unsuccessful results.
Starting and Stopping Profiling Around a Specific Operation
A profiling session should capture the operation developers actually want to investigate.
For example, suppose an application performs a large database synchronization operation.
You can start profiling before the operation and stop it after the operation completes.
import android.content.Context
import android.os.CancellationSignal
import androidx.core.os.Profiling
import androidx.tracing.BufferFillPolicy
import androidx.tracing.SystemTraceRequestBuilder
import java.util.concurrent.Executors
fun profileDatabaseSync(
context: Context,
syncOperation: () -> Unit
) {
val appContext = context.applicationContext
val stopSignal = CancellationSignal()
val executor = Executors.newSingleThreadExecutor()
val request = SystemTraceRequestBuilder().apply {
setCancellationSignal(stopSignal)
setTag("DatabaseSync")
setDurationMs(60000)
setBufferFillPolicy(BufferFillPolicy.RING_BUFFER)
setBufferSizeKb(32768)
}.build()
Profiling.requestProfiling(
appContext,
request,
executor
) { result ->
if (result.errorCode == 0) {
println("Trace: ${result.resultFilePath}")
} else {
println("Profiling error: ${result.errorMessage}")
}
}
executor.execute {
try {
// Run the operation being investigated.
syncOperation()
} finally {
// Stop profiling after the operation.
stopSignal.cancel()
}
}
}
This example demonstrates the general workflow. The profiling request is asynchronous, and Android does not provide a deterministic callback indicating that trace recording has started.
For that reason, the profiling session may need a short initialization period before the operation begins.
Google's profiling guidance recommends a best-effort startup delay when accurate capture of a specific operation is important.
The delay should be tested on representative devices because tracing initialization time can vary.
Also, run expensive operations on an appropriate background executor rather than blocking the main thread.
Capturing Java Heap Dumps
Memory problems can cause applications to slow down, become unstable, or crash.
A Java heap dump provides a snapshot of the application's Java heap, including information about objects and their references.
It is useful for investigating:
Memory leaks.
Unexpected object retention.
Large collections.
Excessive object creation.
Activities or views that remain referenced.
Unexpected memory growth.
ProfilingManager supports Java heap dump requests through PROFILING_TYPE_JAVA_HEAP_DUMP.
With AndroidX, use JavaHeapDumpRequestBuilder to construct the request.
A simplified example looks like this:
import android.content.Context
import androidx.core.os.Profiling
import androidx.tracing.JavaHeapDumpRequestBuilder
import java.util.concurrent.Executors
fun captureJavaHeapDump(context: Context) {
val request = JavaHeapDumpRequestBuilder()
.setTag("MemoryInvestigation")
.build()
val executor = Executors.newSingleThreadExecutor()
Profiling.requestProfiling(
context.applicationContext,
request,
executor
) { result ->
if (result.errorCode == 0) {
println(
"Heap dump: ${result.resultFilePath}"
)
} else {
println(
"Heap dump failed: ${result.errorMessage}"
)
}
}
}
The exact available builder options depend on the AndroidX version being used.
A heap dump can be large and may contain sensitive information about application objects. Handle the resulting file carefully and avoid uploading it without appropriate privacy controls.
Capturing Heap Profiles
A heap dump provides a snapshot of objects currently present in memory.
A heap profile provides information about memory allocations over a profiling period.
This distinction is important.
For example, an application may not retain too much memory at one moment but may allocate objects repeatedly during a scrolling operation.
A heap profile can help identify which allocation paths contribute to memory pressure.
ProfilingManager supports PROFILING_TYPE_HEAP_PROFILE.
AndroidX provides HeapProfileRequestBuilder for configuring these requests.
import android.content.Context
import androidx.core.os.Profiling
import androidx.tracing.HeapProfileRequestBuilder
import java.util.concurrent.Executors
fun captureHeapProfile(context: Context) {
val request = HeapProfileRequestBuilder()
.setTag("AllocationAnalysis")
.build()
val executor = Executors.newSingleThreadExecutor()
Profiling.requestProfiling(
context.applicationContext,
request,
executor
) { result ->
if (result.errorCode == 0) {
println(
"Heap profile: ${result.resultFilePath}"
)
} else {
println(
"Heap profile failed: ${result.errorMessage}"
)
}
}
}
Heap profiles are useful when investigating allocation patterns rather than only the current memory state.
For example, developers can use them to investigate repeated allocations during image processing, JSON parsing, or large list updates.
Capturing Stack Samples
Stack sampling periodically records the call stacks of executing threads.
This helps developers understand which functions are consuming execution time.
ProfilingManager supports this through PROFILING_TYPE_STACK_SAMPLING.
Stack sampling is useful when investigating:
For AndroidX integrations, use StackSamplingRequestBuilder.
import android.content.Context
import androidx.core.os.Profiling
import androidx.tracing.StackSamplingRequestBuilder
import java.util.concurrent.Executors
fun captureStackSamples(context: Context) {
val request = StackSamplingRequestBuilder()
.setTag("CpuInvestigation")
.build()
val executor = Executors.newSingleThreadExecutor()
Profiling.requestProfiling(
context.applicationContext,
request,
executor
) { result ->
if (result.errorCode == 0) {
println(
"Stack profile: ${result.resultFilePath}"
)
} else {
println(
"Stack profiling failed: ${result.errorMessage}"
)
}
}
}
Stack sampling is useful when the application is consuming CPU resources but the exact function responsible for the problem is unknown.
It provides sampled execution information rather than recording every function call.
Registering Automatic Profiling Triggers in Android 17
App-driven profiling works when developers know when to start and stop recording.
However, some problems occur unexpectedly.
An application may encounter an OutOfMemoryError only on devices with limited memory. A cold-start problem may occur only after the application has been removed from memory. Excessive CPU usage may happen during a user workflow that is difficult to reproduce.
Android 17 allows applications to register additional system triggers for these situations.
Accessing ProfilingManager
import android.content.Context
import android.os.ProfilingManager
val profilingManager =
context.applicationContext.getSystemService(
ProfilingManager::class.java
)
The returned manager is used to register profiling triggers and receive profiling results.
Registering an OutOfMemoryError Trigger
The OOM trigger allows Android to capture a Java heap dump when the application encounters an uncaught OutOfMemoryError.
import android.app.Activity
import android.os.Build
import android.os.ProfilingManager
import android.os.ProfilingTrigger
import android.util.Log
import java.util.concurrent.Executors
fun registerOomProfiling(context: Context) {
if (Build.VERSION.SDK_INT < 37) {
return
}
val manager = context.applicationContext
.getSystemService(ProfilingManager::class.java)
?: return
val executor = Executors.newSingleThreadExecutor()
val listener = ProfilingResultConsumer()
manager.registerForAllProfilingResults(
executor,
listener
)
val trigger = ProfilingTrigger.Builder(
ProfilingTrigger.TRIGGER_TYPE_OOM
).build()
manager.addProfilingTriggers(
listOf(trigger)
)
Log.d(
"Profiling",
"OOM profiling trigger registered"
)
}
When an eligible OOM event occurs, Android can capture the heap dump and deliver the result through the global listener.
This is particularly useful when memory problems affect only a small percentage of users.
Registering a Cold-Start Trigger
Cold-start performance directly affects the initial user experience.
A slow cold start may be caused by database initialization, dependency creation, disk operations, or expensive application startup logic.
Android 17 introduces TRIGGER_TYPE_COLD_START to capture a combined system trace and call stack sample during application cold startup.
fun registerColdStartProfiling(context: Context) {
if (Build.VERSION.SDK_INT < 37) {
return
}
val manager = context.applicationContext
.getSystemService(ProfilingManager::class.java)
?: return
val trigger = ProfilingTrigger.Builder(
ProfilingTrigger.TRIGGER_TYPE_COLD_START
).build()
manager.addProfilingTriggers(
listOf(trigger)
)
}
This trigger does not require the application to start a manual profiling session before every launch.
Android manages the capture when the system detects an eligible cold-start event.
Registering an Excessive CPU Usage Trigger
Android 17 also provides TRIGGER_TYPE_KILL_EXCESSIVE_CPU_USAGE.
This trigger captures a snapshot of an active background system trace when the system terminates the application because of excessive CPU usage.
fun registerCpuUsageProfiling(context: Context) {
if (Build.VERSION.SDK_INT < 37) {
return
}
val manager = context.applicationContext
.getSystemService(ProfilingManager::class.java)
?: return
val trigger = ProfilingTrigger.Builder(
ProfilingTrigger.TRIGGER_TYPE_KILL_EXCESSIVE_CPU_USAGE
).build()
manager.addProfilingTriggers(
listOf(trigger)
)
}
This is useful for diagnosing background operations that consume excessive processing resources.
The trigger depends on an active system background trace. If no suitable background trace is running when the event occurs, a profile may not be collected.
Registering Multiple Triggers
Instead of registering each trigger separately, you can register several triggers together.
fun registerPerformanceTriggers(context: Context) {
if (Build.VERSION.SDK_INT < 37) {
return
}
val manager = context.applicationContext
.getSystemService(ProfilingManager::class.java)
?: return
val triggers = listOf(
ProfilingTrigger.Builder(
ProfilingTrigger.TRIGGER_TYPE_OOM
).build(),
ProfilingTrigger.Builder(
ProfilingTrigger.TRIGGER_TYPE_COLD_START
).build(),
ProfilingTrigger.Builder(
ProfilingTrigger.TRIGGER_TYPE_KILL_EXCESSIVE_CPU_USAGE
).build()
)
manager.addProfilingTriggers(triggers)
}
Register only the triggers that support your diagnostic goals.
Trigger registrations persist across application restarts and system reboots. They remain active until explicitly removed or the application is uninstalled.
Receiving Results From System Triggers
Trigger-based profiling uses a global result listener.
The listener must be registered through registerForAllProfilingResults().
Unlike app-driven requests, a request-specific callback cannot receive results from system-triggered profiling.
import android.os.ProfilingResult
import android.util.Log
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
import java.util.function.Consumer
class ApplicationProfileListener :
Consumer<ProfilingResult> {
override fun accept(
result: ProfilingResult
) {
if (result.errorCode == ProfilingResult.ERROR_NONE) {
Log.d(
"Profiling",
"Profile received: ${result.resultFilePath}"
)
Log.d(
"Profiling",
"Trigger type: ${result.triggerType}"
)
// Schedule background processing or upload.
} else {
Log.e(
"Profiling",
"Error: ${result.errorCode}, " +
result.errorMessage
)
}
}
}
Register the listener early in application initialization.
val executor: ExecutorService =
Executors.newSingleThreadExecutor()
val listener = ApplicationProfileListener()
profilingManager.registerForAllProfilingResults(
executor,
listener
)
The callback provides the result file path and trigger information.
Use the trigger type to distinguish whether a profile was generated because of an OOM event, cold start, or another registered condition.
The callback registration does not persist across application restarts. Register it again when the application starts so that previously queued profiling results can be delivered.
Understanding Profiling Rate Limits
ProfilingManager does not guarantee that every request will produce a result.
Android applies rate limiting to reduce the performance and storage impact of repeated profiling sessions.
This applies to both app-driven and trigger-based profiling.
For example, an application that requests a system trace every time a user opens a screen may exceed the available profiling quota.
Developers can also configure a trigger-specific cooldown using setRateLimitingPeriodHours().
val trigger = ProfilingTrigger.Builder(
ProfilingTrigger.TRIGGER_TYPE_COLD_START
)
.setRateLimitingPeriodHours(1)
.build()
This example limits the trigger to one profiling capture per hour, in addition to the system's own rate limiter.
During local testing, Android provides a command to disable rate limiting for app-driven profiling requests:
adb shell device_config put profiling_testing rate_limiter.disabled true
Use this only in a controlled testing environment.
Do not assume that disabling the local rate limiter changes production behavior.
Retrieving and Analyzing Profiling Files
When a profiling operation succeeds, ProfilingResult provides the generated file path.
The application can use this path to process the file.
For example:
if (result.errorCode == ProfilingResult.ERROR_NONE) {
val profilePath = result.resultFilePath
Log.d(
"Profiling",
"Saved profile at: $profilePath"
)
}
The profiling files are delivered to the application's data directory.
Different profile types require different analysis tools.
Profile type | Recommended analysis |
|---|
System trace | Perfetto |
Java heap dump | Android Studio Memory Profiler |
Heap profile | Compatible heap profiling analysis tools |
Stack sampling | Stack profile analysis tools |
System traces can be opened in Perfetto to inspect thread activity, CPU scheduling, and application events.
Heap dumps can be examined to identify retained objects and memory references.
For trigger-based profiles, Android also provides a workflow for retrieving and uploading profile files using background work.
Do not assume that the file will remain available indefinitely. The application should process or upload the file promptly and delete it when it is no longer needed.
Understanding Profiling Privacy
Profiling real user applications requires careful handling of diagnostic data.
Android redacts profiling results before delivering them to applications. The returned profiles contain information about the requesting process rather than unrestricted details from other applications.
However, profiling files may still contain sensitive application information.
For example, a heap dump may reveal:
Developers should apply appropriate privacy controls before uploading profiling files.
Recommended practices include:
Collect profiles only for clearly defined diagnostic purposes.
Avoid unnecessary profiling of every user.
Use secure transport when uploading results.
Restrict access to profiling storage.
Define a retention period.
Delete files after successful processing.
Avoid logging sensitive object contents.
Profiling should be designed as a controlled diagnostic feature rather than an unrestricted data collection mechanism.
Testing ProfilingManager in Android Studio
Before deploying profiling functionality, test it on supported Android versions.
Step 1: Configure the SDK
Update the application configuration:
android {
compileSdk = 37
defaultConfig {
targetSdk = 37
}
}
Use the appropriate Android Gradle Plugin and SDK installation.
Step 2: Test App-Driven Profiling
Run a system trace request from a development screen.
Verify that the callback receives a successful result and that the file path is available.
Step 3: Test Trigger Registration
Register an appropriate profiling trigger.
For example, use the cold-start trigger on Android 17 to test startup profiling.
Step 4: Verify Callback Delivery
Check Logcat for profiling result callbacks.
Verify the error code, trigger type, and result file path.
Step 5: Inspect the Profile
Open system traces in Perfetto and heap dumps in Android Studio Memory Profiler.
Confirm that the captured information contains the expected application activity.
Step 6: Test Rate Limiting
Repeatedly request profiles in a controlled test environment.
Verify that the application handles rate-limited or unsuccessful requests without crashing.
Step 7: Test Older Android Versions
ProfilingManager is available from Android 15, while trigger-based profiling is available from Android 16.
Some triggers are available only from Android 17.
Use API-level checks before calling newer APIs, and verify that the application continues working on older supported versions.
Common Mistakes When Using ProfilingManager
Expecting Every Profiling Request to Succeed
ProfilingManager applies system rate limits, and requests are not guaranteed to be fulfilled.
Always inspect ProfilingResult and handle errors.
Performing Profiling Operations on the Main Thread
Profiling orchestration and file processing should not block the UI thread.
Use background executors or coroutines for these operations.
Forgetting to Register the Global Listener
System-triggered profiling results are delivered through registerForAllProfilingResults().
Registering only a request-specific listener is not sufficient for trigger-based results.
Registering Triggers Without Managing Their Lifecycle
Trigger registrations persist across application restarts and device reboots.
If a diagnostic campaign ends, explicitly remove the triggers using removeProfilingTriggersByType() or clearProfilingTriggers().
Assuming a Trigger Always Produces a Profile
Some triggers depend on a system background trace being active. Profiling quota and other system conditions can also prevent collection.
Design diagnostic workflows to handle missing results.
Keeping Profiling Files Indefinitely
Profiling files can consume significant storage.
Process the files, upload them when appropriate, and delete them after they are no longer required.
Using the Wrong Analysis Tool
A system trace and a Java heap dump contain different types of information.
Use Perfetto for system traces and Android Studio Memory Profiler for Java heap analysis.
ProfilingManager vs Android Studio Profiler
Both tools help developers investigate Android performance problems, but they serve different purposes.
Feature | ProfilingManager | Android Studio Profiler |
|---|
Primary use | Collect profiles programmatically and from real users | Investigate performance during development |
Profile collection | App-driven and system-triggered | Developer-controlled |
Production profiling | Supported with privacy and rate limits | Primarily local debugging |
Automatic triggers | Supported | Not the primary workflow |
System traces | Supported | Supported |
Heap analysis | Supported | Supported |
Result handling | Delivered through callbacks | Inspected in Android Studio |
Best use case | Diagnosing rare field issues | Reproducing and investigating local problems |
Use Android Studio Profiler when an issue can be reproduced locally.
Use ProfilingManager when you need diagnostic information from real-world application behavior or unexpected system events.
The two tools complement each other.
Best Practices for Using ProfilingManager
Register Only Relevant Triggers
Do not register every available trigger without a clear diagnostic purpose.
Choose triggers that correspond to the performance problems you want to investigate.
Use Appropriate Profiling Types
Use system traces for execution and scheduling problems, heap dumps for memory retention, heap profiles for allocation behavior, and stack sampling for CPU analysis.
Selecting the correct profile type makes the resulting data more useful.
Use Tags to Identify Profiling Sessions
Provide meaningful tags such as StartupTrace, MemoryInvestigation, or DatabaseSync.
This helps identify the purpose of a profile when multiple diagnostic sessions are collected.
Process Results in the Background
Use a background executor to handle result callbacks, file processing, and uploads.
Avoid performing expensive operations on the main thread.
Apply Retention and Storage Policies
Profiling files can be large.
Define how long files should be retained, when they should be uploaded, and when they should be deleted.
Monitor Profiling Failures
Record unsuccessful requests and their error messages.
This helps distinguish rate limiting, invalid requests, and other profiling failures.
Combine Profiling With Application Metrics
Profiling files provide detailed execution information, while application metrics help identify broader performance patterns.
Use both to understand how often a problem occurs and what code paths contribute to it.
Advantages and Limitations of ProfilingManager
Advantages | Limitations |
|---|
Supports app-driven profiling | Requests may be rate-limited |
Supports automatic system triggers | Some triggers depend on background traces |
Captures system traces and memory profiles | Profile collection is not guaranteed |
Helps investigate rare production issues | Requires careful file handling |
Provides results through callbacks | Global listeners must be registered again after app restarts |
Supports Android 17 performance triggers | New triggers require compatible Android versions |
Provides redacted profiling results | Application data inside profiles still requires privacy controls |
Conclusion
Android's ProfilingManager provides developers with a practical way to investigate performance problems that are difficult to reproduce locally.
It supports system traces, Java heap dumps, heap profiles, and stack sampling through app-driven requests. Its trigger-based capabilities allow Android to capture diagnostic information when events such as ANRs, application startup, and memory problems occur.
Android 17 expands these capabilities with cold-start, OutOfMemoryError, excessive CPU usage, and anomaly-related triggers.
For production applications, use profiling selectively, register only relevant triggers, handle rate limiting, and process results outside the main thread. Combine the captured profiles with application metrics and testing to identify the underlying causes of performance problems.
By adopting ProfilingManager, Android developers can move beyond local profiling and gain better visibility into how applications behave on real devices.
Join the conversation! Your thoughts help the community grow.