summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2022-02-17 09:57:42 -0800
committerYabin Cui <yabinc@google.com>2022-02-17 10:26:53 -0800
commit0d539c167b5caaa2730e4dc3c53034a652bcee51 (patch)
tree4b8acbe4ec19e503854f337fdd43b0b9e223bea4
parent2719ff2971b7a8f45ad43b172b05bba030ee3d6b (diff)
downloadextras-0d539c167b5caaa2730e4dc3c53034a652bcee51.tar.gz
profcollectd: add wakelock when recording ETM data.
The kernel may panic when trying to hibernate or hotplug CPUs while collecting ETM data. So get wakelock to keep the CPUs on. Bug: 219934028 Test: run profcollectd and Test: dumpsys suspend_control_internal --wakelocks Change-Id: Ie1fea2b6d82d3e27d8b9553aa3967876ff7316ca
-rw-r--r--simpleperf/Android.bp5
-rw-r--r--simpleperf/profcollect.cpp8
2 files changed, 12 insertions, 1 deletions
diff --git a/simpleperf/Android.bp b/simpleperf/Android.bp
index ba4ef198..a24eed9b 100644
--- a/simpleperf/Android.bp
+++ b/simpleperf/Android.bp
@@ -328,7 +328,10 @@ cc_library {
srcs: ["profcollect.cpp"],
host_supported: false,
static_libs: ["libsimpleperf"],
- shared_libs: ["libLLVM_android"],
+ shared_libs: [
+ "libLLVM_android",
+ "libpower",
+ ],
}
rust_bindgen {
diff --git a/simpleperf/profcollect.cpp b/simpleperf/profcollect.cpp
index 39c04ab7..724111e8 100644
--- a/simpleperf/profcollect.cpp
+++ b/simpleperf/profcollect.cpp
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+#include <wakelock/wakelock.h>
#include <include/simpleperf_profcollect.hpp>
#include "ETMRecorder.h"
@@ -42,6 +43,13 @@ bool HasDeviceSupport() {
}
bool Record(const char* event_name, const char* output, float duration) {
+ // The kernel may panic when trying to hibernate or hotplug CPUs while collecting
+ // ETM data. So get wakelock to keep the CPUs on.
+ auto wakelock = android::wakelock::WakeLock::tryGet("profcollectd");
+ if (!wakelock) {
+ LOG(ERROR) << "Failed to request wakelock.";
+ return false;
+ }
auto recordCmd = CreateCommandInstance("record");
std::vector<std::string> args;
args.push_back("-a");