Skip to content

Commit

Permalink
Restore original interceptor.cc
Browse files Browse the repository at this point in the history
  • Loading branch information
lukemartinlogan committed Oct 18, 2022
1 parent 8c86d97 commit 725133e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 73 deletions.
55 changes: 10 additions & 45 deletions adapter/interceptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ void PopulateBufferingPath() {
populated = true;
}

bool IsTracked(const std::string& path, bool log) {
if (log) { LOG(INFO) << "IsTracked path? " << path << std::endl; }
bool IsTracked(const std::string& path) {
if (hermes::adapter::exit) {
return false;
}
Expand All @@ -83,12 +82,7 @@ bool IsTracked(const std::string& path, bool log) {
std::string abs_path = WeaklyCanonical(path).string();

for (const auto& pth : INTERCEPTOR_LIST->hermes_flush_exclusion) {
if (abs_path.rfind(pth) != std::string::npos) {
if (log) {
LOG(INFO) << "Path " << path
<< " is not tracked (hermes_flush_exclusion)"
<< " because: " << pth << std::endl;
}
if (abs_path.find(pth) != std::string::npos) {
return false;
}
}
Expand All @@ -98,32 +92,20 @@ bool IsTracked(const std::string& path, bool log) {
}

for (const auto& pth : INTERCEPTOR_LIST->hermes_paths_inclusion) {
if (abs_path.rfind(pth) != std::string::npos) {
if (log) {
LOG(INFO) << "Path " << path << "is tracked (hermes_paths_inclusion)"
<< " because: " << pth << std::endl;
}
if (abs_path.find(pth) != std::string::npos) {
return true;
}
}

for (auto &pth : kPathExclusions) {
if (abs_path.rfind(pth) != std::string::npos) {
if (log) {
LOG(INFO) << "Path " << path << " is not tracked (kPathExclusions)"
<< " because: " << pth << std::endl;
}
if (abs_path.find(pth) != std::string::npos) {
return false;
}
}

for (const auto& pth : INTERCEPTOR_LIST->hermes_paths_exclusion) {
if (abs_path.rfind(pth) != std::string::npos) {
if (log) {
LOG(INFO) << "Path " << path
<< " is not tracked (hermes_paths_exclusion)"
<< " because: " << pth << std::endl;
}
if (abs_path.find(pth) != std::string::npos ||
pth.find(abs_path) != std::string::npos) {
return false;
}
}
Expand All @@ -132,18 +114,10 @@ bool IsTracked(const std::string& path, bool log) {
auto buffer_mode = INTERCEPTOR_LIST->adapter_mode;
if (buffer_mode == AdapterMode::kBypass) {
if (list->adapter_paths.empty()) {
if (log) {
LOG(INFO) << "Path " << path << " is not tracked (kBypass)"
<< " because adapter_paths empty " << std::endl;
}
return false;
} else {
for (const auto& pth : list->adapter_paths) {
if (path.find(pth) == 0) {
if (log) {
LOG(INFO) << "Path " << path << " is not tracked (kBypass)"
<< " because: " << pth << std::endl;
}
return false;
}
}
Expand All @@ -154,25 +128,16 @@ bool IsTracked(const std::string& path, bool log) {
}
}

bool IsTracked(FILE* fh, bool log) {
if (log) { LOG(INFO) << "IsTracked fh?" << std::endl; }
bool IsTracked(FILE* fh) {
if (hermes::adapter::exit) return false;
atexit(OnExit);
std::string path = GetFilenameFromFP(fh);
if (path == "") return false;
return IsTracked(path, log);
return IsTracked(GetFilenameFromFP(fh));
}

bool IsTracked(int fd, bool log) {
if (log) { LOG(INFO) << "IsTracked fd?" << std::endl; }
bool IsTracked(int fd) {
if (hermes::adapter::exit) return false;
atexit(OnExit);
std::string path = GetFilenameFromFD(fd);
if (path == "") {
if (log) { LOG(INFO) << fd << "is not tracked" << std::endl; }
return false;
}
return IsTracked(path, log);
return IsTracked(GetFilenameFromFD(fd));
}

void OnExit(void) { hermes::adapter::exit = true; }
Expand Down
35 changes: 13 additions & 22 deletions adapter/interceptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,22 @@ inline std::vector<std::string> StringSplit(const char* str, char delimiter) {
}
return v;
}

inline std::string GetFilenameFromFP(FILE* fh) {
char proclnk[kMaxPathLen];
char filename[kMaxPathLen];
int fno = fileno(fh);
snprintf(proclnk, kMaxPathLen, "/proc/self/fd/%d", fno);
size_t r = readlink(proclnk, filename, kMaxPathLen);
filename[r] = '\0';
return filename;
}
inline std::string GetFilenameFromFD(int fd) {
char proclnk[kMaxPathLen];
char filename[kMaxPathLen];
if (fd == -1) return "";
snprintf(proclnk, kMaxPathLen, "/proc/self/fd/%d", fd);
size_t r = readlink(proclnk, filename, kMaxPathLen);
if (r > 0) {
return std::string(filename, r);
} else {
return "";
}
}

inline std::string GetFilenameFromFP(FILE* fh) {
if (fh == nullptr) return "";
int fno = fileno(fh);
return GetFilenameFromFD(fno);
filename[r] = '\0';
return filename;
}

/**
Expand Down Expand Up @@ -202,12 +200,6 @@ void OnExit(void);
} \
}

#define REQUIRE_API(api_name) \
if (real_api->api_name == nullptr) { \
LOG(FATAL) << "HERMES Adapter failed to map symbol: " \
#api_name << std::endl; \
exit(1);

namespace hermes::adapter {
/**
* Loads the buffering paths for Hermes Adapter to exclude. It inserts the
Expand All @@ -224,7 +216,7 @@ void PopulateBufferingPath();
* @return true, if file should be tracked.
* false, if file should not be intercepted.
*/
bool IsTracked(const std::string& path, bool log = false);
bool IsTracked(const std::string& path);

/**
* Check if fh should be tracked. In this method, first Convert fh to path.
Expand All @@ -234,8 +226,7 @@ bool IsTracked(const std::string& path, bool log = false);
* @return true, if file should be tracked.
* false, if file should not be intercepted.
*/
bool IsTracked(FILE* fh, bool log = false);
bool IsTracked(int fd, bool log = false);
bool IsTracked(FILE* fh);
} // namespace hermes::adapter
#else
/**
Expand Down
13 changes: 7 additions & 6 deletions ci/lint.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/bin/bash
HERMES_ROOT=$1
ADAPTER=${HERMES_ROOT}/adapter

cpplint --recursive \
--exclude=${HERMES_ROOT}/src/stb_ds.h \
--exclude=${ADAPTER}/posix/real_api.h \
--exclude=${ADAPTER}/stdio/real_api.h \
--exclude=${ADAPTER}/mpiio/real_api.h \
${HERMES_ROOT}/adapter ${HERMES_ROOT}/benchmarks ${HERMES_ROOT}/data_stager \
${HERMES_ROOT}/src ${HERMES_ROOT}/test
--exclude="${HERMES_ROOT}/src/stb_ds.h" \
--exclude="${ADAPTER}/posix/real_api.h" \
--exclude="${ADAPTER}/stdio/real_api.h" \
--exclude="${ADAPTER}/mpiio/real_api.h" \
"${HERMES_ROOT}/adapter" "${HERMES_ROOT}/benchmarks" "${HERMES_ROOT}/data_stager" \
"${HERMES_ROOT}/src" "${HERMES_ROOT}/test"

0 comments on commit 725133e

Please sign in to comment.