summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-12-14 16:37:48 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-12-14 16:37:48 +0000
commit564b4c8101e136c8e2b8ca18008e6f878a9a6ed5 (patch)
treef30c72fc3dd89b10d9099acb8f7fb20b06e53e93
parentda6ee9877eee93cf1652a3fcd7cfec319be131fc (diff)
parent1af36ac6f10b847787da90b7f9489d9d3fbf8798 (diff)
downloadStatsD-aml_tz4_332714010.tar.gz
Snap for 11219529 from 1af36ac6f10b847787da90b7f9489d9d3fbf8798 to mainline-tzdata4-releaseaml_tz4_332714070aml_tz4_332714050aml_tz4_332714010aml_tz4_332714010
Change-Id: I70ec9f8bca44298eee6185000d5516bddf407852
-rw-r--r--statsd/src/StatsService.cpp23
-rw-r--r--statsd/src/StatsService.h9
-rw-r--r--tests/src/android/cts/statsd/metric/MetricActivationTests.java2
-rw-r--r--tests/src/android/cts/statsd/validation/ProcStatsValidationTests.java14
4 files changed, 45 insertions, 3 deletions
diff --git a/statsd/src/StatsService.cpp b/statsd/src/StatsService.cpp
index 56229499..302b81b1 100644
--- a/statsd/src/StatsService.cpp
+++ b/statsd/src/StatsService.cpp
@@ -168,12 +168,15 @@ StatsService::StatsService(const sp<UidMap>& uidMap, shared_ptr<LogEventQueue> q
init_system_properties();
if (mEventQueue != nullptr) {
- std::thread pushedEventThread([this] { readLogs(); });
- pushedEventThread.detach();
+ mLogsReaderThread = std::make_unique<std::thread>([this] { readLogs(); });
}
}
StatsService::~StatsService() {
+ if (mEventQueue != nullptr) {
+ stopReadingLogs();
+ mLogsReaderThread->join();
+ }
}
/* Runs on a dedicated thread to process pushed events. */
@@ -182,6 +185,13 @@ void StatsService::readLogs() {
while (1) {
// Block until an event is available.
auto event = mEventQueue->waitPop();
+
+ // Below flag will be set when statsd is exiting and log event will be pushed to break
+ // out of waitPop.
+ if (mIsStopRequested) {
+ break;
+ }
+
// Pass it to StatsLogProcess to all configs/metrics
// At this point, the LogEventQueue is not blocked, so that the socketListener
// can read events from the socket and write to buffer to avoid data drop.
@@ -1346,6 +1356,15 @@ void StatsService::statsCompanionServiceDiedImpl() {
mPullerManager->SetStatsCompanionService(nullptr);
}
+void StatsService::stopReadingLogs() {
+ mIsStopRequested = true;
+ // Push this event so that readLogs will process and break out of the loop
+ // after the stop is requested.
+ int64_t timeStamp;
+ std::unique_ptr<LogEvent> logEvent = std::make_unique<LogEvent>(/*uid=*/0, /*pid=*/0);
+ mEventQueue->push(std::move(logEvent), &timeStamp);
+}
+
} // namespace statsd
} // namespace os
} // namespace android
diff --git a/statsd/src/StatsService.h b/statsd/src/StatsService.h
index 95ee8cc6..f8fe03c2 100644
--- a/statsd/src/StatsService.h
+++ b/statsd/src/StatsService.h
@@ -348,6 +348,13 @@ private:
void statsCompanionServiceDiedImpl();
/**
+ * This method is used to stop log reader thread.
+ */
+ void stopReadingLogs();
+
+ std::atomic<bool> mIsStopRequested = false;
+
+ /**
* Tracks the uid <--> package name mapping.
*/
const sp<UidMap> mUidMap;
@@ -390,6 +397,8 @@ private:
mutable mutex mShellSubscriberMutex;
shared_ptr<LogEventQueue> mEventQueue;
+ std::unique_ptr<std::thread> mLogsReaderThread;
+
MultiConditionTrigger mBootCompleteTrigger;
static const inline string kBootCompleteTag = "BOOT_COMPLETE";
static const inline string kUidMapReceivedTag = "UID_MAP";
diff --git a/tests/src/android/cts/statsd/metric/MetricActivationTests.java b/tests/src/android/cts/statsd/metric/MetricActivationTests.java
index 8e796cf9..a95cb1bc 100644
--- a/tests/src/android/cts/statsd/metric/MetricActivationTests.java
+++ b/tests/src/android/cts/statsd/metric/MetricActivationTests.java
@@ -494,7 +494,7 @@ public class MetricActivationTests extends DeviceAtomTestCase {
// Metric 2 Activation 1: 0 seconds
// Metric 2 Activation 2: 0 seconds
rebootDeviceAndWaitUntilReady();
- Thread.sleep(3_000L);
+ Thread.sleep(10_000L);
// Metric 1 event ignored.
// Metric 2 event ignored.
diff --git a/tests/src/android/cts/statsd/validation/ProcStatsValidationTests.java b/tests/src/android/cts/statsd/validation/ProcStatsValidationTests.java
index 5b42aa9c..b5baa362 100644
--- a/tests/src/android/cts/statsd/validation/ProcStatsValidationTests.java
+++ b/tests/src/android/cts/statsd/validation/ProcStatsValidationTests.java
@@ -30,6 +30,7 @@ import com.android.os.AtomsProto.ProcessStatsStateProto;
import com.android.os.StatsLog.DimensionsValue;
import com.android.os.StatsLog.ValueBucketInfo;
import com.android.os.StatsLog.ValueMetricData;
+import com.android.tradefed.device.ITestDevice;
import com.android.tradefed.log.LogUtil;
import java.util.List;
@@ -44,6 +45,10 @@ public class ProcStatsValidationTests extends ProcStateTestCase {
private static final int EXTRA_WAIT_TIME_MS = 1_000; // as buffer when proc state changing.
public void testProcessStatePssValue() throws Exception {
+ if(isPssProfilingDisabled()) {
+ LogUtil.CLog.i("testProcessStatePssValue is ignored when PSS profiling is disabled");
+ return;
+ }
final String fileName = "PROCSTATSQ_PROCS_STATE_PSS_VALUE.pbtxt";
StatsdConfig config = createValidationUtil().getConfig(fileName);
LogUtil.CLog.d("Updating the following config:\n" + config.toString());
@@ -303,4 +308,13 @@ public class ProcStatsValidationTests extends ProcStateTestCase {
assertThat(rssAvgStatsd).isEqualTo(rssAvgProcstats);
*/
}
+
+ private boolean isPssProfilingDisabled() throws Exception {
+ ITestDevice device = getDevice();
+ final String disablePssProfilingKey = "disable_app_profiler_pss_profiling";
+ final String stringToCompare = " " + disablePssProfilingKey + "=true";
+
+ final String dumpsys = device.executeShellCommand("dumpsys activity settings");
+ return (dumpsys.contains(stringToCompare));
+ }
}