Introduction to Btrace
Btrace is a sophisticated project in the world of performance monitoring and tracing, designed to enhance user experience, performance, and data monitoring on various platforms, especially focusing on Windows and Android systems.
Major Update
Btrace recently underwent a major update that significantly improves both user and performance experiences:
-
User Experience Enhancements:
- Windows Support: Btrace now supports Windows, making it more accessible to a broader audience.
- No Python 2.7 Dependency: The reliance on older versions of Python has been removed, simplifying the setup.
- Java-Based Scripting: Scripts are now written in Java, improving usability and reducing interruptions.
- PB Protocol Adoption: The switch to PB protocol for trace artifacts decreases storage needs by 70% and accelerates trace file opening processes by seven times.
-
Performance Improvements:
- Optimized Trace Collection: Memory usage is cut by 80% due to a shift from strings to integers.
- Storage and Queue Optimizations: Using mmap mode for data storage and refining lock-free queue logic minimizes performance loss to 15%, even with millions of methods being traced.
-
Enhanced Monitoring Data:
- Introduced four new data monitoring functionalities, providing detailed insights into Rendering, Binder, thread creation, and various synchronization operations.
Integration
Project Configuration
Integrating Btrace into a project is straightforward:
- Add
rhea-gradle-plugin
as a dependency in your project'sbuild.gradle
.
buildscript {
dependencies {
classpath 'com.bytedance.btrace:rhea-gradle-plugin:2.0.3-rc02'
}
}
- Then, apply the necessary plugins and dependencies in your
app/build.gradle
.
dependencies {
implementation "com.bytedance.btrace:rhea-core:2.0.3-rc02"
}
apply plugin: 'com.bytedance.rhea-trace'
Plugin Configuration
Btrace Version 2.0 simplifies configuration by focusing on compilation settings, allowing dynamic behaviors to be managed via command-line arguments, ensuring backward compatibility with past versions.
Key parameters include:
- traceFilterFilePath: Determines which methods are instrumented.
- needPackageWithMethodMap: Decides if the method mapping file should be included in the APK.
Usage
To use RheaTrace 2.0, ensure you have Java and adb integrated on your machine. Connect your phone, install the Btrace-enabled APK, and run the provided command to begin tracing:
java -jar rhea-trace-shell.jar -a ${your app package name} -t 10 -o output.pb -r rhea.all sched -fullClassName
The resulting trace data can be analyzed using tools like Perfetto.
Script Management
Btrace provides a downloadable script for easy management of tracing tasks.
Known Issues
While Btrace is robust, some known issues include:
- Perfetto Trace Acquisition Failures: Common with custom ROMs. Solutions involve retrying with simple mode configurations.
- Memory Issues with 32-bit APKs: Switching to 64-bit packages or configuring memory usage can mitigate crashes.
Feedback and Contribution
The Btrace team encourages feedback and contribution from the community, providing guidelines for reporting issues and contributing to the project.
Btrace is licensed under the Apache License, encouraging wide usage and contribution from developers interested in furthering its capabilities.