summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Gampe <agampe@google.com>2017-12-27 11:23:41 -0800
committerAndreas Gampe <agampe@google.com>2017-12-27 11:23:41 -0800
commita349850f23b4a414f689796b9d2423ad02454301 (patch)
tree9f6de7ea45d5d44f428a9091ae65bf04978ac09a
parentc445aff2d663e2711471e0f4a883599079d3b13a (diff)
downloadextras-a349850f23b4a414f689796b9d2423ad02454301.tar.gz
Perfprofd: Add IsProfilingEnabled to Config
Move part of enablement to Config. Maintain standard behavior for the old version. The binder version always has profiling enabled, and depends on the caller to determine the state. Test: m Change-Id: I6f27582132c7051299c0132a7d8f301b433c1c8e
-rw-r--r--perfprofd/config.h3
-rw-r--r--perfprofd/perfprofd_binder.cc4
-rw-r--r--perfprofd/perfprofdcore.cc14
-rw-r--r--perfprofd/perfprofdmain.cc21
-rw-r--r--perfprofd/tests/perfprofd_test.cc20
5 files changed, 49 insertions, 13 deletions
diff --git a/perfprofd/config.h b/perfprofd/config.h
index 5bb026ec..341e2df3 100644
--- a/perfprofd/config.h
+++ b/perfprofd/config.h
@@ -93,6 +93,9 @@ struct Config {
virtual bool ShouldStopProfiling() {
return false;
}
+
+ // Is profiling enabled?
+ virtual bool IsProfilingEnabled() const = 0;
};
#endif // SYSTEM_EXTRAS_PERFPROFD_CONFIG_H_
diff --git a/perfprofd/perfprofd_binder.cc b/perfprofd/perfprofd_binder.cc
index 013c8710..50a73288 100644
--- a/perfprofd/perfprofd_binder.cc
+++ b/perfprofd/perfprofd_binder.cc
@@ -74,6 +74,10 @@ class BinderConfig : public Config {
cv_.notify_all();
}
+ bool IsProfilingEnabled() const override {
+ return true;
+ }
+
private:
std::mutex mutex_;
std::condition_variable cv_;
diff --git a/perfprofd/perfprofdcore.cc b/perfprofd/perfprofdcore.cc
index 405e039f..37ca29a4 100644
--- a/perfprofd/perfprofdcore.cc
+++ b/perfprofd/perfprofdcore.cc
@@ -206,22 +206,10 @@ static CKPROFILE_RESULT check_profiling_enabled(const Config& config)
return DONT_PROFILE_RUNNING_IN_EMULATOR;
}
- //
- // Check for existence of semaphore file in config directory
- //
- if (access(config.config_directory.c_str(), F_OK) == -1) {
- W_ALOGW("unable to open config directory %s: (%s)",
- config.config_directory.c_str(), strerror(errno));
+ if (!config.IsProfilingEnabled()) {
return DONT_PROFILE_MISSING_CONFIG_DIR;
}
- // Check for existence of semaphore file
- std::string semaphore_filepath = config.config_directory
- + "/" + SEMAPHORE_FILENAME;
- if (access(semaphore_filepath.c_str(), F_OK) == -1) {
- return DONT_PROFILE_MISSING_SEMAPHORE;
- }
-
// Check for existence of simpleperf/perf executable
std::string pp = config.perf_path;
if (access(pp.c_str(), R_OK|X_OK) == -1) {
diff --git a/perfprofd/perfprofdmain.cc b/perfprofd/perfprofdmain.cc
index 64dfad79..403e0253 100644
--- a/perfprofd/perfprofdmain.cc
+++ b/perfprofd/perfprofdmain.cc
@@ -17,8 +17,11 @@
#include <string.h>
+#include <android-base/logging.h>
+
#include "config.h"
#include "perfprofd_binder.h"
+#include "perfprofdcore.h"
extern int perfprofd_main(int argc, char** argv, Config* config);
@@ -32,6 +35,24 @@ int main(int argc, char** argv)
void Sleep(size_t seconds) override {
sleep(seconds);
}
+ bool IsProfilingEnabled() const override {
+ //
+ // Check for existence of semaphore file in config directory
+ //
+ if (access(config_directory.c_str(), F_OK) == -1) {
+ PLOG(WARNING) << "unable to open config directory " << config_directory;
+ return false;
+ }
+
+ // Check for existence of semaphore file
+ std::string semaphore_filepath = config_directory
+ + "/" + SEMAPHORE_FILENAME;
+ if (access(semaphore_filepath.c_str(), F_OK) == -1) {
+ return false;
+ }
+
+ return true;
+ }
};
PosixSleepConfig config;
return perfprofd_main(argc, argv, &config);
diff --git a/perfprofd/tests/perfprofd_test.cc b/perfprofd/tests/perfprofd_test.cc
index 0dcaa530..54b36ea7 100644
--- a/perfprofd/tests/perfprofd_test.cc
+++ b/perfprofd/tests/perfprofd_test.cc
@@ -227,6 +227,26 @@ class PerfProfdRunner {
// Log sleep calls but don't sleep.
perfprofd_log_info("sleep %d seconds", seconds);
}
+
+ bool IsProfilingEnabled() const override {
+ //
+ // Check for existence of semaphore file in config directory
+ //
+ if (access(config_directory.c_str(), F_OK) == -1) {
+ W_ALOGW("unable to open config directory %s: (%s)",
+ config_directory.c_str(), strerror(errno));
+ return false;
+ }
+
+ // Check for existence of semaphore file
+ std::string semaphore_filepath = config_directory
+ + "/" + SEMAPHORE_FILENAME;
+ if (access(semaphore_filepath.c_str(), F_OK) == -1) {
+ return false;
+ }
+
+ return true;
+ }
};
int invoke()