Last active
June 19, 2020 03:55
-
-
Save weiancheng/fcf52e7c4dd97c9f1b65a08d1b4aa448 to your computer and use it in GitHub Desktop.
[Android ATrace] #android #jni #native #systrace #atrace #c++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <dlfcn.h> | |
void (*ATrace_beginSection) (const char *sectionName); | |
void *(*ATrace_endSection) (void); | |
void *(*ATrace_isEnabled) (void); | |
typedef void (*fp_ATrace_beginSection) (const char *sectionName); | |
typedef void *(*fp_ATrace_endSection) (void); | |
typedef void *(*fp_ATrace_isEnabled) (void); | |
void InitializeATrace() | |
{ | |
void *lib = dlopen("libandroid.so", RTLD_NOW | RTLD_LOCAL); | |
if (lib != NULL) | |
{ | |
ATrace_beginSection = | |
reinterpret_cast<fp_ATrace_beginSection >( | |
dlsym(lib, "ATrace_beginSection")); | |
ATrace_endSection = | |
reinterpret_cast<fp_ATrace_endSection >( | |
dlsym(lib, "ATrace_endSection")); | |
ATrace_isEnabled = | |
reinterpret_cast<fp_ATrace_isEnabled >( | |
dlsym(lib, "ATrace_isEnabled")); | |
LOGI("Composite Plugin:", "ATrace Profiling Initialized"); | |
} | |
else | |
{ | |
LOGE("Composite Plugin:", "Failed to open libandroid.so"); | |
} | |
} | |
// first step | |
InitializeATrace(); | |
// add tag | |
ATrace_beginSection("test tag"); | |
... | |
ATrace_endSection(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment