Python scripts throws errors
I tried to follow the same approach described and reached the point to start / stop tracing but i couldn't pull the tracing file with both approaches for example python3 -m profilo pull_traces --last "package name" throws
Traceback (most recent call last):
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/Users/"username"/profilo/python/profilo/profilo.py", line 19, in <module>
from .device.device import pull_last_trace, pull_all_traces, pull_n_traces
ImportError: attempted relative import with no known parent package
So can u guys modify the description with clear steps how we can run the test app , starting trace . exporting trace files and then checking the result
Hey, @hdakhly .
I just tried running this locally in order to download a trace from the sample app and it works:
$ pwd
profilo/python
$ python3 -m profilo.profilo pull_traces --last com.facebook.profilo.sample
override-main-7859-2020-1-13T10-43-54-F8habzrk3uP-cs-e7a80c2a.log
I noticed that the error you're hitting is related to the relative import. The commands from the demo workflow must be run from profilo/python; are you by any chance running them from profilo/python/profilo/?
Also, plase note that the command is ... -m profilo.profilo ... and you're running just ... -m profilo ....
Can you try fixing the command and running it from the profilo/python/ directory? I'm pretty sure this should fix the problem, but if it doesn't please let me know and I'll gladly help troubleshoot this further =)
Hi @ricardorey10 Thanks for your update problem still there , i've attached the full log of my terminal just to make sure that i followed the same steps 1- Run Sample App 2- Start tracking 3- Stop tracking then
C02WL10UHV2R:~ h.dakhly$ virtualenv -p python3 env
Running virtualenv with interpreter /usr/local/bin/python3
Already using interpreter /usr/local/bin/python3
Using base prefix '/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7'
New python executable in /Users/h.dakhly/env/bin/python3
Not overwriting existing python script /Users/h.dakhly/env/bin/python (you must use /Users/h.dakhly/env/bin/python3)
Installing setuptools, pip, wheel...
done.
C02WL10UHV2R:~ h.dakhly$ source env/bin/activate
(env) C02WL10UHV2R:~ h.dakhly$ cd profilo
(env) C02WL10UHV2R:profilo h.dakhly$ ls
CODE_OF_CONDUCT.md buck_imports env
CONTRIBUTING.md build java
LICENSE cpp python
README.md deps tools
aidl docs website
(env) C02WL10UHV2R:profilo h.dakhly$ cd python
(env) C02WL10UHV2R:python h.dakhly$ ls
demos profilo requirements.txt
(env) C02WL10UHV2R:python h.dakhly$ cd profilo
(env) C02WL10UHV2R:profilo h.dakhly$ ls
BUCK device profilo.py
__init__.py importer symbols
__main__.py model workflow_demo.py
__pycache__ notebook.py
(env) C02WL10UHV2R:profilo h.dakhly$ python3 -m profilo.profilo pull_traces --last com.facebook.sample
Traceback (most recent call last):
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 183, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 109, in _get_module_details
__import__(pkg_name)
File "/Users/h.dakhly/profilo/python/profilo/profilo.py", line 19, in <module>
from .device.device import pull_last_trace, pull_all_traces, pull_n_traces
ImportError: attempted relative import with no known parent package
(env) C02WL10UHV2R:profilo h.dakhly$
I ran the command from the directory and still shows the error , if you tried to run it outside this module it throws another exceptions which is expected but this is what i get. We can schedule a session to debug together if it is not clear
@hdakhly
I believe you still have an error. The sequence of directory changes you are performing is cd profilo -> cd python -> cd profilo. The last cd profilo should not be there (that is, you should run this command inside the profilo/python/ directory, not inside profilo/python/profilo/).
Also, note that the package name is com.facebook.profilo.sample, not com.facebook.sample =)
Check this:
$ pwd
profilo/python
$ python3 -m profilo.profilo pull_traces -h
usage: profilo.py pull_traces [-h] (--last | --all | --count COUNT)
optional arguments:
-h, --help show this help message and exit
--last Pull only the last trace
--all Pull all existing traces
--count COUNT Pull the last COUNT traces
$ cd profilo
$ pwd
profilo/python/profilo
$ python3 -m profilo.profilo pull_traces -h
Traceback (most recent call last):
...
from .device.device import pull_last_trace, pull_all_traces, pull_n_traces
ImportError: attempted relative import with no known parent package
Hopefully this will fix the issue. If it doesn't, please let me know and we'll figure out some other way for me to help you =)
@ricardorey10 Thanks again for your update i was able to proceed further and was able to pull the trace from the device . i've got the following output
override-main-30018-2020-1-14T20-0-17-FPrV_GSB0YS-cs-be3438b8.log
but it works only if you connect physical device not emulators.I've executed the final command which is
python3 -m profilo.workflow_demo override-main-30018-2020-1-14T20-0-17-FPrV_GSB0YS-cs-be3438b8.log
or it should be in a different format ? because i tried and it gave me this exception
Traceback (most recent call last):
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/Users/h.dakhly/profilo/python/profilo/workflow_demo.py", line 271, in <module>
args.func(tracefile, args)
AttributeError: 'Namespace' object has no attribute 'func'
I tried to install the arg parser manually but it was already there , any clue ?
@hdakhly
That override... file is the actual compressed trace. You can inspect it manually by uncompressing it (something along the lines of gunzip -c override... > output_file). However, manual inspection is not the best, though, and that's why we supply some examples of how to analyze it in general.
The idea of workflow_demo is that it can run different analysis. The three types we support right now are blocks, stacks, and syscounters:
$ python3 -m profilo.workflow_demo -h
usage: workflow_demo.py [-h] trace {stacks,blocks,syscounters} ...
Profilo workflow demo
positional arguments:
trace Path to downloaded trace
{stacks,blocks,syscounters}
Demo types
stacks Analyze stacks
blocks Analyze blocks
syscounters Analyze system counters
optional arguments:
-h, --help show this help message and exit
So, from your command above, you're essentially missing the type of analysis that you want to run. For instance, you can do
python3 -m profilo.workflow_demo demos/traces/override-main-23725-... blocks
And that will dump all the framework blocks, such as Choreographer#doFrame.
You can check the options and usage of each with the -h flag, like this:
$ python3 -m profilo.workflow_demo demos/traces/override-main-23725-2018-1-... stacks -h
usage: workflow_demo.py trace stacks [-h] apk
positional arguments:
apk Path to apk (for symbolication
optional arguments:
-h, --help show this help message and exit
Please let me know if you have any more questions =)
@ricardorey10 Hello Again , thanks for the deep explanation . I tried both
python3 -m profilo.workflow_demo override-main-30018-2020-1-14T20-0-17-FPrV_GSB0YS-cs-be3438b8.log blocks
python3 -m profilo.workflow_demo override-main-30018-2020-1-14T20-0-17-FPrV_GSB0YS-cs-be3438b8.log stacks
python3 -m profilo.workflow_demo override-main-30018-2020-1-14T20-0-17-FPrV_GSB0YS-cs-be3438b8.log syscounters
If i'm not mistaken and here is the output i got
(env) C02WL10UHV2R:python h.dakhly$ python3 -m profilo.workflow_demo override-main-30018-2020-1-14T20-0-17-FPrV_GSB0YS-cs-be3438b8.log blocks
Traceback (most recent call last):
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/Users/h.dakhly/profilo/python/profilo/workflow_demo.py", line 271, in <module>
args.func(tracefile, args)
File "/Users/h.dakhly/profilo/python/profilo/workflow_demo.py", line 43, in blocks
trace = interpreter.interpret()
File "/Users/h.dakhly/profilo/python/profilo/importer/interpreter.py", line 185, in interpret
name=COUNTER_NAMES[entry.arg1],
KeyError: 9240667
(env) C02WL10UHV2R:python h.dakhly$ python3 -m profilo.workflow_demo override-main-30018-2020-1-14T20-0-17-FPrV_GSB0YS-cs-be3438b8.log stacks
usage: workflow_demo.py trace stacks [-h] apk
workflow_demo.py trace stacks: error: the following arguments are required: apk
(env) C02WL10UHV2R:python h.dakhly$ python3 -m profilo.workflow_demo override-main-30018-2020-1-14T20-0-17-FPrV_GSB0YS-cs-be3438b8.log syscounters
usage: workflow_demo.py trace syscounters [-h] plotdir
workflow_demo.py trace syscounters: error: the following arguments are required: plotdir
So even blocks didn't dump the content and stacks for sure requires apk
@hdakhly
Couple of things here.
The blocks command does not need any further arguments, as you already noticed, but there was a bug in the code which results in that KeyError (sorry about that :( ). Yesterday I pushed a fix for this via 50a32886308a727c02cc2c1a46d3265dc55dee43. You'll need to pull those changes for the script to work properly.
Now, for the syscounters analysis, you need to supply an output directory where the plots will be stored:
$ python3 -m profilo.workflow_demo demos/traces/override-main-23725-... syscounters -h
usage: workflow_demo.py trace syscounters [-h] plotdir
positional arguments:
plotdir Path where plots will be generated
Similarly, the stacks analysis requires you to supply the APK from the sample app - in order for the script to find symbols -:
$ python3 -m profilo.workflow_demo demos/traces/override-main-23725-2018-1-... stacks -h
usage: workflow_demo.py trace stacks [-h] apk
positional arguments:
apk Path to apk (for symbolication
optional arguments:
-h, --help show this help message and exit
Please let me know if even after pulling the latest changes and supplying all the arguments you're still having problems. Also, if the output doesn't make sense once you get it, I can walk you through it =)
@ricardorey10 Woohooo finally was able to run the blocks one and i got an output that ends with
2190,False,30028,DetachCurrentThread,1,204000.0,204000.0,0.0
2191,False,30027,DetachCurrentThread,1,183000.0,183000.0,0.0
2192,False,30027,Lock contention on Region lock (owner tid: 0),1,5000.0,5000.0,0.0
2193,False,30026,DetachCurrentThread,1,68000.0,68000.0,0.0
2194,False,30026,Lock contention on thread list lock (owner tid: 30025),1,5000.0,5000.0,0.0
2195,False,30025,DetachCurrentThread,1,107000.0,107000.0,0.0
The log was pretty massive 🗡
Finally i have couple of question before moving further , for the system counters you mentioned that we need the plot dir , do we have explicitly to create a folder and specify the full path as the plot dir or is there any option that it can auto create this dir ?
for example
python3 -m profilo.workflow_demo demos/traces/override-main-23725-... syscounters samples/plotdir
Second question is related to the output generated from blocks command , is there a guide or any tool to visual this as it is very hard to go through the output and compare or analyse the result . If you have any guide or you can walk me through this , would be great
One thing forgot to mention that i tried as well
python3 -m profilo.workflow_demo override-main-30018-2020-1-14T20-0-17-FPrV_GSB0YS-cs-be3438b8.log stacks /Users/h.dakhly/profilo/sample.apk
(env) C02WL10UHV2R:python h.dakhly$
as you see that the command was executed against the sample apk but the output is nothing Really appreciate your support
@hdakhly
do we have explicitly to create a folder and specify the full path as the plot dir or is there any option that it can auto create this dir ?
As of now the script does not have an option to create the dir, and you have to supply your own :( Note that the path is relative, so you can even use "." to throw the images in the current directory.
Second question is related to the output generated from blocks command , is there a guide or any tool to visual this as it is very hard to go through the output and compare or analyse the result
Unfortunately, we don't have any open source tool to analyze traces yet. The best we have right now is the workflow_demo script, which should be somewhat "easy" to modify to accommodate custom workflows.
If you have any guide or you can walk me through this , would be great
The best I can do right now would be to explain the format of the output (and a bit of the internals so that it makes sense).
The blocks command, as it somewhat implies, dumps the "blocks" that we collect. Blocks are entities which have a start point and an end point. This allows us to calculate their duration.
So taking line 2190,False,30028,DetachCurrentThread,1,204000.0,204000.0,0.0 as an example:
The first token does not mean anything, it's just to enumerate the blocks.
The next item, False, indicates that this thread (30028, next token) is NOT the main thread.
The next token, DetachCurrentThread, is the block name. I tried to find where in AOSP that block is logged, but I couldn't find it :( Anyway, the point is that these blocks come from actual Android framework code, such as this code here (Choreographer#doFrame blocks are super common, so your trace probably has them).
Then, you have the number of "hits", that is, how many times this block appeared in the trace.
Finally, you have the mean, median, and standard deviation (respectively) of the duration for that block. These times are in nanoseconds, so this DetachCurrentThread block thing happened 1 time (hits = 1), with a mean duration of 204000ns, a median of 204000ns, and a standard deviation of 0.0 (because there's only one block.
Here's an example from a trace of my own:
0,True,23725,Choreographer#doFrame,1141,1375626.643295355,1292000.0,1037057.7705281584
This tells us that thread 23725 is the main thread (because of the True token), that we saw the Choreographer#doFrame block 1141 times, that the mean duration for those blocks was 1375626ns (~1.3ms), with a median of 1292000us (~1.2ms), and a standard deviation of 1037057ns (~1.0ms).
One thing forgot to mention that i tried as well
About this stuff from the stacks, what version of Android are you using? Is this OS9? If that's the case, we don't have support for stack traces for Android 9 yet (it's coming soon-ish, though!), so maybe that's why you don't have any stack data.
@ricardorey10
About this stuff from the stacks, what version of Android are you using? Is this OS9? If that's the case, we don't have support for stack traces for Android 9 yet (it's coming soon-ish, though!), so maybe that's why you don't have any stack data.
I used android 10 , That's why . now everything looks clear except that this link https://fburl.com/ezfiesnb goes to facebook internal Env :D
I'm looking forward for more updates as we are taking performance tracking very serious and this looks promising . wondering also if there anyway i can contribute to it . Thanks for your support .
@hdakhly
Hey, sorry about the broken link. We have an internal url shortener and I accidentally pasted the wrong link. The right one is https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/java/android/view/Choreographer.java;l=718?q=Choreographer%23doFrame
I used android 10 , That's why
Yeah, our support currently goes up to Android 8, and only 32-bit architectures. We're working on supporting Android 9 and 64-bit in the near future, so stay tuned for that =)
wondering also if there anyway i can contribute to it
Contributing is definitely possible, and we'd love to get some extra hands on this =)
If there's anything you'd like to change or improve you can submit a Pull Request with your changes. We'll get them reviewed and merge them into the main branch once we're all happy with the code (i.e., it passes our internal tests, matches the style, etc...)
I'm looking forward for more updates as we are taking performance tracking very serious and this looks promising
If you're interested, we could set up some time to meet. You could tell us a bit about what you're doing and your use cases, and we can share what's on our road map.
Let me know and we'll set something up!
I'm closing this issue now, as I believe it has been solved. @hdakhly feel free to reopen it (or open a new one) if anything comes up.
@ricardorey10 for sure we can arrange something and meet online to discuss in more details . let me know your availability
@hdakhly
We're in California (Pacific Standard Time), and we can meet from around 10AM to 4PM pretty much every week day.
Anyway, while we figure out this stuff about meeting, I have a few questions:
- How is your company (I'm assuming there is a company because you said "WE are taking performance tracking very serious...") using Profilo?
- What kind of issues have you solved or looked into solving with Profilo?
- What kind of things would you like to see supported in the future?