summaryrefslogtreecommitdiff
path: root/base/HidlSupport.cpp
diff options
context:
space:
mode:
authorZhuoyao Zhang <zhuoyao@google.com>2017-01-23 17:37:49 -0800
committerZhuoyao Zhang <zhuoyao@google.com>2017-01-25 20:48:45 -0800
commit93c1e3aa4277de38cf40399980f9876a1f9c9ce4 (patch)
tree83e9271741e3a0fbd8e83c6d1fb021e64ec51223 /base/HidlSupport.cpp
parent3b41bfec5dc21546f08221905819e5b6b840444d (diff)
downloadlibhidl-93c1e3aa4277de38cf40399980f9876a1f9c9ce4.tar.gz
Update HidlInstrumentor.
* Instead of dlsym method HIDL_INSTRUMENTATION_FUNCTION, dlsym HIDL_INSTRUMENTATION_FUNCTION + insterface_name. * This enables a single profiler library that contains the profiling method for all the interfaces defined within the same hidl package. Test: mma for hardware/interface. local test with vts. Change-Id: I076841ea8a565c489b45303e5ca496806d5d10be
Diffstat (limited to 'base/HidlSupport.cpp')
-rw-r--r--base/HidlSupport.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/base/HidlSupport.cpp b/base/HidlSupport.cpp
index 61db8cc..6d5e428 100644
--- a/base/HidlSupport.cpp
+++ b/base/HidlSupport.cpp
@@ -280,8 +280,10 @@ bool hidl_string::empty() const {
// ----------------------------------------------------------------------
// HidlInstrumentor implementation.
-HidlInstrumentor::HidlInstrumentor(const std::string &prefix)
- : mInstrumentationLibPrefix(prefix) {
+HidlInstrumentor::HidlInstrumentor(
+ const std::string &package,
+ const std::string &interface)
+ : mInstrumentationLibPackage(package), mInterfaceName(interface) {
configureInstrumentation(false);
}
@@ -335,11 +337,15 @@ void HidlInstrumentor::registerInstrumentationCallbacks(
continue;
void *handle = dlopen((path + file->d_name).c_str(), RTLD_NOW);
+ char *error;
if (handle == nullptr) {
LOG(WARNING) << "couldn't load file: " << file->d_name
<< " error: " << dlerror();
continue;
}
+
+ dlerror(); /* Clear any existing error */
+
using cb_fun = void (*)(
const InstrumentationEvent,
const char *,
@@ -347,12 +353,12 @@ void HidlInstrumentor::registerInstrumentationCallbacks(
const char *,
const char *,
std::vector<void *> *);
- auto cb = (cb_fun)dlsym(handle, "HIDL_INSTRUMENTATION_FUNCTION");
- if (cb == nullptr) {
+ auto cb = (cb_fun)dlsym(handle,
+ ("HIDL_INSTRUMENTATION_FUNCTION_" + mInterfaceName).c_str());
+ if ((error = dlerror()) != NULL) {
LOG(WARNING)
- << "couldn't find symbol: HIDL_INSTRUMENTATION_FUNCTION, "
- "error: "
- << dlerror();
+ << "couldn't find symbol: HIDL_INSTRUMENTATION_FUNCTION_"
+ << mInterfaceName << ", error: " << error;
continue;
}
instrumentationCallbacks->push_back(cb);
@@ -371,7 +377,7 @@ bool HidlInstrumentor::isInstrumentationLib(const dirent *file) {
#ifdef LIBHIDL_TARGET_DEBUGGABLE
if (file->d_type != DT_REG) return false;
std::cmatch cm;
- std::regex e("^" + mInstrumentationLibPrefix + "(.*).profiler.so$");
+ std::regex e("^" + mInstrumentationLibPackage + "(.*).profiler.so$");
if (std::regex_match(file->d_name, cm, e)) return true;
#endif
return false;