Add option to tune sample collection based on thread sensitivity
Bug: 28065407
Bug: 27865109
Change-Id: Icdb89f8f8874a41c07e73185523d18e8956620d3
diff --git a/runtime/thread.h b/runtime/thread.h
index 3123c71..2218b5a 100644
--- a/runtime/thread.h
+++ b/runtime/thread.h
@@ -1097,6 +1097,13 @@
return debug_disallow_read_barrier_;
}
+ static bool IsSensitiveThread() {
+ if (is_sensitive_thread_hook_ != nullptr) {
+ return (*is_sensitive_thread_hook_)();
+ }
+ return false;
+ }
+
private:
explicit Thread(bool daemon);
~Thread() REQUIRES(!Locks::mutator_lock_, !Locks::thread_suspend_count_lock_);
@@ -1172,6 +1179,10 @@
ALWAYS_INLINE void PassActiveSuspendBarriers()
REQUIRES(!Locks::thread_suspend_count_lock_, !Roles::uninterruptible_);
+ static void SetSensitiveThreadHook(bool (*is_sensitive_thread_hook)()) {
+ is_sensitive_thread_hook_ = is_sensitive_thread_hook;
+ }
+
// 32 bits of atomically changed state and flags. Keeping as 32 bits allows and atomic CAS to
// change from being Suspended to Runnable without a suspend request occurring.
union PACKED(4) StateAndFlags {
@@ -1214,6 +1225,10 @@
// their suspend count is > 0.
static ConditionVariable* resume_cond_ GUARDED_BY(Locks::thread_suspend_count_lock_);
+ // Hook passed by framework which returns true
+ // when StrictMode events are traced for the current thread.
+ static bool (*is_sensitive_thread_hook_)();
+
/***********************************************************************************************/
// Thread local storage. Fields are grouped by size to enable 32 <-> 64 searching to account for
// pointer size differences. To encourage shorter encoding, more frequently used values appear