Skip to content

Commit

Permalink
Include short name in systrace block name
Browse files Browse the repository at this point in the history
Summary:
We log the soname in the systrace blocks, which in prod resolves to the name of the merged library. This leads to traces like https://fburl.com/tracery/5sr15q1q, where we know which merged lib we are loading, but we don't have a way to identify the JNI entry point which triggered the load.

There are many cases (like the one described above) where we see a library getting loaded, but can't reproduce locally.
If we log the short name in addition to so name, debugging these issues will become trivial.

Reviewed By: adicatana

Differential Revision: D53679442

fbshipit-source-id: fa92e00d7139def5e33b7707c2b0626c1bef7ead
  • Loading branch information
Mashiat Sarker Shakkhar authored and facebook-github-bot committed Feb 14, 2024
1 parent 03ae6f8 commit 9ed8695
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions java/com/facebook/soloader/SoLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ private static boolean loadLibraryBySoNameImpl(
if (!loaded) {
try {
LogUtil.d(TAG, "About to load: " + soName);
doLoadLibraryBySoName(soName, loadFlags, oldPolicy);
doLoadLibraryBySoName(soName, shortName, loadFlags, oldPolicy);
} catch (UnsatisfiedLinkError ex) {
String message = ex.getMessage();
if (message != null && message.contains("unexpected e_machine:")) {
Expand Down Expand Up @@ -1074,7 +1074,10 @@ public static File unpackLibraryAndDependencies(String shortName) throws Unsatis
}

private static void doLoadLibraryBySoName(
String soName, int loadFlags, @Nullable StrictMode.ThreadPolicy oldPolicy)
String soName,
@Nullable String shortName,
int loadFlags,
@Nullable StrictMode.ThreadPolicy oldPolicy)
throws UnsatisfiedLinkError {
sSoSourcesLock.readLock().lock();
try {
Expand All @@ -1096,6 +1099,9 @@ private static void doLoadLibraryBySoName(
}

if (SYSTRACE_LIBRARY_LOADING) {
if (shortName != null) {
Api18TraceUtils.beginTraceSection("SoLoader.loadLibrary[", shortName, "]");
}
Api18TraceUtils.beginTraceSection("SoLoader.loadLibrary[", soName, "]");
}

Expand All @@ -1120,6 +1126,9 @@ private static void doLoadLibraryBySoName(
}
} finally {
if (SYSTRACE_LIBRARY_LOADING) {
if (shortName != null) {
Api18TraceUtils.endSection();
}
Api18TraceUtils.endSection();
}

Expand Down

0 comments on commit 9ed8695

Please sign in to comment.