-
Notifications
You must be signed in to change notification settings - Fork 25.5k
[jni][android] Subscribe for record function and if android do atrace #28712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
b6ea5d5
to
d9363de
Compare
|
||
namespace pytorch_jni { | ||
|
||
#ifdef TRACE_ENABLED |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would push this down to everywhere that you're currently doing #ifdef __ANDROID__
. That way, you don't have to put guards around all the Trace calls. Optimized builds with tracing not enabled will just inline all the calls and you won't take any speed or size hit.
daec0dd
to
5d64730
Compare
typedef void* (*fp_ATrace_beginSection)(const char* sectionName); | ||
typedef void* (*fp_ATrace_endSection)(void); | ||
|
||
static void* (*ATrace_beginSection)(const char* sectionName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use the typedefs here?
bool Trace::is_initialized_ = false; | ||
|
||
#if defined(TRACE_ENABLED) && defined(__ANDROID__) | ||
Trace::fp_ATrace_beginSection Trace::ATrace_beginSection = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would drop the = {}
here. Static scalars are always initialized to null/0, and using {}
with a scalar feels weird to me. Just preference, though.
Trace::fp_ATrace_endSection Trace::ATrace_endSection = {}; | ||
#endif | ||
|
||
void Trace::ensureInit() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider moving all of these function definitions (except for init) into the class definition in the header so they can be inlined.
5d64730
to
b8bc742
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@IvanKobzarev has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@IvanKobzarev has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
@IvanKobzarev merged this pull request in aa6e992. |
Summary: ghstack-source-id: 5edaf47 Pull Request resolved: pytorch#28708 Some cpp formatting changes as I run `clang-format -i` Testing on devserver: make assets (models): ``` pushd android/test_app/; python make_assets.py; popd ``` Build test_app apk: ``` TRACE_ENABLED=1 sh android/build_test_app.sh find . -type f -name *apk ./android/test_app/app/build/outputs/apk/mobNet2Quant/debug/test_app-mobNet2Quant-debug.apk ./android/test_app/app/build/outputs/apk/resnet18/debug/test_app-resnet18-debug.apk ``` Install apk: `adb install -r test_app-mobNet2Quant-debug.apk` Run app on the device. Systrace: ``` $ANDROID_HOME/platform-tools/systrace/systrace.py -t 10 -a org.pytorch.testapp.mobNet2Quant sched freq idle am wm gfx view binder_driver hal dalvik camera input res -o trace.html ``` trace.html contains sections like `jni::Module::forward`  Pull Request resolved: pytorch#28712 Differential Revision: D18495898 Pulled By: IvanKobzarev fbshipit-source-id: 0bced4a442f9dd90525520972a2c1f5d51f57df3
ghstack-source-id: 5edaf471557c25098ca0547229f2763760866887
Pull Request resolved: #28708
Some cpp formatting changes as I run
clang-format -i
Testing on devserver:
make assets (models):
Build test_app apk:
Install apk:
adb install -r test_app-mobNet2Quant-debug.apk
Run app on the device.
Systrace:
trace.html contains sections like
jni::Module::forward