Skip to content

Add in-memory log buffer in Android JNI #6656

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

Merged
merged 1 commit into from
Nov 5, 2024

Conversation

GregoryComer
Copy link
Member

@GregoryComer GregoryComer commented Nov 5, 2024

Summary

Add an in-memory log buffer implementation for Android JNI. This is an experimental feature intended to allow developers easier access to ET log strings at runtime.

The new API is availble on the JNI Module class:

public class Module {
  ...
  /** Retrieve the in-memory log buffer, containing the most recent ExecuTorch log entries. */
  public String[] readLogBuffer() 
 ...
}

Test plan

Added temporary test code to Android demo app (not committed):

Log.i("ETTEST", "Reading log buffer after inference");
final String[] logBufferEntries = mModule.readLogBuffer();
for (String log : logBufferEntries) {
  Log.i("ETTEST", log);
}

Output:

2024-11-05 01:55:08.261  9429-10130 ETTEST                  com.example.executorchdemo           I  Reading log buffer after inference
2024-11-05 01:55:08.265  9429-10130 ETTEST                  com.example.executorchdemo           I  [19307862871 resize_outputs XNNExecutor.cpp:215] D Resizing output tensor to a new shape
2024-11-05 01:55:08.265  9429-10130 ETTEST                  com.example.executorchdemo           I  [21851302330 resize_outputs XNNExecutor.cpp:215] D Resizing output tensor to a new shape
2024-11-05 01:55:08.265  9429-10130 ETTEST                  com.example.executorchdemo           I  [21851522561 resize_outputs XNNExecutor.cpp:215] D Resizing output tensor to a new shape
2024-11-05 01:55:08.265  9429-10130 ETTEST                  com.example.executorchdemo           I  [21851558907 resize_outputs XNNExecutor.cpp:215] D Resizing output tensor to a new shape
2024-11-05 01:55:08.265  9429-10130 ETTEST                  com.example.executorchdemo           I  [21851574830 resize_outputs XNNExecutor.cpp:215] D Resizing output tensor to a new shape
2024-11-05 01:55:08.265  9429-10130 ETTEST                  com.example.executorchdemo           I  [21851596754 resize_outputs XNNExecutor.cpp:215] D Resizing output tensor to a new shape
2024-11-05 01:55:08.265  9429-10130 ETTEST                  com.example.executorchdemo           I  [21851610484 resize_outputs XNNExecutor.cpp:215] D Resizing output tensor to a new shape
2024-11-05 01:55:08.265  9429-10130 ETTEST                  com.example.executorchdemo           I  [21851623254 resize_outputs XNNExecutor.cpp:215] D Resizing output tensor to a new shape
2024-11-05 01:55:08.265  9429-10130 ETTEST                  com.example.executorchdemo           I  [21851635407 internal_resize_contiguous tensor_impl.cpp:98] E Attempted to resize a static tensor
2024-11-05 01:55:08.265  9429-10130 ETTEST                  com.example.executorchdemo           I  [21851659792 resize_outputs XNNExecutor.cpp:218] E Failed to resize output tensor for XNNExecutor
2024-11-05 01:55:08.265  9429-10130 ETTEST                  com.example.executorchdemo           I  [21851672369 execute_instruction method.cpp:1110] E CALL_DELEGATE execute failed at instruction 7: 0x10
2024-11-05 01:55:08.280  9429-10130 AndroidRuntime          com.example.executorchdemo           E  FATAL EXCEPTION: Thread-2

Also, I added quick code to ET_LOG 10000 times to sanity check log buffer wrapping. Also, in the medium-term, it would be nice to invest in unit-level tests for the JNI layer.

Copy link

pytorch-bot bot commented Nov 5, 2024

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/6656

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit b194e2a with merge base 97a4600 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 5, 2024
@GregoryComer GregoryComer added the ciflow/android Trigger Android CI label Nov 5, 2024
@GregoryComer GregoryComer force-pushed the android-log-buffer branch 2 times, most recently from 0bb24d6 to 0961bb8 Compare November 5, 2024 10:20
@GregoryComer GregoryComer changed the title [WIP] Add in-memory log buffer in Android JNI Add in-memory log buffer in Android JNI Nov 5, 2024
@facebook-github-bot
Copy link
Contributor

@GregoryComer has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@GregoryComer GregoryComer marked this pull request as ready for review November 5, 2024 11:14
@facebook-github-bot facebook-github-bot merged commit c5b88cc into pytorch:main Nov 5, 2024
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ciflow/android Trigger Android CI CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants