Awesome
Nanoscope
An extremely accurate Android method tracing tool.
Overview
Nanoscope is a method tracing tool optimized for extreme accuracy. The tool's overhead has been measured at around ~20 nanoseconds per method (on a Nexus 6P). To achieve this performance, the interesting pieces of Nanoscope are implemented as a fork of AOSP. For this reason, you'll need to use the Nanoscope Emulator or a device running the Nanoscope OS in order to make use of this tool. The entrypoint for launching the Nanoscope emulator, provisioning a device with the custom OS, and starting/stopping tracing is the nanoscope
command-line tool described below.
For more information on motivation and architecture, check out our blog post and the wiki.
Installation
Install the nanoscope
command
$ brew tap uber/nanoscope
$ brew install nanoscope
Nanoscope Emulator / Devices
Nanoscope only works with the Nanoscope Emulator or with a device that's running the Nanoscope OS.
Launch Nanoscope Emulator
# Prerequisites
# - $ANDROID_HOME environment variable is set
# - macOS
$ nanoscope emulator
Flash ADB-connected phone with the Nanoscope OS
If you want to use Nanoscope with a real device, you can execute the following command to replace your stock Android OS with the Nanoscope OS.
IMPORTANT: This will only work with a Nexus 6P - do not attempt to flash any other device
IMPORTANT: This command installs a custom operating system onto the device. There is no way to undo this operation.
# Prerequisites
# - Nexus 6p is the only supported device at this time
# - OEM Unlocking is enabled (Settings -> Developer Options -> OEM unlocking)
# - Device is connected via ADB
$ nanoscope flash
Usage
Start tracing on ADB-connected device
$ nanoscope start
Tracing... (Press ENTER to stop)
Startup tracing
$ nanoscope start --package=com.example.app
Tracing... (Press ENTER to stop)
It's necessary to specify the application package if you want to start tracing before running the app.
Extensions
In addition to method tracing, Nanoscope can generate additional
information about executing application (e.g. CPU utilization for a
given thread, number of page faults, object allocation
information). You can enable this additional functionality by using
--ext
parameter with nanoscope start
command. It is also necessary
to change the kernel setting of Nexus 6P as follows:
$ adb shell "echo -1 >/proc/sys/kernel/perf_event_paranoid"
Please note that extended functionality DOES NOT work on emulators (and is therefore not included in our emulator release). Additional information about this Nanoscope extension can be found here.
Upgrade
Client
$ brew update && brew upgrade nanoscope
OS
$ brew update && brew upgrade nanoscope
$ nanoscope flash
License
Copyright (C) 2017 Uber Technologies
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.