I want to capture a system trace, using the systrace tool.
I have this device (not-rooted) :
Pixi 4.5 Alcatel
Android 6.0 (API 23)
And I use Android Studio 4.2.2 and I have installed Python 2.7.18, as required (the version 3+ does not match).
Here is the command line to view the list of available categories on my device :
C:\Users\myUser\AppData\Local\Android\Sdk\platform-tools\systrace>C:\Users\myUser\AppData\Local\Programs\Python27\python systrace.py -l
I chose this command with the -l option for my here question because it results (see below) in the expected list plus an extra set of lines which suggests that the error CommandFailedError is related to an exception on HasRoot :
gfx - Graphics
input - Input
view - View System
webview - WebView
wm - Window Manager
am - Activity Manager
sm - Sync Manager
audio - Audio
video - Video
camera - Camera
hal - Hardware Modules
app - Application
res - Resource Loading
dalvik - Dalvik VM
rs - RenderScript
hwui - HWUI
perf - Performance
bionic - Bionic C Library
power - Power Management
sched - CPU Scheduling
freq - CPU Frequency
idle - CPU Idle
load - CPU Load
CRITICAL:root:(TimeoutThread-1-for-MainThread) Exception on HasRoot(myDeviceId, retries=3, timeout=30), attempt 1 of 4: CommandFailedError("(device: myDeviceId) one line of output was expected, but got: ['uid=2000(shell) gid=2000(shell) groups=2000(shell),1004(input),1007(log),1011(adb),1015(sdcard_rw),1028(sdcar
d_r),3001(net_bt_admin),3002(net_bt),3003(inet),3006(net_bw_stats) context=u:r:shell:s0', '']",)
CRITICAL:root:(TimeoutThread-2-for-MainThread) Exception on HasRoot(myDeviceId, retries=3, timeout=30), attempt 2 of 4: CommandFailedError("(device: myDeviceId) one line of output was expected, but got: ['uid=2000(shell) gid=2000(shell) groups=2000(shell),1004(input),1007(log),1011(adb),1015(sdcard_rw),1028(sdcar
d_r),3001(net_bt_admin),3002(net_bt),3003(inet),3006(net_bw_stats) context=u:r:shell:s0', '']",)
CRITICAL:root:(TimeoutThread-3-for-MainThread) Exception on HasRoot(myDeviceId, retries=3, timeout=30), attempt 3 of 4: CommandFailedError("(device: myDeviceId) one line of output was expected, but got: ['uid=2000(shell) gid=2000(shell) groups=2000(shell),1004(input),1007(log),1011(adb),1015(sdcard_rw),1028(sdcar
d_r),3001(net_bt_admin),3002(net_bt),3003(inet),3006(net_bw_stats) context=u:r:shell:s0', '']",)
Traceback (most recent call last):
File "systrace.py", line 49, in <module>
sys.exit(run_systrace.main())
File "C:\Users\myUser\AppData\Local\Android\Sdk\platform-tools\systrace\catapult\systrace\systrace\run_systrace.py", line 205, in main
main_impl(sys.argv)
File "C:\Users\myUser\AppData\Local\Android\Sdk\platform-tools\systrace\catapult\systrace\systrace\run_systrace.py", line 177, in main_impl
atrace_agent.list_categories(options)
File "C:\Users\myUser\AppData\Local\Android\Sdk\platform-tools\systrace\catapult\systrace\systrace\tracing_agents\atrace_agent.py", line 65, in list_categories
if not devutils.HasRoot():
File "C:\Users\myUser\AppData\Local\Android\Sdk\platform-tools\systrace\catapult\systrace\systrace\..\..\devil\devil\android\decorators.py", line 63, in timeout_r
etry_wrapper
impl, timeout, retries, desc=desc, retry_if_func=retry_if_func)
File "C:\Users\myUser\AppData\Local\Android\Sdk\platform-tools\systrace\catapult\systrace\systrace\..\..\devil\devil\utils\timeout_retry.py", line 164, in Run
error_log_func=error_log_func)
File "C:\Users\myUser\AppData\Local\Android\Sdk\platform-tools\systrace\catapult\systrace\systrace\..\..\devil\devil\utils\reraiser_thread.py", line 199, in JoinA
ll
self._JoinAll(watcher, timeout)
File "C:\Users\myUser\AppData\Local\Android\Sdk\platform-tools\systrace\catapult\systrace\systrace\..\..\devil\devil\utils\reraiser_thread.py", line 171, in _Join
All
thread.ReraiseIfException()
File "C:\Users\myUser\AppData\Local\Android\Sdk\platform-tools\systrace\catapult\systrace\systrace\..\..\devil\devil\utils\reraiser_thread.py", line 94, in run
self._ret = self._func(*self._args, **self._kwargs)
File "C:\Users\myUser\AppData\Local\Android\Sdk\platform-tools\systrace\catapult\systrace\systrace\..\..\devil\devil\utils\timeout_retry.py", line 156, in <lambda
>
lambda: func(*args, **kwargs), name=thread_name)
File "C:\Users\myUser\AppData\Local\Android\Sdk\platform-tools\systrace\catapult\systrace\systrace\..\..\devil\devil\android\decorators.py", line 51, in impl
return f(*args, **kwargs)
File "C:\Users\myUser\AppData\Local\Android\Sdk\platform-tools\systrace\catapult\systrace\systrace\..\..\devil\devil\android\device_utils.py", line 562, in HasRoo
t
output = self.RunShellCommand(['id'], single_line=True)
File "C:\Users\myUser\AppData\Local\Android\Sdk\platform-tools\systrace\catapult\systrace\systrace\..\..\devil\devil\android\decorators.py", line 56, in timeout_r
etry_wrapper
return impl()
File "C:\Users\myUser\AppData\Local\Android\Sdk\platform-tools\systrace\catapult\systrace\systrace\..\..\devil\devil\android\decorators.py", line 51, in impl
return f(*args, **kwargs)
File "C:\Users\myUser\AppData\Local\Android\Sdk\platform-tools\systrace\catapult\systrace\systrace\..\..\devil\devil\android\device_utils.py", line 1556, in RunSh
ellCommand
raise device_errors.CommandFailedError(msg % output, str(self))
devil.android.device_errors.CommandFailedError: (device: myDeviceId) one line of output was expected, but got: ['uid=2000(shell) gid=2000(shell) groups=2000(
shell),1004(input),1007(log),1011(adb),1015(sdcard_rw),1028(sdcard_r),3001(net_bt_admin),3002(net_bt),3003(inet),3006(net_bw_stats) context=u:r:shell:s0', '']
By comparison, here is the error CommandFailedError obtained with a command which should generate an html report :
C:\Users\myUser\AppData\Local\Android\Sdk\platform-tools\systrace>C:\Users\myUser\AppData\Local\Programs\Python27\python systrace.py
Traceback (most recent call last):
File "systrace.py", line 49, in <module>
sys.exit(run_systrace.main())
File "C:\Users\myUser\AppData\Local\Android\Sdk\platform-tools\systrace\catapult\systrace\systrace\run_systrace.py", line 205, in main
main_impl(sys.argv)
File "C:\Users\myUser\AppData\Local\Android\Sdk\platform-tools\systrace\catapult\systrace\systrace\run_systrace.py", line 185, in main_impl
controller.StartTracing()
File "C:\Users\myUser\AppData\Local\Android\Sdk\platform-tools\systrace\catapult\systrace\systrace\systrace_runner.py", line 46, in StartTracing
self._tracing_controller.StartTracing()
File "C:\Users\myUser\AppData\Local\Android\Sdk\platform-tools\systrace\catapult\systrace\systrace\tracing_controller.py", line 156, in StartTracing
timeout=self._controller_config.timeout):
File "C:\Users\myUser\AppData\Local\Android\Sdk\platform-tools\systrace\catapult\common\py_utils\py_utils\__init__.py", line 103, in RunWithTimeout
return timeout_retry.Run(func, timeout, 0, args=args)
File "C:\Users\myUser\AppData\Local\Android\Sdk\platform-tools\systrace\catapult\systrace\systrace\..\..\devil\devil\utils\timeout_retry.py", line 164, in Run
error_log_func=error_log_func)
File "C:\Users\myUser\AppData\Local\Android\Sdk\platform-tools\systrace\catapult\systrace\systrace\..\..\devil\devil\utils\reraiser_thread.py", line 199, in JoinA
ll
self._JoinAll(watcher, timeout)
File "C:\Users\myUser\AppData\Local\Android\Sdk\platform-tools\systrace\catapult\systrace\systrace\..\..\devil\devil\utils\reraiser_thread.py", line 171, in _Join
All
thread.ReraiseIfException()
File "C:\Users\myUser\AppData\Local\Android\Sdk\platform-tools\systrace\catapult\systrace\systrace\..\..\devil\devil\utils\reraiser_thread.py", line 94, in run
self._ret = self._func(*self._args, **self._kwargs)
File "C:\Users\myUser\AppData\Local\Android\Sdk\platform-tools\systrace\catapult\systrace\systrace\..\..\devil\devil\utils\timeout_retry.py", line 156, in <lambda
>
lambda: func(*args, **kwargs), name=thread_name)
File "C:\Users\myUser\AppData\Local\Android\Sdk\platform-tools\systrace\catapult\systrace\systrace\tracing_agents\android_cgroup_agent.py", line 59, in StartAgent
Tracing
if not self._device_utils.HasRoot():
File "C:\Users\myUser\AppData\Local\Android\Sdk\platform-tools\systrace\catapult\systrace\systrace\..\..\devil\devil\android\decorators.py", line 56, in timeout_r
etry_wrapper
return impl()
File "C:\Users\myUser\AppData\Local\Android\Sdk\platform-tools\systrace\catapult\systrace\systrace\..\..\devil\devil\android\decorators.py", line 51, in impl
return f(*args, **kwargs)
File "C:\Users\myUser\AppData\Local\Android\Sdk\platform-tools\systrace\catapult\systrace\systrace\..\..\devil\devil\android\device_utils.py", line 562, in HasRoo
t
output = self.RunShellCommand(['id'], single_line=True)
File "C:\Users\myUser\AppData\Local\Android\Sdk\platform-tools\systrace\catapult\systrace\systrace\..\..\devil\devil\android\decorators.py", line 56, in timeout_r
etry_wrapper
return impl()
File "C:\Users\myUser\AppData\Local\Android\Sdk\platform-tools\systrace\catapult\systrace\systrace\..\..\devil\devil\android\decorators.py", line 51, in impl
return f(*args, **kwargs)
File "C:\Users\myUser\AppData\Local\Android\Sdk\platform-tools\systrace\catapult\systrace\systrace\..\..\devil\devil\android\device_utils.py", line 1556, in RunSh
ellCommand
raise device_errors.CommandFailedError(msg % output, str(self))
devil.android.device_errors.CommandFailedError: (device: deviceId) one line of output was expected, but got: ['uid=2000(shell) gid=2000(shell) groups=2000(
shell),1004(input),1007(log),1011(adb),1015(sdcard_rw),1028(sdcard_r),3001(net_bt_admin),3002(net_bt),3003(inet),3006(net_bw_stats) context=u:r:shell:s0', '']
I am sure that there is a proper way to run systrace on an old unrooted device but I just didn't find it.
Does anyone have a clue or a solution? Thanks.
EDIT :
Thanks a lot for your analysis and your answer #yi-yang.
As you recommended, I set single_line to False in the RunShellCommand call. Furthermore, I also modified the return line, which gives the final code in the device_utils.py file, lines 562-563 :
output = self.RunShellCommand(['id'], single_line=False)
return output[0].startswith('uid=0(root)')
Note that I select the first line because there are still two lines, which means that some optional newline at the end needs to be stripped somehow...
Now it works but only for a few categories, as in the following example:
systrace.py -o mynewtrace.html perf idle load
However, for any atrace data, including the very helpful "sched" (see atrace_agent.py), the cpu profiling not possible, as shown by the following messages:
Warning: Only 2 of 3 tracing agents started.
IOError('Unable to get atrace data. Did you forget adb root?')
So the root privileges do matter, despite what the file comments (l. 556-558) claim :-(.
I guess rooting is a must for the full experience!
I try to do a systrace of a react native app running on android:
/home/a/Android/Sdk/platform-tools/systrace/systrace.py --time=5 -o trace.html sched gfx view -a com.mypackage
This is the error I get, but trace_markers seem to be defect:
These categories are unavailable: sched
Starting tracing (5 seconds)
Tracing completed. Collecting output...
/system/bin/sh: <stdin>[2]: can't create /sys/kernel/debug/tracing/trace_marker: No such file or directory
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 763, in run
self.__target(*self.__args, **self.__kwargs)
File "/home/r/Android/Sdk/platform-tools/systrace/catapult/systrace/systrace/tracing_agents/atrace_agent.py", line 194, in _collect_and_preprocess
trace_data = self._collect_trace_data()
File "/home/r/Android/Sdk/platform-tools/systrace/catapult/systrace/systrace/tracing_agents/atrace_agent.py", line 259, in _collect_trace_data
raise IOError('Unable to get atrace data. Did you forget adb root?')
IOError: Unable to get atrace data. Did you forget adb root?
Outputting Systrace results...
Tracing complete, writing results
Traceback (most recent call last):
File "/home/r/Android/Sdk/platform-tools/systrace/systrace.py", line 49, in <module>
sys.exit(run_systrace.main())
File "/home/r/Android/Sdk/platform-tools/systrace/catapult/systrace/systrace/run_systrace.py", line 194, in main
main_impl(sys.argv)
File "/home/r/Android/Sdk/platform-tools/systrace/catapult/systrace/systrace/run_systrace.py", line 191, in main_impl
controller.OutputSystraceResults(write_json=options.write_json)
File "/home/r/Android/Sdk/platform-tools/systrace/catapult/systrace/systrace/systrace_runner.py", line 67, in OutputSystraceResults
self._out_filename)
File "/home/r/Android/Sdk/platform-tools/systrace/catapult/systrace/systrace/output_generator.py", line 70, in GenerateHTMLOutput
html_file.write(_ConvertToHtmlString(result.raw_data))
File "/home/r/Android/Sdk/platform-tools/systrace/catapult/systrace/systrace/output_generator.py", line 92, in _ConvertToHtmlString
raise ValueError('Invalid trace result format for HTML output')
ValueError: Invalid trace result format for HTML output
How could I fix this?
React: 16.0.0-alpha.12
React Native: 0.48.2
Android: 7.1.2 (LineageOS 14.1-20170607)
The problem is:
IOError: Unable to get atrace data. Did you forget adb root?
Try this cmd:
python systrace.py -a com.example.myapp -b 16384 \
-o my_systrace_report.html sched freq idle am wm gfx view binder_driver hal \
dalvik camera input res
I'm trying to work out the instructions defined in http://www.webrtc.org/native-code/android. After the command "gclient sync" is executed and after hours of downloading, at the end the process failed:
fatal: early EOF
The remote end hung up unexpectedly
fatal: index-pack failed
error: RPC failed; result=56, HTTP code = 200
Traceback (most recent call last):
File "C:\depot_tools\depot_tools\gclient_scm.py", line 924, in _Clone
self._Run(clone_cmd, options, cwd=self._root_dir, retry=True)
File "C:\depot_tools\depot_tools\gclient_scm.py", line 1201, in _Run
gclient_utils.CheckCallAndFilterAndHeader(cmd, env=env, **kwargs)
File "C:\depot_tools\depot_tools\gclient_utils.py", line 293, in CheckCallAndF
ilterAndHeader
return CheckCallAndFilter(args, **kwargs)
File "C:\depot_tools\depot_tools\gclient_utils.py", line 538, in CheckCallAndF
ilter
rv, args, kwargs.get('cwd', None), None, None)
CalledProcessError: Command 'git -c core.deltaBaseCacheLimit=512m clone --no-che
ckout --progress --verbose https://chromium.googlesource.com/chromium/src.git C:
\\webrtc_android\\src\\chromium\\_gclient_src_x3yrqm' returned non-zero exit sta
tus 128 in C:\webrtc_android\src\chromium
----------------------------------------
Traceback (most recent call last):
File "C:\depot_tools\depot_tools\gclient.py", line 2325, in <module>
sys.exit(main(sys.argv[1:]))
File "C:\depot_tools\depot_tools\gclient.py", line 2311, in main
return dispatcher.execute(OptionParser(), argv)
File "C:\depot_tools\depot_tools\subcommand.py", line 252, in execute
return command(parser, args[1:])
File "C:\depot_tools\depot_tools\gclient.py", line 2066, in CMDsync
ret = client.RunOnDeps('update', args)
File "C:\depot_tools\depot_tools\gclient.py", line 1523, in RunOnDeps
work_queue.flush(revision_overrides, command, args, options=self._options)
File "C:\depot_tools\depot_tools\gclient_utils.py", line 1024, in run
self.item.run(*self.args, **self.kwargs)
File "C:\depot_tools\depot_tools\gclient.py", line 834, in run
file_list)
File "C:\depot_tools\depot_tools\gclient_scm.py", line 166, in RunCommand
return getattr(self, command)(options, args, file_list)
File "C:\depot_tools\depot_tools\gclient_scm.py", line 418, in update
self._Clone(revision, url, options)
File "C:\depot_tools\depot_tools\gclient_scm.py", line 932, in _Clone
if os.listdir(tmp_dir):
WindowsError: [Error 3] The system cannot find the path specified: 'C:\\webrtc_a
ndroid\\src\\chromium\\_gclient_src_x3yrqm/*.*'
Error: Command 'C:\\depot_tools\\depot_tools\\python276_bin\\python.exe -u src/s
ync_chromium.py --target-revision 47ce5feb1d13ce889da15f76f063a7978a0b5c37' retu
rned non-zero exit status 1 in C:\webrtc_android
Hook ''C:\depot_tools\depot_tools\python276_bin\python.exe' -u src/sync_chromium
.py --target-revision 47ce5feb1d13ce889da15f76f063a7978a0b5c37' took 77717.11 se
cs
Does this has to do with the fact that I'am trying to execute it on Windows?
Independently of your error, you will not be able to fetch and compile code for android under windows. You need to be on the right linux distribution.
I use Facebook's Infer to check my android code
infer -- ./gradlew build
after 8 minutes
Fatal error: exception Sys_error("/Users/lm/project/android_workplace/******/app/build/intermediates/exploded-aar/com.mogujie/user/1.2.17/jars/classes.jar: Too many open files")
Traceback (most recent call last):
File "/Users/lm/project/infer_workplace/infer-osx-v0.4.0/infer/bin/infer", line 180, in <module>
main()
File "/Users/lm/project/infer_workplace/infer-osx-v0.4.0/infer/bin/infer", line 144, in main
capture_exitcode = imported_module.gen_instance(args, cmd).capture()
File "/Users/lm/project/infer_workplace/infer-osx-v0.4.0/infer/bin/../lib/capture/gradle.py", line 83, in capture
return util.run_commands(cmds)
File "/Users/lm/project/infer_workplace/infer-osx-v0.4.0/infer/bin/../lib/capture/util.py", line 40, in run_commands
if not cmd.start():
File "/Users/lm/project/infer_workplace/infer-osx-v0.4.0/infer/bin/inferlib.py", line 692, in start
if self.capture() == os.EX_OK:
File "/Users/lm/project/infer_workplace/infer-osx-v0.4.0/infer/bin/inferlib.py", line 478, in capture
return self.run_infer_frontend()
File "/Users/lm/project/infer_workplace/infer-osx-v0.4.0/infer/bin/inferlib.py", line 469, in run_infer_frontend
self.args.analyzer
File "/Users/lm/project/infer_workplace/infer-osx-v0.4.0/infer/bin/inferlib.py", line 385, in run_command
raise e
subprocess.CalledProcessError: Command '[u'/Users/lm/project/infer_workplace/infer-osx-v0.4.0/infer/bin/InferJava', u'-project_root', '/Users/lm/project/android_workplace/Minicooper4android', u'-results_dir', u'/Users/lm/project/android_workplace/Minicooper4android/infer-out', u'-verbose_out', '/var/folders/2r/7hc18jz1091_jg7_8jcnqlhr0000gn/T/javac_qWbfkP.out', u'-models', u'/Users/lm/project/infer_workplace/infer-osx-v0.4.0/infer/bin/../lib/java/models.jar', u'-no-static_final']' returned non-zero exit status 2
From http://fbinfer.com/support
The maximum number of files a program can simultaneously hold open is a bit low on MacOs. You can increase the limit by running these commands for example:
sysctl -w kern.maxfiles=20480
sysctl -w kern.maxfilesperproc=22480
ulimit -S -n 2048
Trying to run forge run android command and getting this error even though file is present (Ubuntu 12.04). Even if I do not specify the sdk path and allow forge to download it on its own, I am still getting the same error.
2012-07-04 15:08:36,414 [ DEBUG] Exception running detached command:
/home/rockyj/Apps/android-sdk-linux/platform-tools/adb start-server:
[Errno 2] No such file or directory while running
run_android(('/home/rockyj/Workspace/Projects/greeter/development',
u'/home/rockyj/Apps/android-sdk-linux', None, True, None), {})
2012-07-04 15:08:36,417 [ ERROR] Something went wrong that we didn't expect:
2012-07-04 15:08:36,417 [ ERROR] Exception running detached command:
/home/rockyj/Apps/android-sdk-linux/platform-tools/adb start-server:
[Errno 2] No such file or directory
2012-07-04 15:08:36,417 [ DEBUG] Traceback (most recent call last):
File "/home/rockyj/Apps/forge-tools/forge/async.py", line 87, in run
result = self._target(*self._args, **self._kwargs)
File "/home/rockyj/Apps/forge-tools/forge/main.py", line 388, in run
build_to_run=build_to_run,
File "/home/rockyj/Workspace/Projects/greeter/.template/generate_dynamic/customer_goals.py",
line 120, in run_app
build_to_run.run()
File "/home/rockyj/Workspace/Projects/greeter/.template/generate_dynamic/build.py",
line 338, in run
self._run_task(func_name, args, kw)
File "/home/rockyj/Workspace/Projects/greeter/.template/generate_dynamic/build.py",
line 293, in _run_task
self.tasks[func_name](self, *args, **kw)
File "/home/rockyj/Workspace/Projects/greeter/.template/generate_dynamic/android_tasks.py",
line 588, in run_android
run_detached([path_info.adb, 'start-server'], wait=True)
File "/home/rockyj/Workspace/Projects/greeter/.template/generate_dynamic/android_tasks.py",
line 377, in run_detached
raise ShellError(message="Exception running detached command: %s"
% full_command, output=str(output))
ShellError: Exception running detached command:
/home/rockyj/Apps/android-sdk-linux/platform-tools/adb start-server:
[Errno 2] No such file or directory
Please help.
Thanks.
Per the comments, this issue was fixed by installing ia32 libs on Ubuntu.