Merge "libmeminfo: make libdmabufinfo and dmabuf_dump vendor available"

am: 2d31b4b023

Change-Id: I1c2feb4a7b34b589fa302e473f64838eb4bd29bc
This commit is contained in:
Erick Reyes 2019-02-10 08:15:09 -08:00 committed by android-build-merger
commit 9321874f2e
3 changed files with 43 additions and 16 deletions

View file

@ -17,9 +17,11 @@ cc_defaults {
name: "dmabufinfo_defaults", name: "dmabufinfo_defaults",
static_libs: [ static_libs: [
"libbase", "libbase",
"liblog",
"libprocinfo", "libprocinfo",
], ],
shared_libs: [
"liblog",
],
cflags: [ cflags: [
"-Wall", "-Wall",
@ -30,10 +32,9 @@ cc_defaults {
cc_library_static { cc_library_static {
name: "libdmabufinfo", name: "libdmabufinfo",
vendor_available: true,
defaults: ["dmabufinfo_defaults"], defaults: ["dmabufinfo_defaults"],
export_include_dirs: ["include"], export_include_dirs: ["include"],
static_libs: ["libc++fs"],
srcs: [ srcs: [
"dmabufinfo.cpp", "dmabufinfo.cpp",
], ],

View file

@ -14,8 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
#include <dmabufinfo/dmabufinfo.h> #include <dirent.h>
#include <inttypes.h> #include <inttypes.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -35,6 +34,8 @@
#include <android-base/strings.h> #include <android-base/strings.h>
#include <procinfo/process_map.h> #include <procinfo/process_map.h>
#include <dmabufinfo/dmabufinfo.h>
namespace android { namespace android {
namespace dmabufinfo { namespace dmabufinfo {
@ -80,16 +81,42 @@ static bool ReadDmaBufFdInfo(pid_t pid, int fd, std::string* name, std::string*
return true; return true;
} }
// TODO: std::filesystem::is_symlink fails to link on vendor code,
// forcing this workaround.
// Move back to libc++fs once it is vendor-available. See b/124012728
static bool is_symlink(const char *filename)
{
struct stat p_statbuf;
if (lstat(filename, &p_statbuf) < 0) {
return false;
}
if (S_ISLNK(p_statbuf.st_mode) == 1) {
return true;
}
return false;
}
static bool ReadDmaBufFdRefs(pid_t pid, std::vector<DmaBuffer>* dmabufs) { static bool ReadDmaBufFdRefs(pid_t pid, std::vector<DmaBuffer>* dmabufs) {
std::string fdpath = ::android::base::StringPrintf("/proc/%d/fd", pid); std::string fdpath = ::android::base::StringPrintf("/proc/%d/fd", pid);
for (auto& de : std::filesystem::directory_iterator(fdpath)) {
if (!std::filesystem::is_symlink(de.path())) { std::unique_ptr<DIR, int (*)(DIR*)> dir(opendir(fdpath.c_str()), closedir);
if (!dir) {
LOG(ERROR) << "Failed to open " << fdpath << " directory" << std::endl;
return false;
}
struct dirent* dent;
while ((dent = readdir(dir.get()))) {
std::string path =
::android::base::StringPrintf("%s/%s", fdpath.c_str(), dent->d_name);
if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, "..") ||
!is_symlink(path.c_str())) {
continue; continue;
} }
std::string target; std::string target;
if (!::android::base::Readlink(de.path().string(), &target)) { if (!::android::base::Readlink(path, &target)) {
LOG(ERROR) << "Failed to find target for symlink: " << de.path().string(); LOG(ERROR) << "Failed to find target for symlink: " << path;
return false; return false;
} }
@ -98,8 +125,8 @@ static bool ReadDmaBufFdRefs(pid_t pid, std::vector<DmaBuffer>* dmabufs) {
} }
int fd; int fd;
if (!::android::base::ParseInt(de.path().filename().string(), &fd)) { if (!::android::base::ParseInt(dent->d_name, &fd)) {
LOG(ERROR) << "Dmabuf fd: " << de.path().string() << " is invalid"; LOG(ERROR) << "Dmabuf fd: " << path << " is invalid";
return false; return false;
} }
@ -109,13 +136,13 @@ static bool ReadDmaBufFdRefs(pid_t pid, std::vector<DmaBuffer>* dmabufs) {
std::string exporter = "<unknown>"; std::string exporter = "<unknown>";
uint64_t count = 0; uint64_t count = 0;
if (!ReadDmaBufFdInfo(pid, fd, &name, &exporter, &count)) { if (!ReadDmaBufFdInfo(pid, fd, &name, &exporter, &count)) {
LOG(ERROR) << "Failed to read fdinfo for: " << de.path().string(); LOG(ERROR) << "Failed to read fdinfo for: " << path;
return false; return false;
} }
struct stat sb; struct stat sb;
if (stat(de.path().c_str(), &sb) < 0) { if (stat(path.c_str(), &sb) < 0) {
PLOG(ERROR) << "Failed to stat: " << de.path().string(); PLOG(ERROR) << "Failed to stat: " << path;
return false; return false;
} }

View file

@ -22,10 +22,9 @@ cc_binary {
srcs: ["dmabuf_dump.cpp"], srcs: ["dmabuf_dump.cpp"],
shared_libs: [ shared_libs: [
"libbase", "libbase",
"libmeminfo",
], ],
static_libs: [ static_libs: [
"libdmabufinfo", "libdmabufinfo",
"libc++fs",
], ],
soc_specific: true,
} }